Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to leave a comment about 21.

}
return s.headerCall(ctx, "eth_getBlockByNumber", label)
}
Expand Down Expand Up @@ -434,3 +434,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
Loading