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: api: return the correct block gas limit in the EthAPI #11747

Merged
merged 1 commit into from
Mar 21, 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
4 changes: 2 additions & 2 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func init() {
}
}

func NewEthBlock(hasTransactions bool) EthBlock {
func NewEthBlock(hasTransactions bool, tipsetLen int) EthBlock {
b := EthBlock{
Sha3Uncles: EmptyUncleHash, // Sha3Uncles set to a hardcoded value which is used by some clients to determine if has no uncles.
StateRoot: EmptyEthHash,
Expand All @@ -208,7 +208,7 @@ func NewEthBlock(hasTransactions bool) EthBlock {
Extradata: []byte{},
MixHash: EmptyEthHash,
Nonce: EmptyEthNonce,
GasLimit: EthUint64(build.BlockGasLimit), // TODO we map Ethereum blocks to Filecoin tipsets; this is inconsistent.
GasLimit: EthUint64(build.BlockGasLimit * int64(tipsetLen)),
Uncles: []EthHash{},
Transactions: []interface{}{},
}
Expand Down
12 changes: 12 additions & 0 deletions itests/eth_block_hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
"github.com/filecoin-project/lotus/itests/kit"
)

Expand Down Expand Up @@ -49,19 +51,29 @@ func TestEthBlockHashesCorrect_MultiBlockTipset(t *testing.T) {
// let the chain run a little bit longer to minimise the chance of reorgs
n2.WaitTillChain(ctx, kit.HeightAtLeast(head.Height()+50))

tsk := head.Key()
for i := 1; i <= int(head.Height()); i++ {
hex := fmt.Sprintf("0x%x", i)

ts, err := n2.ChainGetTipSetByHeight(ctx, abi.ChainEpoch(i), tsk)
require.NoError(t, err)

ethBlockA, err := n2.EthGetBlockByNumber(ctx, hex, true)
// Cannot use static ErrFullRound error for comparison since it gets reserialized as a JSON RPC error.
if err != nil && strings.Contains(err.Error(), "null round") {
require.Less(t, ts.Height(), abi.ChainEpoch(i), "did not expect a tipset at epoch %d", i)
continue
}
require.NoError(t, err)
require.Equal(t, ts.Height(), abi.ChainEpoch(i), "expected a tipset at epoch %i", i)

ethBlockB, err := n2.EthGetBlockByHash(ctx, ethBlockA.Hash, true)
require.NoError(t, err)

require.Equal(t, ethBlockA, ethBlockB)

numBlocks := len(ts.Blocks())
expGasLimit := ethtypes.EthUint64(int64(numBlocks) * build.BlockGasLimit)
require.Equal(t, expGasLimit, ethBlockB.GasLimit)
}
}
2 changes: 1 addition & 1 deletion node/impl/full/eth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx
return ethtypes.EthBlock{}, xerrors.Errorf("failed to load state-tree root %q: %w", stRoot, err)
}

block := ethtypes.NewEthBlock(len(msgs) > 0)
block := ethtypes.NewEthBlock(len(msgs) > 0, len(ts.Blocks()))

gasUsed := int64(0)
for i, msg := range msgs {
Expand Down