Co-authored-by: Randy Grok <98407738+randygrok@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Randy Grok
Julien Robert
parent
889becd2c0
commit
384fa5fff5
+5
-10
@@ -17,6 +17,7 @@ import (
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/server"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"cosmossdk.io/log"
|
||||
@@ -89,6 +90,7 @@ type BaseApp struct {
|
||||
verifyVoteExt sdk.VerifyVoteExtensionHandler // ABCI VerifyVoteExtension handler
|
||||
prepareCheckStater sdk.PrepareCheckStater // logic to run during commit using the checkState
|
||||
precommiter sdk.Precommiter // logic to run during commit using the deliverState
|
||||
versionModifier server.VersionModifier // interface to get and set the app version
|
||||
|
||||
addrPeerFilter sdk.PeerFilter // filter peers by address and port
|
||||
idPeerFilter sdk.PeerFilter // filter peers by node ID
|
||||
@@ -249,18 +251,11 @@ func (app *BaseApp) Name() string {
|
||||
|
||||
// AppVersion returns the application's protocol version.
|
||||
func (app *BaseApp) AppVersion(ctx context.Context) (uint64, error) {
|
||||
if app.paramStore == nil {
|
||||
return 0, errors.New("app.paramStore is nil")
|
||||
if app.versionModifier == nil {
|
||||
return 0, errors.New("app.versionModifier is nil")
|
||||
}
|
||||
|
||||
cp, err := app.paramStore.Get(ctx)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get consensus params: %w", err)
|
||||
}
|
||||
if cp.Version == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return cp.Version.App, nil
|
||||
return app.versionModifier.AppVersion(ctx)
|
||||
}
|
||||
|
||||
// Version returns the application's version string.
|
||||
|
||||
@@ -81,6 +81,7 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
|
||||
app.SetParamStore(paramStore{db: dbm.NewMemDB()})
|
||||
app.SetTxDecoder(txConfig.TxDecoder())
|
||||
app.SetTxEncoder(txConfig.TxEncoder())
|
||||
app.SetVersionModifier(newMockedVersionModifier(0))
|
||||
|
||||
// mount stores and seal
|
||||
require.Nil(t, app.LoadLatestVersion())
|
||||
|
||||
+13
-14
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"cosmossdk.io/core/server"
|
||||
corestore "cosmossdk.io/core/store"
|
||||
"cosmossdk.io/store/metrics"
|
||||
pruningtypes "cosmossdk.io/store/pruning/types"
|
||||
@@ -146,22 +147,11 @@ func (app *BaseApp) SetVersion(v string) {
|
||||
// SetAppVersion sets the application's version this is used as part of the
|
||||
// header in blocks and is returned to the consensus engine in EndBlock.
|
||||
func (app *BaseApp) SetAppVersion(ctx context.Context, v uint64) error {
|
||||
if app.paramStore == nil {
|
||||
return errors.New("param store must be set to set app version")
|
||||
if app.versionModifier == nil {
|
||||
return errors.New("version modifier must be set to set app version")
|
||||
}
|
||||
|
||||
cp, err := app.paramStore.Get(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get consensus params: %w", err)
|
||||
}
|
||||
if cp.Version == nil {
|
||||
return errors.New("version is not set in param store")
|
||||
}
|
||||
cp.Version.App = v
|
||||
if err := app.paramStore.Set(ctx, cp); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return app.versionModifier.SetAppVersion(ctx, v)
|
||||
}
|
||||
|
||||
func (app *BaseApp) SetDB(db corestore.KVStoreWithBatch) {
|
||||
@@ -323,6 +313,15 @@ func (app *BaseApp) SetTxEncoder(txEncoder sdk.TxEncoder) {
|
||||
app.txEncoder = txEncoder
|
||||
}
|
||||
|
||||
// SetVersionModifier sets the version modifier for the BaseApp that allows to set the app version.
|
||||
func (app *BaseApp) SetVersionModifier(versionModifier server.VersionModifier) {
|
||||
if app.sealed {
|
||||
panic("SetVersionModifier() on sealed BaseApp")
|
||||
}
|
||||
|
||||
app.versionModifier = versionModifier
|
||||
}
|
||||
|
||||
// SetQueryMultiStore set a alternative MultiStore implementation to support grpc query service.
|
||||
//
|
||||
// Ref: https://github.com/cosmos/cosmos-sdk/issues/13317
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
|
||||
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/server"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
@@ -375,3 +376,20 @@ func wonkyMsg(t *testing.T, cfg client.TxConfig, tx signing.Tx) signing.Tx {
|
||||
require.NoError(t, err)
|
||||
return builder.GetTx()
|
||||
}
|
||||
|
||||
func newMockedVersionModifier(startingVersion uint64) server.VersionModifier {
|
||||
return &mockedVersionModifier{version: startingVersion}
|
||||
}
|
||||
|
||||
type mockedVersionModifier struct {
|
||||
version uint64
|
||||
}
|
||||
|
||||
func (m *mockedVersionModifier) SetAppVersion(ctx context.Context, u uint64) error {
|
||||
m.version = u
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockedVersionModifier) AppVersion(ctx context.Context) (uint64, error) {
|
||||
return m.version, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user