Skip to content

Commit

Permalink
Merge pull request #6367 from filecoin-project/feat/safeEthGetBlockBy…
Browse files Browse the repository at this point in the history
…Number

feat: support safe param for eth_getBlockByNumber for 30 blocks
  • Loading branch information
simlecode authored Jun 24, 2024
2 parents c7e8fa7 + 936d433 commit abeac91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
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.

0 comments on commit abeac91

Please sign in to comment.