fix: api: return the correct block gas limit in the EthAPI (#11747)

The gas limit is proportional to the number of blocks.

fixes #11721
This commit is contained in:
Steven Allen 2024-03-21 12:49:55 -07:00 committed by GitHub
parent ea19e1df6b
commit 566584d45c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 3 deletions

View File

@ -197,7 +197,7 @@ func init() {
} }
} }
func NewEthBlock(hasTransactions bool) EthBlock { func NewEthBlock(hasTransactions bool, tipsetLen int) EthBlock {
b := EthBlock{ b := EthBlock{
Sha3Uncles: EmptyUncleHash, // Sha3Uncles set to a hardcoded value which is used by some clients to determine if has no uncles. Sha3Uncles: EmptyUncleHash, // Sha3Uncles set to a hardcoded value which is used by some clients to determine if has no uncles.
StateRoot: EmptyEthHash, StateRoot: EmptyEthHash,
@ -208,7 +208,7 @@ func NewEthBlock(hasTransactions bool) EthBlock {
Extradata: []byte{}, Extradata: []byte{},
MixHash: EmptyEthHash, MixHash: EmptyEthHash,
Nonce: EmptyEthNonce, 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{}, Uncles: []EthHash{},
Transactions: []interface{}{}, Transactions: []interface{}{},
} }

View File

@ -11,6 +11,8 @@ import (
"github.com/filecoin-project/go-state-types/abi" "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" "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 // let the chain run a little bit longer to minimise the chance of reorgs
n2.WaitTillChain(ctx, kit.HeightAtLeast(head.Height()+50)) n2.WaitTillChain(ctx, kit.HeightAtLeast(head.Height()+50))
tsk := head.Key()
for i := 1; i <= int(head.Height()); i++ { for i := 1; i <= int(head.Height()); i++ {
hex := fmt.Sprintf("0x%x", 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) ethBlockA, err := n2.EthGetBlockByNumber(ctx, hex, true)
// Cannot use static ErrFullRound error for comparison since it gets reserialized as a JSON RPC error. // 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") { 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 continue
} }
require.NoError(t, err) 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) ethBlockB, err := n2.EthGetBlockByHash(ctx, ethBlockA.Hash, true)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, ethBlockA, ethBlockB) require.Equal(t, ethBlockA, ethBlockB)
numBlocks := len(ts.Blocks())
expGasLimit := ethtypes.EthUint64(int64(numBlocks) * build.BlockGasLimit)
require.Equal(t, expGasLimit, ethBlockB.GasLimit)
} }
} }

View File

@ -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) 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) gasUsed := int64(0)
for i, msg := range msgs { for i, msg := range msgs {