feat!: Comet v0.38 Integration (#15519)
Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
marbar3778
cool-developer
Aaron Craelius
Matt Kocubinski
Julien Robert
parent
166be3766b
commit
6cee22df52
+40
-16
@@ -5,19 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// InitChainer initializes application state at genesis
|
||||
type InitChainer func(ctx Context, req abci.RequestInitChain) (abci.ResponseInitChain, error)
|
||||
|
||||
// BeginBlocker runs code before the transactions in a block
|
||||
//
|
||||
// Note: applications which set create_empty_blocks=false will not have regular block timing and should use
|
||||
// e.g. BFT timestamps rather than block height for any periodic BeginBlock logic
|
||||
type BeginBlocker func(ctx Context, req abci.RequestBeginBlock) (abci.ResponseBeginBlock, error)
|
||||
|
||||
// EndBlocker runs code after the transactions in a block and return updates to the validator set
|
||||
//
|
||||
// Note: applications which set create_empty_blocks=false will not have regular block timing and should use
|
||||
// e.g. BFT timestamps rather than block height for any periodic EndBlock logic
|
||||
type EndBlocker func(ctx Context, req abci.RequestEndBlock) (abci.ResponseEndBlock, error)
|
||||
type InitChainer func(ctx Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error)
|
||||
|
||||
// PrepareCheckStater runs code during commit after the block has been committed, and the `checkState`
|
||||
// has been branched for the new block.
|
||||
@@ -27,10 +15,46 @@ type PrepareCheckStater func(ctx Context)
|
||||
type Precommiter func(ctx Context)
|
||||
|
||||
// PeerFilter responds to p2p filtering queries from Tendermint
|
||||
type PeerFilter func(info string) abci.ResponseQuery
|
||||
type PeerFilter func(info string) *abci.ResponseQuery
|
||||
|
||||
// ProcessProposalHandler defines a function type alias for processing a proposer
|
||||
type ProcessProposalHandler func(Context, abci.RequestProcessProposal) abci.ResponseProcessProposal
|
||||
type ProcessProposalHandler func(Context, *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error)
|
||||
|
||||
// PrepareProposalHandler defines a function type alias for preparing a proposal
|
||||
type PrepareProposalHandler func(Context, abci.RequestPrepareProposal) abci.ResponsePrepareProposal
|
||||
type PrepareProposalHandler func(Context, *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error)
|
||||
|
||||
// ExtendVoteHandler defines a function type alias for extending a pre-commit vote.
|
||||
type ExtendVoteHandler func(Context, *abci.RequestExtendVote) (*abci.ResponseExtendVote, error)
|
||||
|
||||
// VerifyVoteExtensionHandler defines a function type alias for verifying a
|
||||
// pre-commit vote extension.
|
||||
type VerifyVoteExtensionHandler func(Context, *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error)
|
||||
|
||||
// BeginBlocker defines a function type alias for executing application
|
||||
// business logic before transactions are executed.
|
||||
//
|
||||
// Note: The BeginBlock ABCI method no longer exists in the ABCI specification
|
||||
// as of CometBFT v0.38.0. This function type alias is provided for backwards
|
||||
// compatibility with applications that still use the BeginBlock ABCI method
|
||||
// and allows for existing BeginBlock functionality within applications.
|
||||
type BeginBlocker func(Context) (BeginBlock, error)
|
||||
|
||||
// EndBlocker defines a function type alias for executing application
|
||||
// business logic after transactions are executed but before committing.
|
||||
//
|
||||
// Note: The EndBlock ABCI method no longer exists in the ABCI specification
|
||||
// as of CometBFT v0.38.0. This function type alias is provided for backwards
|
||||
// compatibility with applications that still use the EndBlock ABCI method
|
||||
// and allows for existing EndBlock functionality within applications.
|
||||
type EndBlocker func(Context) (EndBlock, error)
|
||||
|
||||
// EndBlock defines a type which contains endblock events and validator set updates
|
||||
type EndBlock struct {
|
||||
ValidatorUpdates []abci.ValidatorUpdate
|
||||
Events []abci.Event
|
||||
}
|
||||
|
||||
// BeginBlock defines a type which contains beginBlock events
|
||||
type BeginBlock struct {
|
||||
Events []abci.Event
|
||||
}
|
||||
|
||||
@@ -16,6 +16,20 @@ import (
|
||||
"cosmossdk.io/core/header"
|
||||
)
|
||||
|
||||
// ExecMode defines the execution mode which can be set on a Context.
|
||||
type ExecMode uint8
|
||||
|
||||
// All possible execution modes.
|
||||
const (
|
||||
ExecModeCheck ExecMode = iota
|
||||
ExecModeReCheck
|
||||
ExecModeSimulate
|
||||
ExecModePrepareProposal
|
||||
ExecModeProcessProposal
|
||||
ExecModeVoteExtension
|
||||
ExecModeFinalize
|
||||
)
|
||||
|
||||
/*
|
||||
Context is an immutable object contains all information needed to
|
||||
process a request.
|
||||
@@ -40,6 +54,7 @@ type Context struct {
|
||||
blockGasMeter storetypes.GasMeter
|
||||
checkTx bool
|
||||
recheckTx bool // if recheckTx == true, then checkTx must also be true
|
||||
execMode ExecMode
|
||||
minGasPrice DecCoins
|
||||
consParams cmtproto.ConsensusParams
|
||||
eventManager EventManagerI
|
||||
@@ -67,6 +82,7 @@ func (c Context) GasMeter() storetypes.GasMeter { return c.gasMe
|
||||
func (c Context) BlockGasMeter() storetypes.GasMeter { return c.blockGasMeter }
|
||||
func (c Context) IsCheckTx() bool { return c.checkTx }
|
||||
func (c Context) IsReCheckTx() bool { return c.recheckTx }
|
||||
func (c Context) ExecMode() ExecMode { return c.execMode }
|
||||
func (c Context) MinGasPrices() DecCoins { return c.minGasPrice }
|
||||
func (c Context) EventManager() EventManagerI { return c.eventManager }
|
||||
func (c Context) Priority() int64 { return c.priority }
|
||||
@@ -229,6 +245,7 @@ func (c Context) WithTransientKVGasConfig(gasConfig storetypes.GasConfig) Contex
|
||||
// WithIsCheckTx enables or disables CheckTx value for verifying transactions and returns an updated Context
|
||||
func (c Context) WithIsCheckTx(isCheckTx bool) Context {
|
||||
c.checkTx = isCheckTx
|
||||
c.execMode = ExecModeCheck
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -239,6 +256,13 @@ func (c Context) WithIsReCheckTx(isRecheckTx bool) Context {
|
||||
c.checkTx = true
|
||||
}
|
||||
c.recheckTx = isRecheckTx
|
||||
c.execMode = ExecModeReCheck
|
||||
return c
|
||||
}
|
||||
|
||||
// WithExecMode returns a Context with an updated ExecMode.
|
||||
func (c Context) WithExecMode(m ExecMode) Context {
|
||||
c.execMode = m
|
||||
return c
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
// ResponseCheckTxWithEvents returns an ABCI ResponseCheckTx object with fields filled in
|
||||
// from the given error, gas values and events.
|
||||
func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) abci.ResponseCheckTx {
|
||||
func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.ResponseCheckTx {
|
||||
space, code, log := errorsmod.ABCIInfo(err, debug)
|
||||
return abci.ResponseCheckTx{
|
||||
return &abci.ResponseCheckTx{
|
||||
Codespace: space,
|
||||
Code: code,
|
||||
Log: log,
|
||||
@@ -19,11 +19,11 @@ func ResponseCheckTxWithEvents(err error, gw, gu uint64, events []abci.Event, de
|
||||
}
|
||||
}
|
||||
|
||||
// ResponseDeliverTxWithEvents returns an ABCI ResponseDeliverTx object with fields filled in
|
||||
// from the given error, gas values and events.
|
||||
func ResponseDeliverTxWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) abci.ResponseDeliverTx {
|
||||
// ResponseExecTxResultWithEvents returns an ABCI ExecTxResult object with fields
|
||||
// filled in from the given error, gas values and events.
|
||||
func ResponseExecTxResultWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.ExecTxResult {
|
||||
space, code, log := errorsmod.ABCIInfo(err, debug)
|
||||
return abci.ResponseDeliverTx{
|
||||
return &abci.ExecTxResult{
|
||||
Codespace: space,
|
||||
Code: code,
|
||||
Log: log,
|
||||
@@ -35,9 +35,9 @@ func ResponseDeliverTxWithEvents(err error, gw, gu uint64, events []abci.Event,
|
||||
|
||||
// QueryResult returns a ResponseQuery from an error. It will try to parse ABCI
|
||||
// info from the error.
|
||||
func QueryResult(err error, debug bool) abci.ResponseQuery {
|
||||
func QueryResult(err error, debug bool) *abci.ResponseQuery {
|
||||
space, code, log := errorsmod.ABCIInfo(err, debug)
|
||||
return abci.ResponseQuery{
|
||||
return &abci.ResponseQuery{
|
||||
Codespace: space,
|
||||
Code: code,
|
||||
Log: log,
|
||||
|
||||
@@ -6,11 +6,9 @@ import (
|
||||
cosmosmsg "cosmossdk.io/api/cosmos/msg/v1"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/gogoproto/grpc"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
googlegrpc "google.golang.org/grpc"
|
||||
protobuf "google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -56,17 +54,12 @@ type configurator struct {
|
||||
// migrations is a map of moduleName -> fromVersion -> migration script handler
|
||||
migrations map[string]map[uint64]MigrationHandler
|
||||
|
||||
registryCache *protoregistry.Files
|
||||
err error
|
||||
err error
|
||||
}
|
||||
|
||||
// RegisterService implements the grpc.Server interface.
|
||||
func (c *configurator) RegisterService(sd *googlegrpc.ServiceDesc, ss interface{}) {
|
||||
if c.registryCache == nil {
|
||||
c.registryCache, c.err = proto.MergedRegistry()
|
||||
}
|
||||
|
||||
desc, err := c.registryCache.FindDescriptorByName(protoreflect.FullName(sd.ServiceName))
|
||||
desc, err := c.cdc.InterfaceRegistry().FindDescriptorByName(protoreflect.FullName(sd.ServiceName))
|
||||
if err != nil {
|
||||
c.err = err
|
||||
return
|
||||
|
||||
@@ -14,8 +14,7 @@ type AppModuleWithAllExtensions interface {
|
||||
module.HasGenesis
|
||||
module.HasInvariants
|
||||
module.HasConsensusVersion
|
||||
module.BeginBlockAppModule
|
||||
module.EndBlockAppModule
|
||||
module.HasABCIEndblock
|
||||
}
|
||||
|
||||
// CoreAppModule is solely here for the purpose of generating
|
||||
|
||||
+21
-46
@@ -219,17 +219,6 @@ type HasConsensusVersion interface {
|
||||
ConsensusVersion() uint64
|
||||
}
|
||||
|
||||
// BeginBlockAppModule is an extension interface that contains information about the AppModule and BeginBlock.
|
||||
type BeginBlockAppModule interface {
|
||||
AppModule
|
||||
BeginBlock(sdk.Context, abci.RequestBeginBlock)
|
||||
}
|
||||
|
||||
// EndBlockAppModule is an extension interface that contains information about the AppModule and EndBlock.
|
||||
type EndBlockAppModule interface {
|
||||
AppModule
|
||||
EndBlock(sdk.Context, abci.RequestEndBlock) []abci.ValidatorUpdate
|
||||
}
|
||||
type HasABCIEndblock interface {
|
||||
AppModule
|
||||
EndBlock(context.Context) ([]abci.ValidatorUpdate, error)
|
||||
@@ -266,11 +255,11 @@ func (gam GenesisOnlyAppModule) RegisterServices(Configurator) {}
|
||||
func (gam GenesisOnlyAppModule) ConsensusVersion() uint64 { return 1 }
|
||||
|
||||
// BeginBlock returns an empty module begin-block
|
||||
func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) {}
|
||||
func (gam GenesisOnlyAppModule) BeginBlock(ctx sdk.Context) error { return nil }
|
||||
|
||||
// EndBlock returns an empty module end-block
|
||||
func (GenesisOnlyAppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
|
||||
return []abci.ValidatorUpdate{}
|
||||
func (GenesisOnlyAppModule) EndBlock(sdk.Context) ([]abci.ValidatorUpdate, error) {
|
||||
return []abci.ValidatorUpdate{}, nil
|
||||
}
|
||||
|
||||
// Manager defines a module manager that provides the high level utility for managing and executing
|
||||
@@ -363,7 +352,7 @@ func (m *Manager) SetOrderBeginBlockers(moduleNames ...string) {
|
||||
m.assertNoForgottenModules("SetOrderBeginBlockers", moduleNames,
|
||||
func(moduleName string) bool {
|
||||
module := m.Modules[moduleName]
|
||||
_, hasBeginBlock := module.(BeginBlockAppModule)
|
||||
_, hasBeginBlock := module.(appmodule.HasBeginBlocker)
|
||||
return !hasBeginBlock
|
||||
})
|
||||
m.OrderBeginBlockers = moduleNames
|
||||
@@ -374,7 +363,7 @@ func (m *Manager) SetOrderEndBlockers(moduleNames ...string) {
|
||||
m.assertNoForgottenModules("SetOrderEndBlockers", moduleNames,
|
||||
func(moduleName string) bool {
|
||||
module := m.Modules[moduleName]
|
||||
_, hasEndBlock := module.(EndBlockAppModule)
|
||||
_, hasEndBlock := module.(HasABCIEndblock)
|
||||
return !hasEndBlock
|
||||
})
|
||||
m.OrderEndBlockers = moduleNames
|
||||
@@ -443,7 +432,7 @@ func (m *Manager) RegisterServices(cfg Configurator) error {
|
||||
// InitGenesis performs init genesis functionality for modules. Exactly one
|
||||
// module must return a non-empty validator set update to correctly initialize
|
||||
// the chain.
|
||||
func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage) (abci.ResponseInitChain, error) {
|
||||
func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData map[string]json.RawMessage) (*abci.ResponseInitChain, error) {
|
||||
var validatorUpdates []abci.ValidatorUpdate
|
||||
ctx.Logger().Info("initializing blockchain state from genesis.json")
|
||||
for _, moduleName := range m.OrderInitGenesis {
|
||||
@@ -458,12 +447,12 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData
|
||||
// core API genesis
|
||||
source, err := genesis.SourceFromRawJSON(genesisData[moduleName])
|
||||
if err != nil {
|
||||
return abci.ResponseInitChain{}, err
|
||||
return &abci.ResponseInitChain{}, err
|
||||
}
|
||||
|
||||
err = module.InitGenesis(ctx, source)
|
||||
if err != nil {
|
||||
return abci.ResponseInitChain{}, err
|
||||
return &abci.ResponseInitChain{}, err
|
||||
}
|
||||
} else if module, ok := mod.(HasGenesis); ok {
|
||||
ctx.Logger().Debug("running initialization for module", "module", moduleName)
|
||||
@@ -473,7 +462,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData
|
||||
// only one module will update the validator set
|
||||
if len(moduleValUpdates) > 0 {
|
||||
if len(validatorUpdates) > 0 {
|
||||
return abci.ResponseInitChain{}, errors.New("validator InitGenesis updates already set by a previous module")
|
||||
return &abci.ResponseInitChain{}, errors.New("validator InitGenesis updates already set by a previous module")
|
||||
}
|
||||
validatorUpdates = moduleValUpdates
|
||||
}
|
||||
@@ -482,10 +471,10 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData
|
||||
|
||||
// a chain must initialize with a non-empty validator set
|
||||
if len(validatorUpdates) == 0 {
|
||||
return abci.ResponseInitChain{}, fmt.Errorf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction)
|
||||
return &abci.ResponseInitChain{}, fmt.Errorf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction)
|
||||
}
|
||||
|
||||
return abci.ResponseInitChain{
|
||||
return &abci.ResponseInitChain{
|
||||
Validators: validatorUpdates,
|
||||
}, nil
|
||||
}
|
||||
@@ -702,21 +691,19 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version
|
||||
// BeginBlock performs begin block functionality for all modules. It creates a
|
||||
// child context with an event manager to aggregate events emitted from all
|
||||
// modules.
|
||||
func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) (abci.ResponseBeginBlock, error) {
|
||||
func (m *Manager) BeginBlock(ctx sdk.Context) (sdk.BeginBlock, error) {
|
||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||
|
||||
for _, moduleName := range m.OrderBeginBlockers {
|
||||
if module, ok := m.Modules[moduleName].(BeginBlockAppModule); ok {
|
||||
module.BeginBlock(ctx, req)
|
||||
} else if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok {
|
||||
if module, ok := m.Modules[moduleName].(appmodule.HasBeginBlocker); ok {
|
||||
err := module.BeginBlock(ctx)
|
||||
if err != nil {
|
||||
return abci.ResponseBeginBlock{}, err
|
||||
return sdk.BeginBlock{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return abci.ResponseBeginBlock{
|
||||
return sdk.BeginBlock{
|
||||
Events: ctx.EventManager().ABCIEvents(),
|
||||
}, nil
|
||||
}
|
||||
@@ -724,38 +711,26 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) (abci.
|
||||
// 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, error) {
|
||||
func (m *Manager) EndBlock(ctx sdk.Context) (sdk.EndBlock, error) {
|
||||
ctx = ctx.WithEventManager(sdk.NewEventManager())
|
||||
validatorUpdates := []abci.ValidatorUpdate{}
|
||||
|
||||
for _, moduleName := range m.OrderEndBlockers {
|
||||
if module, ok := m.Modules[moduleName].(EndBlockAppModule); ok {
|
||||
moduleValUpdates := module.EndBlock(ctx, req)
|
||||
|
||||
// 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 {
|
||||
return abci.ResponseEndBlock{}, errors.New("validator EndBlock updates already set by a previous module")
|
||||
}
|
||||
|
||||
validatorUpdates = moduleValUpdates
|
||||
}
|
||||
} else if module, ok := m.Modules[moduleName].(appmodule.HasEndBlocker); ok {
|
||||
if module, ok := m.Modules[moduleName].(appmodule.HasEndBlocker); ok {
|
||||
err := module.EndBlock(ctx)
|
||||
if err != nil {
|
||||
return abci.ResponseEndBlock{}, err
|
||||
return sdk.EndBlock{}, err
|
||||
}
|
||||
} else if module, ok := m.Modules[moduleName].(HasABCIEndblock); ok {
|
||||
moduleValUpdates, err := module.EndBlock(ctx)
|
||||
if err != nil {
|
||||
return abci.ResponseEndBlock{}, err
|
||||
return sdk.EndBlock{}, err
|
||||
}
|
||||
// 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 {
|
||||
return abci.ResponseEndBlock{}, errors.New("validator EndBlock updates already set by a previous module")
|
||||
return sdk.EndBlock{}, errors.New("validator EndBlock updates already set by a previous module")
|
||||
}
|
||||
|
||||
for _, updates := range moduleValUpdates {
|
||||
@@ -767,7 +742,7 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (abci.Resp
|
||||
}
|
||||
}
|
||||
|
||||
return abci.ResponseEndBlock{
|
||||
return sdk.EndBlock{
|
||||
ValidatorUpdates: validatorUpdates,
|
||||
Events: ctx.EventManager().ABCIEvents(),
|
||||
}, nil
|
||||
|
||||
+20
-54
@@ -103,38 +103,30 @@ func TestGenesisOnlyAppModule(t *testing.T) {
|
||||
func TestAssertNoForgottenModules(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
t.Cleanup(mockCtrl.Finish)
|
||||
mockAppModule1 := mock.NewMockEndBlockAppModule(mockCtrl)
|
||||
mockAppModule2 := mock.NewMockBeginBlockAppModule(mockCtrl)
|
||||
mockAppModule1 := mock.NewMockHasABCIEndblock(mockCtrl)
|
||||
mockAppModule3 := mock.NewMockCoreAppModule(mockCtrl)
|
||||
|
||||
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
|
||||
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
|
||||
mm := module.NewManager(
|
||||
mockAppModule1,
|
||||
mockAppModule2,
|
||||
module.CoreAppModuleBasicAdaptor("module3", mockAppModule3),
|
||||
)
|
||||
require.NotNil(t, mm)
|
||||
require.Equal(t, 3, len(mm.Modules))
|
||||
require.Equal(t, 2, len(mm.Modules))
|
||||
|
||||
require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderInitGenesis)
|
||||
require.Equal(t, []string{"module1", "module3"}, mm.OrderInitGenesis)
|
||||
require.PanicsWithValue(t, "all modules must be defined when setting SetOrderInitGenesis, missing: [module3]", func() {
|
||||
mm.SetOrderInitGenesis("module2", "module1")
|
||||
mm.SetOrderInitGenesis("module1")
|
||||
})
|
||||
|
||||
require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderExportGenesis)
|
||||
require.Equal(t, []string{"module1", "module3"}, mm.OrderExportGenesis)
|
||||
require.PanicsWithValue(t, "all modules must be defined when setting SetOrderExportGenesis, missing: [module3]", func() {
|
||||
mm.SetOrderExportGenesis("module2", "module1")
|
||||
mm.SetOrderExportGenesis("module1")
|
||||
})
|
||||
|
||||
require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderBeginBlockers)
|
||||
require.PanicsWithValue(t, "all modules must be defined when setting SetOrderBeginBlockers, missing: [module2]", func() {
|
||||
mm.SetOrderBeginBlockers("module1", "module3")
|
||||
})
|
||||
|
||||
require.Equal(t, []string{"module1", "module2", "module3"}, mm.OrderEndBlockers)
|
||||
require.Equal(t, []string{"module1", "module3"}, mm.OrderEndBlockers)
|
||||
require.PanicsWithValue(t, "all modules must be defined when setting SetOrderEndBlockers, missing: [module1]", func() {
|
||||
mm.SetOrderEndBlockers("module2", "module3")
|
||||
mm.SetOrderEndBlockers("module3")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -316,32 +308,12 @@ func TestManager_ExportGenesis(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestManager_BeginBlock(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
t.Cleanup(mockCtrl.Finish)
|
||||
|
||||
mockAppModule1 := mock.NewMockBeginBlockAppModule(mockCtrl)
|
||||
mockAppModule2 := mock.NewMockBeginBlockAppModule(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.RequestBeginBlock{Hash: []byte("test")}
|
||||
|
||||
mockAppModule1.EXPECT().BeginBlock(gomock.Any(), gomock.Eq(req)).Times(1)
|
||||
mockAppModule2.EXPECT().BeginBlock(gomock.Any(), gomock.Eq(req)).Times(1)
|
||||
_, err := mm.BeginBlock(sdk.Context{}, req)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestManager_EndBlock(t *testing.T) {
|
||||
mockCtrl := gomock.NewController(t)
|
||||
t.Cleanup(mockCtrl.Finish)
|
||||
|
||||
mockAppModule1 := mock.NewMockEndBlockAppModule(mockCtrl)
|
||||
mockAppModule2 := mock.NewMockEndBlockAppModule(mockCtrl)
|
||||
mockAppModule1 := mock.NewMockHasABCIEndblock(mockCtrl)
|
||||
mockAppModule2 := mock.NewMockHasABCIEndblock(mockCtrl)
|
||||
mockAppModule3 := mock.NewMockAppModule(mockCtrl)
|
||||
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
|
||||
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
|
||||
@@ -350,18 +322,16 @@ func TestManager_EndBlock(t *testing.T) {
|
||||
require.NotNil(t, mm)
|
||||
require.Equal(t, 3, 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, err := mm.EndBlock(sdk.Context{}, req)
|
||||
mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]abci.ValidatorUpdate{{}}, nil)
|
||||
mockAppModule2.EXPECT().EndBlock(gomock.Any()).Times(1)
|
||||
ret, err := mm.EndBlock(sdk.Context{})
|
||||
require.NoError(t, err)
|
||||
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{{}})
|
||||
_, err = mm.EndBlock(sdk.Context{}, req)
|
||||
mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]abci.ValidatorUpdate{{}}, nil)
|
||||
mockAppModule2.EXPECT().EndBlock(gomock.Any()).Times(1).Return([]abci.ValidatorUpdate{{}}, nil)
|
||||
_, err = mm.EndBlock(sdk.Context{})
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
@@ -500,16 +470,14 @@ func TestCoreAPIManager_BeginBlock(t *testing.T) {
|
||||
require.NotNil(t, mm)
|
||||
require.Equal(t, 2, len(mm.Modules))
|
||||
|
||||
req := abci.RequestBeginBlock{Hash: []byte("test")}
|
||||
|
||||
mockAppModule1.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(nil)
|
||||
mockAppModule2.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(nil)
|
||||
_, err := mm.BeginBlock(sdk.Context{}, req)
|
||||
_, err := mm.BeginBlock(sdk.Context{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// test panic
|
||||
mockAppModule1.EXPECT().BeginBlock(gomock.Any()).Times(1).Return(errors.New("some error"))
|
||||
_, err = mm.BeginBlock(sdk.Context{}, req)
|
||||
_, err = mm.BeginBlock(sdk.Context{})
|
||||
require.EqualError(t, err, "some error")
|
||||
}
|
||||
|
||||
@@ -526,17 +494,15 @@ func TestCoreAPIManager_EndBlock(t *testing.T) {
|
||||
require.NotNil(t, mm)
|
||||
require.Equal(t, 2, len(mm.Modules))
|
||||
|
||||
req := abci.RequestEndBlock{Height: 10}
|
||||
|
||||
mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return(nil)
|
||||
mockAppModule2.EXPECT().EndBlock(gomock.Any()).Times(1).Return(nil)
|
||||
res, err := mm.EndBlock(sdk.Context{}, req)
|
||||
res, err := mm.EndBlock(sdk.Context{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, res.ValidatorUpdates, 0)
|
||||
|
||||
// test panic
|
||||
mockAppModule1.EXPECT().EndBlock(gomock.Any()).Times(1).Return(errors.New("some error"))
|
||||
_, err = mm.EndBlock(sdk.Context{}, req)
|
||||
_, err = mm.EndBlock(sdk.Context{})
|
||||
require.EqualError(t, err, "some error")
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
msg "cosmossdk.io/api/cosmos/msg/v1"
|
||||
|
||||
"cosmossdk.io/x/tx/signing"
|
||||
)
|
||||
|
||||
// ValidateAnnotations validates that the proto annotations are correct.
|
||||
@@ -18,7 +20,7 @@ import (
|
||||
// More validations can be added here in the future.
|
||||
//
|
||||
// If `protoFiles` is nil, then protoregistry.GlobalFile will be used.
|
||||
func ValidateProtoAnnotations(protoFiles *protoregistry.Files) error {
|
||||
func ValidateProtoAnnotations(protoFiles signing.ProtoFileResolver) error {
|
||||
if protoFiles == nil {
|
||||
protoFiles = protoregistry.GlobalFiles
|
||||
}
|
||||
@@ -30,7 +32,7 @@ func ValidateProtoAnnotations(protoFiles *protoregistry.Files) error {
|
||||
if sd.Name() == "Msg" {
|
||||
// We use the heuristic that services name Msg are exactly the
|
||||
// ones that need the proto annotations check.
|
||||
err := validateMsgServiceAnnotations(protoFiles, sd)
|
||||
err := validateMsgServiceAnnotations(sd)
|
||||
if err != nil {
|
||||
serviceErrs = append(serviceErrs, err)
|
||||
}
|
||||
@@ -45,7 +47,7 @@ func ValidateProtoAnnotations(protoFiles *protoregistry.Files) error {
|
||||
|
||||
// validateMsgServiceAnnotations validates that the service has the
|
||||
// `(cosmos.msg.v1.service) = true` proto annotation.
|
||||
func validateMsgServiceAnnotations(protoFiles *protoregistry.Files, sd protoreflect.ServiceDescriptor) error {
|
||||
func validateMsgServiceAnnotations(sd protoreflect.ServiceDescriptor) error {
|
||||
ext := proto.GetExtension(sd.Options(), msg.E_Service)
|
||||
isService, ok := ext.(bool)
|
||||
if !ok {
|
||||
|
||||
@@ -14,11 +14,11 @@ func TestValidateServiceAnnotations(t *testing.T) {
|
||||
// Find an arbitrary query service that hasn't the service=true annotation.
|
||||
sd, err := protoregistry.GlobalFiles.FindDescriptorByName("cosmos.bank.v1beta1.Query")
|
||||
require.NoError(t, err)
|
||||
err = validateMsgServiceAnnotations(nil, sd.(protoreflect.ServiceDescriptor))
|
||||
err = validateMsgServiceAnnotations(sd.(protoreflect.ServiceDescriptor))
|
||||
require.Error(t, err)
|
||||
|
||||
sd, err = protoregistry.GlobalFiles.FindDescriptorByName("cosmos.bank.v1beta1.Msg")
|
||||
require.NoError(t, err)
|
||||
err = validateMsgServiceAnnotations(nil, sd.(protoreflect.ServiceDescriptor))
|
||||
err = validateMsgServiceAnnotations(sd.(protoreflect.ServiceDescriptor))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (s *resultTestSuite) TestNewSearchTxsResult() {
|
||||
}
|
||||
|
||||
func (s *resultTestSuite) TestResponseResultTx() {
|
||||
deliverTxResult := abci.ResponseDeliverTx{
|
||||
deliverTxResult := abci.ExecTxResult{
|
||||
Codespace: "codespace",
|
||||
Code: 1,
|
||||
Data: []byte("data"),
|
||||
|
||||
Reference in New Issue
Block a user