diff --git a/chain/types/ethtypes/eth_types.go b/chain/types/ethtypes/eth_types.go index 7c464f3ec99..0a10bdde7b1 100644 --- a/chain/types/ethtypes/eth_types.go +++ b/chain/types/ethtypes/eth_types.go @@ -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, @@ -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{}{}, } diff --git a/itests/eth_block_hash_test.go b/itests/eth_block_hash_test.go index b582c84e346..8debefa492c 100644 --- a/itests/eth_block_hash_test.go +++ b/itests/eth_block_hash_test.go @@ -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" ) @@ -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) } } diff --git a/node/impl/full/eth_utils.go b/node/impl/full/eth_utils.go index 3e9df852a93..6f09fa41497 100644 --- a/node/impl/full/eth_utils.go +++ b/node/impl/full/eth_utils.go @@ -223,7 +223,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 {