Skip to content

Commit

Permalink
fix: api: return the correct block gas limit in the EthAPI
Browse files Browse the repository at this point in the history
The gas limit is proportional to the number of blocks.

fixes #11721
  • Loading branch information
Stebalien committed Mar 19, 2024
1 parent 2e75f3b commit 2af2f2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 2af2f2c

Please sign in to comment.