Skip to content

Commit 331d456

Browse files
authored
Merge pull request #15 from icon-project/optimize_finding_undelvered_message
Optimize finding undelivered message
2 parents 46dfe20 + 5dd6f0c commit 331d456

File tree

5 files changed

+220
-91
lines changed

5 files changed

+220
-91
lines changed

chain/eth2/client/consensus.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2121
const (
2222
TopicLCOptimisticUpdate = "light_client_optimistic_update"
2323
TopicLCFinalityUpdate = "light_client_finality_update"
24+
25+
requestTimeout = 5 * time.Second
2426
)
2527

2628
type 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).
96100
func (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
)

chain/eth2/proof/single.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewSingleProof(data []byte) (*SingleProof, error) {
4040
ssz := &ssz.Proof{}
4141
proofType := int(data[0])
4242
if proofType != 0 {
43-
return nil, fmt.Errorf("invalid proof type. %d", proofType)
43+
return nil, fmt.Errorf("invalid proof type. %s", data)
4444
}
4545
dataOffset := 1
4646

0 commit comments

Comments
 (0)