From ceeb4b058d79f92513c60c8a162572cb728e5293 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 2 Oct 2024 09:54:02 +0800 Subject: [PATCH 01/13] Problem: opBlockhash broke after sdk50 --- CHANGELOG.md | 1 + app/app.go | 1 + .../contracts/TestBlockTxProperties.sol | 8 ++++ tests/integration_tests/test_block.py | 11 +++++ tests/integration_tests/utils.py | 1 + x/evm/keeper/keeper.go | 12 +++++ x/evm/keeper/state_transition.go | 12 +---- x/evm/keeper/state_transition_test.go | 46 +++++++++---------- 8 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 tests/integration_tests/hardhat/contracts/TestBlockTxProperties.sol create mode 100644 tests/integration_tests/test_block.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 400cc0827f..3ee7a58b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (rpc) [#516](https://github.com/crypto-org-chain/ethermint/pull/516) Avoid method eth_chainId crashed due to nil pointer on IsEIP155 check. * (cli) [#524](https://github.com/crypto-org-chain/ethermint/pull/524) Allow tx evm raw run for generate only when offline with evm-denom flag. * (rpc) [#527](https://github.com/crypto-org-chain/ethermint/pull/527) Fix balance consistency between trace-block and state machine. +* (rpc) [#534](https://github.com/crypto-org-chain/ethermint/pull/534) Fix opBlockhash when no block header in abci request. ### Improvements diff --git a/app/app.go b/app/app.go index f3033bbba6..f08c9fcade 100644 --- a/app/app.go +++ b/app/app.go @@ -1048,6 +1048,7 @@ func (app *EthermintApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config. // RegisterTxService implements the Application.RegisterTxService method. func (app *EthermintApp) RegisterTxService(clientCtx client.Context) { + app.EvmKeeper.WithCometClient(clientCtx.Client) authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } diff --git a/tests/integration_tests/hardhat/contracts/TestBlockTxProperties.sol b/tests/integration_tests/hardhat/contracts/TestBlockTxProperties.sol new file mode 100644 index 0000000000..07d5b0d20d --- /dev/null +++ b/tests/integration_tests/hardhat/contracts/TestBlockTxProperties.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract TestBlockTxProperties { + function getBlockHash(uint256 blockNumber) public view returns (bytes32) { + return blockhash(blockNumber); + } +} diff --git a/tests/integration_tests/test_block.py b/tests/integration_tests/test_block.py new file mode 100644 index 0000000000..b8c1facc32 --- /dev/null +++ b/tests/integration_tests/test_block.py @@ -0,0 +1,11 @@ +from .utils import CONTRACTS, deploy_contract, w3_wait_for_new_blocks + + +def test_call(ethermint): + w3 = ethermint.w3 + contract, res = deploy_contract(w3, CONTRACTS["TestBlockTxProperties"]) + height = w3.eth.get_block_number() + w3_wait_for_new_blocks(w3, 1) + res = contract.caller.getBlockHash(height).hex() + blk = w3.eth.get_block(height) + assert f"0x{res}" == blk.hash.hex(), res diff --git a/tests/integration_tests/utils.py b/tests/integration_tests/utils.py index 4eb1fdcfa3..b450c99eeb 100644 --- a/tests/integration_tests/utils.py +++ b/tests/integration_tests/utils.py @@ -43,6 +43,7 @@ "Calculator": "Calculator.sol", "Caller": "Caller.sol", "Random": "Random.sol", + "TestBlockTxProperties": "TestBlockTxProperties.sol", } diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 39997b685b..e92fa7d6a0 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -21,6 +21,8 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" + tmrpcclient "github.com/cometbft/cometbft/rpc/client" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -73,6 +75,8 @@ type Keeper struct { // Legacy subspace ss paramstypes.Subspace customContractFns []CustomContractFn + + signClient tmrpcclient.SignClient } // NewKeeper generates new evm module keeper @@ -144,6 +148,14 @@ func (k Keeper) ChainID() *big.Int { return k.eip155ChainID } +func (k *Keeper) WithCometClient(c client.CometRPC) { + sc, ok := c.(tmrpcclient.SignClient) + if !ok { + panic("invalid rpc client") + } + k.signClient = sc +} + // ---------------------------------------------------------------------------- // Block Bloom // Required by Web3 API. diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index d8eaccc49c..e559a6252d 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -128,19 +128,11 @@ func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc { case ctx.BlockHeight() > h: // Case 2: if the chain is not the current height we need to retrieve the hash from the store for the // current chain epoch. This only applies if the current height is greater than the requested height. - histInfo, err := k.stakingKeeper.GetHistoricalInfo(ctx, h) + res, err := k.signClient.Header(ctx, &h) if err != nil { - k.Logger(ctx).Debug("historical info not found", "height", h, "err", err.Error()) return common.Hash{} } - - header, err := cmttypes.HeaderFromProto(&histInfo.Header) - if err != nil { - k.Logger(ctx).Error("failed to cast tendermint header from proto", "error", err) - return common.Hash{} - } - - return common.BytesToHash(header.Hash()) + return common.BytesToHash(res.Header.Hash()) default: // Case 3: heights greater than the current one returns an empty hash. return common.Hash{} diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index bdc95a1f87..f8729d878c 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -10,6 +10,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cometbft/cometbft/crypto/tmhash" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" tmtypes "github.com/cometbft/cometbft/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -22,6 +23,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" "github.com/evmos/ethermint/app" + "github.com/evmos/ethermint/rpc/backend/mocks" "github.com/evmos/ethermint/tests" "github.com/evmos/ethermint/testutil" utiltx "github.com/evmos/ethermint/testutil/tx" @@ -92,13 +94,13 @@ func (suite *StateTransitionTestSuite) TestGetHashFn() { testCases := []struct { msg string height uint64 - malleate func() + malleate func(height uint64) expHash common.Hash }{ { "case 1.1: context hash cached", uint64(suite.Ctx.BlockHeight()), - func() { + func(_ uint64) { suite.Ctx = suite.Ctx.WithHeaderHash(tmhash.Sum([]byte("header"))).WithConsensusParams(*testutil.DefaultConsensusParams) }, common.BytesToHash(tmhash.Sum([]byte("header"))), @@ -106,54 +108,48 @@ func (suite *StateTransitionTestSuite) TestGetHashFn() { { "case 1.2: failed to cast Tendermint header", uint64(suite.Ctx.BlockHeight()), - func() { - header := tmproto.Header{} + func(_ uint64) { header.Height = suite.Ctx.BlockHeight() - suite.Ctx = suite.Ctx.WithBlockHeader(header).WithConsensusParams(*testutil.DefaultConsensusParams) + suite.Ctx = suite.Ctx.WithBlockHeader(tmproto.Header{}).WithConsensusParams(*testutil.DefaultConsensusParams) }, common.Hash{}, }, { "case 1.3: hash calculated from Tendermint header", uint64(suite.Ctx.BlockHeight()), - func() { + func(_ uint64) { suite.Ctx = suite.Ctx.WithBlockHeader(header).WithConsensusParams(*testutil.DefaultConsensusParams) }, common.BytesToHash(hash), }, { - "case 2.1: height lower than current one, hist info not found", - 1, - func() { - suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) - }, - common.Hash{}, - }, - { - "case 2.2: height lower than current one, invalid hist info header", + "case 2.1: height lower than current one, header not found", 1, - func() { - suite.App.StakingKeeper.SetHistoricalInfo(suite.Ctx, 1, &stakingtypes.HistoricalInfo{}) + func(height uint64) { + c := mocks.NewClient(suite.T()) + suite.App.EvmKeeper.WithCometClient(c) suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) + height0 := int64(height) + c.On("Header", suite.Ctx, &height0).Return(&tmrpctypes.ResultHeader{Header: &h}, nil) }, common.Hash{}, }, { - "case 2.3: height lower than current one, calculated from hist info header", + "case 2.2: height lower than current one, header found", 1, - func() { - histInfo := &stakingtypes.HistoricalInfo{ - Header: header, - } - suite.App.StakingKeeper.SetHistoricalInfo(suite.Ctx, 1, histInfo) + func(height uint64) { + c := mocks.NewClient(suite.T()) + suite.App.EvmKeeper.WithCometClient(c) suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) + height0 := int64(height) + c.On("Header", suite.Ctx, &height0).Return(&tmrpctypes.ResultHeader{Header: &h}, nil) }, common.BytesToHash(hash), }, { "case 3: height greater than current one", 200, - func() {}, + func(_ uint64) {}, common.Hash{}, }, } @@ -162,7 +158,7 @@ func (suite *StateTransitionTestSuite) TestGetHashFn() { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset - tc.malleate() + tc.malleate(tc.height) hash := suite.App.EvmKeeper.GetHashFn(suite.Ctx)(tc.height) suite.Require().Equal(tc.expHash, hash) From eb1dfff9e8c180d0c5078350fccf6784db1b2107 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 2 Oct 2024 15:43:17 +0800 Subject: [PATCH 02/13] cleanup --- x/evm/keeper/state_transition.go | 40 ++--------- x/evm/keeper/state_transition_test.go | 99 ++++++++++++++++----------- 2 files changed, 65 insertions(+), 74 deletions(-) diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index e559a6252d..bdac3ad5cc 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -21,8 +21,6 @@ import ( "math/big" "sort" - cmttypes "github.com/cometbft/cometbft/types" - errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" @@ -103,40 +101,14 @@ func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc { k.Logger(ctx).Error("failed to cast height to int64", "error", err) return common.Hash{} } - - switch { - case 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. - // Note: The headerHash is only set at begin block, it will be nil in case of a query context - headerHash := ctx.HeaderHash() - if len(headerHash) != 0 { - return common.BytesToHash(headerHash) - } - - // only recompute the hash if not set (eg: checkTxState) - contextBlockHeader := ctx.BlockHeader() - header, err := cmttypes.HeaderFromProto(&contextBlockHeader) - if err != nil { - k.Logger(ctx).Error("failed to cast tendermint header from proto", "error", err) - return common.Hash{} - } - - headerHash = header.Hash() - return common.BytesToHash(headerHash) - - case ctx.BlockHeight() > h: - // Case 2: if the chain is not the current height we need to retrieve the hash from the store for the - // current chain epoch. This only applies if the current height is greater than the requested height. - res, err := k.signClient.Header(ctx, &h) - if err != nil { - return common.Hash{} - } - return common.BytesToHash(res.Header.Hash()) - default: - // Case 3: heights greater than the current one returns an empty hash. + if ctx.BlockHeight() < h { + return common.Hash{} + } + res, err := k.signClient.Header(ctx, &h) + if err != nil { return common.Hash{} } + return common.BytesToHash(res.Header.Hash()) } } diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index f8729d878c..28dd24693a 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -5,15 +5,20 @@ import ( "math" "math/big" "testing" + "time" sdkmath "cosmossdk.io/math" storetypes "cosmossdk.io/store/types" + cmtcrypto "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/tmhash" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmtrand "github.com/cometbft/cometbft/libs/rand" + cmtversion "github.com/cometbft/cometbft/proto/tendermint/version" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" tmtypes "github.com/cometbft/cometbft/types" + "github.com/cometbft/cometbft/version" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -86,10 +91,52 @@ func TestStateTransitionTestSuite(t *testing.T) { suite.Run(t, new(StateTransitionTestSuite)) } +func makeRandHeader() tmtypes.Header { + chainID := "test" + t := time.Now() + height := cmtrand.Int63() + randBytes := cmtrand.Bytes(tmhash.Size) + randAddress := cmtrand.Bytes(cmtcrypto.AddressSize) + h := tmtypes.Header{ + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, + ChainID: chainID, + Height: height, + Time: t, + LastBlockID: tmtypes.BlockID{}, + LastCommitHash: randBytes, + DataHash: randBytes, + ValidatorsHash: randBytes, + NextValidatorsHash: randBytes, + ConsensusHash: randBytes, + AppHash: randBytes, + LastResultsHash: randBytes, + EvidenceHash: randBytes, + ProposerAddress: randAddress, + } + return h +} + +func (suite *StateTransitionTestSuite) registerHeaderError(height uint64) { + c := mocks.NewClient(suite.T()) + suite.App.EvmKeeper.WithCometClient(c) + suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) + height0 := int64(height) + c.On("Header", suite.Ctx, &height0).Return(nil, errortypes.ErrNotFound) +} + +func (suite *StateTransitionTestSuite) registerHeader(header tmtypes.Header) func(uint64) { + return func(height uint64) { + c := mocks.NewClient(suite.T()) + suite.App.EvmKeeper.WithCometClient(c) + suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) + height0 := int64(height) + c.On("Header", suite.Ctx, &height0).Return(&tmrpctypes.ResultHeader{Header: &header}, nil) + } +} + func (suite *StateTransitionTestSuite) TestGetHashFn() { - header := suite.Ctx.BlockHeader() - h, _ := tmtypes.HeaderFromProto(&header) - hash := h.Hash() + header := makeRandHeader() + hash := header.Hash() testCases := []struct { msg string @@ -98,52 +145,27 @@ func (suite *StateTransitionTestSuite) TestGetHashFn() { expHash common.Hash }{ { - "case 1.1: context hash cached", - uint64(suite.Ctx.BlockHeight()), - func(_ uint64) { - suite.Ctx = suite.Ctx.WithHeaderHash(tmhash.Sum([]byte("header"))).WithConsensusParams(*testutil.DefaultConsensusParams) - }, - common.BytesToHash(tmhash.Sum([]byte("header"))), - }, - { - "case 1.2: failed to cast Tendermint header", - uint64(suite.Ctx.BlockHeight()), - func(_ uint64) { - header.Height = suite.Ctx.BlockHeight() - suite.Ctx = suite.Ctx.WithBlockHeader(tmproto.Header{}).WithConsensusParams(*testutil.DefaultConsensusParams) - }, + "case 1.1: height equals to current one, header not found", + 10, + suite.registerHeaderError, common.Hash{}, }, { - "case 1.3: hash calculated from Tendermint header", - uint64(suite.Ctx.BlockHeight()), - func(_ uint64) { - suite.Ctx = suite.Ctx.WithBlockHeader(header).WithConsensusParams(*testutil.DefaultConsensusParams) - }, + "case 1.2: height equals to current one, header found", + 10, + suite.registerHeader(header), common.BytesToHash(hash), }, { "case 2.1: height lower than current one, header not found", 1, - func(height uint64) { - c := mocks.NewClient(suite.T()) - suite.App.EvmKeeper.WithCometClient(c) - suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) - height0 := int64(height) - c.On("Header", suite.Ctx, &height0).Return(&tmrpctypes.ResultHeader{Header: &h}, nil) - }, + suite.registerHeaderError, common.Hash{}, }, { "case 2.2: height lower than current one, header found", 1, - func(height uint64) { - c := mocks.NewClient(suite.T()) - suite.App.EvmKeeper.WithCometClient(c) - suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) - height0 := int64(height) - c.On("Header", suite.Ctx, &height0).Return(&tmrpctypes.ResultHeader{Header: &h}, nil) - }, + suite.registerHeader(header), common.BytesToHash(hash), }, { @@ -153,13 +175,10 @@ func (suite *StateTransitionTestSuite) TestGetHashFn() { common.Hash{}, }, } - for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { suite.SetupTest() // reset - tc.malleate(tc.height) - hash := suite.App.EvmKeeper.GetHashFn(suite.Ctx)(tc.height) suite.Require().Equal(tc.expHash, hash) }) From 839472befb09cf2b5d850c3cec77738e17b23d34 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 10:58:34 +0800 Subject: [PATCH 03/13] Apply suggestions from code review --- x/evm/keeper/abci.go | 2 +- x/evm/keeper/keeper.go | 22 ++++++++++++++++++++++ x/evm/keeper/state_transition.go | 7 +------ x/evm/types/key.go | 8 +++++--- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index d890eb53f3..9b64984124 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -27,7 +27,7 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) error { if _, err := k.EVMBlockConfig(ctx, k.ChainID()); err != nil { return err } - + k.SetHeaderHash(ctx) return nil } diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index e92fa7d6a0..a1575bc85e 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -16,10 +16,12 @@ package keeper import ( + "encoding/binary" "math/big" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" + "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" tmrpcclient "github.com/cometbft/cometbft/rpc/client" "github.com/cosmos/cosmos-sdk/client" @@ -317,3 +319,23 @@ func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, er k.SetTransientGasUsed(ctx, result) return result, nil } + +// SetHeaderHash stores the hash of the current block header in the store. +func (k Keeper) SetHeaderHash(ctx sdk.Context) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) + key := make([]byte, 8) + height, err := ethermint.SafeUint64(ctx.BlockHeight()) + if err != nil { + panic(err) + } + binary.BigEndian.PutUint64(key, height) + store.Set(key, ctx.HeaderHash()) +} + +// GetHeaderHash retrieves the hash of a block header from the store by height. +func (k Keeper) GetHeaderHash(ctx sdk.Context, height uint64) []byte { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) + key := make([]byte, 8) + binary.BigEndian.PutUint64(key, height) + return store.Get(key) +} diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index bdac3ad5cc..d24c138d40 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -98,17 +98,12 @@ func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc { return func(height uint64) common.Hash { h, err := ethermint.SafeInt64(height) if err != nil { - k.Logger(ctx).Error("failed to cast height to int64", "error", err) return common.Hash{} } if ctx.BlockHeight() < h { return common.Hash{} } - res, err := k.signClient.Header(ctx, &h) - if err != nil { - return common.Hash{} - } - return common.BytesToHash(res.Header.Hash()) + return common.BytesToHash(k.GetHeaderHash(ctx, height)) } } diff --git a/x/evm/types/key.go b/x/evm/types/key.go index b3b7173ba9..96e100be63 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -44,6 +44,7 @@ const ( prefixCode = iota + 1 prefixStorage prefixParams + prefixHeaderHash ) // prefix bytes for the EVM object store @@ -55,9 +56,10 @@ const ( // KVStore key prefixes var ( - KeyPrefixCode = []byte{prefixCode} - KeyPrefixStorage = []byte{prefixStorage} - KeyPrefixParams = []byte{prefixParams} + KeyPrefixCode = []byte{prefixCode} + KeyPrefixStorage = []byte{prefixStorage} + KeyPrefixParams = []byte{prefixParams} + KeyPrefixHeaderHash = []byte{prefixHeaderHash} ) // Object Store key prefixes From be9329cb63042810906eee9d20f4cbbe2c69059c Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 13:05:09 +0800 Subject: [PATCH 04/13] DeleteHeaderHash --- app/app.go | 1 - x/evm/keeper/abci.go | 11 +++++ x/evm/keeper/keeper.go | 20 ++++----- x/evm/keeper/state_transition_test.go | 64 +++++++-------------------- 4 files changed, 36 insertions(+), 60 deletions(-) diff --git a/app/app.go b/app/app.go index 99f65ee19c..112f7f1b11 100644 --- a/app/app.go +++ b/app/app.go @@ -1066,7 +1066,6 @@ func (app *EthermintApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config. // RegisterTxService implements the Application.RegisterTxService method. func (app *EthermintApp) RegisterTxService(clientCtx client.Context) { - app.EvmKeeper.WithCometClient(clientCtx.Client) authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 9b64984124..7e86f79970 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -17,8 +17,12 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + ethermint "github.com/evmos/ethermint/types" ) +// HeaderHashNum is the number of header hash to persist. +const HeaderHashNum = 10000 + // BeginBlock sets the sdk Context and EIP155 chain id to the Keeper. func (k *Keeper) BeginBlock(ctx sdk.Context) error { k.WithChainID(ctx) @@ -28,6 +32,13 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) error { return err } k.SetHeaderHash(ctx) + for i := ctx.BlockHeight() - HeaderHashNum; i >= 0; i-- { + h, err := ethermint.SafeUint64(i) + if err != nil { + panic(err) + } + k.DeleteHeaderHash(ctx, h) + } return nil } diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index a1575bc85e..0a8c4b0235 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -23,8 +23,6 @@ import ( "cosmossdk.io/log" "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" - tmrpcclient "github.com/cometbft/cometbft/rpc/client" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -77,8 +75,6 @@ type Keeper struct { // Legacy subspace ss paramstypes.Subspace customContractFns []CustomContractFn - - signClient tmrpcclient.SignClient } // NewKeeper generates new evm module keeper @@ -150,14 +146,6 @@ func (k Keeper) ChainID() *big.Int { return k.eip155ChainID } -func (k *Keeper) WithCometClient(c client.CometRPC) { - sc, ok := c.(tmrpcclient.SignClient) - if !ok { - panic("invalid rpc client") - } - k.signClient = sc -} - // ---------------------------------------------------------------------------- // Block Bloom // Required by Web3 API. @@ -339,3 +327,11 @@ func (k Keeper) GetHeaderHash(ctx sdk.Context, height uint64) []byte { binary.BigEndian.PutUint64(key, height) return store.Get(key) } + +// DeleteHeaderHash removes the hash of a block header from the store by height +func (k Keeper) DeleteHeaderHash(ctx sdk.Context, height uint64) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) + key := make([]byte, 8) + binary.BigEndian.PutUint64(key, height) + store.Delete(key) +} diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index 28dd24693a..cad82800be 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -13,12 +13,10 @@ import ( "github.com/cometbft/cometbft/crypto/tmhash" cmtrand "github.com/cometbft/cometbft/libs/rand" cmtversion "github.com/cometbft/cometbft/proto/tendermint/version" - tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" tmtypes "github.com/cometbft/cometbft/types" "github.com/cometbft/cometbft/version" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - errortypes "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -28,7 +26,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" "github.com/evmos/ethermint/app" - "github.com/evmos/ethermint/rpc/backend/mocks" "github.com/evmos/ethermint/tests" "github.com/evmos/ethermint/testutil" utiltx "github.com/evmos/ethermint/testutil/tx" @@ -91,16 +88,15 @@ func TestStateTransitionTestSuite(t *testing.T) { suite.Run(t, new(StateTransitionTestSuite)) } -func makeRandHeader() tmtypes.Header { +func makeRandHeader(height uint64) tmtypes.Header { chainID := "test" t := time.Now() - height := cmtrand.Int63() randBytes := cmtrand.Bytes(tmhash.Size) randAddress := cmtrand.Bytes(cmtcrypto.AddressSize) h := tmtypes.Header{ Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: chainID, - Height: height, + Height: int64(height), Time: t, LastBlockID: tmtypes.BlockID{}, LastCommitHash: randBytes, @@ -116,26 +112,15 @@ func makeRandHeader() tmtypes.Header { return h } -func (suite *StateTransitionTestSuite) registerHeaderError(height uint64) { - c := mocks.NewClient(suite.T()) - suite.App.EvmKeeper.WithCometClient(c) - suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) - height0 := int64(height) - c.On("Header", suite.Ctx, &height0).Return(nil, errortypes.ErrNotFound) -} - -func (suite *StateTransitionTestSuite) registerHeader(header tmtypes.Header) func(uint64) { - return func(height uint64) { - c := mocks.NewClient(suite.T()) - suite.App.EvmKeeper.WithCometClient(c) - suite.Ctx = suite.Ctx.WithBlockHeight(10).WithConsensusParams(*testutil.DefaultConsensusParams) - height0 := int64(height) - c.On("Header", suite.Ctx, &height0).Return(&tmrpctypes.ResultHeader{Header: &header}, nil) - } +func (suite *StateTransitionTestSuite) registerHeader(header tmtypes.Header) { + suite.Ctx.WithBlockHeight(header.Height) + suite.Ctx.WithHeaderHash(header.Hash()) + suite.App.EvmKeeper.SetHeaderHash(suite.Ctx) } func (suite *StateTransitionTestSuite) TestGetHashFn() { - header := makeRandHeader() + height := uint64(10) + header := makeRandHeader(height) hash := header.Hash() testCases := []struct { @@ -145,35 +130,20 @@ func (suite *StateTransitionTestSuite) TestGetHashFn() { expHash common.Hash }{ { - "case 1.1: height equals to current one, header not found", - 10, - suite.registerHeaderError, + "header not found", + height, + func(height uint64) {}, common.Hash{}, }, { - "case 1.2: height equals to current one, header found", - 10, - suite.registerHeader(header), - common.BytesToHash(hash), - }, - { - "case 2.1: height lower than current one, header not found", - 1, - suite.registerHeaderError, - common.Hash{}, - }, - { - "case 2.2: height lower than current one, header found", - 1, - suite.registerHeader(header), + "header found", + height, + func(height uint64) { + suite.Ctx = suite.Ctx.WithBlockHeight(header.Height).WithHeaderHash(header.Hash()) + suite.App.EvmKeeper.SetHeaderHash(suite.Ctx) + }, common.BytesToHash(hash), }, - { - "case 3: height greater than current one", - 200, - func(_ uint64) {}, - common.Hash{}, - }, } for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.msg), func() { From 8d6162fde805c7225680f613950f55a65858ed82 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 13:06:27 +0800 Subject: [PATCH 05/13] add header_hash_num in param --- client/docs/swagger-ui/swagger.yaml | 120 ++++++++++++++---- proto/ethermint/evm/v1/params.proto | 2 + .../integration_tests/configs/default.jsonnet | 1 + tests/integration_tests/test_block.py | 3 + x/evm/keeper/abci.go | 12 +- x/evm/types/params.pb.go | 88 +++++++++---- 6 files changed, 171 insertions(+), 55 deletions(-) diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index e8c1d48c18..eaa4cc6a98 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -140,6 +140,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -179,7 +183,6 @@ paths: name "y.z". - JSON @@ -357,6 +360,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -396,7 +403,6 @@ paths: name "y.z". - JSON @@ -574,6 +580,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -613,7 +623,6 @@ paths: name "y.z". - JSON @@ -784,6 +793,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -823,7 +836,6 @@ paths: name "y.z". - JSON @@ -1009,6 +1021,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -1048,7 +1064,6 @@ paths: name "y.z". - JSON @@ -1234,6 +1249,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -1273,7 +1292,6 @@ paths: name "y.z". - JSON @@ -1572,6 +1590,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -1611,7 +1633,6 @@ paths: name "y.z". - JSON @@ -1828,7 +1849,7 @@ paths: prague) description: >- ChainConfig defines the Ethereum ChainConfig parameters - using *sdk.Int values + using *sdkmath.Int values instead of *big.Int. allow_unprotected_txs: @@ -1838,6 +1859,10 @@ paths: EIP155 signed) transactions can be executed on the state machine. + header_hash_num: + type: string + format: uint64 + description: header_hash_num is the number of header hash to persist. title: Params defines the EVM module parameters description: >- QueryParamsResponse defines the response type for querying x/evm @@ -1955,6 +1980,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -1994,7 +2023,6 @@ paths: name "y.z". - JSON @@ -2168,6 +2196,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -2207,7 +2239,6 @@ paths: name "y.z". - JSON @@ -2389,6 +2420,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -2428,7 +2463,6 @@ paths: name "y.z". - JSON @@ -2833,6 +2867,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -2872,7 +2910,6 @@ paths: name "y.z". - JSON @@ -3289,6 +3326,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -3328,7 +3369,6 @@ paths: name "y.z". - JSON @@ -3434,7 +3474,7 @@ paths: required: false type: number format: double - - name: msg.hash + - name: msg.deprecated_hash description: hash of the transaction in hex format. in: query required: false @@ -3455,6 +3495,12 @@ paths: required: false type: string format: byte + - name: msg.raw + description: raw is the raw bytes of the ethereum transaction. + in: query + required: false + type: string + format: byte - name: trace_config.tracer description: tracer is a custom javascript tracer. in: query @@ -3835,6 +3881,10 @@ paths: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -3874,7 +3924,6 @@ paths: name "y.z". - JSON @@ -4014,7 +4063,7 @@ definitions: type: string title: prague switch time (nil = no fork, 0 = already on prague) description: >- - ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int + ChainConfig defines the Ethereum ChainConfig parameters using *sdkmath.Int values instead of *big.Int. @@ -4187,6 +4236,10 @@ definitions: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -4222,7 +4275,6 @@ definitions: name "y.z". - JSON @@ -4261,7 +4313,7 @@ definitions: type: number format: double title: size is the encoded storage size of the transaction (DEPRECATED) - hash: + deprecated_hash: type: string title: hash of the transaction in hex format deprecated_from: @@ -4276,6 +4328,10 @@ definitions: against the address derived from the signature (V, R, S) using the secp256k1 elliptic curve + raw: + type: string + format: byte + title: raw is the raw bytes of the ethereum transaction description: MsgEthereumTx encapsulates an Ethereum transaction as an SDK message. ethermint.evm.v1.MsgEthereumTxResponse: type: object @@ -4488,8 +4544,8 @@ definitions: type: string title: prague switch time (nil = no fork, 0 = already on prague) description: >- - ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int - values + ChainConfig defines the Ethereum ChainConfig parameters using + *sdkmath.Int values instead of *big.Int. allow_unprotected_txs: @@ -4497,6 +4553,10 @@ definitions: description: |- allow_unprotected_txs defines if replay-protected (i.e non EIP155 signed) transactions can be executed on the state machine. + header_hash_num: + type: string + format: uint64 + description: header_hash_num is the number of header hash to persist. title: Params defines the EVM module parameters ethermint.evm.v1.QueryAccountResponse: type: object @@ -4685,7 +4745,7 @@ definitions: title: prague switch time (nil = no fork, 0 = already on prague) description: >- ChainConfig defines the Ethereum ChainConfig parameters using - *sdk.Int values + *sdkmath.Int values instead of *big.Int. allow_unprotected_txs: @@ -4693,6 +4753,10 @@ definitions: description: |- allow_unprotected_txs defines if replay-protected (i.e non EIP155 signed) transactions can be executed on the state machine. + header_hash_num: + type: string + format: uint64 + description: header_hash_num is the number of header hash to persist. title: Params defines the EVM module parameters description: >- QueryParamsResponse defines the response type for querying x/evm @@ -4874,8 +4938,8 @@ definitions: type: string title: prague switch time (nil = no fork, 0 = already on prague) description: >- - ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int - values + ChainConfig defines the Ethereum ChainConfig parameters using + *sdkmath.Int values instead of *big.Int. enable_memory: @@ -4986,6 +5050,10 @@ definitions: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -5021,7 +5089,6 @@ definitions: name "y.z". - JSON @@ -5162,6 +5229,10 @@ definitions: if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } + // or ... + if (any.isSameTypeAs(Foo.getDefaultInstance())) { + foo = any.unpack(Foo.getDefaultInstance()); + } Example 3: Pack and unpack a message in Python. @@ -5197,7 +5268,6 @@ definitions: name "y.z". - JSON diff --git a/proto/ethermint/evm/v1/params.proto b/proto/ethermint/evm/v1/params.proto index c4c64323aa..48c0c944ce 100644 --- a/proto/ethermint/evm/v1/params.proto +++ b/proto/ethermint/evm/v1/params.proto @@ -22,4 +22,6 @@ message Params { // allow_unprotected_txs defines if replay-protected (i.e non EIP155 // signed) transactions can be executed on the state machine. bool allow_unprotected_txs = 6; + // header_hash_num is the number of header hash to persist. + uint64 header_hash_num = 7; } \ No newline at end of file diff --git a/tests/integration_tests/configs/default.jsonnet b/tests/integration_tests/configs/default.jsonnet index 1345ee682a..c90f910848 100644 --- a/tests/integration_tests/configs/default.jsonnet +++ b/tests/integration_tests/configs/default.jsonnet @@ -63,6 +63,7 @@ evm: { params: { evm_denom: 'aphoton', + header_hash_num: 2, }, }, gov: { diff --git a/tests/integration_tests/test_block.py b/tests/integration_tests/test_block.py index b8c1facc32..f19b026e57 100644 --- a/tests/integration_tests/test_block.py +++ b/tests/integration_tests/test_block.py @@ -9,3 +9,6 @@ def test_call(ethermint): res = contract.caller.getBlockHash(height).hex() blk = w3.eth.get_block(height) assert f"0x{res}" == blk.hash.hex(), res + w3_wait_for_new_blocks(w3, 1) + res = contract.caller.getBlockHash(height).hex() + assert f"0x{res}" == "0x" + "0" * 64, res diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 7e86f79970..2d21017f56 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -20,19 +20,21 @@ import ( ethermint "github.com/evmos/ethermint/types" ) -// HeaderHashNum is the number of header hash to persist. -const HeaderHashNum = 10000 - // BeginBlock sets the sdk Context and EIP155 chain id to the Keeper. func (k *Keeper) BeginBlock(ctx sdk.Context) error { k.WithChainID(ctx) // cache parameters that's common for the whole block. - if _, err := k.EVMBlockConfig(ctx, k.ChainID()); err != nil { + cfg, err := k.EVMBlockConfig(ctx, k.ChainID()) + if err != nil { return err } k.SetHeaderHash(ctx) - for i := ctx.BlockHeight() - HeaderHashNum; i >= 0; i-- { + headerHashNum, err := ethermint.SafeInt64(cfg.Params.GetHeaderHashNum()) + if err != nil { + panic(err) + } + for i := ctx.BlockHeight() - headerHashNum; i >= 0; i-- { h, err := ethermint.SafeUint64(i) if err != nil { panic(err) diff --git a/x/evm/types/params.pb.go b/x/evm/types/params.pb.go index ed314c775e..165d458898 100644 --- a/x/evm/types/params.pb.go +++ b/x/evm/types/params.pb.go @@ -39,6 +39,8 @@ type Params struct { // allow_unprotected_txs defines if replay-protected (i.e non EIP155 // signed) transactions can be executed on the state machine. AllowUnprotectedTxs bool `protobuf:"varint,6,opt,name=allow_unprotected_txs,json=allowUnprotectedTxs,proto3" json:"allow_unprotected_txs,omitempty"` + // header_hash_num is the number of header hash to persist. + HeaderHashNum uint64 `protobuf:"varint,7,opt,name=header_hash_num,json=headerHashNum,proto3" json:"header_hash_num,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -116,6 +118,13 @@ func (m *Params) GetAllowUnprotectedTxs() bool { return false } +func (m *Params) GetHeaderHashNum() uint64 { + if m != nil { + return m.HeaderHashNum + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "ethermint.evm.v1.Params") } @@ -123,32 +132,34 @@ func init() { func init() { proto.RegisterFile("ethermint/evm/v1/params.proto", fileDescriptor_e7d3c06c1322f20f) } var fileDescriptor_e7d3c06c1322f20f = []byte{ - // 391 bytes of a gzipped FileDescriptorProto + // 423 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x91, 0x41, 0x8b, 0xd3, 0x40, - 0x18, 0x86, 0x93, 0xed, 0x5a, 0x36, 0xd3, 0x15, 0xd6, 0xb1, 0x4a, 0x58, 0xd8, 0x24, 0x44, 0x90, - 0x9c, 0x12, 0xba, 0x1e, 0x04, 0x41, 0xd0, 0xd4, 0x0a, 0xde, 0x96, 0xa0, 0x17, 0x2f, 0x61, 0x9a, - 0x7e, 0xa6, 0x81, 0x99, 0x4c, 0xc8, 0x4c, 0x63, 0xfa, 0x2f, 0xfc, 0x59, 0x3d, 0xf6, 0xe8, 0x29, - 0x48, 0xfa, 0x0f, 0xf2, 0x0b, 0x24, 0xd3, 0xda, 0x56, 0xbd, 0xcd, 0xf7, 0x3d, 0xef, 0xfb, 0xc1, - 0xbc, 0x2f, 0xba, 0x03, 0xb9, 0x84, 0x92, 0x65, 0xb9, 0x0c, 0xa0, 0x62, 0x41, 0x35, 0x09, 0x0a, - 0x52, 0x12, 0x26, 0xfc, 0xa2, 0xe4, 0x92, 0xe3, 0x9b, 0x23, 0xf6, 0xa1, 0x62, 0x7e, 0x35, 0xb9, - 0x1d, 0xa7, 0x3c, 0xe5, 0x0a, 0x06, 0xfd, 0x6b, 0xaf, 0xbb, 0x7d, 0xf1, 0xdf, 0x99, 0x64, 0x49, - 0xb2, 0x3c, 0x4e, 0x78, 0xfe, 0x2d, 0x4b, 0xf7, 0x22, 0xb7, 0xbb, 0x40, 0xc3, 0x07, 0x75, 0x1d, - 0x4f, 0x90, 0x01, 0x15, 0x8b, 0x17, 0x90, 0x73, 0x66, 0xea, 0x8e, 0xee, 0x19, 0xe1, 0xb8, 0x6b, - 0xec, 0x9b, 0x35, 0x61, 0xf4, 0x8d, 0x7b, 0x44, 0x6e, 0x74, 0x05, 0x15, 0xfb, 0xd0, 0x3f, 0xf1, - 0x5b, 0xf4, 0x18, 0x72, 0x32, 0xa7, 0x10, 0x27, 0x25, 0x10, 0x09, 0xe6, 0x85, 0xa3, 0x7b, 0x57, - 0xa1, 0xd9, 0x35, 0xf6, 0xf8, 0x60, 0x3b, 0xc7, 0x6e, 0x74, 0xbd, 0x9f, 0xa7, 0x6a, 0xc4, 0xaf, - 0xd1, 0xe8, 0x0f, 0x27, 0x94, 0x9a, 0x03, 0x65, 0x7e, 0xde, 0x35, 0x36, 0xfe, 0xdb, 0x4c, 0x28, - 0x75, 0x23, 0x74, 0xb0, 0x12, 0x4a, 0xf1, 0x7b, 0x84, 0xa0, 0x96, 0x25, 0x89, 0x21, 0x2b, 0x84, - 0x79, 0xe9, 0x0c, 0xbc, 0x41, 0xe8, 0xb6, 0x8d, 0x6d, 0xcc, 0xfa, 0xed, 0xec, 0xd3, 0x83, 0xe8, - 0x1a, 0xfb, 0xc9, 0xe1, 0xc8, 0x51, 0xe8, 0x46, 0x86, 0x1a, 0x66, 0x59, 0x21, 0xf0, 0x47, 0x74, - 0x7d, 0x1e, 0x87, 0xf9, 0xc8, 0xd1, 0xbd, 0xd1, 0xfd, 0x9d, 0xff, 0x6f, 0xb8, 0xfe, 0xb4, 0x57, - 0x4d, 0x95, 0x28, 0xbc, 0xdc, 0x34, 0xb6, 0x16, 0x8d, 0x92, 0xd3, 0x0a, 0xdf, 0xa3, 0x67, 0x84, - 0x52, 0xfe, 0x3d, 0x5e, 0xe5, 0x7d, 0xa2, 0x90, 0x48, 0x58, 0xc4, 0xb2, 0x16, 0xe6, 0xb0, 0xff, - 0x4d, 0xf4, 0x54, 0xc1, 0x2f, 0x27, 0xf6, 0xb9, 0x16, 0xe1, 0xbb, 0x4d, 0x6b, 0xe9, 0xdb, 0xd6, - 0xd2, 0x7f, 0xb5, 0x96, 0xfe, 0x63, 0x67, 0x69, 0xdb, 0x9d, 0xa5, 0xfd, 0xdc, 0x59, 0xda, 0xd7, - 0x97, 0x69, 0x26, 0x97, 0xab, 0xb9, 0x9f, 0x70, 0xd6, 0x97, 0xc6, 0x45, 0x70, 0x2a, 0xb1, 0x56, - 0x35, 0xca, 0x75, 0x01, 0x62, 0x3e, 0x54, 0xed, 0xbd, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x51, - 0x16, 0x95, 0xc2, 0x2b, 0x02, 0x00, 0x00, + 0x18, 0x86, 0x1b, 0x5b, 0xeb, 0x76, 0xba, 0x8b, 0xeb, 0x58, 0x65, 0x58, 0xd8, 0x24, 0x44, 0x58, + 0x72, 0x4a, 0xe8, 0x7a, 0x10, 0x04, 0x41, 0x53, 0x2b, 0x7a, 0x91, 0x25, 0xe8, 0xc5, 0xcb, 0x30, + 0x4d, 0x3f, 0x9b, 0xc0, 0x4c, 0x26, 0x64, 0xa6, 0xb1, 0xfb, 0x2f, 0x3c, 0xfb, 0x8b, 0xf6, 0xb8, + 0x47, 0x4f, 0x41, 0xda, 0x7f, 0xd0, 0x5f, 0x20, 0x99, 0xd4, 0x76, 0xd5, 0xdb, 0x7c, 0xdf, 0xf3, + 0xbe, 0x1f, 0xcc, 0xfb, 0xa2, 0x73, 0xd0, 0x29, 0x94, 0x22, 0xcb, 0x75, 0x08, 0x95, 0x08, 0xab, + 0x71, 0x58, 0xb0, 0x92, 0x09, 0x15, 0x14, 0xa5, 0xd4, 0x12, 0x9f, 0xee, 0x71, 0x00, 0x95, 0x08, + 0xaa, 0xf1, 0xd9, 0x68, 0x21, 0x17, 0xd2, 0xc0, 0xb0, 0x79, 0xb5, 0xba, 0xb3, 0x67, 0xff, 0x9d, + 0x49, 0x52, 0x96, 0xe5, 0x34, 0x91, 0xf9, 0xd7, 0x6c, 0xd1, 0x8a, 0xbc, 0x1f, 0x5d, 0xd4, 0xbf, + 0x32, 0xd7, 0xf1, 0x18, 0x0d, 0xa0, 0x12, 0x74, 0x0e, 0xb9, 0x14, 0xc4, 0x72, 0x2d, 0x7f, 0x10, + 0x8d, 0xb6, 0xb5, 0x73, 0x7a, 0xcd, 0x04, 0x7f, 0xe9, 0xed, 0x91, 0x17, 0x1f, 0x41, 0x25, 0xde, + 0x36, 0x4f, 0xfc, 0x0a, 0x9d, 0x40, 0xce, 0x66, 0x1c, 0x68, 0x52, 0x02, 0xd3, 0x40, 0xee, 0xb9, + 0x96, 0x7f, 0x14, 0x91, 0x6d, 0xed, 0x8c, 0x76, 0xb6, 0xbb, 0xd8, 0x8b, 0x8f, 0xdb, 0x79, 0x62, + 0x46, 0xfc, 0x02, 0x0d, 0xff, 0x70, 0xc6, 0x39, 0xe9, 0x1a, 0xf3, 0xd3, 0x6d, 0xed, 0xe0, 0xbf, + 0xcd, 0x8c, 0x73, 0x2f, 0x46, 0x3b, 0x2b, 0xe3, 0x1c, 0xbf, 0x41, 0x08, 0x56, 0xba, 0x64, 0x14, + 0xb2, 0x42, 0x91, 0x9e, 0xdb, 0xf5, 0xbb, 0x91, 0xb7, 0xae, 0x9d, 0xc1, 0xb4, 0xd9, 0x4e, 0x3f, + 0x5c, 0xa9, 0x6d, 0xed, 0x3c, 0xda, 0x1d, 0xd9, 0x0b, 0xbd, 0x78, 0x60, 0x86, 0x69, 0x56, 0x28, + 0xfc, 0x0e, 0x1d, 0xdf, 0x8d, 0x83, 0xdc, 0x77, 0x2d, 0x7f, 0x78, 0x79, 0x1e, 0xfc, 0x1b, 0x6e, + 0x30, 0x69, 0x54, 0x13, 0x23, 0x8a, 0x7a, 0x37, 0xb5, 0xd3, 0x89, 0x87, 0xc9, 0x61, 0x85, 0x2f, + 0xd1, 0x13, 0xc6, 0xb9, 0xfc, 0x46, 0x97, 0x79, 0x93, 0x28, 0x24, 0x1a, 0xe6, 0x54, 0xaf, 0x14, + 0xe9, 0x37, 0xbf, 0x89, 0x1f, 0x1b, 0xf8, 0xf9, 0xc0, 0x3e, 0xad, 0x14, 0xbe, 0x40, 0x0f, 0x53, + 0x60, 0x73, 0x28, 0x69, 0xca, 0x54, 0x4a, 0xf3, 0xa5, 0x20, 0x0f, 0x5c, 0xcb, 0xef, 0xc5, 0x27, + 0xed, 0xfa, 0x3d, 0x53, 0xe9, 0xc7, 0xa5, 0x88, 0x5e, 0xdf, 0xac, 0x6d, 0xeb, 0x76, 0x6d, 0x5b, + 0xbf, 0xd6, 0xb6, 0xf5, 0x7d, 0x63, 0x77, 0x6e, 0x37, 0x76, 0xe7, 0xe7, 0xc6, 0xee, 0x7c, 0xb9, + 0x58, 0x64, 0x3a, 0x5d, 0xce, 0x82, 0x44, 0x8a, 0xa6, 0x5c, 0xa9, 0xc2, 0x43, 0xd9, 0x2b, 0x53, + 0xb7, 0xbe, 0x2e, 0x40, 0xcd, 0xfa, 0xa6, 0xe5, 0xe7, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x01, + 0xa5, 0x92, 0x40, 0x53, 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -171,6 +182,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.HeaderHashNum != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.HeaderHashNum)) + i-- + dAtA[i] = 0x38 + } if m.AllowUnprotectedTxs { i-- if m.AllowUnprotectedTxs { @@ -279,6 +295,9 @@ func (m *Params) Size() (n int) { if m.AllowUnprotectedTxs { n += 2 } + if m.HeaderHashNum != 0 { + n += 1 + sovParams(uint64(m.HeaderHashNum)) + } return n } @@ -518,6 +537,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } m.AllowUnprotectedTxs = bool(v != 0) + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HeaderHashNum", wireType) + } + m.HeaderHashNum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HeaderHashNum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) From e699ca405c0cd4085703003c1e3c411d3feef83a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 14:00:33 +0800 Subject: [PATCH 06/13] Apply suggestions from code review --- x/evm/keeper/abci.go | 2 +- x/evm/keeper/keeper.go | 13 +++---------- x/evm/keeper/state_transition.go | 6 ++++++ x/evm/types/key.go | 6 ++++++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 2d21017f56..04c6d1442d 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -34,7 +34,7 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) error { if err != nil { panic(err) } - for i := ctx.BlockHeight() - headerHashNum; i >= 0; i-- { + if i := ctx.BlockHeight() - headerHashNum; i > 0 { h, err := ethermint.SafeUint64(i) if err != nil { panic(err) diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 0a8c4b0235..0b37664c9d 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -16,7 +16,6 @@ package keeper import ( - "encoding/binary" "math/big" errorsmod "cosmossdk.io/errors" @@ -311,27 +310,21 @@ func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, er // SetHeaderHash stores the hash of the current block header in the store. func (k Keeper) SetHeaderHash(ctx sdk.Context) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) - key := make([]byte, 8) height, err := ethermint.SafeUint64(ctx.BlockHeight()) if err != nil { panic(err) } - binary.BigEndian.PutUint64(key, height) - store.Set(key, ctx.HeaderHash()) + store.Set(types.GetHeaderHashKey(height), ctx.HeaderHash()) } // GetHeaderHash retrieves the hash of a block header from the store by height. func (k Keeper) GetHeaderHash(ctx sdk.Context, height uint64) []byte { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) - key := make([]byte, 8) - binary.BigEndian.PutUint64(key, height) - return store.Get(key) + return store.Get(types.GetHeaderHashKey(height)) } // DeleteHeaderHash removes the hash of a block header from the store by height func (k Keeper) DeleteHeaderHash(ctx sdk.Context, height uint64) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) - key := make([]byte, 8) - binary.BigEndian.PutUint64(key, height) - store.Delete(key) + store.Delete(types.GetHeaderHashKey(height)) } diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index d24c138d40..c6d493f56a 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -103,6 +103,12 @@ func (k Keeper) GetHashFn(ctx sdk.Context) vm.GetHashFunc { if ctx.BlockHeight() < h { return common.Hash{} } + if ctx.BlockHeight() == h { + headerHash := ctx.HeaderHash() + if len(headerHash) != 0 { + return common.BytesToHash(headerHash) + } + } return common.BytesToHash(k.GetHeaderHash(ctx, height)) } } diff --git a/x/evm/types/key.go b/x/evm/types/key.go index 96e100be63..37a1c05206 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -112,3 +112,9 @@ func ObjectBloomKey(txIndex, msgIndex int) []byte { binary.BigEndian.PutUint64(key[9:], value) return key[:] } + +func GetHeaderHashKey(height uint64) []byte { + key := make([]byte, len(KeyPrefixHeaderHash)+8) + binary.BigEndian.PutUint64(key, height) + return key +} From 1edfd92735724ac7ffb1aab7c657ea3a34532b37 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 4 Oct 2024 14:35:59 +0800 Subject: [PATCH 07/13] Apply suggestions from code review Signed-off-by: yihuang --- x/evm/types/key.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/evm/types/key.go b/x/evm/types/key.go index 37a1c05206..6e360e7583 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -114,7 +114,8 @@ func ObjectBloomKey(txIndex, msgIndex int) []byte { } func GetHeaderHashKey(height uint64) []byte { - key := make([]byte, len(KeyPrefixHeaderHash)+8) - binary.BigEndian.PutUint64(key, height) + key := make([]byte, len(1+8) + key[0] = prefixHeaderHash + binary.BigEndian.PutUint64(key[1:], height) return key } From 442e3d135f1c57f122ef7e0fcd656ffee2e56667 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 4 Oct 2024 14:39:46 +0800 Subject: [PATCH 08/13] Apply suggestions from code review Signed-off-by: yihuang --- x/evm/keeper/keeper.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 0b37664c9d..ebdf6b32f4 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -309,7 +309,7 @@ func (k Keeper) AddTransientGasUsed(ctx sdk.Context, gasUsed uint64) (uint64, er // SetHeaderHash stores the hash of the current block header in the store. func (k Keeper) SetHeaderHash(ctx sdk.Context) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) + store := ctx.KVStore(k.storeKey) height, err := ethermint.SafeUint64(ctx.BlockHeight()) if err != nil { panic(err) @@ -319,12 +319,12 @@ func (k Keeper) SetHeaderHash(ctx sdk.Context) { // GetHeaderHash retrieves the hash of a block header from the store by height. func (k Keeper) GetHeaderHash(ctx sdk.Context, height uint64) []byte { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) + store := ctx.KVStore(k.storeKey) return store.Get(types.GetHeaderHashKey(height)) } // DeleteHeaderHash removes the hash of a block header from the store by height func (k Keeper) DeleteHeaderHash(ctx sdk.Context, height uint64) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefixHeaderHash) + store := ctx.KVStore(k.storeKey) store.Delete(types.GetHeaderHashKey(height)) } From 9c0b0020a184898c71dce215d19aa5f3d38e94b0 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 4 Oct 2024 14:41:41 +0800 Subject: [PATCH 09/13] Update x/evm/types/key.go Signed-off-by: yihuang --- x/evm/types/key.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/evm/types/key.go b/x/evm/types/key.go index 6e360e7583..ff165c06fb 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -114,7 +114,7 @@ func ObjectBloomKey(txIndex, msgIndex int) []byte { } func GetHeaderHashKey(height uint64) []byte { - key := make([]byte, len(1+8) + var key [1+8]byte key[0] = prefixHeaderHash binary.BigEndian.PutUint64(key[1:], height) return key From 88ab64a887db7fa8fe20b501cbc97d3d7e1a2e3a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 14:44:18 +0800 Subject: [PATCH 10/13] Apply suggestions from code review --- app/upgrades.go | 13 ++++++++++++- tests/integration_tests/configs/cosmovisor.jsonnet | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index f6289b9e20..57bc7eede1 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -19,6 +19,7 @@ import ( "context" upgradetypes "cosmossdk.io/x/upgrade/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" ) @@ -26,7 +27,17 @@ func (app *EthermintApp) RegisterUpgradeHandlers() { planName := "sdk50" app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM) + m, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM) + if err != nil { + return m, err + } + sdkCtx := sdk.UnwrapSDKContext(ctx) + { + params := app.EvmKeeper.GetParams(sdkCtx) + params.HeaderHashNum = 10000 + app.EvmKeeper.SetParams(sdkCtx, params) + } + return m, nil }, ) } diff --git a/tests/integration_tests/configs/cosmovisor.jsonnet b/tests/integration_tests/configs/cosmovisor.jsonnet index 4630f9a5ab..34ec86b27c 100644 --- a/tests/integration_tests/configs/cosmovisor.jsonnet +++ b/tests/integration_tests/configs/cosmovisor.jsonnet @@ -13,6 +13,11 @@ config { }, }, app_state+: { + evm+: { + params+: { + header_hash_num:: super.header_hash_num, + }, + }, feemarket+: { params+: { base_fee:: super.base_fee, From 579dbcbc1f90f01a802613370e2342245fb667bb Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 14:47:16 +0800 Subject: [PATCH 11/13] fix build --- x/evm/keeper/keeper.go | 1 - x/evm/types/key.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index ebdf6b32f4..8689485435 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -20,7 +20,6 @@ import ( errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" - "cosmossdk.io/store/prefix" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/x/evm/types/key.go b/x/evm/types/key.go index ff165c06fb..86dc1efe8a 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -117,5 +117,5 @@ func GetHeaderHashKey(height uint64) []byte { var key [1+8]byte key[0] = prefixHeaderHash binary.BigEndian.PutUint64(key[1:], height) - return key + return key[:] } From fc2fe81b882c25d8b1cb1d5c1e81e0b18bb847f4 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 15:01:27 +0800 Subject: [PATCH 12/13] lint --- app/upgrades.go | 4 +++- x/evm/types/key.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/upgrades.go b/app/upgrades.go index 57bc7eede1..b606d1c9a8 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -35,7 +35,9 @@ func (app *EthermintApp) RegisterUpgradeHandlers() { { params := app.EvmKeeper.GetParams(sdkCtx) params.HeaderHashNum = 10000 - app.EvmKeeper.SetParams(sdkCtx, params) + if err := app.EvmKeeper.SetParams(sdkCtx, params); err != nil { + return m, err + } } return m, nil }, diff --git a/x/evm/types/key.go b/x/evm/types/key.go index 86dc1efe8a..569ce7bb90 100644 --- a/x/evm/types/key.go +++ b/x/evm/types/key.go @@ -114,7 +114,7 @@ func ObjectBloomKey(txIndex, msgIndex int) []byte { } func GetHeaderHashKey(height uint64) []byte { - var key [1+8]byte + var key [1 + 8]byte key[0] = prefixHeaderHash binary.BigEndian.PutUint64(key[1:], height) return key[:] From e9b84b9d9fc6b8e996739cfcfe8c9e7f8c5a896f Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 4 Oct 2024 15:24:04 +0800 Subject: [PATCH 13/13] add default --- app/upgrades.go | 3 ++- x/evm/types/params.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/upgrades.go b/app/upgrades.go index b606d1c9a8..bc1f660a43 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -21,6 +21,7 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + evmtypes "github.com/evmos/ethermint/x/evm/types" ) func (app *EthermintApp) RegisterUpgradeHandlers() { @@ -34,7 +35,7 @@ func (app *EthermintApp) RegisterUpgradeHandlers() { sdkCtx := sdk.UnwrapSDKContext(ctx) { params := app.EvmKeeper.GetParams(sdkCtx) - params.HeaderHashNum = 10000 + params.HeaderHashNum = evmtypes.DefaultHeaderHashNum if err := app.EvmKeeper.SetParams(sdkCtx, params); err != nil { return m, err } diff --git a/x/evm/types/params.go b/x/evm/types/params.go index 27d84155cd..f18b65f4e5 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -34,6 +34,8 @@ var ( DefaultEnableCreate = true // DefaultEnableCall enables contract calls (i.e true) DefaultEnableCall = true + // DefaultHeaderHashNum defines the default number of header hash to persist. + DefaultHeaderHashNum = uint64(10000) ) // NewParams creates a new Params instance @@ -58,6 +60,7 @@ func DefaultParams() Params { EnableCall: DefaultEnableCall, ChainConfig: config, AllowUnprotectedTxs: DefaultAllowUnprotectedTxs, + HeaderHashNum: DefaultHeaderHashNum, } }