diff --git a/evmrpc/setup_test.go b/evmrpc/setup_test.go index 21101ae10d..d9cd74caa7 100644 --- a/evmrpc/setup_test.go +++ b/evmrpc/setup_test.go @@ -909,18 +909,9 @@ func setupLogs() { }) // block 2 - EVMKeeper.SetTxHashesOnHeight(Ctx, MockHeight2, []common.Hash{ - multiTxBlockTx1.Hash(), - multiTxBlockTx2.Hash(), - multiTxBlockTx3.Hash(), - }) EVMKeeper.SetBlockBloom(MultiTxCtx, []ethtypes.Bloom{bloom1, bloom2, bloom3}) // block 8 - EVMKeeper.SetTxHashesOnHeight(Ctx, MockHeight8, []common.Hash{ - multiTxBlockSynthTx.Hash(), - multiTxBlockTx4.Hash(), - }) bloomTx1 := ethtypes.CreateBloom(ethtypes.Receipts{ðtypes.Receipt{Logs: []*ethtypes.Log{{ Address: common.HexToAddress("0x1111111111111111111111111111111111111111"), Topics: []common.Hash{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111"), diff --git a/x/evm/genesis_test.go b/x/evm/genesis_test.go index 84ee837bfd..6462499c84 100644 --- a/x/evm/genesis_test.go +++ b/x/evm/genesis_test.go @@ -24,7 +24,6 @@ func TestExportImportGenesis(t *testing.T) { keeper.SetNonce(ctx, evmAddr, 2) keeper.MockReceipt(ctx, common.BytesToHash([]byte("789")), &types.Receipt{TxType: 2}) keeper.SetBlockBloom(ctx, []ethtypes.Bloom{{1}}) - keeper.SetTxHashesOnHeight(ctx, 5, []common.Hash{common.BytesToHash([]byte("123"))}) keeper.SetERC20CW20Pointer(ctx, "cw20addr", codeAddr) genesis := evm.ExportGenesis(ctx, keeper) assert.NoError(t, genesis.Validate()) @@ -46,7 +45,6 @@ func TestExportImportGenesis(t *testing.T) { _, err := keeper.GetReceipt(origctx, common.BytesToHash([]byte("789"))) require.Nil(t, err) require.Equal(t, keeper.GetBlockBloom(ctx), keeper.GetBlockBloom(origctx)) - require.Equal(t, keeper.GetTxHashesOnHeight(ctx, 5), keeper.GetTxHashesOnHeight(origctx, 5)) _, _, exists := keeper.GetERC20CW20Pointer(origctx, "cw20addr") require.True(t, exists) } diff --git a/x/evm/keeper/tx.go b/x/evm/keeper/tx.go deleted file mode 100644 index 2a5c900933..0000000000 --- a/x/evm/keeper/tx.go +++ /dev/null @@ -1,33 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" - "github.com/sei-protocol/sei-chain/x/evm/types" -) - -// deprecated -func (k *Keeper) GetTxHashesOnHeight(ctx sdk.Context, height int64) (res []common.Hash) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.TxHashesKey(height)) - if bz == nil { - return - } - for i := 0; i <= len(bz)-common.HashLength; i += common.HashLength { - res = append(res, common.Hash(bz[i:i+common.HashLength])) - } - return -} - -// deprecated -func (k *Keeper) SetTxHashesOnHeight(ctx sdk.Context, height int64, hashes []common.Hash) { - if len(hashes) == 0 { - return - } - store := ctx.KVStore(k.storeKey) - bz := []byte{} - for _, hash := range hashes { - bz = append(bz, hash[:]...) - } - store.Set(types.TxHashesKey(height), bz) -} diff --git a/x/evm/keeper/tx_test.go b/x/evm/keeper/tx_test.go deleted file mode 100644 index af8f25c818..0000000000 --- a/x/evm/keeper/tx_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/ethereum/go-ethereum/common" - testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" - "github.com/stretchr/testify/require" -) - -func TestTxHashesOnHeight(t *testing.T) { - k := &testkeeper.EVMTestApp.EvmKeeper - ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}) - require.Empty(t, k.GetTxHashesOnHeight(ctx, 1234)) - hashes := []common.Hash{ - common.HexToHash("0x0750333eac0be1203864220893d8080dd8a8fd7a2ed098dfd92a718c99d437f2"), - common.HexToHash("0x6f0c1476adb51b1646ff35433b410f1e9c326bd6428f90acf39d0bb1a312bc50"), - } - k.SetTxHashesOnHeight(ctx, 1234, hashes) - require.Equal(t, hashes, k.GetTxHashesOnHeight(ctx, 1234)) -} diff --git a/x/evm/migrations/migrate_remove_tx_hashes.go b/x/evm/migrations/migrate_remove_tx_hashes.go new file mode 100644 index 0000000000..8e7d0d10c5 --- /dev/null +++ b/x/evm/migrations/migrate_remove_tx_hashes.go @@ -0,0 +1,13 @@ +package migrations + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sei-protocol/sei-chain/x/evm/keeper" + "github.com/sei-protocol/sei-chain/x/evm/types" +) + +func RemoveTxHashes(ctx sdk.Context, k *keeper.Keeper) error { + store := prefix.NewStore(ctx.KVStore(k.GetStoreKey()), types.TxHashesPrefix) + return store.DeleteAll(nil, nil) +} diff --git a/x/evm/migrations/migrate_remove_tx_hashes_test.go b/x/evm/migrations/migrate_remove_tx_hashes_test.go new file mode 100644 index 0000000000..9e960e0433 --- /dev/null +++ b/x/evm/migrations/migrate_remove_tx_hashes_test.go @@ -0,0 +1,24 @@ +package migrations_test + +import ( + "testing" + + testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" + "github.com/sei-protocol/sei-chain/x/evm/migrations" + "github.com/sei-protocol/sei-chain/x/evm/types" + "github.com/stretchr/testify/require" + tmtypes "github.com/tendermint/tendermint/proto/tendermint/types" +) + +func TestRemoveTxHashes(t *testing.T) { + k := testkeeper.EVMTestApp.EvmKeeper + ctx := testkeeper.EVMTestApp.NewContext(false, tmtypes.Header{}) + store := ctx.KVStore(k.GetStoreKey()) + store.Set(types.TxHashesKey(1), []byte{1}) + store.Set(types.TxHashesKey(2), []byte{2}) + require.Equal(t, []byte{1}, store.Get(types.TxHashesKey(1))) + require.Equal(t, []byte{2}, store.Get(types.TxHashesKey(2))) + require.NoError(t, migrations.RemoveTxHashes(ctx, &k)) + require.Nil(t, store.Get(types.TxHashesKey(1))) + require.Nil(t, store.Get(types.TxHashesKey(2))) +} diff --git a/x/evm/module.go b/x/evm/module.go index 1c03511e22..e4885096bc 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -229,6 +229,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { _ = cfg.RegisterMigration(types.ModuleName, 15, func(ctx sdk.Context) error { return migrations.StoreCWPointerCode(ctx, am.keeper, false, false, true) }) + + _ = cfg.RegisterMigration(types.ModuleName, 16, func(ctx sdk.Context) error { + return migrations.RemoveTxHashes(ctx, am.keeper) + }) } // RegisterInvariants registers the capability module's invariants. @@ -266,7 +270,7 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 15 } +func (AppModule) ConsensusVersion() uint64 { return 16 } // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { @@ -350,7 +354,6 @@ func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.V } } } - am.keeper.SetTxHashesOnHeight(ctx, ctx.BlockHeight(), utils.Filter(utils.Map(evmTxDeferredInfoList, func(i *types.DeferredInfo) common.Hash { return common.BytesToHash(i.TxHash) }), func(h common.Hash) bool { return h.Cmp(ethtypes.EmptyTxsHash) != 0 })) am.keeper.SetBlockBloom(ctx, utils.Map(evmTxDeferredInfoList, func(i *types.DeferredInfo) ethtypes.Bloom { return ethtypes.BytesToBloom(i.TxBloom) })) return []abci.ValidatorUpdate{} } diff --git a/x/evm/types/keys.go b/x/evm/types/keys.go index 06a451238c..1a72b7a852 100644 --- a/x/evm/types/keys.go +++ b/x/evm/types/keys.go @@ -38,7 +38,7 @@ var ( ReceiptKeyPrefix = []byte{0x0b} WhitelistedCodeHashesForBankSendPrefix = []byte{0x0c} BlockBloomPrefix = []byte{0x0d} - TxHashesPrefix = []byte{0x0e} + TxHashesPrefix = []byte{0x0e} // deprecated WhitelistedCodeHashesForDelegateCallPrefix = []byte{0x0f} // TxHashPrefix = []byte{0x10}