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: eth_blockNumber: make it aware of null rounds. #9934

Merged
merged 1 commit into from
Dec 23, 2022
Merged
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
17 changes: 12 additions & 5 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,24 @@ func (a *EthModule) StateNetworkName(ctx context.Context) (dtypes.NetworkName, e
return stmgr.GetNetworkName(ctx, a.StateManager, a.Chain.GetHeaviestTipSet().ParentState())
}

func (a *EthModule) EthBlockNumber(context.Context) (ethtypes.EthUint64, error) {
func (a *EthModule) EthBlockNumber(ctx context.Context) (ethtypes.EthUint64, error) {
// eth_blockNumber needs to return the height of the latest committed tipset.
// Ethereum clients expect all transactions included in this block to have execution outputs.
// This is the parent of the head tipset. The head tipset is speculative, has not been
// recognized by the network, and its messages are only included, not executed.
// See https://github.com/filecoin-project/ref-fvm/issues/1135.
height := a.Chain.GetHeaviestTipSet().Height() - 1
if height < 0 {
height = 0 // genesis is the first ever committed tipset.
heaviest := a.Chain.GetHeaviestTipSet()
if height := heaviest.Height(); height == 0 {
// we're at genesis.
return ethtypes.EthUint64(height), nil
}
return ethtypes.EthUint64(height), nil
// First non-null parent.
effectiveParent := heaviest.Parents()
parent, err := a.Chain.GetTipSetFromKey(ctx, effectiveParent)
if err != nil {
return 0, err
}
return ethtypes.EthUint64(parent.Height()), nil
}

func (a *EthModule) EthAccounts(context.Context) ([]ethtypes.EthAddress, error) {
Expand Down