From e71ff8e8a8cf7bc3c8c721c6c0f23ec386b1f384 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Fri, 30 Aug 2024 09:39:31 +0200 Subject: [PATCH 1/7] fix gas meter error on endblocker --- core/server/app.go | 2 +- runtime/v2/module.go | 8 ----- server/v2/stf/core_branch_service.go | 2 +- server/v2/stf/core_branch_service_test.go | 3 ++ server/v2/stf/go.mod | 4 +++ server/v2/stf/go.sum | 10 ++++++ x/consensus/depinject.go | 38 ++++++++++++++++++++++- 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/core/server/app.go b/core/server/app.go index a785de5011a7..9576fa8825f8 100644 --- a/core/server/app.go +++ b/core/server/app.go @@ -50,7 +50,7 @@ type TxResult struct { } // VersionModifier defines the interface fulfilled by BaseApp -// which allows getting and setting it's appVersion field. This +// which allows getting and setting its appVersion field. This // in turn updates the consensus params that are sent to the // consensus engine in EndBlock type VersionModifier interface { diff --git a/runtime/v2/module.go b/runtime/v2/module.go index 6ae735505d02..6b5fa80ccbba 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -19,7 +19,6 @@ import ( "cosmossdk.io/core/comet" "cosmossdk.io/core/legacy" "cosmossdk.io/core/registry" - "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" "cosmossdk.io/depinject" @@ -99,7 +98,6 @@ func init() { ProvideEnvironment[transaction.Tx], ProvideModuleManager[transaction.Tx], ProvideCometService, - ProvideAppVersionModifier[transaction.Tx], ), appconfig.Invoke(SetupAppBuilder), ) @@ -239,9 +237,3 @@ func storeKeyOverride(config *runtimev2.Module, moduleName string) *runtimev2.St func ProvideCometService() comet.Service { return &services.ContextAwareCometInfoService{} } - -// ProvideAppVersionModifier returns nil, `app.VersionModifier` is a feature of BaseApp and neither used nor required for runtime/v2. -// nil is acceptable, see: https://github.com/cosmos/cosmos-sdk/blob/0a6ee406a02477ae8ccbfcbe1b51fc3930087f4c/x/upgrade/keeper/keeper.go#L438 -func ProvideAppVersionModifier[T transaction.Tx](app *AppBuilder[T]) server.VersionModifier { - return nil -} diff --git a/server/v2/stf/core_branch_service.go b/server/v2/stf/core_branch_service.go index 431730b2334a..9b5d8eea4562 100644 --- a/server/v2/stf/core_branch_service.go +++ b/server/v2/stf/core_branch_service.go @@ -41,7 +41,7 @@ func (bs BranchService) ExecuteWithGasLimit( // restore original context gasUsed = exCtx.meter.Limit() - exCtx.meter.Remaining() _ = originalGasMeter.Consume(gasUsed, "execute-with-gas-limit") - exCtx.setGasLimit(originalGasMeter.Limit() - originalGasMeter.Remaining()) + exCtx.setGasLimit(originalGasMeter.Remaining()) return gasUsed, err } diff --git a/server/v2/stf/core_branch_service_test.go b/server/v2/stf/core_branch_service_test.go index a54783b605e7..9794b26a4d40 100644 --- a/server/v2/stf/core_branch_service_test.go +++ b/server/v2/stf/core_branch_service_test.go @@ -6,6 +6,7 @@ import ( "testing" gogotypes "github.com/cosmos/gogoproto/types" + "github.com/stretchr/testify/require" appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/server/v2/stf/branch" @@ -71,6 +72,7 @@ func TestBranchService(t *testing.T) { t.Run("fail - reverts state", func(t *testing.T) { stfCtx := makeContext() + originalGas := stfCtx.meter.Remaining() gasUsed, err := branchService.ExecuteWithGasLimit(stfCtx, 10000, func(ctx context.Context) error { kvSet(t, ctx, "cookies") return errors.New("fail") @@ -81,6 +83,7 @@ func TestBranchService(t *testing.T) { if gasUsed == 0 { t.Error("expected non-zero gasUsed") } + require.Equal(t, int(originalGas-gasUsed), int(stfCtx.meter.Remaining())) stateNotHas(t, stfCtx.state, "cookies") }) diff --git a/server/v2/stf/go.mod b/server/v2/stf/go.mod index 69d9dd853a73..85a46964223a 100644 --- a/server/v2/stf/go.mod +++ b/server/v2/stf/go.mod @@ -7,10 +7,14 @@ replace cosmossdk.io/core => ../../../core require ( cosmossdk.io/core v0.11.0 github.com/cosmos/gogoproto v1.7.0 + github.com/stretchr/testify v1.8.4 github.com/tidwall/btree v1.7.0 ) require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.6.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect google.golang.org/protobuf v1.34.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/v2/stf/go.sum b/server/v2/stf/go.sum index 201794168336..4f6b17704f38 100644 --- a/server/v2/stf/go.sum +++ b/server/v2/stf/go.sum @@ -1,10 +1,20 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro= github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/x/consensus/depinject.go b/x/consensus/depinject.go index 127144d91a51..b225c07b4ddf 100644 --- a/x/consensus/depinject.go +++ b/x/consensus/depinject.go @@ -1,13 +1,14 @@ package consensus import ( + "context" modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/server" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" "cosmossdk.io/x/consensus/keeper" - "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" @@ -23,6 +24,7 @@ func init() { appconfig.RegisterModule( &modulev1.Module{}, appconfig.Provide(ProvideModule), + appconfig.Provide(ProvideAppVersionModifier), ) } @@ -72,3 +74,37 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { BaseAppOption: baseappOpt, } } + +type versionModifier struct { + Keeper keeper.Keeper +} + +func (v versionModifier) SetAppVersion(ctx context.Context, version uint64) error { + params, err := v.Keeper.Params(ctx, nil) + if err != nil { + return err + } + + updatedParams := params.Params + updatedParams.Version.App = version + + err = v.Keeper.ParamsStore.Set(ctx, *updatedParams) + if err != nil { + return err + } + + return nil +} + +func (v versionModifier) AppVersion(ctx context.Context) (uint64, error) { + params, err := v.Keeper.Params(ctx, nil) + if err != nil { + return 0, err + } + + return params.Params.Version.GetApp(), nil +} + +func ProvideAppVersionModifier(k keeper.Keeper) server.VersionModifier { + return versionModifier{Keeper: k} +} From fbb1d29b092cc70df3ec513db9f4a6b13a291696 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Mon, 2 Sep 2024 21:13:54 +0200 Subject: [PATCH 2/7] Fix error with nil pointer on msgRouter when gov proposal. --- server/v2/stf/core_branch_service.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/v2/stf/core_branch_service.go b/server/v2/stf/core_branch_service.go index 9b5d8eea4562..5a83dff6be7c 100644 --- a/server/v2/stf/core_branch_service.go +++ b/server/v2/stf/core_branch_service.go @@ -62,6 +62,8 @@ func (bs BranchService) execute(ctx *executionContext, f func(ctx context.Contex branchFn: ctx.branchFn, makeGasMeter: ctx.makeGasMeter, makeGasMeteredStore: ctx.makeGasMeteredStore, + msgRouter: ctx.msgRouter, + queryRouter: ctx.queryRouter, } err := f(branchedCtx) From eeb0d7af1f89b1f9210cea2bd301ab1fd152f73f Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 3 Sep 2024 20:45:56 +0200 Subject: [PATCH 3/7] remove require lib --- server/v2/stf/core_branch_service_test.go | 9 +++++---- server/v2/stf/go.mod | 4 ---- server/v2/stf/go.sum | 10 ---------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/server/v2/stf/core_branch_service_test.go b/server/v2/stf/core_branch_service_test.go index 9794b26a4d40..0394ce0f3b1a 100644 --- a/server/v2/stf/core_branch_service_test.go +++ b/server/v2/stf/core_branch_service_test.go @@ -5,13 +5,11 @@ import ( "errors" "testing" - gogotypes "github.com/cosmos/gogoproto/types" - "github.com/stretchr/testify/require" - appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/server/v2/stf/branch" "cosmossdk.io/server/v2/stf/gas" "cosmossdk.io/server/v2/stf/mock" + gogotypes "github.com/cosmos/gogoproto/types" ) func TestBranchService(t *testing.T) { @@ -83,7 +81,10 @@ func TestBranchService(t *testing.T) { if gasUsed == 0 { t.Error("expected non-zero gasUsed") } - require.Equal(t, int(originalGas-gasUsed), int(stfCtx.meter.Remaining())) + if stfCtx.meter.Remaining() != originalGas-gasUsed { + t.Error("expected gas to be reverted") + } + stateNotHas(t, stfCtx.state, "cookies") }) diff --git a/server/v2/stf/go.mod b/server/v2/stf/go.mod index 85a46964223a..69d9dd853a73 100644 --- a/server/v2/stf/go.mod +++ b/server/v2/stf/go.mod @@ -7,14 +7,10 @@ replace cosmossdk.io/core => ../../../core require ( cosmossdk.io/core v0.11.0 github.com/cosmos/gogoproto v1.7.0 - github.com/stretchr/testify v1.8.4 github.com/tidwall/btree v1.7.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect google.golang.org/protobuf v1.34.2 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/server/v2/stf/go.sum b/server/v2/stf/go.sum index 4f6b17704f38..201794168336 100644 --- a/server/v2/stf/go.sum +++ b/server/v2/stf/go.sum @@ -1,20 +1,10 @@ github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro= github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From f8994b64be3f3179bb424e036d1ae3da740332af Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 3 Sep 2024 21:08:01 +0200 Subject: [PATCH 4/7] temp commit on AppVersion on v1 --- baseapp/baseapp.go | 15 +++++---------- baseapp/options.go | 22 ++++++++-------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 75f3b6a6a811..0bdb72db9ae1 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -2,6 +2,7 @@ package baseapp import ( "context" + "cosmossdk.io/core/server" "errors" "fmt" "maps" @@ -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 @@ -254,18 +256,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. diff --git a/baseapp/options.go b/baseapp/options.go index bcff418fb8b0..794f1f93401d 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -2,6 +2,7 @@ package baseapp import ( "context" + "cosmossdk.io/core/server" "errors" "fmt" "io" @@ -119,6 +120,10 @@ func SetOptimisticExecution(opts ...func(*oe.OptimisticExecution)) func(*BaseApp } } +func SetVersionModifier(vm server.VersionModifier) func(*BaseApp) { + return func(app *BaseApp) { app.versionModifier = vm } +} + // SetIncludeNestedMsgsGas sets the message types for which gas costs for its nested messages are calculated when simulating. func SetIncludeNestedMsgsGas(msgs []sdk.Msg) func(*BaseApp) { return func(app *BaseApp) { @@ -160,22 +165,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 dbm.DB) { From 5de834040270221df4780ddc4c2993c75c42d93d Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Tue, 3 Sep 2024 22:07:13 +0200 Subject: [PATCH 5/7] include Version Modifier also to simapp v1 --- baseapp/options.go | 12 ++++++++---- runtime/module.go | 6 ------ simapp/app.go | 3 +++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/baseapp/options.go b/baseapp/options.go index 794f1f93401d..19716f0dd0f2 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -120,10 +120,6 @@ func SetOptimisticExecution(opts ...func(*oe.OptimisticExecution)) func(*BaseApp } } -func SetVersionModifier(vm server.VersionModifier) func(*BaseApp) { - return func(app *BaseApp) { app.versionModifier = vm } -} - // SetIncludeNestedMsgsGas sets the message types for which gas costs for its nested messages are calculated when simulating. func SetIncludeNestedMsgsGas(msgs []sdk.Msg) func(*BaseApp) { return func(app *BaseApp) { @@ -331,6 +327,14 @@ func (app *BaseApp) SetTxEncoder(txEncoder sdk.TxEncoder) { app.txEncoder = txEncoder } +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 diff --git a/runtime/module.go b/runtime/module.go index f8883e0e8e27..27c4046614e4 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -15,7 +15,6 @@ import ( "cosmossdk.io/core/appmodule" "cosmossdk.io/core/comet" "cosmossdk.io/core/legacy" - "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" @@ -103,7 +102,6 @@ func init() { ProvideEnvironment, ProvideTransientStoreService, ProvideModuleManager, - ProvideAppVersionModifier, ProvideCometService, ), appconfig.Invoke(SetupAppBuilder), @@ -293,10 +291,6 @@ func ProvideTransientStoreService( return transientStoreService{key: storeKey} } -func ProvideAppVersionModifier(app *AppBuilder) server.VersionModifier { - return app.app -} - func ProvideCometService() comet.Service { return NewContextAwareCometInfoService() } diff --git a/simapp/app.go b/simapp/app.go index 1e64e65dee18..c7de0b1ff338 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -290,6 +290,9 @@ func NewSimApp( app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensustypes.StoreKey]), logger.With(log.ModuleKey, "x/consensus")), authtypes.NewModuleAddress(govtypes.ModuleName).String()) bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) + // set the version modifier + bApp.SetVersionModifier(consensus.ProvideAppVersionModifier(app.ConsensusParamsKeeper)) + // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, From aa14418314cc622e62231f81429b3260ccc7983f Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Wed, 4 Sep 2024 18:49:07 +0200 Subject: [PATCH 6/7] add changes based on code review --- baseapp/options.go | 1 + simapp/CHANGELOG.md | 1 + x/consensus/depinject.go | 1 + 3 files changed, 3 insertions(+) diff --git a/baseapp/options.go b/baseapp/options.go index 19716f0dd0f2..1ca4cef37f60 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -327,6 +327,7 @@ 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") diff --git a/simapp/CHANGELOG.md b/simapp/CHANGELOG.md index 3c46633c7080..d1e5e702cb01 100644 --- a/simapp/CHANGELOG.md +++ b/simapp/CHANGELOG.md @@ -45,6 +45,7 @@ Always refer to the [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/mai * [#20771](https://github.com/cosmos/cosmos-sdk/pull/20771) Use client/v2 `GetNodeHomeDirectory` helper in `app.go` and use the `DefaultNodeHome` constant everywhere in the app. * [#20490](https://github.com/cosmos/cosmos-sdk/pull/20490) Refactor simulations to make use of `testutil/sims` instead of `runsims`. * [#19726](https://github.com/cosmos/cosmos-sdk/pull/19726) Update APIs to match CometBFT v1. +* [#21508](https://github.com/cosmos/cosmos-sdk/pull/21508) Abstract the way we update the version of the app state in `app.go` using the interface `VersionModifier`. diff --git a/x/consensus/depinject.go b/x/consensus/depinject.go index b225c07b4ddf..07048b4c8684 100644 --- a/x/consensus/depinject.go +++ b/x/consensus/depinject.go @@ -66,6 +66,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { m := NewAppModule(in.Cdc, k) baseappOpt := func(app *baseapp.BaseApp) { app.SetParamStore(k.ParamsStore) + app.SetVersionModifier(versionModifier{Keeper: k}) } return ModuleOutputs{ From efc3217f13c079502164bba4e40355aa7ebe3bf5 Mon Sep 17 00:00:00 2001 From: Randy Grok Date: Thu, 5 Sep 2024 17:35:49 +0200 Subject: [PATCH 7/7] include mocked version modifier --- baseapp/baseapp_test.go | 1 + baseapp/utils_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index ecaf6894b400..22b046cf8a63 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -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()) diff --git a/baseapp/utils_test.go b/baseapp/utils_test.go index 970aa0cedce5..3d1a867100f1 100644 --- a/baseapp/utils_test.go +++ b/baseapp/utils_test.go @@ -3,6 +3,7 @@ package baseapp_test import ( "bytes" "context" + "cosmossdk.io/core/server" "encoding/binary" "encoding/json" "errors" @@ -445,3 +446,20 @@ func (n NestedMessgesServerImpl) Check(ctx context.Context, message *baseapptest sdkCtx.GasMeter().ConsumeGas(gas, "nested messages test") return nil, nil } + +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 +}