diff --git a/app/abci.go b/app/abci.go index a0f2bb7808..dae5fe314e 100644 --- a/app/abci.go +++ b/app/abci.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/legacytm" "github.com/sei-protocol/sei-chain/app/legacyabci" "github.com/sei-protocol/sei-chain/utils/metrics" abci "github.com/tendermint/tendermint/abci/types" @@ -50,11 +51,19 @@ func (app *App) MidBlock(ctx sdk.Context, height int64) []abci.Event { return app.BaseApp.MidBlock(ctx, height) } -func (app *App) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (res abci.ResponseEndBlock) { +func (app *App) EndBlock(ctx sdk.Context, height int64, blockGasUsed int64) (res abci.ResponseEndBlock) { spanCtx, span := app.GetBaseApp().TracingInfo.StartWithContext("EndBlock", ctx.TraceSpanContext()) defer span.End() ctx = ctx.WithTraceSpanContext(spanCtx) - return app.BaseApp.EndBlock(ctx, req) + defer telemetry.MeasureSince(time.Now(), "abci", "end_block") + ctx = ctx.WithEventManager(sdk.NewEventManager()) + defer telemetry.MeasureSince(time.Now(), "module", "total_end_block") + res.ValidatorUpdates = legacyabci.EndBlock(ctx, height, blockGasUsed, app.EndBlockKeepers) + res.Events = sdk.MarkEventsToIndex(ctx.EventManager().ABCIEvents(), app.IndexEvents) + if cp := app.GetConsensusParams(ctx); cp != nil { + res.ConsensusParamUpdates = legacytm.ABCIToLegacyConsensusParams(cp) + } + return res } func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTxV2) (*abci.ResponseCheckTxV2, error) { diff --git a/app/app.go b/app/app.go index d9911e8e01..d0d5de44fe 100644 --- a/app/app.go +++ b/app/app.go @@ -337,6 +337,7 @@ type App struct { TokenFactoryKeeper tokenfactorykeeper.Keeper BeginBlockKeepers legacyabci.BeginBlockKeepers + EndBlockKeepers legacyabci.EndBlockKeepers // mm is the module manager mm *module.Manager @@ -744,37 +745,18 @@ func New( IBCKeeper: app.IBCKeeper, EvmKeeper: &app.EvmKeeper, } + app.EndBlockKeepers = legacyabci.EndBlockKeepers{ + CrisisKeeper: &app.CrisisKeeper, + GovKeeper: &app.GovKeeper, + StakingKeeper: &app.StakingKeeper, + OracleKeeper: &app.OracleKeeper, + EvmKeeper: &app.EvmKeeper, + } app.mm.SetOrderMidBlockers( oracletypes.ModuleName, ) - app.mm.SetOrderEndBlockers( - crisistypes.ModuleName, - govtypes.ModuleName, - stakingtypes.ModuleName, - capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - minttypes.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - authz.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, - ibchost.ModuleName, - ibctransfertypes.ModuleName, - oracletypes.ModuleName, - epochmoduletypes.ModuleName, - evmtypes.ModuleName, - wasm.ModuleName, - tokenfactorytypes.ModuleName, - ) - // NOTE: The genutils module must occur after staking so that pools are // properly initialized with tokens from genesis accounts. // NOTE: Capability module must occur first so that it can initialize any capabilities @@ -861,7 +843,6 @@ func New( app.SetAnteHandler(anteHandler) app.SetMidBlocker(app.MidBlocker) - app.SetEndBlocker(app.EndBlocker) app.SetPrepareProposalHandler(app.PrepareProposalHandler) app.SetProcessProposalHandler(app.ProcessProposalHandler) app.SetFinalizeBlocker(app.FinalizeBlocker) @@ -1037,11 +1018,6 @@ func (app *App) MidBlocker(ctx sdk.Context, height int64) []abci.Event { return app.mm.MidBlock(ctx, height) } -// EndBlocker application updates every end block -func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { - return app.mm.EndBlock(ctx, req) -} - // InitChainer application update at chain initialization func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { var genesisState GenesisState @@ -1443,10 +1419,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ } } - endBlockResp = app.EndBlock(ctx, abci.RequestEndBlock{ - Height: req.GetHeight(), - BlockGasUsed: evmTotalGasUsed, - }) + endBlockResp = app.EndBlock(ctx, req.GetHeight(), evmTotalGasUsed) events = append(events, endBlockResp.Events...) return events, txResults, endBlockResp, nil diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index b41ead0d45..12de421d03 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -120,8 +120,7 @@ func (s *KeeperTestHelper) SetupTokenFactory() { // EndBlock ends the block. func (s *KeeperTestHelper) EndBlock() { - reqEndBlock := abci.RequestEndBlock{Height: s.Ctx.BlockHeight()} - s.App.EndBlocker(s.Ctx, reqEndBlock) + legacyabci.EndBlock(s.Ctx, s.Ctx.BlockHeight(), 0, s.App.EndBlockKeepers) } // AllocateRewardsToValidator allocates reward tokens to a distribution module then allocates rewards to the validator address. diff --git a/app/legacyabci/begin_block.go b/app/legacyabci/begin_block.go index a59986c0a8..8197a85b7f 100644 --- a/app/legacyabci/begin_block.go +++ b/app/legacyabci/begin_block.go @@ -56,6 +56,9 @@ func BeginBlock( slashing.BeginBlocker(ctx, votes, *keepers.SlashingKeeper) evidence.BeginBlocker(ctx, byzantineValidators, *keepers.EvidenceKeeper) staking.BeginBlocker(ctx, *keepers.StakingKeeper) - ibcclient.BeginBlocker(ctx, keepers.IBCKeeper.ClientKeeper) + func() { + defer telemetry.ModuleMeasureSince("ibc", time.Now(), telemetry.MetricKeyBeginBlocker) + ibcclient.BeginBlocker(ctx, keepers.IBCKeeper.ClientKeeper) + }() keepers.EvmKeeper.BeginBlock(ctx) } diff --git a/app/legacyabci/end_block.go b/app/legacyabci/end_block.go new file mode 100644 index 0000000000..59f68a9e69 --- /dev/null +++ b/app/legacyabci/end_block.go @@ -0,0 +1,32 @@ +package legacyabci + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + "github.com/cosmos/cosmos-sdk/x/gov" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper" + "github.com/sei-protocol/sei-chain/x/oracle" + oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper" + abci "github.com/tendermint/tendermint/abci/types" +) + +type EndBlockKeepers struct { + CrisisKeeper *crisiskeeper.Keeper + GovKeeper *govkeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + OracleKeeper *oraclekeeper.Keeper + EvmKeeper *evmkeeper.Keeper +} + +func EndBlock(ctx sdk.Context, height int64, blockGasUsed int64, keepers EndBlockKeepers) []abci.ValidatorUpdate { + crisis.EndBlocker(ctx, *keepers.CrisisKeeper) + gov.EndBlocker(ctx, *keepers.GovKeeper) + vals := staking.EndBlocker(ctx, *keepers.StakingKeeper) + oracle.EndBlocker(ctx, *keepers.OracleKeeper) + keepers.EvmKeeper.EndBlock(ctx, height, blockGasUsed) + return vals +} diff --git a/app/test_helpers.go b/app/test_helpers.go index 1ce28bc218..5c019031f2 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -205,8 +205,7 @@ func (s *TestWrapper) BeginBlock() { } func (s *TestWrapper) EndBlock() { - reqEndBlock := abci.RequestEndBlock{Height: s.Ctx.BlockHeight()} - s.App.EndBlocker(s.Ctx, reqEndBlock) + legacyabci.EndBlock(s.Ctx, s.Ctx.BlockHeight(), 0, s.App.EndBlockKeepers) } func setupReceiptStore() (seidbtypes.StateStore, error) { diff --git a/sei-cosmos/tests/mocks/types_module_module.go b/sei-cosmos/tests/mocks/types_module_module.go index 26a0137d0a..6d61dc1081 100644 --- a/sei-cosmos/tests/mocks/types_module_module.go +++ b/sei-cosmos/tests/mocks/types_module_module.go @@ -448,20 +448,6 @@ func (mr *MockAppModuleMockRecorder) MidBlock(arg0, arg1 interface{}) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MidBlock", reflect.TypeOf((*MockAppModule)(nil).MidBlock), arg0, arg1) } -// EndBlock mocks base method. -func (m *MockAppModule) EndBlock(arg0 types0.Context, arg1 abci.RequestEndBlock) []abci.ValidatorUpdate { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) - ret0, _ := ret[0].([]abci.ValidatorUpdate) - return ret0 -} - -// EndBlock indicates an expected call of EndBlock. -func (mr *MockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModule)(nil).EndBlock), arg0, arg1) -} - // ExportGenesis mocks base method. func (m *MockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() @@ -1317,20 +1303,6 @@ func (mr *MockEndBlockAppModuleMockRecorder) DefaultGenesis(arg0 interface{}) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultGenesis", reflect.TypeOf((*MockEndBlockAppModule)(nil).DefaultGenesis), arg0) } -// EndBlock mocks base method. -func (m *MockEndBlockAppModule) EndBlock(arg0 types0.Context, arg1 types1.RequestEndBlock) []types1.ValidatorUpdate { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "EndBlock", arg0, arg1) - ret0, _ := ret[0].([]types1.ValidatorUpdate) - return ret0 -} - -// EndBlock indicates an expected call of EndBlock. -func (mr *MockEndBlockAppModuleMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockEndBlockAppModule)(nil).EndBlock), arg0, arg1) -} - // ExportGenesis mocks base method. func (m *MockEndBlockAppModule) ExportGenesis(arg0 types0.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() diff --git a/sei-cosmos/types/module/module.go b/sei-cosmos/types/module/module.go index 7ca036a682..32233f0a16 100644 --- a/sei-cosmos/types/module/module.go +++ b/sei-cosmos/types/module/module.go @@ -258,11 +258,6 @@ func (gam GenesisOnlyAppModule) RegisterServices(Configurator) {} // ConsensusVersion implements AppModule/ConsensusVersion. func (gam GenesisOnlyAppModule) ConsensusVersion() uint64 { return 1 } -// EndBlock returns an empty module end-block -func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // Manager defines a module manager that provides the high level utility for managing and executing // operations for a group of modules type Manager struct { @@ -270,7 +265,6 @@ type Manager struct { OrderInitGenesis []string OrderExportGenesis []string OrderMidBlockers []string - OrderEndBlockers []string OrderMigrations []string } @@ -288,7 +282,6 @@ func NewManager(modules ...AppModule) *Manager { Modules: moduleMap, OrderInitGenesis: modulesStr, OrderExportGenesis: modulesStr, - OrderEndBlockers: modulesStr, } } @@ -309,12 +302,6 @@ func (m *Manager) SetOrderMidBlockers(moduleNames ...string) { m.OrderMidBlockers = moduleNames } -// SetOrderEndBlockers sets the order of set end-blocker calls -func (m *Manager) SetOrderEndBlockers(moduleNames ...string) { - m.assertNoForgottenModules("SetOrderEndBlockers", moduleNames) - m.OrderEndBlockers = moduleNames -} - // SetOrderMigrations sets the order of migrations to be run. If not set // then migrations will be run with an order defined in `DefaultMigrationsOrder`. func (m *Manager) SetOrderMigrations(moduleNames ...string) { @@ -604,39 +591,6 @@ func (m *Manager) MidBlock(ctx sdk.Context, height int64) []abci.Event { return ctx.EventManager().ABCIEvents() } -// EndBlock performs end block functionality for all modules. It creates a -// child context with an event manager to aggregate events emitted from all -// modules. -func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - validatorUpdates := []abci.ValidatorUpdate{} - defer telemetry.MeasureSince(time.Now(), "module", "total_end_block") - for _, moduleName := range m.OrderEndBlockers { - module, ok := m.Modules[moduleName].(EndBlockAppModule) - if !ok { - continue - } - moduleStartTime := time.Now() - moduleValUpdates := module.EndBlock(ctx, req) - telemetry.ModuleMeasureSince(moduleName, moduleStartTime, "module", "end_block") - // use these validator updates if provided, the module manager assumes - // only one module will update the validator set - if len(moduleValUpdates) > 0 { - if len(validatorUpdates) > 0 { - panic("validator EndBlock updates already set by a previous module") - } - - validatorUpdates = moduleValUpdates - } - - } - - return abci.ResponseEndBlock{ - ValidatorUpdates: validatorUpdates, - Events: ctx.EventManager().ABCIEvents(), - } -} - // GetVersionMap gets consensus version from all modules func (m *Manager) GetVersionMap() VersionMap { vermap := make(VersionMap) diff --git a/sei-cosmos/types/module/module_test.go b/sei-cosmos/types/module/module_test.go index 68e358dd50..ad30fbfd57 100644 --- a/sei-cosmos/types/module/module_test.go +++ b/sei-cosmos/types/module/module_test.go @@ -111,10 +111,6 @@ func TestManagerOrderSetters(t *testing.T) { require.Empty(t, mm.OrderMidBlockers) mm.SetOrderMidBlockers("module2", "module1") require.Equal(t, []string{"module2", "module1"}, mm.OrderMidBlockers) - - require.Equal(t, []string{"module1", "module2"}, mm.OrderEndBlockers) - mm.SetOrderEndBlockers("module2", "module1") - require.Equal(t, []string{"module2", "module1"}, mm.OrderEndBlockers) } func TestManager_RegisterInvariants(t *testing.T) { @@ -262,28 +258,3 @@ func TestManager_MidBlock(t *testing.T) { mockAppModule2.EXPECT().MidBlock(gomock.Any(), gomock.Eq(height)).Times(1) mm.MidBlock(sdk.NewContext(nil, tmproto.Header{}, false, nil), height) } - -func TestManager_EndBlock(t *testing.T) { - mockCtrl := gomock.NewController(t) - t.Cleanup(mockCtrl.Finish) - - mockAppModule1 := mocks.NewMockAppModule(mockCtrl) - mockAppModule2 := mocks.NewMockAppModule(mockCtrl) - mockAppModule1.EXPECT().Name().Times(2).Return("module1") - mockAppModule2.EXPECT().Name().Times(2).Return("module2") - mm := module.NewManager(mockAppModule1, mockAppModule2) - require.NotNil(t, mm) - require.Equal(t, 2, len(mm.Modules)) - - req := abci.RequestEndBlock{Height: 10} - - mockAppModule1.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}}) - mockAppModule2.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1) - ret := mm.EndBlock(sdk.NewContext(nil, tmproto.Header{}, false, nil), req) - require.Equal(t, []abci.ValidatorUpdate{{}}, ret.ValidatorUpdates) - - // test panic - mockAppModule1.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}}) - mockAppModule2.EXPECT().EndBlock(gomock.Any(), gomock.Eq(req)).Times(1).Return([]abci.ValidatorUpdate{{}}) - require.Panics(t, func() { mm.EndBlock(sdk.NewContext(nil, tmproto.Header{}, false, nil), req) }) -} diff --git a/sei-cosmos/x/crisis/module.go b/sei-cosmos/x/crisis/module.go index 42c39ca310..3c92a8db5a 100644 --- a/sei-cosmos/x/crisis/module.go +++ b/sei-cosmos/x/crisis/module.go @@ -177,10 +177,3 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } - -// EndBlock returns the end blocker for the crisis module. It returns no validator -// updates. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - EndBlocker(ctx, *am.keeper) - return []abci.ValidatorUpdate{} -} diff --git a/sei-cosmos/x/feegrant/module/module.go b/sei-cosmos/x/feegrant/module/module.go index e789e45945..21a748578b 100644 --- a/sei-cosmos/x/feegrant/module/module.go +++ b/sei-cosmos/x/feegrant/module/module.go @@ -188,9 +188,3 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } - -// EndBlock returns the end blocker for the feegrant module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} diff --git a/sei-cosmos/x/gov/module.go b/sei-cosmos/x/gov/module.go index 8ef3a291a4..b201eff7fb 100644 --- a/sei-cosmos/x/gov/module.go +++ b/sei-cosmos/x/gov/module.go @@ -200,10 +200,3 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } - -// EndBlock returns the end blocker for the gov module. It returns no validator -// updates. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - EndBlocker(ctx, am.keeper) - return []abci.ValidatorUpdate{} -} diff --git a/sei-cosmos/x/staking/module.go b/sei-cosmos/x/staking/module.go index ce412479b5..f1ee1ff2d3 100644 --- a/sei-cosmos/x/staking/module.go +++ b/sei-cosmos/x/staking/module.go @@ -177,9 +177,3 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } - -// EndBlock returns the end blocker for the staking module. It returns no validator -// updates. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return EndBlocker(ctx, am.keeper) -} diff --git a/sei-wasmd/app/app.go b/sei-wasmd/app/app.go index bb806d7f19..182f40fc92 100644 --- a/sei-wasmd/app/app.go +++ b/sei-wasmd/app/app.go @@ -21,6 +21,7 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/genesis" + "github.com/cosmos/cosmos-sdk/types/legacytm" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/utils" "github.com/cosmos/cosmos-sdk/x/auth" @@ -574,30 +575,6 @@ func NewWasmApp( crisis.NewAppModule(&app.crisisKeeper, skipGenesisInvariants), // always be last to make sure that it checks for all invariants and not only part of them ) - app.mm.SetOrderEndBlockers( - crisistypes.ModuleName, - govtypes.ModuleName, - stakingtypes.ModuleName, - capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - minttypes.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - authz.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - upgradetypes.ModuleName, - vestingtypes.ModuleName, - // additional non simd modules - ibctransfertypes.ModuleName, - ibchost.ModuleName, - icatypes.ModuleName, - wasm.ModuleName, - ) - // NOTE: The genutils module must occur after staking so that pools are // properly initialized with tokens from genesis accounts. // NOTE: Capability module must occur first so that it can initialize any capabilities @@ -665,7 +642,6 @@ func NewWasmApp( app.SetAnteHandler(anteHandler) app.SetInitChainer(app.InitChainer) - app.SetEndBlocker(app.EndBlocker) app.SetPrepareProposalHandler(app.PrepareProposalHandler) app.SetProcessProposalHandler(app.ProcessProposalHandler) app.SetFinalizeBlocker(app.FinalizeBlocker) @@ -723,8 +699,8 @@ func (app *WasmApp) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestPro func (app *WasmApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) { capability.BeginBlocker(ctx, *app.capabilityKeeper) distr.BeginBlocker(ctx, []abci.VoteInfo{}, app.distrKeeper) - slashing.BeginBlocker(ctx, []abci.VoteInfo{}, *&app.slashingKeeper) - evidence.BeginBlocker(ctx, []abci.Misbehavior{}, *&app.evidenceKeeper) + slashing.BeginBlocker(ctx, []abci.VoteInfo{}, app.slashingKeeper) + evidence.BeginBlocker(ctx, []abci.Misbehavior{}, app.evidenceKeeper) staking.BeginBlocker(ctx, app.stakingKeeper) ibcclient.BeginBlocker(ctx, app.ibcKeeper.ClientKeeper) events := []abci.Event{} @@ -756,10 +732,9 @@ func (app *WasmApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBl Codespace: deliverTxResp.Codespace, }) } - endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ - Height: req.Height, - }) - events = append(events, endBlockResp.Events...) + vals := app.EndBlocker(ctx) + events = append(events, sdk.MarkEventsToIndex(ctx.EventManager().ABCIEvents(), app.IndexEvents)...) + cpUpdates := legacytm.ABCIToLegacyConsensusParams(app.GetConsensusParams(ctx)) app.SetDeliverStateToCommit() app.WriteState() @@ -767,7 +742,7 @@ func (app *WasmApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBl return &abci.ResponseFinalizeBlock{ Events: events, TxResults: txResults, - ValidatorUpdates: utils.Map(endBlockResp.ValidatorUpdates, func(v abci.ValidatorUpdate) abci.ValidatorUpdate { + ValidatorUpdates: utils.Map(vals, func(v abci.ValidatorUpdate) abci.ValidatorUpdate { return abci.ValidatorUpdate{ PubKey: v.PubKey, Power: v.Power, @@ -775,30 +750,25 @@ func (app *WasmApp) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBl }), ConsensusParamUpdates: &tmproto.ConsensusParams{ Block: &tmproto.BlockParams{ - MaxBytes: endBlockResp.ConsensusParamUpdates.Block.MaxBytes, - MaxGas: endBlockResp.ConsensusParamUpdates.Block.MaxGas, + MaxBytes: cpUpdates.Block.MaxBytes, + MaxGas: cpUpdates.Block.MaxGas, }, Evidence: &tmproto.EvidenceParams{ - MaxAgeNumBlocks: endBlockResp.ConsensusParamUpdates.Evidence.MaxAgeNumBlocks, - MaxAgeDuration: endBlockResp.ConsensusParamUpdates.Evidence.MaxAgeDuration, - MaxBytes: endBlockResp.ConsensusParamUpdates.Block.MaxBytes, + MaxAgeNumBlocks: cpUpdates.Evidence.MaxAgeNumBlocks, + MaxAgeDuration: cpUpdates.Evidence.MaxAgeDuration, + MaxBytes: cpUpdates.Evidence.MaxBytes, }, Validator: &tmproto.ValidatorParams{ - PubKeyTypes: endBlockResp.ConsensusParamUpdates.Validator.PubKeyTypes, + PubKeyTypes: cpUpdates.Validator.PubKeyTypes, }, Version: &tmproto.VersionParams{ - AppVersion: endBlockResp.ConsensusParamUpdates.Version.AppVersion, + AppVersion: cpUpdates.Version.AppVersion, }, }, AppHash: appHash, }, nil } -// EndBlocker application updates every end block -func (app *WasmApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { - return app.mm.EndBlock(ctx, req) -} - // InitChainer application update at chain initialization func (app *WasmApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { var genesisState GenesisState @@ -811,6 +781,12 @@ func (app *WasmApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci return app.mm.InitGenesis(ctx, app.appCodec, genesisState, genesis.GenesisImportConfig{}) } +func (app *WasmApp) EndBlocker(ctx sdk.Context) []abci.ValidatorUpdate { + crisis.EndBlocker(ctx, app.crisisKeeper) + gov.EndBlocker(ctx, app.govKeeper) + return staking.EndBlocker(ctx, app.stakingKeeper) +} + // LoadHeight loads a particular height func (app *WasmApp) LoadHeight(height int64) error { return app.LoadVersion(height) diff --git a/sei-wasmd/benchmarks/app_test.go b/sei-wasmd/benchmarks/app_test.go index 9ca3ca9159..e532d4e2a8 100644 --- a/sei-wasmd/benchmarks/app_test.go +++ b/sei-wasmd/benchmarks/app_test.go @@ -167,7 +167,7 @@ func InitializeWasmApp(b testing.TB, db dbm.DB, numAccounts int) AppInfo { attr := evt.Attributes[0] contractAddr := string(attr.Value) - wasmApp.EndBlock(wasmApp.GetContextForDeliverTx([]byte{}), abci.RequestEndBlock{Height: height}) + wasmApp.EndBlock(wasmApp.GetContextForDeliverTx([]byte{}), height, 0) wasmApp.SetDeliverStateToCommit() wasmApp.Commit(context.Background()) diff --git a/sei-wasmd/benchmarks/bench_test.go b/sei-wasmd/benchmarks/bench_test.go index 6a3fbbd5bb..79a1b46fc8 100644 --- a/sei-wasmd/benchmarks/bench_test.go +++ b/sei-wasmd/benchmarks/bench_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" "github.com/syndtr/goleveldb/leveldb/opt" - abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -114,7 +113,7 @@ func BenchmarkTxSending(b *testing.B) { require.NoError(b, err) } - appInfo.App.EndBlock(appInfo.App.GetContextForDeliverTx([]byte{}), abci.RequestEndBlock{Height: height}) + appInfo.App.EndBlock(appInfo.App.GetContextForDeliverTx([]byte{}), height, 0) appInfo.App.SetDeliverStateToCommit() appInfo.App.Commit(context.Background()) height++ diff --git a/sei-wasmd/x/wasm/module.go b/sei-wasmd/x/wasm/module.go index 7d7ca9fa1f..e70ab444e9 100644 --- a/sei-wasmd/x/wasm/module.go +++ b/sei-wasmd/x/wasm/module.go @@ -203,12 +203,6 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- return chRaw } -// EndBlock returns the end blocker for the wasm module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - // ____________________________________________________________________________ // AddModuleInitFlags implements servertypes.ModuleInitFlags interface. diff --git a/x/epoch/keeper/abci.go b/x/epoch/keeper/abci.go index fcd476b9ea..c410b7c9b6 100644 --- a/x/epoch/keeper/abci.go +++ b/x/epoch/keeper/abci.go @@ -2,13 +2,16 @@ package keeper import ( "fmt" + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sei-protocol/sei-chain/utils/metrics" "github.com/sei-protocol/sei-chain/x/epoch/types" ) func (k Keeper) BeginBlock(ctx sdk.Context) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) lastEpoch := k.GetEpoch(ctx) ctx.Logger().Info(fmt.Sprintf("Current block time %s, last %s; duration %d", ctx.BlockTime().String(), lastEpoch.CurrentEpochStartTime.String(), lastEpoch.EpochDuration)) diff --git a/x/epoch/module.go b/x/epoch/module.go index 34232b2d45..efb2b08a1b 100644 --- a/x/epoch/module.go +++ b/x/epoch/module.go @@ -186,9 +186,3 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 2 } - -// EndBlock executes all ABCI EndBlock logic respective to the capability module. It -// returns no validator updates. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} diff --git a/x/epoch/module_test.go b/x/epoch/module_test.go index 3790030fde..9586bd8284 100644 --- a/x/epoch/module_test.go +++ b/x/epoch/module_test.go @@ -12,7 +12,6 @@ import ( epoch "github.com/sei-protocol/sei-chain/x/epoch" "github.com/sei-protocol/sei-chain/x/epoch/types" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) @@ -26,7 +25,6 @@ func TestBasic(t *testing.T) { app.AccountKeeper, app.BankKeeper, ) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) require.Equal(t, appModule.Name(), types.ModuleName) appModule.RegisterCodec(app.LegacyAmino()) @@ -35,7 +33,6 @@ func TestBasic(t *testing.T) { require.NotNil(t, appModule.GetQueryCmd()) require.Equal(t, appModule.Route().Path(), types.RouterKey) - require.Equal(t, appModule.EndBlock(ctx, abci.RequestEndBlock{}), []abci.ValidatorUpdate{}) } // This test is just to make sure that the routes can be added without crashing diff --git a/x/evm/keeper/abci.go b/x/evm/keeper/abci.go index 44f72bb33d..11774e3c8f 100644 --- a/x/evm/keeper/abci.go +++ b/x/evm/keeper/abci.go @@ -1,18 +1,27 @@ package keeper import ( + "fmt" "math" + "time" + ethtypes "github.com/ethereum/go-ethereum/core/types" + + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/vm" + "github.com/sei-protocol/sei-chain/utils" + "github.com/sei-protocol/sei-chain/utils/metrics" "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/sei-protocol/sei-chain/x/evm/types" abci "github.com/tendermint/tendermint/abci/types" ) func (k *Keeper) BeginBlock(ctx sdk.Context) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) // clear tx/tx responses from last block if !ctx.IsTracing() { k.SetMsgs([]*types.MsgEVMTransaction{}) @@ -49,3 +58,106 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) { } } } + +func (k *Keeper) EndBlock(ctx sdk.Context, height int64, blockGasUsed int64) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + // TODO: remove after all TxHashes have been removed + k.RemoveFirstNTxHashes(ctx, DefaultTxHashesToRemove) + + // Migrate legacy EVM receipts to receipt.db in small batches every N blocks + if ctx.BlockHeight()%LegacyReceiptMigrationInterval == 0 { + if migrated, err := k.MigrateLegacyReceiptsBatch(ctx, LegacyReceiptMigrationBatchSize); err != nil { + ctx.Logger().Error(fmt.Sprintf("failed migrating legacy receipts: %s", err)) + } else if migrated > 0 { + ctx.Logger().Info(fmt.Sprintf("migrated %d legacy EVM receipts to receipt.db", migrated)) + } + } + + if scanned, deleted := k.PruneZeroStorageSlots(ctx, ZeroStorageCleanupBatchSize); deleted > 0 { + ctx.Logger().Info(fmt.Sprintf("pruned %d zero-value contract storage slots while scanning %d keys", deleted, scanned)) + } + + newBaseFee := k.AdjustDynamicBaseFeePerGas(ctx, uint64(blockGasUsed)) // nolint:gosec + if newBaseFee != nil { + metrics.GaugeEvmBlockBaseFee(newBaseFee.TruncateInt().BigInt(), height) + } + var coinbase sdk.AccAddress + if k.EthBlockTestConfig.Enabled { + blocks := k.BlockTest.Json.Blocks + block, err := blocks[ctx.BlockHeight()-1].Decode() + if err != nil { + panic(err) + } + coinbase = k.GetSeiAddressOrDefault(ctx, block.Header_.Coinbase) + } else if k.EthReplayConfig.Enabled { + coinbase = k.GetSeiAddressOrDefault(ctx, k.ReplayBlock.Header_.Coinbase) + k.SetReplayedHeight(ctx) + } else { + coinbase = k.AccountKeeper().GetModuleAddress(authtypes.FeeCollectorName) + } + evmTxDeferredInfoList := k.GetAllEVMTxDeferredInfo(ctx) + denom := k.GetBaseDenom(ctx) + surplus := k.GetAnteSurplusSum(ctx) + for _, deferredInfo := range evmTxDeferredInfoList { + txHash := common.BytesToHash(deferredInfo.TxHash) + if deferredInfo.Error != "" && txHash.Cmp(ethtypes.EmptyTxsHash) != 0 { + _ = k.SetTransientReceipt(ctx, txHash, &types.Receipt{ + TxHashHex: txHash.Hex(), + TransactionIndex: deferredInfo.TxIndex, + VmError: deferredInfo.Error, + BlockNumber: uint64(ctx.BlockHeight()), // nolint:gosec + }) + continue + } + idx := int(deferredInfo.TxIndex) + coinbaseAddress := state.GetCoinbaseAddress(idx) + useiBalance := k.BankKeeper().GetBalance(ctx, coinbaseAddress, denom).Amount + lockedUseiBalance := k.BankKeeper().LockedCoins(ctx, coinbaseAddress).AmountOf(denom) + balance := useiBalance.Sub(lockedUseiBalance) + weiBalance := k.BankKeeper().GetWeiBalance(ctx, coinbaseAddress) + if !balance.IsZero() || !weiBalance.IsZero() { + if err := k.BankKeeper().SendCoinsAndWei(ctx, coinbaseAddress, coinbase, balance, weiBalance); err != nil { + ctx.Logger().Error(fmt.Sprintf("failed to send usei surplus from %s to coinbase account due to %s", coinbaseAddress.String(), err)) + } + } + surplus = surplus.Add(deferredInfo.Surplus) + } + if surplus.IsPositive() { + surplusUsei, surplusWei := state.SplitUseiWeiAmount(surplus.BigInt()) + if surplusUsei.GT(sdk.ZeroInt()) { + if err := k.BankKeeper().AddCoins(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), surplusUsei)), true); err != nil { + ctx.Logger().Error("failed to send usei surplus of %s to EVM module account", surplusUsei) + } + } + if surplusWei.GT(sdk.ZeroInt()) { + if err := k.BankKeeper().AddWei(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), surplusWei); err != nil { + ctx.Logger().Error("failed to send wei surplus of %s to EVM module account", surplusWei) + } + } + } + allBlooms := utils.Map(evmTxDeferredInfoList, func(i *types.DeferredInfo) ethtypes.Bloom { return ethtypes.BytesToBloom(i.TxBloom) }) + evmOnlyBlooms := make([]ethtypes.Bloom, 0, len(evmTxDeferredInfoList)) + for _, di := range evmTxDeferredInfoList { + if len(di.TxHash) == 0 { + continue + } + r, err := k.GetTransientReceipt(ctx, common.BytesToHash(di.TxHash), uint64(di.TxIndex)) + if err != nil { + continue + } + // Only EVM receipts in this block that are not synthetic + if r.TxType == types.ShellEVMTxType || r.BlockNumber != uint64(ctx.BlockHeight()) { //nolint:gosec + continue + } + if len(r.Logs) == 0 { + continue + } + // Re-create a per-tx bloom from EVM-only logs (exclude synthetic receipts but not synthetic logs) + evmOnlyBloom := ethtypes.CreateBloom(ðtypes.Receipt{ + Logs: GetLogsForTx(r, 0), + }) + evmOnlyBlooms = append(evmOnlyBlooms, evmOnlyBloom) + } + k.SetBlockBloom(ctx, allBlooms) + k.SetEvmOnlyBlockBloom(ctx, evmOnlyBlooms) +} diff --git a/x/evm/module.go b/x/evm/module.go index cb635d522e..7baed53847 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -6,8 +6,7 @@ import ( "fmt" // this line is used by starport scaffolding # 1 - "github.com/ethereum/go-ethereum/common" - ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -19,13 +18,9 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/sei-protocol/sei-chain/utils" - "github.com/sei-protocol/sei-chain/utils/metrics" "github.com/sei-protocol/sei-chain/x/evm/client/cli" "github.com/sei-protocol/sei-chain/x/evm/keeper" "github.com/sei-protocol/sei-chain/x/evm/migrations" - "github.com/sei-protocol/sei-chain/x/evm/state" "github.com/sei-protocol/sei-chain/x/evm/types" ) @@ -287,109 +282,3 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 21 } - -// EndBlock executes all ABCI EndBlock logic respective to the evm module. It -// returns no validator updates. -func (am AppModule) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) []abci.ValidatorUpdate { - // TODO: remove after all TxHashes have been removed - am.keeper.RemoveFirstNTxHashes(ctx, keeper.DefaultTxHashesToRemove) - - // Migrate legacy EVM receipts to receipt.db in small batches every N blocks - if ctx.BlockHeight()%keeper.LegacyReceiptMigrationInterval == 0 { - if migrated, err := am.keeper.MigrateLegacyReceiptsBatch(ctx, keeper.LegacyReceiptMigrationBatchSize); err != nil { - ctx.Logger().Error(fmt.Sprintf("failed migrating legacy receipts: %s", err)) - } else if migrated > 0 { - ctx.Logger().Info(fmt.Sprintf("migrated %d legacy EVM receipts to receipt.db", migrated)) - } - } - - if scanned, deleted := am.keeper.PruneZeroStorageSlots(ctx, keeper.ZeroStorageCleanupBatchSize); deleted > 0 { - ctx.Logger().Info(fmt.Sprintf("pruned %d zero-value contract storage slots while scanning %d keys", deleted, scanned)) - } - - newBaseFee := am.keeper.AdjustDynamicBaseFeePerGas(ctx, uint64(req.BlockGasUsed)) // nolint:gosec - if newBaseFee != nil { - metrics.GaugeEvmBlockBaseFee(newBaseFee.TruncateInt().BigInt(), req.Height) - } - var coinbase sdk.AccAddress - if am.keeper.EthBlockTestConfig.Enabled { - blocks := am.keeper.BlockTest.Json.Blocks - block, err := blocks[ctx.BlockHeight()-1].Decode() - if err != nil { - panic(err) - } - coinbase = am.keeper.GetSeiAddressOrDefault(ctx, block.Header_.Coinbase) - } else if am.keeper.EthReplayConfig.Enabled { - coinbase = am.keeper.GetSeiAddressOrDefault(ctx, am.keeper.ReplayBlock.Header_.Coinbase) - am.keeper.SetReplayedHeight(ctx) - } else { - coinbase = am.keeper.AccountKeeper().GetModuleAddress(authtypes.FeeCollectorName) - } - evmTxDeferredInfoList := am.keeper.GetAllEVMTxDeferredInfo(ctx) - denom := am.keeper.GetBaseDenom(ctx) - surplus := am.keeper.GetAnteSurplusSum(ctx) - for _, deferredInfo := range evmTxDeferredInfoList { - txHash := common.BytesToHash(deferredInfo.TxHash) - if deferredInfo.Error != "" && txHash.Cmp(ethtypes.EmptyTxsHash) != 0 { - _ = am.keeper.SetTransientReceipt(ctx, txHash, &types.Receipt{ - TxHashHex: txHash.Hex(), - TransactionIndex: deferredInfo.TxIndex, - VmError: deferredInfo.Error, - BlockNumber: uint64(ctx.BlockHeight()), // nolint:gosec - }) - continue - } - idx := int(deferredInfo.TxIndex) - coinbaseAddress := state.GetCoinbaseAddress(idx) - useiBalance := am.keeper.BankKeeper().GetBalance(ctx, coinbaseAddress, denom).Amount - lockedUseiBalance := am.keeper.BankKeeper().LockedCoins(ctx, coinbaseAddress).AmountOf(denom) - balance := useiBalance.Sub(lockedUseiBalance) - weiBalance := am.keeper.BankKeeper().GetWeiBalance(ctx, coinbaseAddress) - if !balance.IsZero() || !weiBalance.IsZero() { - if err := am.keeper.BankKeeper().SendCoinsAndWei(ctx, coinbaseAddress, coinbase, balance, weiBalance); err != nil { - ctx.Logger().Error(fmt.Sprintf("failed to send usei surplus from %s to coinbase account due to %s", coinbaseAddress.String(), err)) - } - } - surplus = surplus.Add(deferredInfo.Surplus) - } - if surplus.IsPositive() { - surplusUsei, surplusWei := state.SplitUseiWeiAmount(surplus.BigInt()) - if surplusUsei.GT(sdk.ZeroInt()) { - if err := am.keeper.BankKeeper().AddCoins(ctx, am.keeper.AccountKeeper().GetModuleAddress(types.ModuleName), sdk.NewCoins(sdk.NewCoin(am.keeper.GetBaseDenom(ctx), surplusUsei)), true); err != nil { - ctx.Logger().Error("failed to send usei surplus of %s to EVM module account", surplusUsei) - } - } - if surplusWei.GT(sdk.ZeroInt()) { - if err := am.keeper.BankKeeper().AddWei(ctx, am.keeper.AccountKeeper().GetModuleAddress(types.ModuleName), surplusWei); err != nil { - ctx.Logger().Error("failed to send wei surplus of %s to EVM module account", surplusWei) - } - } - } - allBlooms := utils.Map(evmTxDeferredInfoList, func(i *types.DeferredInfo) ethtypes.Bloom { return ethtypes.BytesToBloom(i.TxBloom) }) - evmOnlyBlooms := make([]ethtypes.Bloom, 0, len(evmTxDeferredInfoList)) - for _, di := range evmTxDeferredInfoList { - if len(di.TxHash) == 0 { - continue - } - r, err := am.keeper.GetTransientReceipt(ctx, common.BytesToHash(di.TxHash), uint64(di.TxIndex)) - if err != nil { - continue - } - // Only EVM receipts in this block that are not synthetic - if r.TxType == types.ShellEVMTxType || r.BlockNumber != uint64(ctx.BlockHeight()) { //nolint:gosec - continue - } - if len(r.Logs) == 0 { - continue - } - // Re-create a per-tx bloom from EVM-only logs (exclude synthetic receipts but not synthetic logs) - evmOnlyBloom := ethtypes.CreateBloom(ðtypes.Receipt{ - Logs: keeper.GetLogsForTx(r, 0), - }) - evmOnlyBlooms = append(evmOnlyBlooms, evmOnlyBloom) - } - am.keeper.SetBlockBloom(ctx, allBlooms) - am.keeper.SetEvmOnlyBlockBloom(ctx, evmOnlyBlooms) - - return []abci.ValidatorUpdate{} -} diff --git a/x/evm/module_test.go b/x/evm/module_test.go index 850056ed65..ce98b785fb 100644 --- a/x/evm/module_test.go +++ b/x/evm/module_test.go @@ -71,7 +71,6 @@ func TestABCI(t *testing.T) { amt := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10))) k.BankKeeper().MintCoins(ctx, types.ModuleName, amt) k.BankKeeper().SendCoinsFromModuleToAccount(ctx, types.ModuleName, sdk.AccAddress(evmAddr1[:]), amt) - m := evm.NewAppModule(nil, k) // first block k.BeginBlock(ctx) // 1st tx @@ -95,7 +94,7 @@ func TestABCI(t *testing.T) { k.AppendToEvmTxDeferredInfo(ctx.WithTxIndex(3), ethtypes.Bloom{}, common.Hash{3}, surplus) k.SetTxResults([]*abci.ExecTxResult{{Code: 0}, {Code: 0}, {Code: 0}, {Code: 0}}) k.SetMsgs([]*types.MsgEVMTransaction{nil, {}, nil, {}}) - m.EndBlock(ctx, abci.RequestEndBlock{}) + k.EndBlock(ctx, 0, 0) require.Equal(t, uint64(0), k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), "usei").Amount.Uint64()) require.Equal(t, uint64(2), k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(authtypes.FeeCollectorName), "usei").Amount.Uint64()) @@ -111,7 +110,7 @@ func TestABCI(t *testing.T) { k.AppendToEvmTxDeferredInfo(ctx.WithTxIndex(2), ethtypes.Bloom{}, common.Hash{2}, surplus) k.SetTxResults([]*abci.ExecTxResult{{Code: 0}, {Code: 0}, {Code: 0}}) k.SetMsgs([]*types.MsgEVMTransaction{nil, nil, {}}) - m.EndBlock(ctx, abci.RequestEndBlock{}) + k.EndBlock(ctx, 0, 0) require.Equal(t, uint64(1), k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), "usei").Amount.Uint64()) require.Equal(t, uint64(2), k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(authtypes.FeeCollectorName), "usei").Amount.Uint64()) @@ -120,7 +119,7 @@ func TestABCI(t *testing.T) { msg := mockEVMTransactionMessage(t) k.SetMsgs([]*types.MsgEVMTransaction{msg}) k.SetTxResults([]*abci.ExecTxResult{{Code: 1, Log: "test error"}}) - m.EndBlock(ctx, abci.RequestEndBlock{}) + k.EndBlock(ctx, 0, 0) err = k.FlushTransientReceipts(ctx) require.NoError(t, err) tx, _ := msg.AsTransaction() @@ -146,7 +145,6 @@ func TestLegacyReceiptMigrationInterval(t *testing.T) { a := app.Setup(t, false, false, false) k := a.EvmKeeper ctx := a.GetContextForDeliverTx([]byte{}) - m := evm.NewAppModule(nil, &k) // Seed a legacy receipt directly into KV txHash := common.BytesToHash([]byte{0x42}) @@ -163,7 +161,7 @@ func TestLegacyReceiptMigrationInterval(t *testing.T) { for i := int64(1); i <= interval; i++ { ctx = ctx.WithBlockHeight(i) k.BeginBlock(ctx) - m.EndBlock(ctx, abci.RequestEndBlock{}) + k.EndBlock(ctx, 0, 0) } require.NoError(t, k.FlushTransientReceipts(ctx)) @@ -185,11 +183,10 @@ func TestAnteSurplus(t *testing.T) { a := app.Setup(t, false, false, false) k := a.EvmKeeper ctx := a.GetContextForDeliverTx([]byte{}) - m := evm.NewAppModule(nil, &k) // first block k.BeginBlock(ctx) k.AddAnteSurplus(ctx, common.BytesToHash([]byte("1234")), sdk.NewInt(1_000_000_000_001)) - m.EndBlock(ctx, abci.RequestEndBlock{}) + k.EndBlock(ctx, 0, 0) require.Equal(t, uint64(1), k.BankKeeper().GetBalance(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName), "usei").Amount.Uint64()) require.Equal(t, uint64(1), k.BankKeeper().GetWeiBalance(ctx, k.AccountKeeper().GetModuleAddress(types.ModuleName)).Uint64()) // ante surplus should be cleared diff --git a/x/mint/module.go b/x/mint/module.go index 3dcd35d618..b1475b46c8 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -175,12 +175,6 @@ func (am AppModule) ExportGenesisStream(ctx sdk.Context, cdc codec.JSONCodec) <- // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 3 } -// EndBlock returns the end blocker for the mint module. It returns no validator -// updates. -func (AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -} - func NewProposalHandler(k keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { diff --git a/x/oracle/module.go b/x/oracle/module.go index febb8f72a9..c089d3074f 100644 --- a/x/oracle/module.go +++ b/x/oracle/module.go @@ -187,9 +187,3 @@ func (AppModule) ConsensusVersion() uint64 { return 6 } func (am AppModule) MidBlock(ctx sdk.Context, _ int64) { MidBlocker(ctx, am.keeper) } - -// EndBlock returns the end blocker for the oracle module. -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) (ret []abci.ValidatorUpdate) { - EndBlocker(ctx, am.keeper) - return []abci.ValidatorUpdate{} -} diff --git a/x/tokenfactory/module.go b/x/tokenfactory/module.go index cde0f397de..56af911577 100644 --- a/x/tokenfactory/module.go +++ b/x/tokenfactory/module.go @@ -193,9 +193,3 @@ func (am AppModuleBasic) ValidateGenesisStream(cdc codec.JSONCodec, config clien // ConsensusVersion implements ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 5 } - -// EndBlock executes all ABCI EndBlock logic respective to the tokenfactory module. It -// returns no validator updates. -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - return []abci.ValidatorUpdate{} -}