Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"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"
Expand Down Expand Up @@ -50,11 +51,19 @@
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)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
res.Events = sdk.MarkEventsToIndex(ctx.EventManager().ABCIEvents(), app.IndexEvents)
if cp := app.GetConsensusParams(ctx); cp != nil {

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
res.ConsensusParamUpdates = legacytm.ABCIToLegacyConsensusParams(cp)
}
return res
}

func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTxV2) (*abci.ResponseCheckTxV2, error) {
Expand Down
45 changes: 9 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ type App struct {
TokenFactoryKeeper tokenfactorykeeper.Keeper

BeginBlockKeepers legacyabci.BeginBlockKeepers
EndBlockKeepers legacyabci.EndBlockKeepers

// mm is the module manager
mm *module.Manager
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@

// 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)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning test

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
}

// AllocateRewardsToValidator allocates reward tokens to a distribution module then allocates rewards to the validator address.
Expand Down
5 changes: 4 additions & 1 deletion app/legacyabci/begin_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
32 changes: 32 additions & 0 deletions app/legacyabci/end_block.go
Original file line number Diff line number Diff line change
@@ -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)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
gov.EndBlocker(ctx, *keepers.GovKeeper)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
vals := staking.EndBlocker(ctx, *keepers.StakingKeeper)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
oracle.EndBlocker(ctx, *keepers.OracleKeeper)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
keepers.EvmKeeper.EndBlock(ctx, height, blockGasUsed)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
return vals
}
3 changes: 1 addition & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@
}

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)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning test

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
}

func setupReceiptStore() (seidbtypes.StateStore, error) {
Expand Down
28 changes: 0 additions & 28 deletions sei-cosmos/tests/mocks/types_module_module.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 0 additions & 46 deletions sei-cosmos/types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,13 @@ 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 {
Modules map[string]AppModule
OrderInitGenesis []string
OrderExportGenesis []string
OrderMidBlockers []string
OrderEndBlockers []string
OrderMigrations []string
}

Expand All @@ -288,7 +282,6 @@ func NewManager(modules ...AppModule) *Manager {
Modules: moduleMap,
OrderInitGenesis: modulesStr,
OrderExportGenesis: modulesStr,
OrderEndBlockers: modulesStr,
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 0 additions & 29 deletions sei-cosmos/types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) })
}
7 changes: 0 additions & 7 deletions sei-cosmos/x/crisis/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
6 changes: 0 additions & 6 deletions sei-cosmos/x/feegrant/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
7 changes: 0 additions & 7 deletions sei-cosmos/x/gov/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
6 changes: 0 additions & 6 deletions sei-cosmos/x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading
Loading