Skip to content

Commit

Permalink
Remove TxHashes from EVM module
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jan 3, 2025
1 parent e26df24 commit 4579ac8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 68 deletions.
9 changes: 0 additions & 9 deletions evmrpc/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{&ethtypes.Receipt{Logs: []*ethtypes.Log{{
Address: common.HexToAddress("0x1111111111111111111111111111111111111111"),
Topics: []common.Hash{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111"),
Expand Down
2 changes: 0 additions & 2 deletions x/evm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
}
33 changes: 0 additions & 33 deletions x/evm/keeper/tx.go

This file was deleted.

21 changes: 0 additions & 21 deletions x/evm/keeper/tx_test.go

This file was deleted.

13 changes: 13 additions & 0 deletions x/evm/migrations/migrate_remove_tx_hashes.go
Original file line number Diff line number Diff line change
@@ -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)
}
24 changes: 24 additions & 0 deletions x/evm/migrations/migrate_remove_tx_hashes_test.go
Original file line number Diff line number Diff line change
@@ -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)))
}
7 changes: 5 additions & 2 deletions x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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{}
}
2 changes: 1 addition & 1 deletion x/evm/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 4579ac8

Please sign in to comment.