@@ -6,21 +6,23 @@ import (
66 "io"
77 nhttp "net/http"
88 "strconv"
9+ "time"
910
1011 eth2client "github.com/attestantio/go-eth2-client"
1112 api "github.com/attestantio/go-eth2-client/api/v1"
1213 "github.com/attestantio/go-eth2-client/http"
1314 "github.com/attestantio/go-eth2-client/spec"
1415 "github.com/attestantio/go-eth2-client/spec/capella"
1516 "github.com/attestantio/go-eth2-client/spec/phase0"
16- "github.com/icon-project/btp2/common/errors"
1717 "github.com/icon-project/btp2/common/log"
1818 "github.com/rs/zerolog"
1919)
2020
2121const (
2222 TopicLCOptimisticUpdate = "light_client_optimistic_update"
2323 TopicLCFinalityUpdate = "light_client_finality_update"
24+
25+ requestTimeout = 5 * time .Second
2426)
2527
2628type ConsensusLayer struct {
@@ -93,6 +95,8 @@ func (c *ConsensusLayer) GetReceiptsRootProof(slot int64) ([]byte, error) {
9395 return io .ReadAll (resp .Body )
9496}
9597
98+ // SlotToBlockNumber returns execution block number for consensus slot
99+ // If slot has no block, returns (0, nil).
96100func (c * ConsensusLayer ) SlotToBlockNumber (slot phase0.Slot ) (uint64 , error ) {
97101 var sn phase0.Slot
98102 if slot == 0 {
@@ -107,10 +111,7 @@ func (c *ConsensusLayer) SlotToBlockNumber(slot phase0.Slot) (uint64, error) {
107111 }
108112
109113 block , err := c .BeaconBlock (strconv .FormatInt (int64 (sn ), 10 ))
110- if block == nil {
111- return 0 , errors .NotFoundError .Errorf ("there is no block at slot %d" , slot )
112- }
113- if err != nil {
114+ if err != nil || block == nil {
114115 return 0 , err
115116 }
116117 return block .BlockNumber ()
@@ -124,6 +125,7 @@ func NewConsensusLayer(uri string, log log.Logger) (*ConsensusLayer, error) {
124125 ctx , cancel := context .WithCancel (context .Background ())
125126 service , err := http .New (
126127 ctx ,
128+ http .WithTimeout (requestTimeout ),
127129 http .WithAddress (uri ),
128130 http .WithLogLevel (zerolog .WarnLevel ),
129131 )
0 commit comments