From 95e848d327510faf8a91398e661d99652bac473a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 7 Dec 2022 22:36:53 +0100 Subject: [PATCH 01/28] refactor: set genesis module order in app config --- runtime/app.go | 4 +--- simapp/app_config.go | 19 +++++++++++++++++++ simapp/app_v2.go | 32 -------------------------------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index 75e412744b01..cfa421aa07f0 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -76,8 +76,7 @@ func (a *App) RegisterModules(modules ...module.AppModule) error { // Load finishes all initialization operations and loads the app. func (a *App) Load(loadLatest bool) error { // register runtime module services - err := a.registerRuntimeServices() - if err != nil { + if err := a.registerRuntimeServices(); err != nil { return err } @@ -86,7 +85,6 @@ func (a *App) Load(loadLatest bool) error { if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) - a.SetInitChainer(a.InitChainer) } if len(a.config.ExportGenesis) != 0 { diff --git a/simapp/app_config.go b/simapp/app_config.go index e3c1c261d80c..f70c15b362ff 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -50,6 +50,21 @@ import ( ) var ( + + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // NOTE: The genutils module must also occur after auth so that it can access the params from auth. + // NOTE: Capability module must occur first so that it can initialize any capabilities + // so that other modules that want to create or claim capabilities afterwards in InitChain + // can do so safely. + genesisModuleOrder = []string{ + capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, + distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, + minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, + feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, + vestingtypes.ModuleName, consensustypes.ModuleName, + } + // module account permissions moduleAccPerms = []*authmodulev1.ModuleAccountPermission{ {Account: authtypes.FeeCollectorName}, @@ -133,6 +148,10 @@ var ( KvStoreKey: "acc", }, }, + InitGenesis: genesisModuleOrder, + // When ExportGenesis is not specified, the export genesis module order + // is equal to the init genesis order + // ExportGenesis: genesisModuleOrder, }), }, { diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 9dcba3bb85e2..99136e8236e3 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -35,29 +35,20 @@ import ( _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" - vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" "github.com/cosmos/cosmos-sdk/x/bank" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/capability" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" - capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" consensus "github.com/cosmos/cosmos-sdk/x/consensus" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" "github.com/cosmos/cosmos-sdk/x/crisis" crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/evidence" evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" "github.com/cosmos/cosmos-sdk/x/genutil" @@ -65,14 +56,10 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov" govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/group" groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" - minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - "github.com/cosmos/cosmos-sdk/x/nft" nftkeeper "github.com/cosmos/cosmos-sdk/x/nft/keeper" nftmodule "github.com/cosmos/cosmos-sdk/x/nft/module" "github.com/cosmos/cosmos-sdk/x/params" @@ -81,14 +68,11 @@ import ( paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) var ( @@ -278,22 +262,6 @@ func NewSimApp( // Sets the version setter for the upgrade module app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - // NOTE: The genutils module must occur after staking so that pools are - // properly initialized with tokens from genesis accounts. - // NOTE: The genutils module must also occur after auth so that it can access the params from auth. - // NOTE: Capability module must occur first so that it can initialize any capabilities - // so that other modules that want to create or claim capabilities afterwards in InitChain - // can do so safely. - genesisModuleOrder := []string{ - capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, - distrtypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, - minttypes.ModuleName, crisistypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, - feegrant.ModuleName, nft.ModuleName, group.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, - vestingtypes.ModuleName, consensustypes.ModuleName, - } - app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) - app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) - // Uncomment if you want to set a custom migration order here. // app.ModuleManager.SetOrderMigrations(custom order) From 7d53ceb53bb2fc8ac74ad80ea5f9ef268be39d67 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 00:16:33 +0100 Subject: [PATCH 02/28] set custom migration order via app config --- .../app/runtime/v1alpha1/module.pulsar.go | 192 +++++++++++++++--- api/cosmos/consensus/v1/query.pulsar.go | 7 +- api/cosmos/consensus/v1/tx.pulsar.go | 2 +- go.mod | 3 + go.sum | 2 - .../cosmos/app/runtime/v1alpha1/module.proto | 5 + runtime/app.go | 5 + runtime/module.go | 3 +- simapp/app_config.go | 2 + simapp/app_v2.go | 14 -- simapp/go.mod | 3 + simapp/go.sum | 2 - x/consensus/types/query.pb.go | 7 +- x/consensus/types/tx.pb.go | 2 +- 14 files changed, 196 insertions(+), 53 deletions(-) diff --git a/api/cosmos/app/runtime/v1alpha1/module.pulsar.go b/api/cosmos/app/runtime/v1alpha1/module.pulsar.go index 56b5ff66fc27..6e3ba0311553 100644 --- a/api/cosmos/app/runtime/v1alpha1/module.pulsar.go +++ b/api/cosmos/app/runtime/v1alpha1/module.pulsar.go @@ -248,6 +248,52 @@ func (x *_Module_6_list) IsValid() bool { return x.list != nil } +var _ protoreflect.List = (*_Module_7_list)(nil) + +type _Module_7_list struct { + list *[]string +} + +func (x *_Module_7_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_Module_7_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_Module_7_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_Module_7_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_Module_7_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message Module at list field OrderMigrations as it is not of Message kind")) +} + +func (x *_Module_7_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_Module_7_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_Module_7_list) IsValid() bool { + return x.list != nil +} + var ( md_Module protoreflect.MessageDescriptor fd_Module_app_name protoreflect.FieldDescriptor @@ -256,6 +302,7 @@ var ( fd_Module_init_genesis protoreflect.FieldDescriptor fd_Module_export_genesis protoreflect.FieldDescriptor fd_Module_override_store_keys protoreflect.FieldDescriptor + fd_Module_order_migrations protoreflect.FieldDescriptor ) func init() { @@ -267,6 +314,7 @@ func init() { fd_Module_init_genesis = md_Module.Fields().ByName("init_genesis") fd_Module_export_genesis = md_Module.Fields().ByName("export_genesis") fd_Module_override_store_keys = md_Module.Fields().ByName("override_store_keys") + fd_Module_order_migrations = md_Module.Fields().ByName("order_migrations") } var _ protoreflect.Message = (*fastReflection_Module)(nil) @@ -370,6 +418,12 @@ func (x *fastReflection_Module) Range(f func(protoreflect.FieldDescriptor, proto return } } + if len(x.OrderMigrations) != 0 { + value := protoreflect.ValueOfList(&_Module_7_list{list: &x.OrderMigrations}) + if !f(fd_Module_order_migrations, value) { + return + } + } } // Has reports whether a field is populated. @@ -397,6 +451,8 @@ func (x *fastReflection_Module) Has(fd protoreflect.FieldDescriptor) bool { return len(x.ExportGenesis) != 0 case "cosmos.app.runtime.v1alpha1.Module.override_store_keys": return len(x.OverrideStoreKeys) != 0 + case "cosmos.app.runtime.v1alpha1.Module.order_migrations": + return len(x.OrderMigrations) != 0 default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.app.runtime.v1alpha1.Module")) @@ -425,6 +481,8 @@ func (x *fastReflection_Module) Clear(fd protoreflect.FieldDescriptor) { x.ExportGenesis = nil case "cosmos.app.runtime.v1alpha1.Module.override_store_keys": x.OverrideStoreKeys = nil + case "cosmos.app.runtime.v1alpha1.Module.order_migrations": + x.OrderMigrations = nil default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.app.runtime.v1alpha1.Module")) @@ -474,6 +532,12 @@ func (x *fastReflection_Module) Get(descriptor protoreflect.FieldDescriptor) pro } listValue := &_Module_6_list{list: &x.OverrideStoreKeys} return protoreflect.ValueOfList(listValue) + case "cosmos.app.runtime.v1alpha1.Module.order_migrations": + if len(x.OrderMigrations) == 0 { + return protoreflect.ValueOfList(&_Module_7_list{}) + } + listValue := &_Module_7_list{list: &x.OrderMigrations} + return protoreflect.ValueOfList(listValue) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.app.runtime.v1alpha1.Module")) @@ -516,6 +580,10 @@ func (x *fastReflection_Module) Set(fd protoreflect.FieldDescriptor, value proto lv := value.List() clv := lv.(*_Module_6_list) x.OverrideStoreKeys = *clv.list + case "cosmos.app.runtime.v1alpha1.Module.order_migrations": + lv := value.List() + clv := lv.(*_Module_7_list) + x.OrderMigrations = *clv.list default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.app.runtime.v1alpha1.Module")) @@ -566,6 +634,12 @@ func (x *fastReflection_Module) Mutable(fd protoreflect.FieldDescriptor) protore } value := &_Module_6_list{list: &x.OverrideStoreKeys} return protoreflect.ValueOfList(value) + case "cosmos.app.runtime.v1alpha1.Module.order_migrations": + if x.OrderMigrations == nil { + x.OrderMigrations = []string{} + } + value := &_Module_7_list{list: &x.OrderMigrations} + return protoreflect.ValueOfList(value) case "cosmos.app.runtime.v1alpha1.Module.app_name": panic(fmt.Errorf("field app_name of message cosmos.app.runtime.v1alpha1.Module is not mutable")) default: @@ -598,6 +672,9 @@ func (x *fastReflection_Module) NewField(fd protoreflect.FieldDescriptor) protor case "cosmos.app.runtime.v1alpha1.Module.override_store_keys": list := []*StoreKeyConfig{} return protoreflect.ValueOfList(&_Module_6_list{list: &list}) + case "cosmos.app.runtime.v1alpha1.Module.order_migrations": + list := []string{} + return protoreflect.ValueOfList(&_Module_7_list{list: &list}) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.app.runtime.v1alpha1.Module")) @@ -701,6 +778,12 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { n += 1 + l + runtime.Sov(uint64(l)) } } + if len(x.OrderMigrations) > 0 { + for _, s := range x.OrderMigrations { + l = len(s) + n += 1 + l + runtime.Sov(uint64(l)) + } + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -730,6 +813,15 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if len(x.OrderMigrations) > 0 { + for iNdEx := len(x.OrderMigrations) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.OrderMigrations[iNdEx]) + copy(dAtA[i:], x.OrderMigrations[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.OrderMigrations[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } if len(x.OverrideStoreKeys) > 0 { for iNdEx := len(x.OverrideStoreKeys) - 1; iNdEx >= 0; iNdEx-- { encoded, err := options.Marshal(x.OverrideStoreKeys[iNdEx]) @@ -1032,6 +1124,38 @@ func (x *fastReflection_Module) ProtoMethods() *protoiface.Methods { return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err } iNdEx = postIndex + case 7: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field OrderMigrations", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.OrderMigrations = append(x.OrderMigrations, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -1591,6 +1715,10 @@ type Module struct { // override_store_keys is an optional list of overrides for the module store keys // to be used in keeper construction. OverrideStoreKeys []*StoreKeyConfig `protobuf:"bytes,6,rep,name=override_store_keys,json=overrideStoreKeys,proto3" json:"override_store_keys,omitempty"` + // order_migrations defines the order in which module migrations are performed + // If this is left empty, it uses the default migration order + // https://pkg.go.dev/github.com/cosmos/cosmos-sdk@v0.47.0-alpha2/types/module#DefaultMigrationsOrder + OrderMigrations []string `protobuf:"bytes,7,rep,name=order_migrations,json=orderMigrations,proto3" json:"order_migrations,omitempty"` } func (x *Module) Reset() { @@ -1655,6 +1783,13 @@ func (x *Module) GetOverrideStoreKeys() []*StoreKeyConfig { return nil } +func (x *Module) GetOrderMigrations() []string { + if x != nil { + return x.OrderMigrations + } + return nil +} + // StoreKeyConfig may be supplied to override the default module store key, which // is the module name. type StoreKeyConfig struct { @@ -1711,7 +1846,7 @@ var file_cosmos_app_runtime_v1alpha1_module_proto_rawDesc = []byte{ 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x1a, 0x20, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x6d, 0x6f, 0x64, - 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd9, 0x02, 0x0a, 0x06, 0x4d, 0x6f, + 0x75, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x03, 0x0a, 0x06, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x61, 0x70, 0x70, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x70, 0x70, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x62, 0x65, 0x67, 0x69, 0x6e, 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x72, @@ -1729,32 +1864,35 @@ var file_cosmos_app_runtime_v1alpha1_module_proto_rawDesc = []byte{ 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x4b, 0x65, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x11, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x4b, 0x65, 0x79, 0x73, - 0x3a, 0x43, 0xba, 0xc0, 0x96, 0xda, 0x01, 0x3d, 0x0a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x15, - 0x0a, 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x76, 0x31, 0x61, - 0x6c, 0x70, 0x68, 0x61, 0x31, 0x22, 0x53, 0x0a, 0x0e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x4b, 0x65, - 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, - 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x6f, - 0x64, 0x75, 0x6c, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0c, 0x6b, 0x76, 0x5f, 0x73, - 0x74, 0x6f, 0x72, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x6b, 0x76, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x4b, 0x65, 0x79, 0x42, 0xfb, 0x01, 0x0a, 0x1f, 0x63, - 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x75, - 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x0b, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x72, 0x75, 0x6e, 0x74, 0x69, - 0x6d, 0x65, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x72, 0x75, 0x6e, 0x74, - 0x69, 0x6d, 0x65, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, - 0x52, 0xaa, 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x52, - 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, - 0x02, 0x1b, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x70, 0x5c, 0x52, 0x75, 0x6e, - 0x74, 0x69, 0x6d, 0x65, 0x5c, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xe2, 0x02, 0x27, - 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x70, 0x5c, 0x52, 0x75, 0x6e, 0x74, 0x69, - 0x6d, 0x65, 0x5c, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1e, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x3a, 0x3a, 0x41, 0x70, 0x70, 0x3a, 0x3a, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x3a, 0x3a, - 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x29, 0x0a, 0x10, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0f, 0x6f, 0x72, 0x64, 0x65, + 0x72, 0x4d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x3a, 0x43, 0xba, 0xc0, 0x96, + 0xda, 0x01, 0x3d, 0x0a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, + 0x6b, 0x2f, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x15, 0x0a, 0x13, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, + 0x22, 0x53, 0x0a, 0x0e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x4b, 0x65, 0x79, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x4e, + 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0c, 0x6b, 0x76, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x5f, + 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6b, 0x76, 0x53, 0x74, 0x6f, + 0x72, 0x65, 0x4b, 0x65, 0x79, 0x42, 0xfb, 0x01, 0x0a, 0x1f, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, + 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, + 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x0b, 0x4d, 0x6f, 0x64, 0x75, 0x6c, + 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x2f, 0x76, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x76, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x41, 0x52, 0xaa, 0x02, 0x1b, 0x43, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, + 0x65, 0x2e, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, 0x1b, 0x43, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x70, 0x5c, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5c, + 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xe2, 0x02, 0x27, 0x43, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x5c, 0x41, 0x70, 0x70, 0x5c, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5c, 0x56, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0xea, 0x02, 0x1e, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x70, 0x70, + 0x3a, 0x3a, 0x52, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x3a, 0x3a, 0x56, 0x31, 0x61, 0x6c, 0x70, + 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/cosmos/consensus/v1/query.pulsar.go b/api/cosmos/consensus/v1/query.pulsar.go index 8cce55a6a622..2e60bb1777e1 100644 --- a/api/cosmos/consensus/v1/query.pulsar.go +++ b/api/cosmos/consensus/v1/query.pulsar.go @@ -820,7 +820,7 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// QueryParamsRequest defines the request type for querying x/consensus_param parameters. +// QueryParamsRequest defines the request type for querying x/consensus parameters. type QueryParamsRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -847,12 +847,15 @@ func (*QueryParamsRequest) Descriptor() ([]byte, []int) { return file_cosmos_consensus_v1_query_proto_rawDescGZIP(), []int{0} } -// QueryParamsResponse defines the response type for querying x/consensus_param parameters. +// QueryParamsResponse defines the response type for querying x/consensus parameters. type QueryParamsResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // params are the tendermint consensus params stored in the consensus module. + // Please note that `params.version` is not populated in this response, it is + // tracked separately in the x/upgrade module. Params *types.ConsensusParams `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` } diff --git a/api/cosmos/consensus/v1/tx.pulsar.go b/api/cosmos/consensus/v1/tx.pulsar.go index b455e4ca0088..9fe12cdd84df 100644 --- a/api/cosmos/consensus/v1/tx.pulsar.go +++ b/api/cosmos/consensus/v1/tx.pulsar.go @@ -1051,7 +1051,7 @@ type MsgUpdateParams struct { // authority is the address of the governance account. Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - // params defines the x/consensus_params parameters to update. + // params defines the x/consensus parameters to update. // VersionsParams is not included in this Msg because it is tracked // separarately in x/upgrade. // diff --git a/go.mod b/go.mod index acd50cc3fa6a..8081aeef3302 100644 --- a/go.mod +++ b/go.mod @@ -162,6 +162,9 @@ require ( ) replace ( + // temporarily until tagging new api + cosmossdk.io/api => ./api + github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 diff --git a/go.sum b/go.sum index fde4f8e9980a..8957654976ad 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/proto/cosmos/app/runtime/v1alpha1/module.proto b/proto/cosmos/app/runtime/v1alpha1/module.proto index 4598ba44dc2f..71cae9f86aee 100644 --- a/proto/cosmos/app/runtime/v1alpha1/module.proto +++ b/proto/cosmos/app/runtime/v1alpha1/module.proto @@ -37,6 +37,11 @@ message Module { // override_store_keys is an optional list of overrides for the module store keys // to be used in keeper construction. repeated StoreKeyConfig override_store_keys = 6; + + // order_migrations defines the order in which module migrations are performed + // If this is left empty, it uses the default migration order + // https://pkg.go.dev/github.com/cosmos/cosmos-sdk@v0.47.0-alpha2/types/module#DefaultMigrationsOrder + repeated string order_migrations = 7; } // StoreKeyConfig may be supplied to override the default module store key, which diff --git a/runtime/app.go b/runtime/app.go index cfa421aa07f0..f307aa8956a1 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -85,6 +85,7 @@ func (a *App) Load(loadLatest bool) error { if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) + a.SetInitChainer(a.InitChainer) } if len(a.config.ExportGenesis) != 0 { @@ -103,6 +104,10 @@ func (a *App) Load(loadLatest bool) error { a.SetEndBlocker(a.EndBlocker) } + if len(a.config.OrderMigrations) != 0 { + a.ModuleManager.SetOrderMigrations(a.config.OrderMigrations...) + } + if loadLatest { if err := a.LoadLatestVersion(); err != nil { return err diff --git a/runtime/module.go b/runtime/module.go index d19f8df801c0..dac10653379e 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -81,11 +81,10 @@ type AppInputs struct { } func SetupAppBuilder(inputs AppInputs) { - mm := module.NewManagerFromMap(inputs.Modules) app := inputs.AppBuilder.app app.baseAppOptions = inputs.BaseAppOptions app.config = inputs.Config - app.ModuleManager = mm + app.ModuleManager = module.NewManagerFromMap(inputs.Modules) app.appConfig = inputs.AppConfig for name, mod := range inputs.Modules { diff --git a/simapp/app_config.go b/simapp/app_config.go index f70c15b362ff..914be6588ec1 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -152,6 +152,8 @@ var ( // When ExportGenesis is not specified, the export genesis module order // is equal to the init genesis order // ExportGenesis: genesisModuleOrder, + // Uncomment if you want to set a custom migration order here. + // OrderMigrations: nil, }), }, { diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 99136e8236e3..774dd601957e 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -27,7 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -262,9 +260,6 @@ func NewSimApp( // Sets the version setter for the upgrade module app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - // Uncomment if you want to set a custom migration order here. - // app.ModuleManager.SetOrderMigrations(custom order) - app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. @@ -288,9 +283,6 @@ func NewSimApp( // initialize stores app.MountKVStores(app.keys) - // initialize BaseApp - app.SetInitChainer(app.InitChainer) - if err := app.Load(loadLatest); err != nil { panic(err) } @@ -301,12 +293,6 @@ func NewSimApp( // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } -// InitChainer application update at chain initialization -func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - return app.App.InitChainer(ctx, req) -} - // LoadHeight loads a particular height func (app *SimApp) LoadHeight(height int64) error { return app.LoadVersion(height) diff --git a/simapp/go.mod b/simapp/go.mod index 1919b10d3b40..deeaa2eeec3a 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -162,6 +162,9 @@ require ( ) replace ( + // temporarily until tagging new api + cosmossdk.io/api => ../api + github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // Simapp always use the latest version of the cosmos-sdk github.com/cosmos/cosmos-sdk => ../. diff --git a/simapp/go.sum b/simapp/go.sum index 771d1d52b9df..1e2fae3bec85 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -46,8 +46,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= diff --git a/x/consensus/types/query.pb.go b/x/consensus/types/query.pb.go index cad159a682a2..6b66f70ff431 100644 --- a/x/consensus/types/query.pb.go +++ b/x/consensus/types/query.pb.go @@ -29,7 +29,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// QueryParamsRequest defines the request type for querying x/consensus_param parameters. +// QueryParamsRequest defines the request type for querying x/consensus parameters. type QueryParamsRequest struct { } @@ -66,8 +66,11 @@ func (m *QueryParamsRequest) XXX_DiscardUnknown() { var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo -// QueryParamsResponse defines the response type for querying x/consensus_param parameters. +// QueryParamsResponse defines the response type for querying x/consensus parameters. type QueryParamsResponse struct { + // params are the tendermint consensus params stored in the consensus module. + // Please note that `params.version` is not populated in this response, it is + // tracked separately in the x/upgrade module. Params *types.ConsensusParams `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` } diff --git a/x/consensus/types/tx.pb.go b/x/consensus/types/tx.pb.go index 1c36f34eef75..6244d2ef8564 100644 --- a/x/consensus/types/tx.pb.go +++ b/x/consensus/types/tx.pb.go @@ -34,7 +34,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MsgUpdateParams struct { // authority is the address of the governance account. Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - // params defines the x/consensus_params parameters to update. + // params defines the x/consensus parameters to update. // VersionsParams is not included in this Msg because it is tracked // separarately in x/upgrade. // From 1b566fb6ba5639b278b196d8feb064a8366a1714 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 00:53:34 +0100 Subject: [PATCH 03/28] updates --- runtime/app.go | 8 +++++--- runtime/builder.go | 9 ++++++--- simapp/app.go | 12 +++++++++--- simapp/app_v2.go | 1 - simapp/genesis.go | 7 ------- simapp/state.go | 3 ++- simapp/test_helpers.go | 6 +++--- testutil/sims/app_helpers.go | 2 +- 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index f307aa8956a1..f24f4a1a44a0 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -80,9 +80,6 @@ func (a *App) Load(loadLatest bool) error { return err } - a.configurator = module.NewConfigurator(a.cdc, a.MsgServiceRouter(), a.GRPCQueryRouter()) - a.ModuleManager.RegisterServices(a.configurator) - if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) a.SetInitChainer(a.InitChainer) @@ -176,6 +173,11 @@ func (a *App) Configurator() module.Configurator { return a.configurator } +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. +func (a *App) DefaultGenesis() map[string]json.RawMessage { + return a.basicManager.DefaultGenesis(a.cdc) +} + // UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time. // // NOTE: This should only be used in testing. diff --git a/runtime/builder.go b/runtime/builder.go index f73805c17cac..85e454549749 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -8,6 +8,7 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" ) @@ -18,10 +19,9 @@ type AppBuilder struct { app *App } -// DefaultGenesis returns a default genesis from the registered -// AppModuleBasic's. +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. func (a *AppBuilder) DefaultGenesis() map[string]json.RawMessage { - return a.app.basicManager.DefaultGenesis(a.app.cdc) + return a.app.DefaultGenesis() } // Build builds an *App instance. @@ -43,5 +43,8 @@ func (a *AppBuilder) Build( bApp.MountStores(a.app.storeKeys...) a.app.BaseApp = bApp + a.app.configurator = module.NewConfigurator(a.app.cdc, a.app.MsgServiceRouter(), a.app.GRPCQueryRouter()) + a.app.ModuleManager.RegisterServices(a.app.configurator) + return a.app } diff --git a/simapp/app.go b/simapp/app.go index d8b04f4d752a..f3eff334891d 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -353,9 +353,6 @@ func NewSimApp( // Set legacy router for backwards compatibility with gov v1beta1 govKeeper.SetLegacyRouter(govRouter) - // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - app.RegisterUpgradeHandlers() - app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper) // create evidence keeper with router @@ -442,6 +439,10 @@ func NewSimApp( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.ModuleManager.RegisterServices(app.configurator) + // RegisterUpgradeHandlers is used for registering any on-chain upgrades. + // Make sure it's called after `app.ModuleManager` and `app.configurator` are set. + app.RegisterUpgradeHandlers() + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules)) reflectionSvc, err := runtimeservices.NewReflectionService() @@ -591,6 +592,11 @@ func (app *SimApp) TxConfig() client.TxConfig { return app.txConfig } +// DefaultGenesis returns a default genesis from the registered AppModuleBasic's. +func (a *App) DefaultGenesis() map[string]json.RawMessage { + return ModuleBasics.DefaultGenesis(a.appCodec) +} + // GetKey returns the KVStoreKey for the provided store key. // // NOTE: This is solely to be used for testing purposes. diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 774dd601957e..9d0c193681d5 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -263,7 +263,6 @@ func NewSimApp( app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. - // Make sure it's called after `app.ModuleManager` and `app.configurator` are set. app.RegisterUpgradeHandlers() // add test gRPC service for testing gRPC queries in isolation diff --git a/simapp/genesis.go b/simapp/genesis.go index a002aead9ae5..69fa46b90efa 100644 --- a/simapp/genesis.go +++ b/simapp/genesis.go @@ -2,8 +2,6 @@ package simapp import ( "encoding/json" - - "github.com/cosmos/cosmos-sdk/codec" ) // GenesisState of the blockchain is represented here as a map of raw json @@ -14,8 +12,3 @@ import ( // the ModuleBasicManager which populates json from each BasicModule // object provided to it during init. type GenesisState map[string]json.RawMessage - -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return ModuleBasics.DefaultGenesis(cdc) -} diff --git a/simapp/state.go b/simapp/state.go index 29b3259ffe78..f872b9c22ab2 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -144,7 +144,8 @@ func AppStateRandomizedFn( accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, ) (json.RawMessage, []simtypes.Account) { numAccs := int64(len(accs)) - genesisState := NewDefaultGenesisState(cdc) + // TODO - in case runtime.RegisterModules(...) is used, the genesis state of the module won't be reflected here + genesisState := ModuleBasics.DefaultGenesis(cdc) // generate a random amount of initial stake coins and a random initial // number of bonded accounts diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 402e8c014f1d..b06f83838636 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -50,7 +50,7 @@ func setup(withGenesis bool, invCheckPeriod uint) (*SimApp, GenesisState) { app := NewSimApp(log.NewNopLogger(), db, nil, true, appOptions) if withGenesis { - return app, NewDefaultGenesisState(app.AppCodec()) + return app, app.DefaultGenesis() } return app, GenesisState{} } @@ -75,7 +75,7 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio } app := NewSimApp(options.Logger, options.DB, nil, true, options.AppOpts) - genesisState := NewDefaultGenesisState(app.appCodec) + genesisState := app.DefaultGenesis() genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balance) require.NoError(t, err) @@ -180,7 +180,7 @@ func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState { }, } - genesisState := NewDefaultGenesisState(app.appCodec) + genesisState := app.DefaultGenesis() genesisState, err = simtestutil.GenesisStateWithValSet(app.AppCodec(), genesisState, valSet, []authtypes.GenesisAccount{acc}, balances...) require.NoError(t, err) diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index d73477af72fa..7bfdc7be5952 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -148,7 +148,7 @@ func SetupWithConfiguration(appConfig depinject.Config, startupConfig StartupCon balances = append(balances, banktypes.Balance{Address: ga.GenesisAccount.GetAddress().String(), Coins: ga.Coins}) } - genesisState, err := GenesisStateWithValSet(codec, appBuilder.DefaultGenesis(), valSet, genAccounts, balances...) + genesisState, err := GenesisStateWithValSet(codec, app.DefaultGenesis(), valSet, genAccounts, balances...) if err != nil { return nil, fmt.Errorf("failed to create genesis state: %w", err) } From 2006601ee5417e7b2e7d5d88b3891aa1e9f60712 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 00:55:27 +0100 Subject: [PATCH 04/28] updates --- simapp/test_helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index b06f83838636..3016d57e7f4a 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -250,7 +250,7 @@ func NewTestNetworkFixture() network.TestFixture { return network.TestFixture{ AppConstructor: appCtr, - GenesisState: ModuleBasics.DefaultGenesis(app.AppCodec()), + GenesisState: app.DefaultGenesis(), EncodingConfig: testutil.TestEncodingConfig{ InterfaceRegistry: app.InterfaceRegistry(), Codec: app.AppCodec(), From 527f082839a19e020bbb413ce02350fdab7c982c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 01:01:58 +0100 Subject: [PATCH 05/28] updates --- client/grpc_query_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index b0b2b0afbcfe..bc0dbeab1e33 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -70,7 +70,7 @@ func (s *IntegrationTestSuite) SetupSuite() { Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(s.genesisAccountBalance))), } - genesisState, err := sims.GenesisStateWithValSet(cdc, appBuilder.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance) + genesisState, err := sims.GenesisStateWithValSet(cdc, app.DefaultGenesis(), valSet, []authtypes.GenesisAccount{acc}, balance) s.NoError(err) stateBytes, err := tmjson.MarshalIndent(genesisState, "", " ") From e2ec990276589b52dc045c6ebe481e83d1890b3f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 01:39:25 +0100 Subject: [PATCH 06/28] updates --- simapp/app_v2.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 9d0c193681d5..7e7cf5f3cb72 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -10,6 +10,7 @@ import ( "path/filepath" "github.com/tendermint/tendermint/libs/log" + "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" "cosmossdk.io/depinject" @@ -26,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -257,9 +259,6 @@ func NewSimApp( /**** Module Options ****/ - // Sets the version setter for the upgrade module - app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. @@ -286,6 +285,10 @@ func NewSimApp( panic(err) } + // Set upgrade module options + app.UpgradeKeeper.SetVersionSetter(app.BaseApp) + app.UpgradeKeeper.SetModuleVersionMap(sdk.NewContext(app.BaseApp.CommitMultiStore(), types.Header{}, false, logger), app.ModuleManager.GetVersionMap()) + return app } From f393e1c5f6b979fd51d568110d3db1ea599fb8bb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 01:46:50 +0100 Subject: [PATCH 07/28] updates --- simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/app.go b/simapp/app.go index f3eff334891d..2f7c91ae32fb 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -593,7 +593,7 @@ func (app *SimApp) TxConfig() client.TxConfig { } // DefaultGenesis returns a default genesis from the registered AppModuleBasic's. -func (a *App) DefaultGenesis() map[string]json.RawMessage { +func (a *SimApp) DefaultGenesis() map[string]json.RawMessage { return ModuleBasics.DefaultGenesis(a.appCodec) } From b3a4c238bd8f16a9cd0ea48a91284d822cab6444 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 10:02:08 +0100 Subject: [PATCH 08/28] add replace directive in tests --- tests/go.mod | 3 +++ tests/go.sum | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index ad2686f1556a..9660c44a08b3 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -160,6 +160,9 @@ require ( ) replace ( + // temporarily until tagging new api + cosmossdk.io/api => ../api + // We always want to test against the latest version of the simapp. cosmossdk.io/simapp => ../simapp github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 diff --git a/tests/go.sum b/tests/go.sum index cdcd7db5ac37..683d2b79bb97 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -46,8 +46,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= cloud.google.com/go/storage v1.27.0 h1:YOO045NZI9RKfCj1c5A/ZtuuENUc8OAW+gHdGnDgyMQ= cloud.google.com/go/storage v1.27.0/go.mod h1:x9DOL8TK/ygDUMieqwfhdpQryTeEkhGKMi80i/iqR2s= -cosmossdk.io/api v0.2.5 h1:XKq7CAxTWs7JObceQKkjdI9J+aLB8ofXDGBEaPcPsks= -cosmossdk.io/api v0.2.5/go.mod h1:vxhlMTeKWgQUaanTHPq7/vR3dkhhJ6pOgXK0EIBrBYw= cosmossdk.io/core v0.3.2 h1:KlQIufpJHJvOs7YLGTZsZcCo1WlkencDXepsr8STKZQ= cosmossdk.io/core v0.3.2/go.mod h1:CO7vbe+evrBvHc0setFHL/u7nlY7HJGzdRSBkT/sirc= cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw= From e8f19abb85143c4487eb9ca04e619c044e782ae7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 12:27:49 +0100 Subject: [PATCH 09/28] improve description --- simapp/app.go | 16 ++++++++++++++++ simapp/app_v2.go | 24 +++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 2f7c91ae32fb..40374b46bd14 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -228,6 +228,22 @@ func NewSimApp( interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig + // Below we could construct and set an application specific mempool and ABCI 1.0 Prepare and Process Proposal + // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override + // them. + // + // nonceMempool := mempool.NewSenderNonceMempool() + // mempoolOpt := baseapp.SetMempool(nonceMempool) + // prepareOpt := func(app *baseapp.BaseApp) { + // app.SetPrepareProposal(app.DefaultPrepareProposal()) + // } + // processOpt := func(app *baseapp.BaseApp) { + // app.SetProcessProposal(app.DefaultProcessProposal()) + // } + // + // Further down we'd set the options in the AppBuilder like below. + // baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) + bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 7e7cf5f3cb72..dd3bd6479f9c 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -10,7 +10,6 @@ import ( "path/filepath" "github.com/tendermint/tendermint/libs/log" - "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" "cosmossdk.io/depinject" @@ -27,7 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -174,20 +172,20 @@ func NewSimApp( app = &SimApp{} appBuilder *runtime.AppBuilder // Below we could construct and set an application specific mempool and ABCI 1.0 Prepare and Process Proposal - // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override + // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override // them. // - //nonceMempool = mempool.NewNonceMempool() - //mempoolOpt = baseapp.SetMempool(nonceMempool) - //prepareOpt = func(app *baseapp.BaseApp) { - // app.SetPrepareProposal(app.DefaultPrepareProposal()) - //} - //processOpt = func(app *baseapp.BaseApp) { - // app.SetProcessProposal(app.DefaultProcessProposal()) - //} + // nonceMempool = mempool.NewSenderNonceMempool() + // mempoolOpt = baseapp.SetMempool(nonceMempool) + // prepareOpt = func(app *baseapp.BaseApp) { + // app.SetPrepareProposal(app.DefaultPrepareProposal()) + // } + // processOpt = func(app *baseapp.BaseApp) { + // app.SetProcessProposal(app.DefaultProcessProposal()) + // } // // Further down we'd set the options in the AppBuilder like below. - //baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) + // baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) // merge the AppConfig and other configuration in one config appConfig = depinject.Configs( @@ -287,7 +285,7 @@ func NewSimApp( // Set upgrade module options app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - app.UpgradeKeeper.SetModuleVersionMap(sdk.NewContext(app.BaseApp.CommitMultiStore(), types.Header{}, false, logger), app.ModuleManager.GetVersionMap()) + // app.UpgradeKeeper.SetModuleVersionMap(sdk.NewContext(app.BaseApp.CommitMultiStore(), types.Header{}, false, logger), app.ModuleManager.GetVersionMap()) return app } From 351c94209d9211d0ca5d09cc45a9d28b16ab9e81 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 13:06:33 +0100 Subject: [PATCH 10/28] split in follow-up --- simapp/app_config.go | 2 +- simapp/app_v2.go | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/simapp/app_config.go b/simapp/app_config.go index 914be6588ec1..250833558577 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -148,7 +148,7 @@ var ( KvStoreKey: "acc", }, }, - InitGenesis: genesisModuleOrder, + // InitGenesis: genesisModuleOrder, // When ExportGenesis is not specified, the export genesis module order // is equal to the init genesis order // ExportGenesis: genesisModuleOrder, diff --git a/simapp/app_v2.go b/simapp/app_v2.go index dd3bd6479f9c..5930cdb71013 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -26,6 +27,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -257,6 +259,13 @@ func NewSimApp( /**** Module Options ****/ + // Set upgrade module options + + // TODO to be done in app config + app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) + app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) + app.UpgradeKeeper.SetVersionSetter(app.BaseApp) + app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. @@ -279,20 +288,27 @@ func NewSimApp( // initialize stores app.MountKVStores(app.keys) + // initialize BaseApp + // TODO should not be needed after x/upgrade app config refactor + app.SetInitChainer(app.InitChainer) + if err := app.Load(loadLatest); err != nil { panic(err) } - // Set upgrade module options - app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - // app.UpgradeKeeper.SetModuleVersionMap(sdk.NewContext(app.BaseApp.CommitMultiStore(), types.Header{}, false, logger), app.ModuleManager.GetVersionMap()) - return app } // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } +// InitChainer application update at chain initialization +func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + // TODO to set in app config + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + return app.App.InitChainer(ctx, req) +} + // LoadHeight loads a particular height func (app *SimApp) LoadHeight(height int64) error { return app.LoadVersion(height) From 4b944f82742a43b444c4561c59542ccb9a4b6641 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 13:48:47 +0100 Subject: [PATCH 11/28] refactor: improve `x/upgrade` app config --- simapp/app_config.go | 2 +- simapp/app_v2.go | 21 --------------------- x/upgrade/module.go | 28 +++++++++++++++++++++++----- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/simapp/app_config.go b/simapp/app_config.go index 250833558577..914be6588ec1 100644 --- a/simapp/app_config.go +++ b/simapp/app_config.go @@ -148,7 +148,7 @@ var ( KvStoreKey: "acc", }, }, - // InitGenesis: genesisModuleOrder, + InitGenesis: genesisModuleOrder, // When ExportGenesis is not specified, the export genesis module order // is equal to the init genesis order // ExportGenesis: genesisModuleOrder, diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 5930cdb71013..9909984e8443 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -27,7 +26,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -258,14 +256,6 @@ func NewSimApp( } /**** Module Options ****/ - - // Set upgrade module options - - // TODO to be done in app config - app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) - app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) - app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. @@ -288,10 +278,6 @@ func NewSimApp( // initialize stores app.MountKVStores(app.keys) - // initialize BaseApp - // TODO should not be needed after x/upgrade app config refactor - app.SetInitChainer(app.InitChainer) - if err := app.Load(loadLatest); err != nil { panic(err) } @@ -302,13 +288,6 @@ func NewSimApp( // Name returns the name of the App func (app *SimApp) Name() string { return app.BaseApp.Name() } -// InitChainer application update at chain initialization -func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - // TODO to set in app config - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - return app.App.InitChainer(ctx, req) -} - // LoadHeight loads a particular height func (app *SimApp) LoadHeight(height int64) error { return app.LoadVersion(height) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index d8cb76940643..101b4ede0479 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -5,16 +5,16 @@ import ( "encoding/json" "fmt" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cast" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + modulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -26,9 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - - modulev1 "cosmossdk.io/api/cosmos/upgrade/module/v1" - + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/upgrade/client/cli" "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -156,6 +154,7 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide(ProvideModule), + appmodule.Invoke(InvokeKeeperOptions), ) } @@ -204,3 +203,22 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh} } + +func InvokeKeeperOptions(upgradeKeeper keeper.Keeper, modules map[string]appmodule.AppModule, baseApp *baseapp.BaseApp) { + fmt.Println(modules) + fmt.Println(upgradeKeeper) + + if baseApp == nil { + return + } + + upgradeKeeper.SetVersionSetter(baseApp) + + ctxWithStore := sdk.Context{} + ctxWithStore = ctxWithStore. + WithMultiStore(baseApp.CommitMultiStore()). + WithGasMeter(store.NewInfiniteGasMeter()). + WithKVGasConfig(store.KVGasConfig()) + + upgradeKeeper.SetModuleVersionMap(ctxWithStore, module.NewManagerFromMap(modules).GetVersionMap()) +} From 5d48a375b16e1362b28528dc48f564a0657a24c0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 14:19:09 +0100 Subject: [PATCH 12/28] updates --- x/upgrade/module.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 101b4ede0479..b404ed9212e2 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -205,10 +205,7 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { } func InvokeKeeperOptions(upgradeKeeper keeper.Keeper, modules map[string]appmodule.AppModule, baseApp *baseapp.BaseApp) { - fmt.Println(modules) - fmt.Println(upgradeKeeper) - - if baseApp == nil { + if len(modules) == 0 || baseApp == nil { return } From fde91f6a10fe6840a030b3c5c73bcd5025a0fbfe Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 14:42:09 +0100 Subject: [PATCH 13/28] updates --- runtime/app.go | 10 ++++++++++ simapp/app_v2.go | 31 +++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index f24f4a1a44a0..5dc45eb9c4df 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -173,11 +173,21 @@ func (a *App) Configurator() module.Configurator { return a.configurator } +// LoadHeight loads a particular height +func (a *App) LoadHeight(height int64) error { + return a.LoadVersion(height) +} + // DefaultGenesis returns a default genesis from the registered AppModuleBasic's. func (a *App) DefaultGenesis() map[string]json.RawMessage { return a.basicManager.DefaultGenesis(a.cdc) } +// GetStoreKeys returns all the keys stored store keys. +func (a *App) GetStoreKeys() []storetypes.StoreKey { + return a.storeKeys +} + // UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time. // // NOTE: This should only be used in testing. diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 5930cdb71013..31fe67a01658 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -126,9 +126,6 @@ type SimApp struct { txConfig client.TxConfig interfaceRegistry codectypes.InterfaceRegistry - // keys to access the substores - keys map[string]*storetypes.KVStoreKey - // keepers AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper @@ -252,7 +249,7 @@ func NewSimApp( app.App = appBuilder.Build(logger, db, traceStore, baseAppOptions...) // load state streaming if enabled - if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.keys); err != nil { + if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil { fmt.Printf("failed to load state streaming: %s", err) os.Exit(1) } @@ -285,9 +282,6 @@ func NewSimApp( app.sm.RegisterStoreDecoders() - // initialize stores - app.MountKVStores(app.keys) - // initialize BaseApp // TODO should not be needed after x/upgrade app config refactor app.SetInitChainer(app.InitChainer) @@ -309,11 +303,6 @@ func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci. return app.App.InitChainer(ctx, req) } -// LoadHeight loads a particular height -func (app *SimApp) LoadHeight(height int64) error { - return app.LoadVersion(height) -} - // LegacyAmino returns SimApp's amino codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable @@ -344,11 +333,6 @@ func (app *SimApp) TxConfig() client.TxConfig { // // NOTE: This is solely to be used for testing purposes. func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { - kvsk := app.keys[storeKey] - if kvsk != nil { - return kvsk - } - sk := app.UnsafeFindStoreKey(storeKey) kvStoreKey, ok := sk.(*storetypes.KVStoreKey) if !ok { @@ -357,6 +341,17 @@ func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { return kvStoreKey } +func (app *SimApp) kvStoreKeys() map[string]*storetypes.KVStoreKey { + keys := make(map[string]*storetypes.KVStoreKey) + for _, k := range app.GetStoreKeys() { + if kv, ok := k.(*storetypes.KVStoreKey); ok { + keys[kv.Name()] = kv + } + } + + return keys +} + // GetSubspace returns a param subspace for a given module name. // // NOTE: This is solely to be used for testing purposes. @@ -374,7 +369,7 @@ func (app *SimApp) SimulationManager() *module.SimulationManager { // API server. func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { app.App.RegisterAPIRoutes(apiSvr, apiConfig) - // register swagger API from root so that other applications can override easily + // register swagger API in app.go so that other applications can override easily if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil { panic(err) } From 77d27e1f6e07b8d00101ff687b959bf13fe64ba0 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 14:46:28 +0100 Subject: [PATCH 14/28] remove todos --- simapp/app_v2.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 31fe67a01658..14d4cdac98e3 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -257,11 +257,10 @@ func NewSimApp( /**** Module Options ****/ // Set upgrade module options + app.UpgradeKeeper.SetVersionSetter(app.BaseApp) - // TODO to be done in app config app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...) app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...) - app.UpgradeKeeper.SetVersionSetter(app.BaseApp) app.ModuleManager.RegisterInvariants(app.CrisisKeeper) @@ -283,7 +282,6 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // initialize BaseApp - // TODO should not be needed after x/upgrade app config refactor app.SetInitChainer(app.InitChainer) if err := app.Load(loadLatest); err != nil { @@ -298,7 +296,6 @@ func (app *SimApp) Name() string { return app.BaseApp.Name() } // InitChainer application update at chain initialization func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - // TODO to set in app config app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) return app.App.InitChainer(ctx, req) } From 55eab411f7b4b5baf5706a570e0c56aad2f0081f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 18:23:24 +0100 Subject: [PATCH 15/28] updates --- simapp/app.go | 2 +- simapp/app_v2.go | 4 ++-- x/upgrade/abci.go | 2 +- x/upgrade/abci_test.go | 8 ++++---- x/upgrade/handler.go | 6 +++--- x/upgrade/keeper/grpc_query_test.go | 2 +- x/upgrade/keeper/keeper.go | 4 ++-- x/upgrade/keeper/keeper_test.go | 2 +- x/upgrade/keeper/migrations.go | 4 ++-- x/upgrade/keeper/msg_server.go | 4 ++-- x/upgrade/module.go | 16 +++++++++------- 11 files changed, 28 insertions(+), 26 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 40374b46bd14..ee81d217e55e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -184,7 +184,7 @@ type SimApp struct { DistrKeeper distrkeeper.Keeper GovKeeper govkeeper.Keeper CrisisKeeper *crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper + UpgradeKeeper *upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper AuthzKeeper authzkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 8c559f1b972b..18b57cbb56fb 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -134,7 +134,7 @@ type SimApp struct { DistrKeeper distrkeeper.Keeper GovKeeper *govkeeper.Keeper CrisisKeeper *crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper + UpgradeKeeper *upgradekeeper.Keeper ParamsKeeper paramskeeper.Keeper AuthzKeeper authzkeeper.Keeper EvidenceKeeper evidencekeeper.Keeper @@ -253,7 +253,7 @@ func NewSimApp( } /**** Module Options ****/ - + app.ModuleManager.RegisterInvariants(app.CrisisKeeper) // RegisterUpgradeHandlers is used for registering any on-chain upgrades. diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index 5f05af61dd64..7fc5e11c1e9c 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -20,7 +20,7 @@ import ( // The purpose is to ensure the binary is switched EXACTLY at the desired block, and to allow // a migration to be executed if needed upon this switch (migration defined in the new binary) // skipUpgradeHeightArray is a set of block heights for which the upgrade must be skipped -func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { +func BeginBlocker(k *keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) plan, found := k.GetUpgradePlan(ctx) diff --git a/x/upgrade/abci_test.go b/x/upgrade/abci_test.go index aa8b855cf6ec..2e40db1e54ca 100644 --- a/x/upgrade/abci_test.go +++ b/x/upgrade/abci_test.go @@ -32,7 +32,7 @@ type TestSuite struct { suite.Suite module module.BeginBlockAppModule - keeper keeper.Keeper + keeper *keeper.Keeper handler govtypesv1beta1.Handler ctx sdk.Context baseApp *baseapp.BaseApp @@ -510,18 +510,18 @@ func TestDowngradeVerification(t *testing.T) { ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) testCases := map[string]struct { - preRun func(keeper.Keeper, sdk.Context, string) + preRun func(*keeper.Keeper, sdk.Context, string) expectPanic bool }{ "valid binary": { - preRun: func(k keeper.Keeper, ctx sdk.Context, name string) { + preRun: func(k *keeper.Keeper, ctx sdk.Context, name string) { k.SetUpgradeHandler(planName, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) { return vm, nil }) }, }, "downgrade with an active plan": { - preRun: func(k keeper.Keeper, ctx sdk.Context, name string) { + preRun: func(k *keeper.Keeper, ctx sdk.Context, name string) { handler := upgrade.NewSoftwareUpgradeProposalHandler(k) err := handler(ctx, &types.SoftwareUpgradeProposal{Title: "test", Plan: types.Plan{Name: "another" + planName, Height: ctx.BlockHeight() + 1}}) require.NoError(t, err, name) diff --git a/x/upgrade/handler.go b/x/upgrade/handler.go index 9825d90a2728..3625ba6c1872 100644 --- a/x/upgrade/handler.go +++ b/x/upgrade/handler.go @@ -13,7 +13,7 @@ import ( // to abort a previously voted upgrade. // //nolint:staticcheck // we are intentionally using a deprecated proposal here. -func NewSoftwareUpgradeProposalHandler(k keeper.Keeper) govtypes.Handler { +func NewSoftwareUpgradeProposalHandler(k *keeper.Keeper) govtypes.Handler { return func(ctx sdk.Context, content govtypes.Content) error { switch c := content.(type) { case *types.SoftwareUpgradeProposal: @@ -29,12 +29,12 @@ func NewSoftwareUpgradeProposalHandler(k keeper.Keeper) govtypes.Handler { } //nolint:staticcheck // we are intentionally using a deprecated proposal here. -func handleSoftwareUpgradeProposal(ctx sdk.Context, k keeper.Keeper, p *types.SoftwareUpgradeProposal) error { +func handleSoftwareUpgradeProposal(ctx sdk.Context, k *keeper.Keeper, p *types.SoftwareUpgradeProposal) error { return k.ScheduleUpgrade(ctx, p.Plan) } //nolint:staticcheck // we are intentionally using a deprecated proposal here. -func handleCancelSoftwareUpgradeProposal(ctx sdk.Context, k keeper.Keeper, _ *types.CancelSoftwareUpgradeProposal) error { +func handleCancelSoftwareUpgradeProposal(ctx sdk.Context, k *keeper.Keeper, _ *types.CancelSoftwareUpgradeProposal) error { k.ClearUpgradePlan(ctx) return nil } diff --git a/x/upgrade/keeper/grpc_query_test.go b/x/upgrade/keeper/grpc_query_test.go index 41f904ccbede..1cd07ca4bdb8 100644 --- a/x/upgrade/keeper/grpc_query_test.go +++ b/x/upgrade/keeper/grpc_query_test.go @@ -23,7 +23,7 @@ import ( type UpgradeTestSuite struct { suite.Suite - upgradeKeeper keeper.Keeper + upgradeKeeper *keeper.Keeper ctx sdk.Context queryClient types.QueryClient encCfg moduletestutil.TestEncodingConfig diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 86d0ce15e60e..b9674274ebab 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -43,8 +43,8 @@ type Keeper struct { // cdc - the app-wide binary codec // homePath - root directory of the application's config // vs - the interface implemented by baseapp which allows setting baseapp's protocol version field -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter, authority string) Keeper { - return Keeper{ +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, homePath string, vs xp.ProtocolVersionSetter, authority string) *Keeper { + return &Keeper{ homePath: homePath, skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, diff --git a/x/upgrade/keeper/keeper_test.go b/x/upgrade/keeper/keeper_test.go index a8c7da8ae9ab..e36cca81abce 100644 --- a/x/upgrade/keeper/keeper_test.go +++ b/x/upgrade/keeper/keeper_test.go @@ -28,7 +28,7 @@ type KeeperTestSuite struct { key *storetypes.KVStoreKey baseApp *baseapp.BaseApp - upgradeKeeper keeper.Keeper + upgradeKeeper *keeper.Keeper homeDir string ctx sdk.Context msgSrvr types.MsgServer diff --git a/x/upgrade/keeper/migrations.go b/x/upgrade/keeper/migrations.go index 2415bc1f6227..5ee2b06b5e69 100644 --- a/x/upgrade/keeper/migrations.go +++ b/x/upgrade/keeper/migrations.go @@ -11,11 +11,11 @@ import ( // Migrator is a struct for handling in-place store migrations. type Migrator struct { - keeper Keeper + keeper *Keeper } // NewMigrator returns a new Migrator. -func NewMigrator(keeper Keeper) Migrator { +func NewMigrator(keeper *Keeper) Migrator { return Migrator{keeper: keeper} } diff --git a/x/upgrade/keeper/msg_server.go b/x/upgrade/keeper/msg_server.go index 1e1249f5e899..3e4a7f1fc008 100644 --- a/x/upgrade/keeper/msg_server.go +++ b/x/upgrade/keeper/msg_server.go @@ -10,12 +10,12 @@ import ( ) type msgServer struct { - Keeper + *Keeper } // NewMsgServerImpl returns an implementation of the upgrade MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(k Keeper) types.MsgServer { +func NewMsgServerImpl(k *Keeper) types.MsgServer { return &msgServer{ Keeper: k, } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index b404ed9212e2..0a8db6186e3b 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" store "github.com/cosmos/cosmos-sdk/store/types" @@ -83,11 +84,11 @@ func (b AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry // AppModule implements the sdk.AppModule interface type AppModule struct { AppModuleBasic - keeper keeper.Keeper + keeper *keeper.Keeper } // NewAppModule creates a new AppModule object -func NewAppModule(keeper keeper.Keeper) AppModule { +func NewAppModule(keeper *keeper.Keeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, keeper: keeper, @@ -154,7 +155,6 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide(ProvideModule), - appmodule.Invoke(InvokeKeeperOptions), ) } @@ -171,9 +171,10 @@ type UpgradeInputs struct { type UpgradeOutputs struct { depinject.Out - UpgradeKeeper keeper.Keeper + UpgradeKeeper *keeper.Keeper Module appmodule.AppModule GovHandler govv1beta1.HandlerRoute + BaseAppOption runtime.BaseAppOption } func ProvideModule(in UpgradeInputs) UpgradeOutputs { @@ -198,10 +199,13 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { // set the governance module account as the authority for conducting upgrades k := keeper.NewKeeper(skipUpgradeHeights, in.Key, in.Cdc, homePath, nil, authority.String()) + baseappOpt := func(app *baseapp.BaseApp) { + k.SetVersionSetter(app) + } m := NewAppModule(k) gh := govv1beta1.HandlerRoute{RouteKey: types.RouterKey, Handler: NewSoftwareUpgradeProposalHandler(k)} - return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh} + return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt} } func InvokeKeeperOptions(upgradeKeeper keeper.Keeper, modules map[string]appmodule.AppModule, baseApp *baseapp.BaseApp) { @@ -209,8 +213,6 @@ func InvokeKeeperOptions(upgradeKeeper keeper.Keeper, modules map[string]appmodu return } - upgradeKeeper.SetVersionSetter(baseApp) - ctxWithStore := sdk.Context{} ctxWithStore = ctxWithStore. WithMultiStore(baseApp.CommitMultiStore()). From 666a54dc33e112471ce2e501d954c3f856ca7c03 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 8 Dec 2022 23:13:45 +0100 Subject: [PATCH 16/28] updates --- go.mod | 3 --- runtime/app.go | 2 +- simapp/go.mod | 3 --- tests/go.mod | 3 --- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 5ac860357674..1d474e7e498a 100644 --- a/go.mod +++ b/go.mod @@ -162,9 +162,6 @@ require ( ) replace ( - // temporarily until tagging new api - cosmossdk.io/api => ./api - github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // dgrijalva/jwt-go is deprecated and doesn't receive security updates. // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 diff --git a/runtime/app.go b/runtime/app.go index 5dc45eb9c4df..c0815f5df2e5 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -183,7 +183,7 @@ func (a *App) DefaultGenesis() map[string]json.RawMessage { return a.basicManager.DefaultGenesis(a.cdc) } -// GetStoreKeys returns all the keys stored store keys. +// GetStoreKeys returns all the stored store keys. func (a *App) GetStoreKeys() []storetypes.StoreKey { return a.storeKeys } diff --git a/simapp/go.mod b/simapp/go.mod index dfca1822022d..504e9c28a1dd 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -162,9 +162,6 @@ require ( ) replace ( - // temporarily until tagging new api - cosmossdk.io/api => ../api - github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // Simapp always use the latest version of the cosmos-sdk github.com/cosmos/cosmos-sdk => ../. diff --git a/tests/go.mod b/tests/go.mod index f4cba8e4116e..ec4bcc97ff67 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -160,9 +160,6 @@ require ( ) replace ( - // temporarily until tagging new api - cosmossdk.io/api => ../api - // We always want to test against the latest version of the simapp. cosmossdk.io/simapp => ../simapp github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 From 4725bc876ee8e1dcfe0b8674e108db6fe4bbaed4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 9 Dec 2022 16:21:29 +0100 Subject: [PATCH 17/28] updates --- core/sonar-project.properties | 2 +- simapp/state.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/sonar-project.properties b/core/sonar-project.properties index 8db28773d859..43825ddb3792 100644 --- a/core/sonar-project.properties +++ b/core/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=cosmos-sdk-core sonar.organization=cosmos -sonar.projectName=Cosmos SDK Core +sonar.projectName=Cosmos SDK - Core sonar.project.monorepo.enabled=true sonar.sources=. diff --git a/simapp/state.go b/simapp/state.go index f872b9c22ab2..ee1836ea7676 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -144,7 +144,6 @@ func AppStateRandomizedFn( accs []simtypes.Account, genesisTimestamp time.Time, appParams simtypes.AppParams, ) (json.RawMessage, []simtypes.Account) { numAccs := int64(len(accs)) - // TODO - in case runtime.RegisterModules(...) is used, the genesis state of the module won't be reflected here genesisState := ModuleBasics.DefaultGenesis(cdc) // generate a random amount of initial stake coins and a random initial From c0c19ae1caaa02ee4552c810d6a0977e24f3948e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 11 Dec 2022 11:16:26 +0100 Subject: [PATCH 18/28] don't use fmt in app.go --- simapp/app.go | 5 ++--- simapp/app_v2.go | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index ee81d217e55e..5f716a085989 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -4,7 +4,6 @@ package simapp import ( "encoding/json" - "fmt" "io" "os" "path/filepath" @@ -265,7 +264,7 @@ func NewSimApp( // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil { - fmt.Printf("failed to load state streaming: %s", err) + app.logger.Error("failed to load state streaming", "error", err) os.Exit(1) } @@ -514,7 +513,7 @@ func NewSimApp( if loadLatest { if err := app.LoadLatestVersion(); err != nil { - fmt.Println(err.Error()) + app.Logger().Error("error on loading last version", "error", err) os.Exit(1) } } diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 18b57cbb56fb..5d8baa07e998 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -4,7 +4,6 @@ package simapp import ( _ "embed" - "fmt" "io" "os" "path/filepath" @@ -248,7 +247,7 @@ func NewSimApp( // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil { - fmt.Printf("failed to load state streaming: %s", err) + app.logger.Error("failed to load state streaming", "error", err) os.Exit(1) } From 7eb957336cce658cf3fc433e1d109b5e023eb9f5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sun, 11 Dec 2022 11:18:28 +0100 Subject: [PATCH 19/28] updates --- simapp/app.go | 4 ++-- simapp/app_v2.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 5f716a085989..0c006e137534 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -264,7 +264,7 @@ func NewSimApp( // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil { - app.logger.Error("failed to load state streaming", "error", err) + logger.Error("failed to load state streaming", "error", err) os.Exit(1) } @@ -513,7 +513,7 @@ func NewSimApp( if loadLatest { if err := app.LoadLatestVersion(); err != nil { - app.Logger().Error("error on loading last version", "error", err) + logger.Error("error on loading last version", "error", err) os.Exit(1) } } diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 5d8baa07e998..41d698fd8da1 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -247,7 +247,7 @@ func NewSimApp( // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil { - app.logger.Error("failed to load state streaming", "error", err) + logger.Error("failed to load state streaming", "error", err) os.Exit(1) } From 328b92f9b7dc2dd97f9c442e6743fd86a57c12f2 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 12 Dec 2022 14:31:16 +0100 Subject: [PATCH 20/28] updates --- runtime/app.go | 15 ++++++++++++++- simapp/app_v2.go | 8 ++++++++ x/upgrade/module.go | 14 -------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index c0815f5df2e5..83b78e1062bf 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -48,6 +48,7 @@ type App struct { baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter appConfig *appv1alpha1.Config + initChainer sdk.InitChainer } // RegisterModules registers the provided modules with the module manager and @@ -82,7 +83,9 @@ func (a *App) Load(loadLatest bool) error { if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) - a.SetInitChainer(a.InitChainer) + if a.initChainer == nil { + a.SetInitChainer(a.InitChainer) + } } if len(a.config.ExportGenesis) != 0 { @@ -165,10 +168,12 @@ func (a *App) RegisterTendermintService(clientCtx client.Context) { ) } +// RegisterNodeService registers the node gRPC service on the app gRPC router. func (a *App) RegisterNodeService(clientCtx client.Context) { nodeservice.RegisterNodeService(clientCtx, a.GRPCQueryRouter()) } +// Configurator returns the app's configurator. func (a *App) Configurator() module.Configurator { return a.configurator } @@ -188,6 +193,14 @@ func (a *App) GetStoreKeys() []storetypes.StoreKey { return a.storeKeys } +// SetInitChainer sets the init chainer function +// It wraps `BaseApp.SetInitChainer` to allow setting a custom init chainer from an app. +// TODO possibly improve app wiring to allow setting custom init chainer logic (before init genesis). +func (a *App) SetInitChainer(initChainer sdk.InitChainer) { + a.initChainer = initChainer + a.BaseApp.SetInitChainer(initChainer) +} + // UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time. // // NOTE: This should only be used in testing. diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 41d698fd8da1..b18da3d083f7 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -25,6 +26,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -272,6 +274,12 @@ func NewSimApp( app.sm.RegisterStoreDecoders() + // Set custom init chainer that registers the module versions in the upgrade module + app.SetInitChainer(func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + return app.App.InitChainer(ctx, req) + }) + if err := app.Load(loadLatest); err != nil { panic(err) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 0a8db6186e3b..39fd852a75a8 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -207,17 +207,3 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt} } - -func InvokeKeeperOptions(upgradeKeeper keeper.Keeper, modules map[string]appmodule.AppModule, baseApp *baseapp.BaseApp) { - if len(modules) == 0 || baseApp == nil { - return - } - - ctxWithStore := sdk.Context{} - ctxWithStore = ctxWithStore. - WithMultiStore(baseApp.CommitMultiStore()). - WithGasMeter(store.NewInfiniteGasMeter()). - WithKVGasConfig(store.KVGasConfig()) - - upgradeKeeper.SetModuleVersionMap(ctxWithStore, module.NewManagerFromMap(modules).GetVersionMap()) -} From 6e5eb265ecbe5520b57df24b896c0e17b45bf9f3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 12 Dec 2022 14:35:18 +0100 Subject: [PATCH 21/28] improve comment --- simapp/app_v2.go | 1 + 1 file changed, 1 insertion(+) diff --git a/simapp/app_v2.go b/simapp/app_v2.go index b18da3d083f7..7ef4da949b1f 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -275,6 +275,7 @@ func NewSimApp( app.sm.RegisterStoreDecoders() // Set custom init chainer that registers the module versions in the upgrade module + // NOTE: this is not required for apps that do not need custom pre-init genesis logic app.SetInitChainer(func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) return app.App.InitChainer(ctx, req) From d1a9328fc8268345b41e5e2a69d2b326ee48984b Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 12 Dec 2022 14:40:45 +0100 Subject: [PATCH 22/28] update logger error --- simapp/app.go | 4 ++-- simapp/app_v2.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 0c006e137534..68b4abad0bff 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -264,7 +264,7 @@ func NewSimApp( // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, logger, keys); err != nil { - logger.Error("failed to load state streaming", "error", err) + logger.Error("failed to load state streaming", "err", err) os.Exit(1) } @@ -513,7 +513,7 @@ func NewSimApp( if loadLatest { if err := app.LoadLatestVersion(); err != nil { - logger.Error("error on loading last version", "error", err) + logger.Error("error on loading last version", "err", err) os.Exit(1) } } diff --git a/simapp/app_v2.go b/simapp/app_v2.go index 7ef4da949b1f..aaf67385b6e0 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -249,7 +249,7 @@ func NewSimApp( // load state streaming if enabled if _, _, err := streaming.LoadStreamingServices(app.App.BaseApp, appOpts, app.appCodec, logger, app.kvStoreKeys()); err != nil { - logger.Error("failed to load state streaming", "error", err) + logger.Error("failed to load state streaming", "err", err) os.Exit(1) } From aca5f70ea34fa08e59ae3c69e088bd57527ca169 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 12 Dec 2022 15:54:16 +0100 Subject: [PATCH 23/28] fix e2e --- tests/e2e/upgrade/suite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/upgrade/suite.go b/tests/e2e/upgrade/suite.go index 59c463f1aa0a..bf17567a54f8 100644 --- a/tests/e2e/upgrade/suite.go +++ b/tests/e2e/upgrade/suite.go @@ -13,7 +13,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) -func NewIntegrationTestSuite(cfg network.Config, keeper keeper.Keeper, ctx sdk.Context) *IntegrationTestSuite { +func NewIntegrationTestSuite(cfg network.Config, keeper *keeper.Keeper, ctx sdk.Context) *IntegrationTestSuite { return &IntegrationTestSuite{ cfg: cfg, upgradeKeeper: keeper, @@ -24,7 +24,7 @@ func NewIntegrationTestSuite(cfg network.Config, keeper keeper.Keeper, ctx sdk.C type IntegrationTestSuite struct { suite.Suite - upgradeKeeper keeper.Keeper + upgradeKeeper *keeper.Keeper cfg network.Config network *network.Network ctx sdk.Context From 4e34404ce48643e909b52673179ec5c79f6f41d6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 13 Dec 2022 02:00:15 +0100 Subject: [PATCH 24/28] updates --- runtime/app.go | 13 +------------ simapp/app_v2.go | 9 --------- x/upgrade/module.go | 15 ++++++++++++++- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index 83b78e1062bf..2642089e2c90 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -48,7 +48,6 @@ type App struct { baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter appConfig *appv1alpha1.Config - initChainer sdk.InitChainer } // RegisterModules registers the provided modules with the module manager and @@ -83,9 +82,7 @@ func (a *App) Load(loadLatest bool) error { if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) - if a.initChainer == nil { - a.SetInitChainer(a.InitChainer) - } + a.SetInitChainer(a.InitChainer) } if len(a.config.ExportGenesis) != 0 { @@ -193,14 +190,6 @@ func (a *App) GetStoreKeys() []storetypes.StoreKey { return a.storeKeys } -// SetInitChainer sets the init chainer function -// It wraps `BaseApp.SetInitChainer` to allow setting a custom init chainer from an app. -// TODO possibly improve app wiring to allow setting custom init chainer logic (before init genesis). -func (a *App) SetInitChainer(initChainer sdk.InitChainer) { - a.initChainer = initChainer - a.BaseApp.SetInitChainer(initChainer) -} - // UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time. // // NOTE: This should only be used in testing. diff --git a/simapp/app_v2.go b/simapp/app_v2.go index aaf67385b6e0..e40316179280 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" @@ -26,7 +25,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/streaming" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/testutil/testdata_pulsar" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -274,13 +272,6 @@ func NewSimApp( app.sm.RegisterStoreDecoders() - // Set custom init chainer that registers the module versions in the upgrade module - // NOTE: this is not required for apps that do not need custom pre-init genesis logic - app.SetInitChainer(func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) - return app.App.InitChainer(ctx, req) - }) - if err := app.Load(loadLatest); err != nil { panic(err) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 39fd852a75a8..42df8aaa0402 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -119,7 +119,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { + // set version map automatically if available + if versionMap != nil { + am.keeper.SetModuleVersionMap(ctx, *versionMap) + } + return []abci.ValidatorUpdate{} } @@ -155,6 +160,7 @@ func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { func init() { appmodule.Register(&modulev1.Module{}, appmodule.Provide(ProvideModule), + appmodule.Invoke(PopulateVersionMap), ) } @@ -207,3 +213,10 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt} } + +var versionMap *module.VersionMap = nil + +func PopulateVersionMap(modules map[string]appmodule.AppModule) { + vm := module.NewManagerFromMap(modules).GetVersionMap() + versionMap = &vm +} From 8639ce176cfcc2e27a97631f46dfd0455f3ed377 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 13 Dec 2022 11:39:41 +0100 Subject: [PATCH 25/28] set legacy router at correct place --- simapp/app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 68b4abad0bff..cc7dee35e80e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -359,15 +359,15 @@ func NewSimApp( app.StakingKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + // Set legacy router for backwards compatibility with gov v1beta1 + govKeeper.SetLegacyRouter(govRouter) + app.GovKeeper = *govKeeper.SetHooks( govtypes.NewMultiGovHooks( // register the governance hooks ), ) - // Set legacy router for backwards compatibility with gov v1beta1 - govKeeper.SetLegacyRouter(govRouter) - app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper) // create evidence keeper with router From a445d92d446cc69c72d1c7ec6a285a59308e82eb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 13 Dec 2022 19:57:26 +0100 Subject: [PATCH 26/28] updates --- runtime/app.go | 14 +++++++++++++- simapp/app_v2.go | 11 +++++++++++ x/upgrade/module.go | 12 +++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/runtime/app.go b/runtime/app.go index 2642089e2c90..2d4202985d2d 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -48,6 +48,9 @@ type App struct { baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter appConfig *appv1alpha1.Config + // initChainer is the init chainer function defined by the app config. + // this is only required if the chain wants to add special InitChainer logic. + initChainer sdk.InitChainer } // RegisterModules registers the provided modules with the module manager and @@ -82,7 +85,9 @@ func (a *App) Load(loadLatest bool) error { if len(a.config.InitGenesis) != 0 { a.ModuleManager.SetOrderInitGenesis(a.config.InitGenesis...) - a.SetInitChainer(a.InitChainer) + if a.initChainer == nil { + a.SetInitChainer(a.InitChainer) + } } if len(a.config.ExportGenesis) != 0 { @@ -190,6 +195,13 @@ func (a *App) GetStoreKeys() []storetypes.StoreKey { return a.storeKeys } +// SetInitChainer sets the init chainer function +// It wraps `BaseApp.SetInitChainer` to allow setting a custom init chainer from an app. +func (a *App) SetInitChainer(initChainer sdk.InitChainer) { + a.initChainer = initChainer + a.BaseApp.SetInitChainer(initChainer) +} + // UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time. // // NOTE: This should only be used in testing. diff --git a/simapp/app_v2.go b/simapp/app_v2.go index e40316179280..99f93d531638 100644 --- a/simapp/app_v2.go +++ b/simapp/app_v2.go @@ -272,6 +272,17 @@ func NewSimApp( app.sm.RegisterStoreDecoders() + // A custom InitChainer can be set if extra pre-init-genesis logic is required. + // By default, when using app wiring enabled module, this is not required. + // For instance, the upgrade module will set automatically the module version map in its init genesis thanks to app wiring. + // However, when registering a module manually (i.e. that does not support app wiring), the module version map + // must be set manually as follow. The upgrade module will de-duplicate the module version map. + // + // app.SetInitChainer(func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + // app.UpgradeKeeper.SetModuleVersionMap(ctx, app.ModuleManager.GetVersionMap()) + // return app.App.InitChainer(ctx, req) + // }) + if err := app.Load(loadLatest); err != nil { panic(err) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 42df8aaa0402..412ccbf6477c 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -122,7 +122,17 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { // set version map automatically if available if versionMap != nil { - am.keeper.SetModuleVersionMap(ctx, *versionMap) + newVersionMap := *versionMap + + // chains can still use a custom init chainer to setting the version map + // however this means that we need to combine the module version map with app wiring enabled module + for name, version := range am.keeper.GetModuleVersionMap(ctx) { + if _, ok := newVersionMap[name]; !ok { + newVersionMap[name] = version + } + } + + am.keeper.SetModuleVersionMap(ctx, newVersionMap) } return []abci.ValidatorUpdate{} From ec9121efa00a8c8ceb0a23827edeb49988cdff79 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 13 Dec 2022 23:16:55 +0100 Subject: [PATCH 27/28] remove global --- x/upgrade/keeper/keeper.go | 13 +++++++++++++ x/upgrade/module.go | 19 +++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index b9674274ebab..8ae041cb3cf1 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -35,6 +35,7 @@ type Keeper struct { versionSetter xp.ProtocolVersionSetter // implements setting the protocol version field on BaseApp downgradeVerified bool // tells if we've already sanity checked that this binary version isn't being used against an old state. authority string // the address capable of executing and cancelling an upgrade. Usually the gov module account + initVersionMap module.VersionMap // the module version map at init genesis } // NewKeeper constructs an upgrade Keeper which requires the following arguments: @@ -65,6 +66,18 @@ func (k *Keeper) GetVersionSetter() xp.ProtocolVersionSetter { return k.versionSetter } +// SetInitVersionMap sets the initial version map. +// This is only used in app wiring and should not be used in any other context. +func (k *Keeper) SetInitVersionMap(vm module.VersionMap) { + k.initVersionMap = vm +} + +// GetInitVersionMap gets the initial version map +// This is only used in upgrade InitGenesis and should not be used in any other context. +func (k *Keeper) GetInitVersionMap() module.VersionMap { + return k.initVersionMap +} + // SetUpgradeHandler sets an UpgradeHandler for the upgrade specified by name. This handler will be called when the upgrade // with this name is applied. In order for an upgrade with the given name to proceed, a handler for this upgrade // must be set even if it is a no-op function. diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 412ccbf6477c..d075d23f41d9 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -121,18 +121,16 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis is ignored, no sense in serializing future upgrades func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { // set version map automatically if available - if versionMap != nil { - newVersionMap := *versionMap - + if versionMap := am.keeper.GetInitVersionMap(); versionMap != nil { // chains can still use a custom init chainer to setting the version map // however this means that we need to combine the module version map with app wiring enabled module for name, version := range am.keeper.GetModuleVersionMap(ctx) { - if _, ok := newVersionMap[name]; !ok { - newVersionMap[name] = version + if _, ok := versionMap[name]; !ok { + versionMap[name] = version } } - am.keeper.SetModuleVersionMap(ctx, newVersionMap) + am.keeper.SetModuleVersionMap(ctx, versionMap) } return []abci.ValidatorUpdate{} @@ -224,9 +222,10 @@ func ProvideModule(in UpgradeInputs) UpgradeOutputs { return UpgradeOutputs{UpgradeKeeper: k, Module: m, GovHandler: gh, BaseAppOption: baseappOpt} } -var versionMap *module.VersionMap = nil +func PopulateVersionMap(upgradeKeeper *keeper.Keeper, modules map[string]appmodule.AppModule) { + if upgradeKeeper == nil { + return + } -func PopulateVersionMap(modules map[string]appmodule.AppModule) { - vm := module.NewManagerFromMap(modules).GetVersionMap() - versionMap = &vm + upgradeKeeper.SetInitVersionMap(module.NewManagerFromMap(modules).GetVersionMap()) } From 2eabd59498f169c77f13248b32c7508851cc79fa Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 14 Dec 2022 01:07:34 +0100 Subject: [PATCH 28/28] improve comment --- x/upgrade/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/upgrade/module.go b/x/upgrade/module.go index d075d23f41d9..79fb66336521 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -122,8 +122,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { // set version map automatically if available if versionMap := am.keeper.GetInitVersionMap(); versionMap != nil { - // chains can still use a custom init chainer to setting the version map - // however this means that we need to combine the module version map with app wiring enabled module + // chains can still use a custom init chainer for setting the version map + // this means that we need to combine the manually wired modules version map with app wiring enabled modules version map for name, version := range am.keeper.GetModuleVersionMap(ctx) { if _, ok := versionMap[name]; !ok { versionMap[name] = version