diff --git a/CHANGELOG.md b/CHANGELOG.md index 578d175c3..4c5ab66af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,56 @@ Ref: https://keepachangelog.com/en/1.0.0/ --> # Changelog +## v5.8.0 +sei-chain +* [#1840](https://github.com/sei-protocol/sei-chain/pull/1840) Add migration for new params +* [#1837](https://github.com/sei-protocol/sei-chain/pull/1837) Move token id from Data to Topic in ERC721 Event +* [#1836](https://github.com/sei-protocol/sei-chain/pull/1836) Properly handle gas in pointer precompile +* [#1835](https://github.com/sei-protocol/sei-chain/pull/1835) Check TX nonce before registering hook to bump nonce for failed tx +* [#1832](https://github.com/sei-protocol/sei-chain/pull/1832) Show CW transactions that have synthetic EVM events in eth_getBlock response +* [#1831](https://github.com/sei-protocol/sei-chain/pull/1831) Fork event manager when creating EVM snapshots +* [#1830](https://github.com/sei-protocol/sei-chain/pull/1830) Add wasm contract query gas limit +* [#1826](https://github.com/sei-protocol/sei-chain/pull/1826) limit MsgExec max nested level +* [#1821](https://github.com/sei-protocol/sei-chain/pull/1821) Add antehandler for EVM to check gas exceed limit or not +* [#1818](https://github.com/sei-protocol/sei-chain/pull/1818) Prevent ddos against associate msgs +* [#1816](https://github.com/sei-protocol/sei-chain/pull/1816) Actually remove dex module +* [#1813](https://github.com/sei-protocol/sei-chain/pull/1813) Tune Configs +* [#1812](https://github.com/sei-protocol/sei-chain/pull/1812) Evidence Max Bytes Update +* [#1785](https://github.com/sei-protocol/sei-chain/pull/1785) Allow CW->ERC pointers to be called through wasmd precompile +* [#1778](https://github.com/sei-protocol/sei-chain/pull/1778) Bump nonce even if tx fails + +sei-cosmos +* [#535](https://github.com/sei-protocol/sei-cosmos/pull/535) init app earliest version correctly after state sync +* [#534](https://github.com/sei-protocol/sei-cosmos/pull/534) Stop executing the handler when proposal is submitted +* [#533](https://github.com/sei-protocol/sei-cosmos/pull/533) Delete kvstore specified in store upgrades +* [#532](https://github.com/sei-protocol/sei-cosmos/pull/532) Add max gas limit check in ante handler +* [#528](https://github.com/sei-protocol/sei-cosmos/pull/528) Add logs for snapshot export and impor + +sei-wasmd +* [63](https://github.com/sei-protocol/sei-wasmd/pull/63) Add CW dispatch call depth +* [62](https://github.com/sei-protocol/sei-wasmd/pull/62) Patch Gas mispricing in CW VM + +sei-tendermint +* [#242](https://github.com/sei-protocol/sei-tendermint/pull/242) Allow hyphen in event query + +## v5.7.5 +sei-chain +* [#1795](https://github.com/sei-protocol/sei-chain/pull/1795) Do not charge gas for feecollector address query +* [#1782](https://github.com/sei-protocol/sei-chain/pull/1782) Update excessBlobGas and BlobBaseFee to fix simulate evmcontext +* [#1741](https://github.com/sei-protocol/sei-chain/pull/1782) Update excessBlobGas and BlobBaseFee to fix simulate evmcontext + +sei-cosmos +* [#530](https://github.com/sei-protocol/sei-cosmos/pull/530) Add EVMEntryViaWasmdPrecompile flag +* [#519](https://github.com/sei-protocol/sei-cosmos/pull/519) Genesis export stream +* [#529](https://github.com/sei-protocol/sei-cosmos/pull/529) Add DeliverTx callback +* [#528](https://github.com/sei-protocol/sei-cosmos/pull/528) Add logs for snapshot export and import + +sei-wasmd +* [58](https://github.com/sei-protocol/sei-wasmd/pull/58) Genesis Export OOM + +sei-tendermint +* [#239](https://github.com/sei-protocol/sei-tendermint/pull/239) Use Marshal and UnmarshalJSON For HexBytes + ## v5.7.1 & v5.7.2 sei-chain * [#1779](https://github.com/sei-protocol/sei-chain/pull/1779) Fix subscribe logs empty params crash diff --git a/evmrpc/block.go b/evmrpc/block.go index 4753f00e5..cefd19011 100644 --- a/evmrpc/block.go +++ b/evmrpc/block.go @@ -71,7 +71,8 @@ func (a *BlockAPI) GetBlockByHash(ctx context.Context, blockHash common.Hash, fu if err != nil { return nil, err } - return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, a.keeper, a.txConfig.TxDecoder(), fullTx) + blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height)) + return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx) } func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (result map[string]interface{}, returnErr error) { @@ -89,7 +90,8 @@ func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, if err != nil { return nil, err } - return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, a.keeper, a.txConfig.TxDecoder(), fullTx) + blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height)) + return EncodeTmBlock(a.ctxProvider(LatestCtxHeight), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx) } func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (result []map[string]interface{}, returnErr error) { @@ -154,6 +156,7 @@ func EncodeTmBlock( ctx sdk.Context, block *coretypes.ResultBlock, blockRes *coretypes.ResultBlockResults, + blockBloom ethtypes.Bloom, k *keeper.Keeper, txDecoder sdk.TxDecoder, fullTx bool, @@ -231,7 +234,7 @@ func EncodeTmBlock( "nonce": ethtypes.BlockNonce{}, // inapplicable to Sei "mixHash": common.Hash{}, // inapplicable to Sei "sha3Uncles": ethtypes.EmptyUncleHash, // inapplicable to Sei - "logsBloom": k.GetBlockBloom(ctx, block.Block.Height), + "logsBloom": blockBloom, "stateRoot": appHash, "miner": miner, "difficulty": (*hexutil.Big)(big.NewInt(0)), // inapplicable to Sei diff --git a/evmrpc/block_test.go b/evmrpc/block_test.go index 37b5090df..58d796ec8 100644 --- a/evmrpc/block_test.go +++ b/evmrpc/block_test.go @@ -110,11 +110,7 @@ func verifyBlockResult(t *testing.T, resObj map[string]interface{}) { require.Equal(t, "0x5", resObj["gasUsed"]) require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000001", resObj["hash"]) // see setup_tests.go, which have one transaction for block 0x8 (latest) - if resObj["number"] == "0x8" { - require.Equal(t, "0x00002000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000", resObj["logsBloom"]) - } else { - require.Equal(t, "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", resObj["logsBloom"]) - } + require.Equal(t, "0x00002000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000200000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000", resObj["logsBloom"]) require.Equal(t, "0x0000000000000000000000000000000000000005", resObj["miner"]) require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", resObj["mixHash"]) require.Equal(t, "0x0000000000000000", resObj["nonce"]) @@ -174,7 +170,7 @@ func TestEncodeTmBlock_EmptyTransactions(t *testing.T) { } // Call EncodeTmBlock with empty transactions - result, err := evmrpc.EncodeTmBlock(ctx, block, blockRes, k, Decoder, true) + result, err := evmrpc.EncodeTmBlock(ctx, block, blockRes, ethtypes.Bloom{}, k, Decoder, true) require.Nil(t, err) // Assert txHash is equal to ethtypes.EmptyTxsHash @@ -220,7 +216,7 @@ func TestEncodeBankMsg(t *testing.T) { }, }, } - res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, k, Decoder, true) + res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, ethtypes.Bloom{}, k, Decoder, true) require.Nil(t, err) txs := res["transactions"].([]interface{}) require.Equal(t, 0, len(txs)) @@ -268,7 +264,7 @@ func TestEncodeWasmExecuteMsg(t *testing.T) { }, }, } - res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, k, Decoder, true) + res, err := evmrpc.EncodeTmBlock(ctx, &resBlock, &resBlockRes, ethtypes.Bloom{}, k, Decoder, true) require.Nil(t, err) txs := res["transactions"].([]interface{}) require.Equal(t, 1, len(txs)) diff --git a/evmrpc/filter.go b/evmrpc/filter.go index a8abee155..04f5f561c 100644 --- a/evmrpc/filter.go +++ b/evmrpc/filter.go @@ -339,9 +339,13 @@ func (f *LogFetcher) GetLogsForBlock(ctx context.Context, block *coretypes.Resul func (f *LogFetcher) FindBlockesByBloom(begin, end int64, filters [][]bloomIndexes) (res []int64) { //TODO: parallelize - ctx := f.ctxProvider(LatestCtxHeight) for height := begin; height <= end; height++ { - blockBloom := f.k.GetBlockBloom(ctx, height) + if height == 0 { + // no block bloom on genesis height + continue + } + ctx := f.ctxProvider(height) + blockBloom := f.k.GetBlockBloom(ctx) if MatchFilters(blockBloom, filters) { res = append(res, height) } diff --git a/evmrpc/filter_test.go b/evmrpc/filter_test.go index 77e211b74..94581979d 100644 --- a/evmrpc/filter_test.go +++ b/evmrpc/filter_test.go @@ -266,7 +266,7 @@ func TestFilterGetFilterChanges(t *testing.T) { EVMKeeper.SetTxHashesOnHeight(Ctx, 9, []common.Hash{ common.HexToHash("0x123456789012345678902345678901234567890123456789012345678900005"), }) - EVMKeeper.SetBlockBloom(Ctx, 9, []ethtypes.Bloom{bloom}) + EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom}) Ctx = Ctx.WithBlockHeight(9) resObj = sendRequest(t, TestPort, "getFilterChanges", filterId) Ctx = Ctx.WithBlockHeight(8) diff --git a/evmrpc/setup_test.go b/evmrpc/setup_test.go index 3d6ff7ddb..898e566ee 100644 --- a/evmrpc/setup_test.go +++ b/evmrpc/setup_test.go @@ -407,11 +407,13 @@ func (m *MockBadClient) BroadcastTx(context.Context, tmtypes.Tx) (*coretypes.Res var EVMKeeper *keeper.Keeper var Ctx sdk.Context +var MultiTxCtx sdk.Context func init() { types.RegisterInterfaces(EncodingConfig.InterfaceRegistry) testApp := app.Setup(false, false) Ctx = testApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(8) + MultiTxCtx, _ = Ctx.CacheContext() EVMKeeper = &testApp.EvmKeeper EVMKeeper.InitGenesis(Ctx, *evmtypes.DefaultGenesis()) seiAddr, err := sdk.AccAddressFromHex(common.Bytes2Hex([]byte("seiAddr"))) @@ -427,6 +429,12 @@ func init() { panic(err) } testApp.Commit(context.Background()) + ctxProvider := func(height int64) sdk.Context { + if height == MultiTxBlockHeight { + return MultiTxCtx + } + return Ctx + } // Start good http server goodConfig := evmrpc.DefaultConfig goodConfig.HTTPPort = TestPort @@ -437,7 +445,7 @@ func init() { if err != nil { panic(err) } - HttpServer, err := evmrpc.NewEVMHTTPServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, func(int64) sdk.Context { return Ctx }, TxConfig, "") + HttpServer, err := evmrpc.NewEVMHTTPServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, ctxProvider, TxConfig, "") if err != nil { panic(err) } @@ -449,7 +457,7 @@ func init() { badConfig := evmrpc.DefaultConfig badConfig.HTTPPort = TestBadPort badConfig.FilterTimeout = 500 * time.Millisecond - badHTTPServer, err := evmrpc.NewEVMHTTPServer(infoLog, badConfig, &MockBadClient{}, EVMKeeper, func(int64) sdk.Context { return Ctx }, TxConfig, "") + badHTTPServer, err := evmrpc.NewEVMHTTPServer(infoLog, badConfig, &MockBadClient{}, EVMKeeper, ctxProvider, TxConfig, "") if err != nil { panic(err) } @@ -458,7 +466,7 @@ func init() { } // Start ws server - wsServer, err := evmrpc.NewEVMWebSocketServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, func(int64) sdk.Context { return Ctx }, TxConfig, "") + wsServer, err := evmrpc.NewEVMWebSocketServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, ctxProvider, TxConfig, "") if err != nil { panic(err) } @@ -723,8 +731,8 @@ func setupLogs() { EVMKeeper.SetTxHashesOnHeight(Ctx, MockHeight, []common.Hash{ multiTxBlockTx4.Hash(), }) - EVMKeeper.SetBlockBloom(Ctx, MultiTxBlockHeight, []ethtypes.Bloom{bloom1, bloom2, bloom3}) - EVMKeeper.SetBlockBloom(Ctx, MockHeight, []ethtypes.Bloom{bloom4}) + EVMKeeper.SetBlockBloom(MultiTxCtx, []ethtypes.Bloom{bloom1, bloom2, bloom3}) + EVMKeeper.SetBlockBloom(Ctx, []ethtypes.Bloom{bloom4}) } //nolint:deadcode diff --git a/x/evm/genesis.go b/x/evm/genesis.go index c90d3bf70..84bd848fd 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -26,6 +26,10 @@ func InitGenesis(ctx sdk.Context, k *keeper.Keeper, genState types.GenesisState) k.SetNonce(ctx, common.HexToAddress(nonce.Address), nonce.Nonce) } for _, serialized := range genState.Serialized { + if len(serialized.Key) == 0 { + ctx.KVStore(k.GetStoreKey()).Set(serialized.Prefix, serialized.Value) + continue + } k.PrefixStore(ctx, serialized.Prefix).Set(serialized.Key, serialized.Value) } } diff --git a/x/evm/genesis_test.go b/x/evm/genesis_test.go index 2ad13e0f4..f43dc2d60 100644 --- a/x/evm/genesis_test.go +++ b/x/evm/genesis_test.go @@ -23,7 +23,7 @@ func TestExportImportGenesis(t *testing.T) { keeper.SetState(ctx, codeAddr, common.BytesToHash([]byte("123")), common.BytesToHash([]byte("456"))) keeper.SetNonce(ctx, evmAddr, 2) keeper.MockReceipt(ctx, common.BytesToHash([]byte("789")), &types.Receipt{TxType: 2}) - keeper.SetBlockBloom(ctx, 5, []ethtypes.Bloom{{1}}) + 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) @@ -42,7 +42,7 @@ func TestExportImportGenesis(t *testing.T) { require.Equal(t, keeper.GetNonce(ctx, evmAddr), keeper.GetNonce(origctx, evmAddr)) _, err := keeper.GetReceipt(origctx, common.BytesToHash([]byte("789"))) require.Nil(t, err) - require.Equal(t, keeper.GetBlockBloom(ctx, 5), keeper.GetBlockBloom(origctx, 5)) + 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/log.go b/x/evm/keeper/log.go index b7078759f..25a8515cc 100644 --- a/x/evm/keeper/log.go +++ b/x/evm/keeper/log.go @@ -1,7 +1,7 @@ package keeper import ( - "bytes" + "encoding/binary" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" @@ -11,7 +11,21 @@ import ( "github.com/sei-protocol/sei-chain/x/evm/types" ) -func (k *Keeper) GetBlockBloom(ctx sdk.Context, height int64) (res ethtypes.Bloom) { +func (k *Keeper) GetBlockBloom(ctx sdk.Context) (res ethtypes.Bloom) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.BlockBloomPrefix) + if bz != nil { + res.SetBytes(bz) + return + } + cutoff := k.GetLegacyBlockBloomCutoffHeight(ctx) + if cutoff == 0 || ctx.BlockHeight() < cutoff { + res = k.GetLegacyBlockBloom(ctx, ctx.BlockHeight()) + } + return +} + +func (k *Keeper) GetLegacyBlockBloom(ctx sdk.Context, height int64) (res ethtypes.Bloom) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.BlockBloomKey(height)) if bz != nil { @@ -20,19 +34,31 @@ func (k *Keeper) GetBlockBloom(ctx sdk.Context, height int64) (res ethtypes.Bloo return } -func (k *Keeper) SetBlockBloom(ctx sdk.Context, height int64, blooms []ethtypes.Bloom) { +func (k *Keeper) SetBlockBloom(ctx sdk.Context, blooms []ethtypes.Bloom) { blockBloom := make([]byte, ethtypes.BloomByteLength) for _, bloom := range blooms { or := make([]byte, ethtypes.BloomByteLength) bitutil.ORBytes(or, blockBloom, bloom[:]) blockBloom = or } - if bytes.Equal(blockBloom, make([]byte, ethtypes.BloomByteLength)) { - // early return if bloom is empty - return - } store := ctx.KVStore(k.storeKey) - store.Set(types.BlockBloomKey(height), blockBloom) + store.Set(types.BlockBloomPrefix, blockBloom) +} + +func (k *Keeper) SetLegacyBlockBloomCutoffHeight(ctx sdk.Context) { + store := ctx.KVStore(k.storeKey) + bz := make([]byte, 8) + binary.BigEndian.PutUint64(bz, uint64(ctx.BlockHeight())) + store.Set(types.LegacyBlockBloomCutoffHeightKey, bz) +} + +func (k *Keeper) GetLegacyBlockBloomCutoffHeight(ctx sdk.Context) int64 { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.LegacyBlockBloomCutoffHeightKey) + if len(bz) == 0 { + return 0 + } + return int64(binary.BigEndian.Uint64(bz)) } func GetLogsForTx(receipt *types.Receipt) []*ethtypes.Log { diff --git a/x/evm/keeper/log_test.go b/x/evm/keeper/log_test.go index 8f3644d00..9f698d831 100644 --- a/x/evm/keeper/log_test.go +++ b/x/evm/keeper/log_test.go @@ -1,4 +1,4 @@ -package keeper +package keeper_test import ( "testing" @@ -7,6 +7,8 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" + testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper" + "github.com/sei-protocol/sei-chain/x/evm/keeper" evmtypes "github.com/sei-protocol/sei-chain/x/evm/types" ) @@ -26,7 +28,7 @@ func TestConvertEthLog(t *testing.T) { } // Convert the ethtypes.Log to a types.Log - log := ConvertEthLog(ethLog) + log := keeper.ConvertEthLog(ethLog) // Check that the fields match require.Equal(t, ethLog.Address.Hex(), log.Address) @@ -67,7 +69,7 @@ func TestGetLogsForTx(t *testing.T) { } // Convert the types.Receipt to a list of ethtypes.Log objects - logs := GetLogsForTx(receipt) + logs := keeper.GetLogsForTx(receipt) // Check that the fields match require.Equal(t, len(receipt.Logs), len(logs)) @@ -81,3 +83,11 @@ func TestGetLogsForTx(t *testing.T) { require.Equal(t, uint(receipt.Logs[i].Index), log.Index) } } + +func TestLegacyBlockBloomCutoffHeight(t *testing.T) { + k := &testkeeper.EVMTestApp.EvmKeeper + ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(123) + require.Equal(t, int64(0), k.GetLegacyBlockBloomCutoffHeight(ctx)) + k.SetLegacyBlockBloomCutoffHeight(ctx) + require.Equal(t, int64(123), k.GetLegacyBlockBloomCutoffHeight(ctx)) +} diff --git a/x/evm/migrations/migrate_block_bloom.go b/x/evm/migrations/migrate_block_bloom.go new file mode 100644 index 000000000..e98e5244e --- /dev/null +++ b/x/evm/migrations/migrate_block_bloom.go @@ -0,0 +1,25 @@ +package migrations + +import ( + 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 MigrateBlockBloom(ctx sdk.Context, k *keeper.Keeper) error { + k.SetLegacyBlockBloomCutoffHeight(ctx) + + prefsToDelete := [][]byte{} + k.IterateAll(ctx, types.BlockBloomPrefix, func(key, _ []byte) bool { + if len(key) > 0 { + prefsToDelete = append(prefsToDelete, key) + } + return false + }) + store := k.PrefixStore(ctx, types.BlockBloomPrefix) + for _, pref := range prefsToDelete { + store.Delete(pref) + } + + return nil +} diff --git a/x/evm/migrations/migrate_block_bloom_test.go b/x/evm/migrations/migrate_block_bloom_test.go new file mode 100644 index 000000000..688b66571 --- /dev/null +++ b/x/evm/migrations/migrate_block_bloom_test.go @@ -0,0 +1,22 @@ +package migrations_test + +import ( + "testing" + + ethtypes "github.com/ethereum/go-ethereum/core/types" + 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" +) + +func TestMigrateBlockBloom(t *testing.T) { + k := testkeeper.EVMTestApp.EvmKeeper + ctx := testkeeper.EVMTestApp.GetContextForDeliverTx([]byte{}).WithBlockHeight(8) + k.PrefixStore(ctx, types.BlockBloomPrefix).Set([]byte{1, 2, 3}, []byte{4, 5, 6}) + k.SetBlockBloom(ctx, []ethtypes.Bloom{}) + require.Nil(t, migrations.MigrateBlockBloom(ctx, &k)) + require.Nil(t, k.PrefixStore(ctx, types.BlockBloomPrefix).Get([]byte{1, 2, 3})) + require.NotNil(t, k.GetBlockBloom(ctx)) + require.Equal(t, int64(8), k.GetLegacyBlockBloomCutoffHeight(ctx)) +} diff --git a/x/evm/module.go b/x/evm/module.go index fbbd882a3..16d44ecb5 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -212,6 +212,10 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { _ = cfg.RegisterMigration(types.ModuleName, 11, func(ctx sdk.Context) error { return migrations.MigrateDeliverTxHookWasmGasLimitParam(ctx, am.keeper) }) + + _ = cfg.RegisterMigration(types.ModuleName, 12, func(ctx sdk.Context) error { + return migrations.MigrateBlockBloom(ctx, am.keeper) + }) } // RegisterInvariants registers the capability module's invariants. @@ -249,7 +253,7 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- } // ConsensusVersion implements ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 12 } +func (AppModule) ConsensusVersion() uint64 { return 13 } // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { @@ -330,6 +334,6 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val } } 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, ctx.BlockHeight(), utils.Map(evmTxDeferredInfoList, func(i *types.DeferredInfo) ethtypes.Bloom { return ethtypes.BytesToBloom(i.TxBloom) })) + 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/module_test.go b/x/evm/module_test.go index d9ad4a0dd..c8bd73ebe 100644 --- a/x/evm/module_test.go +++ b/x/evm/module_test.go @@ -59,7 +59,7 @@ func TestModuleExportGenesis(t *testing.T) { func TestConsensusVersion(t *testing.T) { k, _ := testkeeper.MockEVMKeeper() module := evm.NewAppModule(nil, k) - assert.Equal(t, uint64(12), module.ConsensusVersion()) + assert.Equal(t, uint64(13), module.ConsensusVersion()) } func TestABCI(t *testing.T) { diff --git a/x/evm/types/keys.go b/x/evm/types/keys.go index 3234b73c8..d6e269b3f 100644 --- a/x/evm/types/keys.go +++ b/x/evm/types/keys.go @@ -54,6 +54,8 @@ var ( AnteSurplusPrefix = []byte{0x18} // transient DeferredInfoPrefix = []byte{0x19} // transient + + LegacyBlockBloomCutoffHeightKey = []byte{0x1a} ) var (