Skip to content

Commit

Permalink
fix(op-node): l1 client use eth_getFinalizedBlock to get finalized bl…
Browse files Browse the repository at this point in the history
…ock (bnb-chain#36)

Co-authored-by: Owen <[email protected]>
  • Loading branch information
bnoieh and owen-reorg committed Oct 11, 2023
1 parent 59bac7c commit 5bbdb8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions op-node/sources/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ func (s *EthClient) InfoByLabel(ctx context.Context, label eth.BlockLabel) (eth.
return s.headerCall(ctx, "eth_getBlockByNumber", label)
}

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.headerCall(ctx, "eth_getBlockByNumber", label)
}

func (s *EthClient) InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error) {
if header, ok := s.headersCache.Get(hash); ok {
if txs, ok := s.transactionsCache.Get(hash); ok {
Expand Down
2 changes: 1 addition & 1 deletion op-node/sources/l1_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewL1Client(client client.RPC, log log.Logger, metrics caching.Metrics, con
// L1BlockRefByLabel returns the [eth.L1BlockRef] for the given block label.
// 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.InfoByLabel(ctx, label)
info, err := s.BSCInfoByLabel(ctx, label)
if err != nil {
// Both geth and erigon like to serve non-standard errors for the safe and finalized heads, correct that.
// This happens when the chain just started and nothing is marked as safe/finalized yet.
Expand Down

0 comments on commit 5bbdb8b

Please sign in to comment.