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 #6367

Merged
merged 1 commit into from
Jun 24, 2024
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
16 changes: 16 additions & 0 deletions app/submodule/eth/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ func getTipsetByBlockNumber(ctx context.Context, store *chain.Store, blkParam st
return nil, fmt.Errorf("cannot get parent tipset")
}
return parent, nil
case "safe":
latestHeight := head.Height() - 1
safeHeight := latestHeight - types.SafeEpochDelay
ts, err := store.GetTipSetByHeight(ctx, head, safeHeight, true)
if err != nil {
return nil, fmt.Errorf("cannot get tipset at height: %v", safeHeight)
}
return ts, nil
case "finalized":
latestHeight := head.Height() - 1
safeHeight := latestHeight - constants.Finality
ts, err := store.GetTipSetByHeight(ctx, head, safeHeight, true)
if err != nil {
return nil, fmt.Errorf("cannot get tipset at height: %v", safeHeight)
}
return ts, nil
default:
var num types.EthUint64
err := num.UnmarshalJSON([]byte(`"` + blkParam + `"`))
Expand Down
6 changes: 6 additions & 0 deletions venus-shared/actors/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import (

var ErrInvalidAddress = errors.New("invalid Filecoin Eth address")

// Research into Filecoin chain behaviour suggests that probabilistic finality
// generally approaches the intended stability guarantee at, or near, 30 epochs.
// Although a strictly "finalized" safe recommendation remains 900 epochs.
// See https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0089.md
const SafeEpochDelay = abi.ChainEpoch(30)

// mainnet
var Eip155ChainID = 314

Expand Down
1 change: 1 addition & 0 deletions venus-shared/types/eth.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading