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

feat: support "safe" param for eth_getBlockByNumber for 30 blocks #12110

Merged
merged 6 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions gateway/proxy_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (gw *Node) checkBlkParam(ctx context.Context, blkParam string, lookback eth
break
}
num = ethtypes.EthUint64(head.Height()) - lookback
case "safe":
safeEpochDelay := 30 // https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0089.md
rvagg marked this conversation as resolved.
Show resolved Hide resolved
num = ethtypes.EthUint64(head.Height()) - lookback - ethtypes.EthUint64(safeEpochDelay)
default:
if err := num.UnmarshalJSON([]byte(`"` + blkParam + `"`)); err != nil {
return fmt.Errorf("cannot parse block number: %v", err)
Expand Down
9 changes: 9 additions & 0 deletions node/impl/full/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func getTipsetByBlockNumber(ctx context.Context, chain *store.ChainStore, blkPar
return nil, fmt.Errorf("cannot get parent tipset")
}
return parent, nil
case "safe":
safeEpochDelay := abi.ChainEpoch(30) // https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0089.md
latestHeight := head.Height() - 1
safeHeight := latestHeight - safeEpochDelay
ts, err := chain.GetTipsetByHeight(ctx, safeHeight, head, true)
if err != nil {
return nil, fmt.Errorf("cannot get tipset at height: %v", safeHeight)
}
return ts, nil
default:
var num ethtypes.EthUint64
err := num.UnmarshalJSON([]byte(`"` + blkParam + `"`))
Expand Down