Skip to content

Commit

Permalink
fix(op-node): eth_client replace eth_getFinalizedBlock to eth_getFina…
Browse files Browse the repository at this point in the history
…lizedHeader (#67)

* fix(op-node): eth_client replace eth_getFinalizedBlock to eth_getFinalizedHeader

* fix error msg catch
  • Loading branch information
bnoieh authored Oct 18, 2023
1 parent f2ead6f commit 209f0b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion op-node/sources/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (s *EthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.
func (s *EthClient) BSCInfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.BlockInfo, error) {
// can't hit the cache when querying the head due to reorgs / changes.
if label == eth.Finalized {
return s.headerCall(ctx, "eth_getFinalizedBlock", numberID(15))
return s.bscFinalizedHeader(ctx, 21)
}
return s.headerCall(ctx, "eth_getBlockByNumber", label)
}
Expand Down Expand Up @@ -438,3 +438,20 @@ func (s *EthClient) ReadStorageAt(ctx context.Context, address common.Address, s
func (s *EthClient) Close() {
s.client.Close()
}

func (s *EthClient) bscFinalizedHeader(ctx context.Context, probabilisticFinalized int64) (eth.BlockInfo, error) {
var header *rpcHeader
err := s.client.CallContext(ctx, &header, "eth_getFinalizedHeader", probabilisticFinalized) // headers are just blocks without txs
if err != nil {
return nil, err
}
if header == nil {
return nil, ethereum.NotFound
}
info, err := header.Info(s.trustRPC, s.mustBePostMerge)
if err != nil {
return nil, err
}
s.headersCache.Add(info.Hash(), info)
return info, nil
}
2 changes: 1 addition & 1 deletion op-node/sources/l1_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewL1Client(client client.RPC, log log.Logger, metrics caching.Metrics, con
// Notice, we cannot cache a block reference by label because labels are not guaranteed to be unique.
func (s *L1Client) L1BlockRefByLabel(ctx context.Context, label eth.BlockLabel) (eth.L1BlockRef, error) {
info, err := s.BSCInfoByLabel(ctx, label)
if label == eth.Finalized && err != nil && strings.Contains(err.Error(), "eth_getFinalizedBlock does not exist") {
if label == eth.Finalized && err != nil && strings.Contains(err.Error(), "eth_getFinalizedHeader does not exist") {
// op-e2e not support bsc as L1 currently, so fallback to not use bsc specific method eth_getFinalizedBlock
info, err = s.InfoByLabel(ctx, label)
}
Expand Down

0 comments on commit 209f0b7

Please sign in to comment.