diff --git a/docs/architecture/adr-001-state.md b/docs/architecture/adr-001-state.md index 4985747d..8ae0901f 100644 --- a/docs/architecture/adr-001-state.md +++ b/docs/architecture/adr-001-state.md @@ -256,7 +256,7 @@ func (k *Keeper) NewEVM(msg core.Message, config *params.ChainConfig) *vm.EVM { Transfer: core.Transfer, GetHash: k.GetHashFn(), Coinbase: common.Address{}, // there's no beneficiary since we're not mining - GasLimit: blockGasMeter.Limit(), + GasLimit: gasLimit, BlockNumber: blockHeight, Time: blockTime, Difficulty: 0, // unused. Only required in PoW context diff --git a/ethereum/rpc/backend/backend.go b/ethereum/rpc/backend/backend.go index 4406c400..940293e6 100644 --- a/ethereum/rpc/backend/backend.go +++ b/ethereum/rpc/backend/backend.go @@ -229,7 +229,12 @@ func (e *EVMBackend) EthBlockFromTendermint( validatorAddr := common.BytesToAddress(addr) bloom := ethtypes.BytesToBloom(blockBloomResp.Bloom) - formattedBlock := types.FormatBlock(block.Header, block.Size(), ethermint.DefaultRPCGasLimit, new(big.Int).SetUint64(gasUsed), ethRPCTxs, bloom, validatorAddr) + + gasLimit, err := types.BlockMaxGasFromConsensusParams(types.ContextWithHeight(block.Height), e.clientCtx) + if err != nil { + e.logger.Error("failed to query consensus params", "error", err.Error()) + } + formattedBlock := types.FormatBlock(block.Header, block.Size(), gasLimit, new(big.Int).SetUint64(gasUsed), ethRPCTxs, bloom, validatorAddr) return formattedBlock, nil } diff --git a/ethereum/rpc/types/utils.go b/ethereum/rpc/types/utils.go index 1f5c48bb..4aaf4149 100644 --- a/ethereum/rpc/types/utils.go +++ b/ethereum/rpc/types/utils.go @@ -132,7 +132,7 @@ func EthTransactionsFromTendermint(clientCtx client.Context, txs []tmtypes.Tx) ( func BlockMaxGasFromConsensusParams(ctx context.Context, clientCtx client.Context) (int64, error) { resConsParams, err := clientCtx.Client.ConsensusParams(ctx, nil) if err != nil { - return 0, err + return int64(^uint32(0)), err } gasLimit := resConsParams.ConsensusParams.Block.MaxGas diff --git a/init.sh b/init.sh index ab72c201..e8f449eb 100755 --- a/init.sh +++ b/init.sh @@ -29,6 +29,9 @@ cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["mint"]["params"]["mi # increase block time (?) cat $HOME/.ethermintd/config/genesis.json | jq '.consensus_params["block"]["time_iota_ms"]="30000"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json +# Set gas limit in genesis +cat $HOME/.ethermintd/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json + # disable produce empty block if [[ "$OSTYPE" == "darwin"* ]]; then sed -i '' 's/create_empty_blocks = true/create_empty_blocks = false/g' $HOME/.ethermintd/config/config.toml diff --git a/tests/solidity/init-test-node.sh b/tests/solidity/init-test-node.sh index b742b7ef..fe9a8c29 100755 --- a/tests/solidity/init-test-node.sh +++ b/tests/solidity/init-test-node.sh @@ -25,6 +25,9 @@ echo $USER2_MNEMONIC | ethermintd keys add $USER2_KEY --recover --keyring-backen ethermintd init $MONIKER --chain-id $CHAINID +# Set gas limit in genesis +cat $HOME/.ethermintd/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json + # Allocate genesis accounts (cosmos formatted addresses) ethermintd add-genesis-account "$(ethermintd keys show $VAL_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test ethermintd add-genesis-account "$(ethermintd keys show $USER1_KEY -a --keyring-backend test)" 1000000000000000000000aphoton,1000000000000000000stake --keyring-backend test diff --git a/types/block.go b/types/block.go index cf48b8df..40d77bca 100644 --- a/types/block.go +++ b/types/block.go @@ -7,10 +7,13 @@ import sdk "github.com/cosmos/cosmos-sdk/types" // NOTE: see https://github.com/cosmos/cosmos-sdk/issues/9514 for full reference func BlockGasLimit(ctx sdk.Context) uint64 { blockGasMeter := ctx.BlockGasMeter() - if blockGasMeter != nil { + + // Get the limit from the gas meter only if its not null and not an InfiniteGasMeter + if blockGasMeter != nil && blockGasMeter.Limit() != 0 { return blockGasMeter.Limit() } + // Otherwise get from the consensus parameters cp := ctx.ConsensusParams() if cp == nil || cp.Block == nil { return 0 diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index 815c590e..12b64cbb 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -67,7 +67,21 @@ func (k Keeper) GetHashFn() vm.GetHashFunc { case k.ctx.BlockHeight() == h: // Case 1: The requested height matches the one from the context so we can retrieve the header // hash directly from the context. - return common.BytesToHash(k.ctx.HeaderHash()) + // Note: The headerHash is only set at begin block, it will be nil in case of a query context + headerHash := k.ctx.HeaderHash() + if len(headerHash) != 0 { + return common.BytesToHash(headerHash) + } + + // only recompute the hash if not set + contextBlockHeader := k.ctx.BlockHeader() + header, err := tmtypes.HeaderFromProto(&contextBlockHeader) + if err != nil { + k.Logger(k.ctx).Error("failed to cast tendermint header from proto", "error", err) + return common.Hash{} + } + headerHash = header.Hash() + return common.BytesToHash(headerHash) case k.ctx.BlockHeight() > h: // Case 2: if the chain is not the current height we need to retrieve the hash from the store for the