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
32 changes: 30 additions & 2 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,44 @@
"context"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/app/legacyabci"
"github.com/sei-protocol/sei-chain/utils/metrics"
abci "github.com/tendermint/tendermint/abci/types"
)

func (app *App) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
func (app *App) BeginBlock(
ctx sdk.Context,
height int64,
votes []abci.VoteInfo,
byzantineValidators []abci.Misbehavior,
checkHeight bool,
) (res abci.ResponseBeginBlock) {
spanCtx, beginBlockSpan := app.GetBaseApp().TracingInfo.StartWithContext("BeginBlock", ctx.TraceSpanContext())
defer beginBlockSpan.End()
ctx = ctx.WithTraceSpanContext(spanCtx)
return app.BaseApp.BeginBlock(ctx, req)
ctx = ctx.WithEventManager(sdk.NewEventManager())
defer telemetry.MeasureSince(time.Now(), "abci", "begin_block")
// inline begin block
if checkHeight {
if err := app.ValidateHeight(height); err != 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
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
}
metrics.GaugeSeidVersionAndCommit(app.versionInfo.Version, app.versionInfo.GitCommit)
// check if we've reached a target height, if so, execute any applicable handlers
if app.forkInitializer != nil {
app.forkInitializer(ctx)
app.forkInitializer = nil
}
if app.HardForkManager.TargetHeightReached(ctx) {
app.HardForkManager.ExecuteForTargetHeight(ctx)

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
}
legacyabci.BeginBlock(ctx, height, votes, byzantineValidators, app.BeginBlockKeepers)

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 abci.ResponseBeginBlock{
Events: sdk.MarkEventsToIndex(ctx.EventManager().ABCIEvents(), app.IndexEvents),
}
}

func (app *App) MidBlock(ctx sdk.Context, height int64) []abci.Event {
Expand Down
87 changes: 17 additions & 70 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import (
"github.com/sei-protocol/sei-chain/aclmapping"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
"github.com/sei-protocol/sei-chain/app/antedecorators"
"github.com/sei-protocol/sei-chain/app/legacyabci"
appparams "github.com/sei-protocol/sei-chain/app/params"
"github.com/sei-protocol/sei-chain/app/upgrades"
v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
Expand Down Expand Up @@ -351,6 +352,8 @@ type App struct {

TokenFactoryKeeper tokenfactorykeeper.Keeper

BeginBlockKeepers legacyabci.BeginBlockKeepers

// mm is the module manager
mm *module.Manager

Expand Down Expand Up @@ -762,36 +765,17 @@ func New(
// this line is used by starport scaffolding # stargate/app/appModule
)

// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
epochmoduletypes.ModuleName,
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
oracletypes.ModuleName,
evmtypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
acltypes.ModuleName,
)
app.BeginBlockKeepers = legacyabci.BeginBlockKeepers{
EpochKeeper: &app.EpochKeeper,
UpgradeKeeper: &app.UpgradeKeeper,
CapabilityKeeper: app.CapabilityKeeper,
DistrKeeper: &app.DistrKeeper,
SlashingKeeper: &app.SlashingKeeper,
EvidenceKeeper: &app.EvidenceKeeper,
StakingKeeper: &app.StakingKeeper,
IBCKeeper: app.IBCKeeper,
EvmKeeper: &app.EvmKeeper,
}

app.mm.SetOrderMidBlockers(
oracletypes.ModuleName,
Expand Down Expand Up @@ -875,7 +859,6 @@ func New(

// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

signModeHandler := encodingConfig.TxConfig.SignModeHandler()
// app.batchVerifier = ante.NewSR25519BatchVerifier(app.AccountKeeper, signModeHandler)
Expand Down Expand Up @@ -1060,20 +1043,6 @@ func (app *App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }
// GetStateStore returns the state store of the application
func (app *App) GetStateStore() seidb.StateStore { return app.stateStore }

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
metrics.GaugeSeidVersionAndCommit(app.versionInfo.Version, app.versionInfo.GitCommit)
// check if we've reached a target height, if so, execute any applicable handlers
if app.forkInitializer != nil {
app.forkInitializer(ctx)
app.forkInitializer = nil
}
if app.HardForkManager.TargetHeightReached(ctx) {
app.HardForkManager.ExecuteForTargetHeight(ctx)
}
return app.mm.BeginBlock(ctx, req)
}

// MidBlocker application updates every mid block
func (app *App) MidBlocker(ctx sdk.Context, height int64) []abci.Event {
return app.mm.MidBlock(ctx, height)
Expand Down Expand Up @@ -1626,29 +1595,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
ctx = ctx.WithTraceSpanContext(blockSpanCtx)

events = []abci.Event{}
beginBlockReq := abci.RequestBeginBlock{
Hash: req.GetHash(),
ByzantineValidators: utils.Map(req.GetByzantineValidators(), func(mis abci.Misbehavior) abci.Evidence {
return abci.Evidence(mis)
}),
LastCommitInfo: abci.LastCommitInfo{
Round: lastCommit.Round,
Votes: utils.Map(lastCommit.Votes, func(vote abci.VoteInfo) abci.VoteInfo {
return abci.VoteInfo{
Validator: vote.Validator,
SignedLastBlock: vote.SignedLastBlock,
}
}),
},
Header: tmproto.Header{
ChainID: app.ChainID,
Height: req.GetHeight(),
Time: req.GetTime(),
ProposerAddress: ctx.BlockHeader().ProposerAddress,
},
Simulate: simulate,
}
beginBlockResp := app.BeginBlock(ctx, beginBlockReq)
beginBlockResp := app.BeginBlock(ctx, req.GetHeight(), lastCommit.Votes, req.GetByzantineValidators(), true)
events = append(events, beginBlockResp.Events...)

evmTxs := make([]*evmtypes.MsgEVMTransaction, len(txs)) // nil for non-EVM txs
Expand Down Expand Up @@ -1932,7 +1879,7 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
}

if app.evmRPCConfig.HTTPEnabled {
evmHTTPServer, err := evmrpc.NewEVMHTTPServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, app.BaseApp, app.TracerAnteHandler, app.RPCContextProvider, txConfigProvider, DefaultNodeHome, nil)
evmHTTPServer, err := evmrpc.NewEVMHTTPServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, app.BeginBlockKeepers, app.BaseApp, app.TracerAnteHandler, app.RPCContextProvider, txConfigProvider, DefaultNodeHome, nil)
if err != nil {
panic(err)
}
Expand All @@ -1945,7 +1892,7 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
}

if app.evmRPCConfig.WSEnabled {
evmWSServer, err := evmrpc.NewEVMWebSocketServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, app.BaseApp, app.TracerAnteHandler, app.RPCContextProvider, txConfigProvider, DefaultNodeHome)
evmWSServer, err := evmrpc.NewEVMWebSocketServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, app.BeginBlockKeepers, app.BaseApp, app.TracerAnteHandler, app.RPCContextProvider, txConfigProvider, DefaultNodeHome)
if err != nil {
panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/sei-protocol/sei-chain/app/legacyabci"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -67,7 +68,7 @@ func (s *KeeperTestHelper) Commit() {
panic(err)
}
newHeader := tmtypes.Header{Height: oldHeight + 1, ChainID: oldHeader.ChainID, Time: time.Now().UTC()}
s.App.BeginBlock(s.Ctx, abci.RequestBeginBlock{Header: newHeader})
legacyabci.BeginBlock(s.Ctx, newHeader.Height, []abci.VoteInfo{}, []abci.Misbehavior{}, s.App.BeginBlockKeepers)
s.Ctx = s.App.GetBaseApp().NewContext(false, newHeader)
}

Expand Down
61 changes: 61 additions & 0 deletions app/legacyabci/begin_block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package legacyabci

import (
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
abci "github.com/tendermint/tendermint/abci/types"

"github.com/cosmos/cosmos-sdk/x/distribution"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"

"github.com/cosmos/cosmos-sdk/x/evidence"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"

"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"

ibcclient "github.com/cosmos/ibc-go/v3/modules/core/02-client"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
epochmodulekeeper "github.com/sei-protocol/sei-chain/x/epoch/keeper"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
)

type BeginBlockKeepers struct {
EpochKeeper *epochmodulekeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
DistrKeeper *distrkeeper.Keeper
SlashingKeeper *slashingkeeper.Keeper
EvidenceKeeper *evidencekeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
EvmKeeper *evmkeeper.Keeper
}

func BeginBlock(
ctx sdk.Context,
height int64,
votes []abci.VoteInfo,
byzantineValidators []abci.Misbehavior,
keepers BeginBlockKeepers,
) {
defer telemetry.MeasureSince(time.Now(), "module", "total_begin_block")

keepers.EpochKeeper.BeginBlock(ctx)

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
upgrade.BeginBlocker(*keepers.UpgradeKeeper, ctx)

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
capability.BeginBlocker(ctx, *keepers.CapabilityKeeper)

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
distribution.BeginBlocker(ctx, votes, *keepers.DistrKeeper)

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
slashing.BeginBlocker(ctx, votes, *keepers.SlashingKeeper)

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
evidence.BeginBlocker(ctx, byzantineValidators, *keepers.EvidenceKeeper)

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
staking.BeginBlocker(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
ibcclient.BeginBlocker(ctx, keepers.IBCKeeper.ClientKeeper)
keepers.EvmKeeper.BeginBlock(ctx)

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
}
4 changes: 2 additions & 2 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/sei-protocol/sei-chain/app/legacyabci"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
)

Expand Down Expand Up @@ -194,9 +195,8 @@
SignedLastBlock: true,
}},
}
reqBeginBlock := abci.RequestBeginBlock{Header: header, LastCommitInfo: lastCommitInfo}

s.App.BeginBlocker(s.Ctx, reqBeginBlock)
legacyabci.BeginBlock(s.Ctx, header.Height, lastCommitInfo.Votes, []abci.Misbehavior{}, s.App.BeginBlockKeepers)

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 (s *TestWrapper) EndBlock() {
Expand Down
7 changes: 4 additions & 3 deletions app/upgrades/fork_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/app/apptesting"
"github.com/sei-protocol/sei-chain/app/legacyabci"
"github.com/sei-protocol/sei-chain/app/upgrades"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -86,7 +87,7 @@ func (suite *ForkTestSuite) TestHardForkManager() {
// increments height and runs begin block
suite.Ctx = suite.Ctx.WithBlockHeight(2)
newHeader := tmtypes.Header{Height: suite.Ctx.BlockHeight(), ChainID: suite.Ctx.ChainID(), Time: time.Now().UTC()}
suite.App.BeginBlocker(suite.Ctx, abci.RequestBeginBlock{Header: newHeader})
legacyabci.BeginBlock(suite.Ctx, newHeader.Height, []abci.VoteInfo{}, []abci.Misbehavior{}, suite.App.BeginBlockKeepers)
suite.Require().False(runFlag1)
suite.Require().False(runFlag2)
suite.Require().False(runFlag3)
Expand All @@ -96,7 +97,7 @@ func (suite *ForkTestSuite) TestHardForkManager() {
// run with height of 3 - runflag 1 should now be true
suite.Ctx = suite.Ctx.WithBlockHeight(3)
newHeader = tmtypes.Header{Height: suite.Ctx.BlockHeight(), ChainID: suite.Ctx.ChainID(), Time: time.Now().UTC()}
suite.App.BeginBlocker(suite.Ctx, abci.RequestBeginBlock{Header: newHeader})
suite.App.BeginBlock(suite.Ctx, newHeader.Height, []abci.VoteInfo{}, []abci.Misbehavior{}, false)
suite.Require().True(runFlag1)
suite.Require().False(runFlag2)
suite.Require().False(runFlag3)
Expand All @@ -107,7 +108,7 @@ func (suite *ForkTestSuite) TestHardForkManager() {
suite.Require().Panics(func() {
suite.Ctx = suite.Ctx.WithBlockHeight(4)
newHeader = tmtypes.Header{Height: suite.Ctx.BlockHeight(), ChainID: suite.Ctx.ChainID(), Time: time.Now().UTC()}
suite.App.BeginBlocker(suite.Ctx, abci.RequestBeginBlock{Header: newHeader})
suite.App.BeginBlock(suite.Ctx, newHeader.Height, []abci.VoteInfo{}, []abci.Misbehavior{}, false)
})
suite.Require().True(runFlag3)
suite.Require().False(runFlag4)
Expand Down
4 changes: 3 additions & 1 deletion evmrpc/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethereum/go-ethereum/export"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/sei-protocol/sei-chain/app/legacyabci"
"github.com/sei-protocol/sei-chain/precompiles/wasmd"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/types"
Expand Down Expand Up @@ -44,6 +45,7 @@ func NewSendAPI(
txConfigProvider func(int64) client.TxConfig,
sendConfig *SendConfig,
k *keeper.Keeper,
beginBlockKeepers legacyabci.BeginBlockKeepers,
ctxProvider func(int64) sdk.Context,
homeDir string,
simulateConfig *SimulateConfig,
Expand All @@ -60,7 +62,7 @@ func NewSendAPI(
keeper: k,
ctxProvider: ctxProvider,
homeDir: homeDir,
backend: NewBackend(ctxProvider, k, txConfigProvider, tmClient, simulateConfig, app, antehandler, globalBlockCache, cacheCreationMutex),
backend: NewBackend(ctxProvider, k, beginBlockKeepers, txConfigProvider, tmClient, simulateConfig, app, antehandler, globalBlockCache, cacheCreationMutex),
connectionType: connectionType,
}
}
Expand Down
Loading
Loading