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:
Aleksandr Bezobchuk
2023-05-24 16:09:19 +00:00
committed by GitHub
co-authored by marbar3778 cool-developer Aaron Craelius Matt Kocubinski Julien Robert
parent 166be3766b
commit 6cee22df52
148 changed files with 14747 additions and 15262 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ func Example_oneModule() {
Params: params,
},
// this allows to the begin and end blocker of the module before and after the message
integration.WithAutomaticBeginEndBlock(),
integration.WithAutomaticFinalizeBlock(),
// this allows to commit the state after the message
integration.WithAutomaticCommit(),
)
+4 -4
View File
@@ -2,17 +2,17 @@ package integration
// Config is the configuration for the integration app.
type Config struct {
AutomaticBeginEndBlock bool
AutomaticFinalizeBlock bool
AutomaticCommit bool
}
// Option is a function that can be used to configure the integration app.
type Option func(*Config)
// WithAutomaticBlockCreation enables begin/end block calls.
func WithAutomaticBeginEndBlock() Option {
// WithAutomaticFinalizeBlock calls ABCI finalize block.
func WithAutomaticFinalizeBlock() Option {
return func(cfg *Config) {
cfg.AutomaticBeginEndBlock = true
cfg.AutomaticFinalizeBlock = true
}
}
+45 -35
View File
@@ -4,13 +4,12 @@ import (
"context"
"fmt"
cmtabcitypes "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"cosmossdk.io/log"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
cmtabcitypes "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/baseapp"
@@ -32,13 +31,21 @@ const appName = "integration-app"
type App struct {
*baseapp.BaseApp
ctx sdk.Context
logger log.Logger
queryHelper *baseapp.QueryServiceTestHelper
ctx sdk.Context
logger log.Logger
moduleManager module.Manager
queryHelper *baseapp.QueryServiceTestHelper
}
// NewIntegrationApp creates an application for testing purposes. This application is able to route messages to their respective handlers.
func NewIntegrationApp(sdkCtx sdk.Context, logger log.Logger, keys map[string]*storetypes.KVStoreKey, appCodec codec.Codec, modules ...module.AppModule) *App {
// NewIntegrationApp creates an application for testing purposes. This application
// is able to route messages to their respective handlers.
func NewIntegrationApp(
sdkCtx sdk.Context,
logger log.Logger,
keys map[string]*storetypes.KVStoreKey,
appCodec codec.Codec,
modules ...module.AppModule,
) *App {
db := dbm.NewMemDB()
interfaceRegistry := codectypes.NewInterfaceRegistry()
@@ -50,22 +57,22 @@ func NewIntegrationApp(sdkCtx sdk.Context, logger log.Logger, keys map[string]*s
bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseapp.SetChainID(appName))
bApp.MountKVStores(keys)
bApp.SetInitChainer(func(ctx sdk.Context, req cmtabcitypes.RequestInitChain) (cmtabcitypes.ResponseInitChain, error) {
bApp.SetInitChainer(func(ctx sdk.Context, _ *cmtabcitypes.RequestInitChain) (*cmtabcitypes.ResponseInitChain, error) {
for _, mod := range modules {
if m, ok := mod.(module.HasGenesis); ok {
m.InitGenesis(ctx, appCodec, m.DefaultGenesis(appCodec))
}
}
return cmtabcitypes.ResponseInitChain{}, nil
return &cmtabcitypes.ResponseInitChain{}, nil
})
moduleManager := module.NewManager(modules...)
bApp.SetBeginBlocker(func(_ sdk.Context, req cmtabcitypes.RequestBeginBlock) (cmtabcitypes.ResponseBeginBlock, error) {
return moduleManager.BeginBlock(sdkCtx, req)
bApp.SetBeginBlocker(func(_ sdk.Context) (sdk.BeginBlock, error) {
return moduleManager.BeginBlock(sdkCtx)
})
bApp.SetEndBlocker(func(_ sdk.Context, req cmtabcitypes.RequestEndBlock) (cmtabcitypes.ResponseEndBlock, error) {
return moduleManager.EndBlock(sdkCtx, req)
bApp.SetEndBlocker(func(_ sdk.Context) (sdk.EndBlock, error) {
return moduleManager.EndBlock(sdkCtx)
})
router := baseapp.NewMsgServiceRouter()
@@ -73,7 +80,6 @@ func NewIntegrationApp(sdkCtx sdk.Context, logger log.Logger, keys map[string]*s
bApp.SetMsgServiceRouter(router)
if keys[consensusparamtypes.StoreKey] != nil {
// set baseApp param store
consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), authtypes.NewModuleAddress("gov").String(), runtime.EventService{})
bApp.SetParamStore(consensusParamsKeeper.ParamsStore)
@@ -81,13 +87,18 @@ func NewIntegrationApp(sdkCtx sdk.Context, logger log.Logger, keys map[string]*s
if err := bApp.LoadLatestVersion(); err != nil {
panic(fmt.Errorf("failed to load application version from store: %w", err))
}
bApp.InitChain(cmtabcitypes.RequestInitChain{ChainId: appName, ConsensusParams: simtestutil.DefaultConsensusParams})
if _, err := bApp.InitChain(&cmtabcitypes.RequestInitChain{ChainId: appName, ConsensusParams: simtestutil.DefaultConsensusParams}); err != nil {
panic(fmt.Errorf("failed to initialize application: %w", err))
}
} else {
if err := bApp.LoadLatestVersion(); err != nil {
panic(fmt.Errorf("failed to load application version from store: %w", err))
}
bApp.InitChain(cmtabcitypes.RequestInitChain{ChainId: appName})
if _, err := bApp.InitChain(&cmtabcitypes.RequestInitChain{ChainId: appName}); err != nil {
panic(fmt.Errorf("failed to initialize application: %w", err))
}
}
bApp.Commit()
@@ -95,39 +106,36 @@ func NewIntegrationApp(sdkCtx sdk.Context, logger log.Logger, keys map[string]*s
ctx := sdkCtx.WithBlockHeader(cmtproto.Header{ChainID: appName}).WithIsCheckTx(true)
return &App{
BaseApp: bApp,
logger: logger,
ctx: ctx,
queryHelper: baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry),
BaseApp: bApp,
logger: logger,
ctx: ctx,
moduleManager: *moduleManager,
queryHelper: baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry),
}
}
// RunMsg allows to run a message and return the response.
// RunMsg provides the ability to run a message and return the response.
// In order to run a message, the application must have a handler for it.
// These handlers are registered on the application message service router.
// The result of the message execution is returned as a Any type.
// The result of the message execution is returned as an Any type.
// That any type can be unmarshaled to the expected response type.
// If the message execution fails, an error is returned.
func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) {
// set options
cfg := Config{}
cfg := &Config{}
for _, opt := range option {
opt(&cfg)
opt(cfg)
}
if cfg.AutomaticCommit {
defer app.Commit()
}
if cfg.AutomaticBeginEndBlock {
if cfg.AutomaticFinalizeBlock {
height := app.LastBlockHeight() + 1
app.logger.Info("Running beging block", "height", height)
app.BeginBlock(cmtabcitypes.RequestBeginBlock{Header: cmtproto.Header{Height: height, ChainID: appName}})
defer func() {
app.logger.Info("Running end block", "height", height)
app.EndBlock(cmtabcitypes.RequestEndBlock{})
}()
if _, err := app.FinalizeBlock(&cmtabcitypes.RequestFinalizeBlock{Height: height}); err != nil {
return nil, fmt.Errorf("failed to run finalize block: %w", err)
}
}
app.logger.Info("Running msg", "msg", msg.String())
@@ -155,8 +163,8 @@ func (app *App) RunMsg(msg sdk.Msg, option ...Option) (*codectypes.Any, error) {
return response, nil
}
// Context returns the application context.
// It can be unwraped to a sdk.Context, with the sdk.UnwrapSDKContext function.
// Context returns the application context. It can be unwrapped to a sdk.Context,
// with the sdk.UnwrapSDKContext function.
func (app *App) Context() context.Context {
return app.ctx
}
@@ -171,9 +179,11 @@ func (app *App) QueryHelper() *baseapp.QueryServiceTestHelper {
func CreateMultiStore(keys map[string]*storetypes.KVStoreKey, logger log.Logger) storetypes.CommitMultiStore {
db := dbm.NewMemDB()
cms := store.NewCommitMultiStore(db, logger, metrics.NewNoOpMetrics())
for key := range keys {
cms.MountStoreWithDB(keys[key], storetypes.StoreTypeIAVL, db)
}
_ = cms.LoadLatestVersion()
return cms
}
+6 -17
View File
@@ -44,18 +44,6 @@ func (m *MockAppModuleWithAllExtensions) EXPECT() *MockAppModuleWithAllExtension
return m.recorder
}
// BeginBlock mocks base method.
func (m *MockAppModuleWithAllExtensions) BeginBlock(arg0 types1.Context, arg1 types.RequestBeginBlock) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "BeginBlock", arg0, arg1)
}
// BeginBlock indicates an expected call of BeginBlock.
func (mr *MockAppModuleWithAllExtensionsMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).BeginBlock), arg0, arg1)
}
// ConsensusVersion mocks base method.
func (m *MockAppModuleWithAllExtensions) ConsensusVersion() uint64 {
m.ctrl.T.Helper()
@@ -85,17 +73,18 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) DefaultGenesis(arg0 interf
}
// EndBlock mocks base method.
func (m *MockAppModuleWithAllExtensions) EndBlock(arg0 types1.Context, arg1 types.RequestEndBlock) []types.ValidatorUpdate {
func (m *MockAppModuleWithAllExtensions) EndBlock(arg0 context.Context) ([]types.ValidatorUpdate, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "EndBlock", arg0, arg1)
ret := m.ctrl.Call(m, "EndBlock", arg0)
ret0, _ := ret[0].([]types.ValidatorUpdate)
return ret0
ret1, _ := ret[1].(error)
return ret0, ret1
}
// EndBlock indicates an expected call of EndBlock.
func (mr *MockAppModuleWithAllExtensionsMockRecorder) EndBlock(arg0, arg1 interface{}) *gomock.Call {
func (mr *MockAppModuleWithAllExtensionsMockRecorder) EndBlock(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).EndBlock), arg0, arg1)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EndBlock", reflect.TypeOf((*MockAppModuleWithAllExtensions)(nil).EndBlock), arg0)
}
// ExportGenesis mocks base method.
-228
View File
@@ -653,234 +653,6 @@ func (mr *MockHasConsensusVersionMockRecorder) ConsensusVersion() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConsensusVersion", reflect.TypeOf((*MockHasConsensusVersion)(nil).ConsensusVersion))
}
// MockBeginBlockAppModule is a mock of BeginBlockAppModule interface.
type MockBeginBlockAppModule struct {
ctrl *gomock.Controller
recorder *MockBeginBlockAppModuleMockRecorder
}
// MockBeginBlockAppModuleMockRecorder is the mock recorder for MockBeginBlockAppModule.
type MockBeginBlockAppModuleMockRecorder struct {
mock *MockBeginBlockAppModule
}
// NewMockBeginBlockAppModule creates a new mock instance.
func NewMockBeginBlockAppModule(ctrl *gomock.Controller) *MockBeginBlockAppModule {
mock := &MockBeginBlockAppModule{ctrl: ctrl}
mock.recorder = &MockBeginBlockAppModuleMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockBeginBlockAppModule) EXPECT() *MockBeginBlockAppModuleMockRecorder {
return m.recorder
}
// BeginBlock mocks base method.
func (m *MockBeginBlockAppModule) BeginBlock(arg0 types1.Context, arg1 types.RequestBeginBlock) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "BeginBlock", arg0, arg1)
}
// BeginBlock indicates an expected call of BeginBlock.
func (mr *MockBeginBlockAppModuleMockRecorder) BeginBlock(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeginBlock", reflect.TypeOf((*MockBeginBlockAppModule)(nil).BeginBlock), arg0, arg1)
}
// GetQueryCmd mocks base method.
func (m *MockBeginBlockAppModule) GetQueryCmd() *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetQueryCmd")
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetQueryCmd indicates an expected call of GetQueryCmd.
func (mr *MockBeginBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetQueryCmd))
}
// GetTxCmd mocks base method.
func (m *MockBeginBlockAppModule) GetTxCmd() *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTxCmd")
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetTxCmd indicates an expected call of GetTxCmd.
func (mr *MockBeginBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockBeginBlockAppModule)(nil).GetTxCmd))
}
// Name mocks base method.
func (m *MockBeginBlockAppModule) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockBeginBlockAppModuleMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockBeginBlockAppModule)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockBeginBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockBeginBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockBeginBlockAppModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterInterfaces", arg0)
}
// RegisterInterfaces indicates an expected call of RegisterInterfaces.
func (mr *MockBeginBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterInterfaces), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockBeginBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockBeginBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockBeginBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// MockEndBlockAppModule is a mock of EndBlockAppModule interface.
type MockEndBlockAppModule struct {
ctrl *gomock.Controller
recorder *MockEndBlockAppModuleMockRecorder
}
// MockEndBlockAppModuleMockRecorder is the mock recorder for MockEndBlockAppModule.
type MockEndBlockAppModuleMockRecorder struct {
mock *MockEndBlockAppModule
}
// NewMockEndBlockAppModule creates a new mock instance.
func NewMockEndBlockAppModule(ctrl *gomock.Controller) *MockEndBlockAppModule {
mock := &MockEndBlockAppModule{ctrl: ctrl}
mock.recorder = &MockEndBlockAppModuleMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockEndBlockAppModule) EXPECT() *MockEndBlockAppModuleMockRecorder {
return m.recorder
}
// EndBlock mocks base method.
func (m *MockEndBlockAppModule) EndBlock(arg0 types1.Context, arg1 types.RequestEndBlock) []types.ValidatorUpdate {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "EndBlock", arg0, arg1)
ret0, _ := ret[0].([]types.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)
}
// GetQueryCmd mocks base method.
func (m *MockEndBlockAppModule) GetQueryCmd() *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetQueryCmd")
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetQueryCmd indicates an expected call of GetQueryCmd.
func (mr *MockEndBlockAppModuleMockRecorder) GetQueryCmd() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetQueryCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetQueryCmd))
}
// GetTxCmd mocks base method.
func (m *MockEndBlockAppModule) GetTxCmd() *cobra.Command {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetTxCmd")
ret0, _ := ret[0].(*cobra.Command)
return ret0
}
// GetTxCmd indicates an expected call of GetTxCmd.
func (mr *MockEndBlockAppModuleMockRecorder) GetTxCmd() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTxCmd", reflect.TypeOf((*MockEndBlockAppModule)(nil).GetTxCmd))
}
// Name mocks base method.
func (m *MockEndBlockAppModule) Name() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Name")
ret0, _ := ret[0].(string)
return ret0
}
// Name indicates an expected call of Name.
func (mr *MockEndBlockAppModuleMockRecorder) Name() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockEndBlockAppModule)(nil).Name))
}
// RegisterGRPCGatewayRoutes mocks base method.
func (m *MockEndBlockAppModule) RegisterGRPCGatewayRoutes(arg0 client.Context, arg1 *runtime.ServeMux) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterGRPCGatewayRoutes", arg0, arg1)
}
// RegisterGRPCGatewayRoutes indicates an expected call of RegisterGRPCGatewayRoutes.
func (mr *MockEndBlockAppModuleMockRecorder) RegisterGRPCGatewayRoutes(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterGRPCGatewayRoutes", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterGRPCGatewayRoutes), arg0, arg1)
}
// RegisterInterfaces mocks base method.
func (m *MockEndBlockAppModule) RegisterInterfaces(arg0 types0.InterfaceRegistry) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterInterfaces", arg0)
}
// RegisterInterfaces indicates an expected call of RegisterInterfaces.
func (mr *MockEndBlockAppModuleMockRecorder) RegisterInterfaces(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInterfaces", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterInterfaces), arg0)
}
// RegisterLegacyAminoCodec mocks base method.
func (m *MockEndBlockAppModule) RegisterLegacyAminoCodec(arg0 *codec.LegacyAmino) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "RegisterLegacyAminoCodec", arg0)
}
// RegisterLegacyAminoCodec indicates an expected call of RegisterLegacyAminoCodec.
func (mr *MockEndBlockAppModuleMockRecorder) RegisterLegacyAminoCodec(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterLegacyAminoCodec", reflect.TypeOf((*MockEndBlockAppModule)(nil).RegisterLegacyAminoCodec), arg0)
}
// MockHasABCIEndblock is a mock of HasABCIEndblock interface.
type MockHasABCIEndblock struct {
ctrl *gomock.Controller
+5 -2
View File
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
cmtcfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/node"
"github.com/cometbft/cometbft/p2p"
pvm "github.com/cometbft/cometbft/privval"
@@ -17,6 +18,7 @@ import (
cmttime "github.com/cometbft/cometbft/types/time"
"golang.org/x/sync/errgroup"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
servercmtlog "github.com/cosmos/cosmos-sdk/server/log"
@@ -50,13 +52,14 @@ func startInProcess(cfg Config, val *Validator) error {
return appGenesis.ToGenesisDoc()
}
cmtApp := server.NewCometABCIWrapper(app)
tmNode, err := node.NewNode( //resleak:notresource
cmtCfg,
pvm.LoadOrGenFilePV(cmtCfg.PrivValidatorKeyFile(), cmtCfg.PrivValidatorStateFile()),
nodeKey,
proxy.NewLocalClientCreator(app),
proxy.NewLocalClientCreator(cmtApp),
appGenesisProvider,
node.DefaultDBProvider,
cmtcfg.DefaultDBProvider,
node.DefaultMetricsProvider(cmtCfg.Instrumentation),
servercmtlog.CometLoggerWrapper{Logger: logger.With("module", val.Moniker)},
)
+13 -12
View File
@@ -157,23 +157,24 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon
}
// init chain will set the validator set and initialize the genesis accounts
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
_, err = app.InitChain(&abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
})
if err != nil {
return nil, fmt.Errorf("failed to init chain: %w", err)
}
// commit genesis changes
if !startupConfig.AtGenesis {
app.Commit()
app.BeginBlock(abci.RequestBeginBlock{Header: cmtproto.Header{
_, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{
Height: app.LastBlockHeight() + 1,
AppHash: app.LastCommitID().Hash,
ValidatorsHash: valSet.Hash(),
NextValidatorsHash: valSet.Hash(),
}})
})
if err != nil {
return nil, fmt.Errorf("failed to finalize block: %w", err)
}
}
return app, nil
+23 -9
View File
@@ -6,6 +6,7 @@ import (
"testing"
"time"
"cosmossdk.io/errors"
types2 "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/require"
@@ -120,20 +121,33 @@ func SignCheckDeliver(
require.Nil(t, res)
}
// Simulate a sending a transaction and committing a block
app.BeginBlock(types2.RequestBeginBlock{Header: header})
gInfo, res, err := app.SimDeliver(txCfg.TxEncoder(), tx)
bz, err := txCfg.TxEncoder()(tx)
require.NoError(t, err)
resBlock, err := app.FinalizeBlock(&types2.RequestFinalizeBlock{
Height: header.Height,
Txs: [][]byte{bz},
})
require.NoError(t, err)
require.Equal(t, 1, len(resBlock.TxResults))
txResult := resBlock.TxResults[0]
finalizeSuccess := txResult.Code == 0
if expPass {
require.NoError(t, err)
require.NotNil(t, res)
require.True(t, finalizeSuccess)
} else {
require.Error(t, err)
require.Nil(t, res)
require.False(t, finalizeSuccess)
}
app.EndBlock(types2.RequestEndBlock{})
app.Commit()
return gInfo, res, err
gInfo := sdk.GasInfo{GasWanted: uint64(txResult.GasWanted), GasUsed: uint64(txResult.GasUsed)}
txRes := sdk.Result{Data: txResult.Data, Log: txResult.Log, Events: txResult.Events}
if finalizeSuccess {
err = nil
} else {
err = errors.ABCIError(txResult.Codespace, txResult.Code, txResult.Log)
}
return gInfo, &txRes, err
}
+20 -27
View File
@@ -9,7 +9,6 @@ import (
"syscall"
"cosmossdk.io/log"
abcitypes "github.com/cometbft/cometbft/abci/types"
cmtcfg "github.com/cometbft/cometbft/config"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/node"
@@ -17,7 +16,10 @@ import (
"github.com/cometbft/cometbft/privval"
"github.com/cometbft/cometbft/proxy"
cmttypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/server"
servercmtlog "github.com/cosmos/cosmos-sdk/server/log"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@@ -27,21 +29,15 @@ import (
// As CometStart is more broadly used in the codebase,
// the number of available methods on CometStarter will grow.
type CometStarter struct {
logger log.Logger
app abcitypes.Application
cfg *cmtcfg.Config
valPrivKey cmted25519.PrivKey
genesis []byte
rootDir string
rpcListen bool
logger log.Logger
app servertypes.ABCI
cfg *cmtcfg.Config
valPrivKey cmted25519.PrivKey
genesis []byte
rootDir string
rpcListen bool
tcpAddrChooser func() string
startTries int
startTries int
}
// NewCometStarter accepts a minimal set of arguments to start comet with an ABCI app.
@@ -49,7 +45,7 @@ type CometStarter struct {
//
// NewCometStarter(...).Logger(...).Start()
func NewCometStarter(
app abcitypes.Application,
app servertypes.ABCI,
cfg *cmtcfg.Config,
valPrivKey cmted25519.PrivKey,
genesis []byte,
@@ -92,16 +88,12 @@ func NewCometStarter(
// and bumping it up to 12 makes it almost never fail.
const defaultStartTries = 12
return &CometStarter{
logger: log.NewNopLogger(),
app: app,
logger: log.NewNopLogger(),
app: app,
cfg: cfg,
genesis: genesis,
valPrivKey: valPrivKey,
rootDir: rootDir,
rootDir: rootDir,
startTries: defaultStartTries,
}
}
@@ -132,8 +124,8 @@ func (s *CometStarter) Start() (n *node.Node, err error) {
return nil, err
}
// Wrap this defer in an anonymous function so we don't immediately evaluate n,
// which would always be nil at thi spoint.
// Wrap this defer in an anonymous function so we don't immediately evaluate
// n, which would always be nil at this point.
defer func() {
globalCometMu.Release(n)
}()
@@ -153,6 +145,7 @@ func (s *CometStarter) Start() (n *node.Node, err error) {
return appGenesis.ToGenesisDoc()
}
cmtApp := server.NewCometABCIWrapper(s.app)
for i := 0; i < s.startTries; i++ {
s.cfg.P2P.ListenAddress = s.likelyAvailableAddress()
if s.rpcListen {
@@ -163,9 +156,9 @@ func (s *CometStarter) Start() (n *node.Node, err error) {
s.cfg,
fpv,
nodeKey,
proxy.NewLocalClientCreator(s.app),
proxy.NewLocalClientCreator(cmtApp),
appGenesisProvider,
node.DefaultDBProvider,
cmtcfg.DefaultDBProvider,
node.DefaultMetricsProvider(s.cfg.Instrumentation),
servercmtlog.CometLoggerWrapper{Logger: s.logger},
)
+3 -3
View File
@@ -44,9 +44,9 @@ func NewNetwork(nVals int, createCometStarter func(int) *CometStarter) (Nodes, e
return
}
// Notify that the new node's switch is available,
// so this node can be peered with the other nodes.
switchCh <- n.PEXReactor().Switch
// Notify that the new node's switch is available, so this node can be
// peered with the other nodes.
switchCh <- n.Switch()
// And assign the node into its correct index in the ordered slice.
nodes[i] = n
+15 -4
View File
@@ -12,15 +12,26 @@ import (
// If totalWait has elapsed and the desired height has not been reached,
// an error is returned.
func WaitForNodeHeight(n *node.Node, desiredHeight int64, totalWait time.Duration) error {
const backoff = 100 * time.Millisecond
attempts := int64(totalWait / backoff)
const backOff = 100 * time.Millisecond
attempts := int64(totalWait / backOff)
// In Comet 0.37, the consensus state was exposed directly on the Node.
// As of 0.38, the node no longer exposes consensus state,
// but the consensus state is available as a field on the RPC environment.
//
// Luckily, in 0.38 the RPC environment is no longer a package-level singleton,
// so retrieving the RPC environment for a single node should be safe.
env, err := n.ConfigureRPC()
if err != nil {
return fmt.Errorf("failed to configure RPC to reach into consensus state: %w", err)
}
curHeight := int64(-1)
for i := int64(0); i < attempts; i++ {
curHeight = n.ConsensusState().GetLastHeight()
curHeight = env.ConsensusState.GetState().LastBlockHeight
if curHeight < desiredHeight {
time.Sleep(backoff)
time.Sleep(backOff)
continue
}