From 459012c72b6e28cf33b23789b54bbca52050f724 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 10 Apr 2024 10:53:38 +0200 Subject: [PATCH 1/9] fix!: split out upgrade into a separate signal module --- app/app.go | 29 ++++--- app/module/migrations_test.go | 12 +-- app/test/std_sdk_test.go | 6 +- app/test/upgrade_test.go | 32 +++++++ .../{upgrade => signal}/v1/query.proto | 4 +- .../celestia/{upgrade => signal}/v1/tx.proto | 4 +- x/{upgrade => signal}/README.md | 12 +-- x/{upgrade => signal}/cli/cli_test.go | 2 +- x/{upgrade => signal}/cli/query.go | 2 +- x/{upgrade => signal}/cli/tx.go | 2 +- x/{upgrade => signal}/integration_test.go | 14 +-- x/{upgrade => signal}/interfaces.go | 2 +- x/{upgrade => signal}/keeper.go | 4 +- .../tally_test.go => signal/keeper_test.go} | 76 +++++++++++++--- x/{upgrade => signal}/legacy_test.go | 2 +- x/{upgrade => signal}/module.go | 6 +- x/{upgrade => signal}/types/codec.go | 2 - x/{upgrade => signal}/types/errors.go | 0 x/{upgrade => signal}/types/msgs.go | 16 ++-- x/{upgrade => signal}/types/query.pb.go | 73 ++++++++-------- x/{upgrade => signal}/types/query.pb.gw.go | 2 +- x/{upgrade => signal}/types/tx.pb.go | 86 +++++++++---------- x/{upgrade => signal}/types/tx.pb.gw.go | 2 +- x/upgrade/ibc.go | 75 ---------------- x/upgrade/keeper_test.go | 59 ------------- x/upgrade/upgrade_test.go | 84 ------------------ 26 files changed, 236 insertions(+), 372 deletions(-) create mode 100644 app/test/upgrade_test.go rename proto/celestia/{upgrade => signal}/v1/query.proto (87%) rename proto/celestia/{upgrade => signal}/v1/tx.proto (90%) rename x/{upgrade => signal}/README.md (68%) rename x/{upgrade => signal}/cli/cli_test.go (94%) rename x/{upgrade => signal}/cli/query.go (95%) rename x/{upgrade => signal}/cli/tx.go (97%) rename x/{upgrade => signal}/integration_test.go (80%) rename x/{upgrade => signal}/interfaces.go (95%) rename x/{upgrade => signal}/keeper.go (98%) rename x/{upgrade/tally_test.go => signal/keeper_test.go} (78%) rename x/{upgrade => signal}/legacy_test.go (99%) rename x/{upgrade => signal}/module.go (96%) rename x/{upgrade => signal}/types/codec.go (86%) rename x/{upgrade => signal}/types/errors.go (100%) rename x/{upgrade => signal}/types/msgs.go (82%) rename x/{upgrade => signal}/types/query.pb.go (85%) rename x/{upgrade => signal}/types/query.pb.gw.go (99%) rename x/{upgrade => signal}/types/tx.pb.go (87%) rename x/{upgrade => signal}/types/tx.pb.gw.go (99%) delete mode 100644 x/upgrade/ibc.go delete mode 100644 x/upgrade/keeper_test.go delete mode 100644 x/upgrade/upgrade_test.go diff --git a/app/app.go b/app/app.go index 77c061e197..d22ac03f97 100644 --- a/app/app.go +++ b/app/app.go @@ -9,8 +9,6 @@ import ( "github.com/celestiaorg/celestia-app/v2/x/mint" mintkeeper "github.com/celestiaorg/celestia-app/v2/x/mint/keeper" minttypes "github.com/celestiaorg/celestia-app/v2/x/mint/types" - "github.com/celestiaorg/celestia-app/v2/x/upgrade" - upgradetypes "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" @@ -68,6 +66,8 @@ import ( "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" + upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/cosmos/ibc-go/v6/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" @@ -97,6 +97,8 @@ import ( "github.com/celestiaorg/celestia-app/v2/x/blobstream" blobstreamkeeper "github.com/celestiaorg/celestia-app/v2/x/blobstream/keeper" blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types" + "github.com/celestiaorg/celestia-app/v2/x/signal" + signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types" ibctestingtypes "github.com/cosmos/ibc-go/v6/testing/types" packetforward "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router" @@ -134,7 +136,7 @@ var ( vesting.AppModuleBasic{}, blob.AppModuleBasic{}, blobstream.AppModuleBasic{}, - upgrade.AppModuleBasic{}, + signal.AppModuleBasic{}, minfee.AppModuleBasic{}, packetforward.AppModuleBasic{}, icaModule{}, @@ -194,7 +196,8 @@ type App struct { DistrKeeper distrkeeper.Keeper GovKeeper govkeeper.Keeper CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgrade.Keeper + UpgradeKeeper upgradekeeper.Keeper // This is included purely for the IBC Keeper. It is not used for upgrading + SignalKeeper signal.Keeper ParamsKeeper paramskeeper.Keeper IBCKeeper *ibckeeper.Keeper // IBCKeeper must be a pointer in the app, so we can SetRouter on it correctly EvidenceKeeper evidencekeeper.Keeper @@ -254,6 +257,7 @@ func New( ibchost.StoreKey, packetforwardtypes.StoreKey, icahosttypes.StoreKey, + signaltypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -315,7 +319,10 @@ func New( ) app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper) - app.UpgradeKeeper = upgrade.NewKeeper(keys[upgradetypes.StoreKey], stakingKeeper) + // The ugrade keeper is intialised solely for the ibc keeper which depends on it to know what the next validator hash is for after the + // upgrade. This keeper is not used for the actual upgrades but merely for compatibility reasons. Ideally IBC has their own upgrade module + // for performing IBC based upgrades. Note, as we use rolling upgrades, IBC technically never needs this functionality. + app.UpgradeKeeper = upgradekeeper.NewKeeper(nil, keys[upgradetypes.StoreKey], appCodec, "", app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.upgradeHeight = upgradeHeight app.BlobstreamKeeper = *blobstreamkeeper.NewKeeper( @@ -334,7 +341,7 @@ func New( ), ) - // ... other modules keepers + app.SignalKeeper = signal.NewKeeper(keys[signaltypes.StoreKey], app.StakingKeeper) app.IBCKeeper = ibckeeper.NewKeeper( appCodec, @@ -510,7 +517,7 @@ func New( FromVersion: v1, ToVersion: v2, }, { - Module: upgrade.NewAppModule(app.UpgradeKeeper), + Module: signal.NewAppModule(app.SignalKeeper), FromVersion: v2, ToVersion: v2, }, { @@ -554,7 +561,7 @@ func New( paramstypes.ModuleName, authz.ModuleName, vestingtypes.ModuleName, - upgradetypes.ModuleName, + signaltypes.ModuleName, minfee.ModuleName, icatypes.ModuleName, packetforwardtypes.ModuleName, @@ -580,7 +587,7 @@ func New( paramstypes.ModuleName, authz.ModuleName, vestingtypes.ModuleName, - upgradetypes.ModuleName, + signaltypes.ModuleName, minfee.ModuleName, packetforwardtypes.ModuleName, icatypes.ModuleName, @@ -614,7 +621,7 @@ func New( feegrant.ModuleName, paramstypes.ModuleName, authz.ModuleName, - upgradetypes.ModuleName, + signaltypes.ModuleName, packetforwardtypes.ModuleName, icatypes.ModuleName, ) @@ -684,7 +691,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo } } // from v2 to v3 and onwards we use a signalling mechanism - } else if shouldUpgrade, newVersion := app.UpgradeKeeper.ShouldUpgrade(); shouldUpgrade { + } else if shouldUpgrade, newVersion := app.SignalKeeper.ShouldUpgrade(); shouldUpgrade { // Version changes must be increasing. Downgrades are not permitted if newVersion > currentVersion { if err := app.Upgrade(ctx, currentVersion, newVersion); err != nil { diff --git a/app/module/migrations_test.go b/app/module/migrations_test.go index 045693b593..584259ddd7 100644 --- a/app/module/migrations_test.go +++ b/app/module/migrations_test.go @@ -6,8 +6,8 @@ import ( "github.com/celestiaorg/celestia-app/v2/app" "github.com/celestiaorg/celestia-app/v2/app/encoding" "github.com/celestiaorg/celestia-app/v2/app/module" - "github.com/celestiaorg/celestia-app/v2/x/upgrade" - upgradetypes "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + "github.com/celestiaorg/celestia-app/v2/x/signal" + signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types" "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/tests/mocks" @@ -76,15 +76,15 @@ func TestConfiguratorRegistersAllMessageTypes(t *testing.T) { cdc := encoding.MakeConfig(app.ModuleEncodingRegisters...) configurator := module.NewConfigurator(cdc.Codec, mockServer, mockServer) - storeKey := sdk.NewKVStoreKey(upgradetypes.StoreKey) + storeKey := sdk.NewKVStoreKey(signaltypes.StoreKey) db := dbm.NewMemDB() stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) require.NoError(t, stateStore.LoadLatestVersion()) - keeper := upgrade.NewKeeper(storeKey, nil) - upgradeModule := upgrade.NewAppModule(keeper) + keeper := signal.NewKeeper(storeKey, nil) + upgradeModule := signal.NewAppModule(keeper) mm, err := module.NewManager([]module.VersionedModule{ {Module: upgradeModule, FromVersion: 2, ToVersion: 2}, }) @@ -94,7 +94,7 @@ func TestConfiguratorRegistersAllMessageTypes(t *testing.T) { mm.RegisterServices(configurator) acceptedMessages := configurator.GetAcceptedMessages() require.Equal(t, map[uint64]map[string]struct{}{ - 2: {"/celestia.upgrade.v1.MsgSignalVersion": {}, "/celestia.upgrade.v1.MsgTryUpgrade": {}}, + 2: {"/celestia.signal.v1.MsgSignalVersion": {}, "/celestia.signal.v1.MsgTryUpgrade": {}}, }, acceptedMessages) require.NotNil(t, keeper) diff --git a/app/test/std_sdk_test.go b/app/test/std_sdk_test.go index 268eefe62d..10fe6e3405 100644 --- a/app/test/std_sdk_test.go +++ b/app/test/std_sdk_test.go @@ -11,7 +11,7 @@ import ( "github.com/celestiaorg/celestia-app/v2/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v2/test/util/testfactory" "github.com/celestiaorg/celestia-app/v2/test/util/testnode" - upgrade "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + signal "github.com/celestiaorg/celestia-app/v2/x/signal/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/testutil/mock" @@ -292,7 +292,7 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() { msgFunc: func() (msgs []sdk.Msg, signer string) { account := s.unusedAccount() addr := testfactory.GetAddress(s.cctx.Keyring, account) - msg := upgrade.NewMsgTryUpgrade(addr) + msg := signal.NewMsgTryUpgrade(addr) return []sdk.Msg{msg}, account }, expectedCode: abci.CodeTypeOK, @@ -301,7 +301,7 @@ func (s *StandardSDKIntegrationTestSuite) TestStandardSDK() { name: "signal a version change", msgFunc: func() (msgs []sdk.Msg, signer string) { valAccount := s.getValidatorAccount() - msg := upgrade.NewMsgSignalVersion(valAccount, 2) + msg := signal.NewMsgSignalVersion(valAccount, 2) return []sdk.Msg{msg}, s.getValidatorName() }, expectedCode: abci.CodeTypeOK, diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go new file mode 100644 index 0000000000..4cea521252 --- /dev/null +++ b/app/test/upgrade_test.go @@ -0,0 +1,32 @@ +package app_test + +import ( + "testing" + + v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" + v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" + "github.com/stretchr/testify/require" + abci "github.com/tendermint/tendermint/abci/types" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmversion "github.com/tendermint/tendermint/proto/tendermint/version" +) + +func TestUpgradeAppVersion(t *testing.T) { + testApp, _ := setupTestApp(t, 3) + + supportedVersions := []uint64{v1.Version, v2.Version} + + require.Equal(t, supportedVersions, testApp.SupportedVersions()) + + testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ + Height: 2, + Version: tmversion.Consensus{App: 1}, + }}) + // app version should not have changed yet + require.EqualValues(t, 1, testApp.AppVersion()) + respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) + // now the app version changes + require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) + require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) + require.EqualValues(t, 2, testApp.AppVersion()) +} diff --git a/proto/celestia/upgrade/v1/query.proto b/proto/celestia/signal/v1/query.proto similarity index 87% rename from proto/celestia/upgrade/v1/query.proto rename to proto/celestia/signal/v1/query.proto index 73351a7cbb..3672e7f787 100644 --- a/proto/celestia/upgrade/v1/query.proto +++ b/proto/celestia/signal/v1/query.proto @@ -1,9 +1,9 @@ syntax = "proto3"; -package celestia.upgrade.v1; +package celestia.signal.v1; import "google/api/annotations.proto"; -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; +option go_package = "github.com/celestiaorg/celestia-app/x/signal/types"; // Query defines the upgrade Query service. service Query { diff --git a/proto/celestia/upgrade/v1/tx.proto b/proto/celestia/signal/v1/tx.proto similarity index 90% rename from proto/celestia/upgrade/v1/tx.proto rename to proto/celestia/signal/v1/tx.proto index 63891a5528..db9aa3b452 100644 --- a/proto/celestia/upgrade/v1/tx.proto +++ b/proto/celestia/signal/v1/tx.proto @@ -1,9 +1,9 @@ syntax = "proto3"; -package celestia.upgrade.v1; +package celestia.signal.v1; import "google/api/annotations.proto"; -option go_package = "github.com/celestiaorg/celestia-app/x/upgrade/types"; +option go_package = "github.com/celestiaorg/celestia-app/x/signal/types"; // Msg defines the upgrade Msg service. service Msg { diff --git a/x/upgrade/README.md b/x/signal/README.md similarity index 68% rename from x/upgrade/README.md rename to x/signal/README.md index 542ed3b26c..1a0975f644 100644 --- a/x/upgrade/README.md +++ b/x/signal/README.md @@ -1,6 +1,6 @@ -# `x/upgrade` +# `x/signal` -This upgrade module is a fork of the cosmos-sdk's [x/upgrade](https://github.com/cosmos/cosmos-sdk/tree/main/x/upgrade) module. The primary purpose of this module is to allow for rolling network upgrades as proposed in [ADR-018](../../docs/architecture/adr-018-network-upgrades.md) and [CIP-10](https://github.com/celestiaorg/CIPs/blob/main/cips/cip-10.md). +The signal module acts as a coordinating mechanism for the application on when it should transition from one app version to another. The application itself handles multiple versioned modules as well as migrations, however it requires some protocol for knowing which height to perform this upgrade as it is critical that all nodes upgrade at the same point. Note: this module won't be used for upgrading from app version v1 to v2 but will be used for upgrading from v2 to v3 and onwards. @@ -27,18 +27,18 @@ See [types/msgs.go](./types/msgs.go) for the message types. ```shell celestia-appd query upgrade tally -celestia-appd tx upgrade signal -celestia-appd tx upgrade try-upgrade +celestia-appd tx signal signal +celestia-appd tx signal try-upgrade ``` ### gRPC ```api -celestia.upgrade.v1.Query/VersionTally +celestia.signal.v1.Query/VersionTally ``` ```shell -grpcurl -plaintext localhost:9090 celestia.upgrade.v1.Query/VersionTally +grpcurl -plaintext localhost:9090 celestia.signal.v1.Query/VersionTally ``` ## Appendix diff --git a/x/upgrade/cli/cli_test.go b/x/signal/cli/cli_test.go similarity index 94% rename from x/upgrade/cli/cli_test.go rename to x/signal/cli/cli_test.go index ccca928456..82d6dd0500 100644 --- a/x/upgrade/cli/cli_test.go +++ b/x/signal/cli/cli_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/celestiaorg/celestia-app/v2/test/util/testnode" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/cli" + "github.com/celestiaorg/celestia-app/v2/x/signal/cli" testutil "github.com/cosmos/cosmos-sdk/testutil/cli" "github.com/stretchr/testify/suite" ) diff --git a/x/upgrade/cli/query.go b/x/signal/cli/query.go similarity index 95% rename from x/upgrade/cli/query.go rename to x/signal/cli/query.go index 50371d7af7..565f808a26 100644 --- a/x/upgrade/cli/query.go +++ b/x/signal/cli/query.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + "github.com/celestiaorg/celestia-app/v2/x/signal/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" diff --git a/x/upgrade/cli/tx.go b/x/signal/cli/tx.go similarity index 97% rename from x/upgrade/cli/tx.go rename to x/signal/cli/tx.go index a297e2a539..9f021654af 100644 --- a/x/upgrade/cli/tx.go +++ b/x/signal/cli/tx.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + "github.com/celestiaorg/celestia-app/v2/x/signal/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" diff --git a/x/upgrade/integration_test.go b/x/signal/integration_test.go similarity index 80% rename from x/upgrade/integration_test.go rename to x/signal/integration_test.go index e08662aba6..17b3e3f751 100644 --- a/x/upgrade/integration_test.go +++ b/x/signal/integration_test.go @@ -1,11 +1,11 @@ -package upgrade_test +package signal_test import ( "testing" "github.com/celestiaorg/celestia-app/v2/app" testutil "github.com/celestiaorg/celestia-app/v2/test/util" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + "github.com/celestiaorg/celestia-app/v2/x/signal/types" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,7 +27,7 @@ func TestUpgradeIntegration(t *testing.T) { goCtx := sdk.WrapSDKContext(ctx) ctx = sdk.UnwrapSDKContext(goCtx) - res, err := app.UpgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + res, err := app.SignalKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ Version: 2, }) require.NoError(t, err) @@ -37,13 +37,13 @@ func TestUpgradeIntegration(t *testing.T) { valAddr, err := sdk.ValAddressFromBech32(validators[0].OperatorAddress) require.NoError(t, err) - _, err = app.UpgradeKeeper.SignalVersion(ctx, &types.MsgSignalVersion{ + _, err = app.SignalKeeper.SignalVersion(ctx, &types.MsgSignalVersion{ ValidatorAddress: valAddr.String(), Version: 2, }) require.NoError(t, err) - res, err = app.UpgradeKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ + res, err = app.SignalKeeper.VersionTally(goCtx, &types.QueryVersionTallyRequest{ Version: 2, }) require.NoError(t, err) @@ -51,10 +51,10 @@ func TestUpgradeIntegration(t *testing.T) { require.EqualValues(t, 1, res.ThresholdPower) require.EqualValues(t, 1, res.TotalVotingPower) - _, err = app.UpgradeKeeper.TryUpgrade(ctx, nil) + _, err = app.SignalKeeper.TryUpgrade(ctx, nil) require.NoError(t, err) - shouldUpgrade, version := app.UpgradeKeeper.ShouldUpgrade() + shouldUpgrade, version := app.SignalKeeper.ShouldUpgrade() require.True(t, shouldUpgrade) require.EqualValues(t, 2, version) } diff --git a/x/upgrade/interfaces.go b/x/signal/interfaces.go similarity index 95% rename from x/upgrade/interfaces.go rename to x/signal/interfaces.go index ae745bb655..6e49023128 100644 --- a/x/upgrade/interfaces.go +++ b/x/signal/interfaces.go @@ -1,4 +1,4 @@ -package upgrade +package signal import ( "cosmossdk.io/math" diff --git a/x/upgrade/keeper.go b/x/signal/keeper.go similarity index 98% rename from x/upgrade/keeper.go rename to x/signal/keeper.go index 0852eb14f3..36bb88cea2 100644 --- a/x/upgrade/keeper.go +++ b/x/signal/keeper.go @@ -1,11 +1,11 @@ -package upgrade +package signal import ( "context" "encoding/binary" sdkmath "cosmossdk.io/math" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + "github.com/celestiaorg/celestia-app/v2/x/signal/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" diff --git a/x/upgrade/tally_test.go b/x/signal/keeper_test.go similarity index 78% rename from x/upgrade/tally_test.go rename to x/signal/keeper_test.go index e9289d2f4e..419a3f08de 100644 --- a/x/upgrade/tally_test.go +++ b/x/signal/keeper_test.go @@ -1,13 +1,17 @@ -package upgrade_test +package signal_test import ( + "fmt" + "math" + "math/big" "testing" - "cosmossdk.io/math" - "github.com/celestiaorg/celestia-app/v2/x/upgrade" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/celestiaorg/celestia-app/v2/x/signal" + "github.com/celestiaorg/celestia-app/v2/x/signal/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -20,6 +24,52 @@ import ( tmdb "github.com/tendermint/tm-db" ) +func TestGetVotingPowerThreshold(t *testing.T) { + bigInt := big.NewInt(0) + bigInt.SetString("23058430092136939509", 10) + + type testCase struct { + name string + validators map[string]int64 + want sdkmath.Int + } + testCases := []testCase{ + { + name: "empty validators", + validators: map[string]int64{}, + want: sdkmath.NewInt(0), + }, + { + name: "one validator with 6 power returns 5 because the defaultSignalThreshold is 5/6", + validators: map[string]int64{"a": 6}, + want: sdkmath.NewInt(5), + }, + { + name: "one validator with 11 power (11 * 5/6 = 9.16666667) so should round up to 10", + validators: map[string]int64{"a": 11}, + want: sdkmath.NewInt(10), + }, + { + name: "one validator with voting power of math.MaxInt64", + validators: map[string]int64{"a": math.MaxInt64}, + want: sdkmath.NewInt(7686143364045646503), + }, + { + name: "multiple validators with voting power of math.MaxInt64", + validators: map[string]int64{"a": math.MaxInt64, "b": math.MaxInt64, "c": math.MaxInt64}, + want: sdkmath.NewIntFromBigInt(bigInt), + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + stakingKeeper := newMockStakingKeeper(tc.validators) + k := signal.NewKeeper(nil, stakingKeeper) + got := k.GetVotingPowerThreshold(sdk.Context{}) + assert.Equal(t, tc.want, got, fmt.Sprintf("want %v, got %v", tc.want.String(), got.String())) + }) + } +} + func TestSignalVersion(t *testing.T) { upgradeKeeper, ctx, _ := setup(t) goCtx := sdk.WrapSDKContext(ctx) @@ -202,17 +252,17 @@ func TestThresholdVotingPower(t *testing.T) { {total: 6, threshold: 5}, {total: 59, threshold: 50}, } { - mockStakingKeeper.totalVotingPower = math.NewInt(tc.total) + mockStakingKeeper.totalVotingPower = sdkmath.NewInt(tc.total) threshold := upgradeKeeper.GetVotingPowerThreshold(ctx) require.EqualValues(t, tc.threshold, threshold.Int64()) } } -func setup(t *testing.T) (upgrade.Keeper, sdk.Context, *mockStakingKeeper) { - upgradeStore := sdk.NewKVStoreKey(types.StoreKey) +func setup(t *testing.T) (signal.Keeper, sdk.Context, *mockStakingKeeper) { + signalStore := sdk.NewKVStoreKey(types.StoreKey) db := tmdb.NewMemDB() stateStore := store.NewCommitMultiStore(db) - stateStore.MountStoreWithDB(upgradeStore, storetypes.StoreTypeIAVL, nil) + stateStore.MountStoreWithDB(signalStore, storetypes.StoreTypeIAVL, nil) require.NoError(t, stateStore.LoadLatestVersion()) mockCtx := sdk.NewContext(stateStore, tmproto.Header{ Version: tmversion.Consensus{ @@ -229,19 +279,19 @@ func setup(t *testing.T) (upgrade.Keeper, sdk.Context, *mockStakingKeeper) { }, ) - upgradeKeeper := upgrade.NewKeeper(upgradeStore, mockStakingKeeper) + upgradeKeeper := signal.NewKeeper(signalStore, mockStakingKeeper) return upgradeKeeper, mockCtx, mockStakingKeeper } -var _ upgrade.StakingKeeper = (*mockStakingKeeper)(nil) +var _ signal.StakingKeeper = (*mockStakingKeeper)(nil) type mockStakingKeeper struct { - totalVotingPower math.Int + totalVotingPower sdkmath.Int validators map[string]int64 } func newMockStakingKeeper(validators map[string]int64) *mockStakingKeeper { - totalVotingPower := math.NewInt(0) + totalVotingPower := sdkmath.NewInt(0) for _, power := range validators { totalVotingPower = totalVotingPower.AddRaw(power) } @@ -251,7 +301,7 @@ func newMockStakingKeeper(validators map[string]int64) *mockStakingKeeper { } } -func (m *mockStakingKeeper) GetLastTotalPower(_ sdk.Context) math.Int { +func (m *mockStakingKeeper) GetLastTotalPower(_ sdk.Context) sdkmath.Int { return m.totalVotingPower } diff --git a/x/upgrade/legacy_test.go b/x/signal/legacy_test.go similarity index 99% rename from x/upgrade/legacy_test.go rename to x/signal/legacy_test.go index 036c6f9e3e..36642cde2d 100644 --- a/x/upgrade/legacy_test.go +++ b/x/signal/legacy_test.go @@ -1,4 +1,4 @@ -package upgrade_test +package signal_test import ( "context" diff --git a/x/upgrade/module.go b/x/signal/module.go similarity index 96% rename from x/upgrade/module.go rename to x/signal/module.go index b2074d17e2..266b3411ed 100644 --- a/x/upgrade/module.go +++ b/x/signal/module.go @@ -1,4 +1,4 @@ -package upgrade +package signal import ( "context" @@ -8,8 +8,8 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/cli" - "github.com/celestiaorg/celestia-app/v2/x/upgrade/types" + "github.com/celestiaorg/celestia-app/v2/x/signal/cli" + "github.com/celestiaorg/celestia-app/v2/x/signal/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" diff --git a/x/upgrade/types/codec.go b/x/signal/types/codec.go similarity index 86% rename from x/upgrade/types/codec.go rename to x/signal/types/codec.go index 95a0940ace..49a08996f6 100644 --- a/x/upgrade/types/codec.go +++ b/x/signal/types/codec.go @@ -5,13 +5,11 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) // RegisterLegacyAminoCodec registers the upgrade types on the provided // LegacyAmino codec. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(upgradetypes.Plan{}, "cosmos-sdk/Plan", nil) cdc.RegisterConcrete(&MsgTryUpgrade{}, URLMsgTryUpgrade, nil) cdc.RegisterConcrete(&MsgSignalVersion{}, URLMsgSignalVersion, nil) } diff --git a/x/upgrade/types/errors.go b/x/signal/types/errors.go similarity index 100% rename from x/upgrade/types/errors.go rename to x/signal/types/errors.go diff --git a/x/upgrade/types/msgs.go b/x/signal/types/msgs.go similarity index 82% rename from x/upgrade/types/msgs.go rename to x/signal/types/msgs.go index 96085ce52d..b453d1f612 100644 --- a/x/upgrade/types/msgs.go +++ b/x/signal/types/msgs.go @@ -5,23 +5,17 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( - StoreKey = upgradetypes.StoreKey + ModuleName = "signal" - // Copied from cosmos/cosmos-sdk/x/upgrade/types/keys.go: - ModuleName = upgradetypes.ModuleName - - // QuerierRoute defines the module's query routing key + StoreKey = ModuleName QuerierRoute = ModuleName + RouterKey = ModuleName - // RouterKey defines the module's message routing key - RouterKey = ModuleName - - URLMsgSignalVersion = "/celestia.upgrade.v1.Msg/SignalVersion" - URLMsgTryUpgrade = "/celestia.upgrade.v1.Msg/TryUpgrade" + URLMsgSignalVersion = "/celestia.signal.v1.Msg/SignalVersion" + URLMsgTryUpgrade = "/celestia.signal_test.v1.Msg/TryUpgrade" ) var ( diff --git a/x/upgrade/types/query.pb.go b/x/signal/types/query.pb.go similarity index 85% rename from x/upgrade/types/query.pb.go rename to x/signal/types/query.pb.go index 7fb02d6d82..1f2998df99 100644 --- a/x/upgrade/types/query.pb.go +++ b/x/signal/types/query.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: celestia/upgrade/v1/query.proto +// source: celestia/signal/v1/query.proto package types @@ -37,7 +37,7 @@ func (m *QueryVersionTallyRequest) Reset() { *m = QueryVersionTallyReque func (m *QueryVersionTallyRequest) String() string { return proto.CompactTextString(m) } func (*QueryVersionTallyRequest) ProtoMessage() {} func (*QueryVersionTallyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_7dd2290b21d03efa, []int{0} + return fileDescriptor_7af24246367e432c, []int{0} } func (m *QueryVersionTallyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -84,7 +84,7 @@ func (m *QueryVersionTallyResponse) Reset() { *m = QueryVersionTallyResp func (m *QueryVersionTallyResponse) String() string { return proto.CompactTextString(m) } func (*QueryVersionTallyResponse) ProtoMessage() {} func (*QueryVersionTallyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_7dd2290b21d03efa, []int{1} + return fileDescriptor_7af24246367e432c, []int{1} } func (m *QueryVersionTallyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -135,35 +135,36 @@ func (m *QueryVersionTallyResponse) GetTotalVotingPower() uint64 { } func init() { - proto.RegisterType((*QueryVersionTallyRequest)(nil), "celestia.upgrade.v1.QueryVersionTallyRequest") - proto.RegisterType((*QueryVersionTallyResponse)(nil), "celestia.upgrade.v1.QueryVersionTallyResponse") -} - -func init() { proto.RegisterFile("celestia/upgrade/v1/query.proto", fileDescriptor_7dd2290b21d03efa) } - -var fileDescriptor_7dd2290b21d03efa = []byte{ - // 331 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xcd, 0x4e, 0x02, 0x31, - 0x14, 0x85, 0x29, 0xfe, 0x25, 0x95, 0xa8, 0xa9, 0x1b, 0x44, 0x1d, 0x15, 0x17, 0xba, 0x90, 0x36, - 0x88, 0x4f, 0xe0, 0xde, 0x44, 0x89, 0x61, 0xe1, 0x86, 0x14, 0x68, 0x86, 0x49, 0xc6, 0xb9, 0xa5, - 0xbd, 0x33, 0x4a, 0x8c, 0x1b, 0x9f, 0xc0, 0x68, 0xdc, 0xf9, 0x40, 0x2e, 0x49, 0xdc, 0xb8, 0x34, - 0xe0, 0x83, 0x18, 0x66, 0x86, 0x11, 0x13, 0x4c, 0xdc, 0xb5, 0xa7, 0xdf, 0x39, 0xbd, 0x3f, 0x74, - 0xa7, 0xad, 0x7c, 0x65, 0xd1, 0x93, 0x22, 0xd4, 0xae, 0x91, 0x1d, 0x25, 0xa2, 0xaa, 0xe8, 0x85, - 0xca, 0xf4, 0xb9, 0x36, 0x80, 0xc0, 0xd6, 0x27, 0x00, 0x4f, 0x01, 0x1e, 0x55, 0x4b, 0x5b, 0x2e, - 0x80, 0xeb, 0x2b, 0x21, 0xb5, 0x27, 0x64, 0x10, 0x00, 0x4a, 0xf4, 0x20, 0xb0, 0x89, 0xa5, 0x7c, - 0x42, 0x8b, 0x17, 0xe3, 0x84, 0x86, 0x32, 0xd6, 0x83, 0xe0, 0x52, 0xfa, 0x7e, 0xbf, 0xae, 0x7a, - 0xa1, 0xb2, 0xc8, 0x8a, 0x74, 0x29, 0x4a, 0xe4, 0x22, 0xd9, 0x25, 0x87, 0xf3, 0xf5, 0xc9, 0xb5, - 0xfc, 0x42, 0xe8, 0xc6, 0x0c, 0x9b, 0xd5, 0x10, 0x58, 0xc5, 0xf6, 0x68, 0x21, 0x02, 0xf4, 0x02, - 0xb7, 0xa9, 0xe1, 0x46, 0x99, 0xd4, 0xbc, 0x9c, 0x68, 0xe7, 0x63, 0x89, 0x1d, 0xd0, 0x55, 0xec, - 0x1a, 0x65, 0xbb, 0xe0, 0x77, 0x52, 0x2a, 0x1f, 0x53, 0x2b, 0x99, 0x9c, 0x80, 0x47, 0x94, 0x21, - 0xa0, 0xf4, 0x9b, 0xbf, 0x12, 0xe7, 0x62, 0x76, 0x2d, 0x7e, 0x69, 0xfc, 0xc4, 0x1e, 0xbf, 0x12, - 0xba, 0x10, 0xd7, 0xc5, 0x9e, 0x08, 0x2d, 0x4c, 0x17, 0xc7, 0x2a, 0x7c, 0xc6, 0x70, 0xf8, 0x5f, - 0xbd, 0x97, 0xf8, 0x7f, 0xf1, 0xa4, 0xe7, 0xf2, 0xfe, 0xc3, 0xfb, 0xd7, 0x73, 0x7e, 0x9b, 0x6d, - 0x4e, 0xef, 0x06, 0xc7, 0x88, 0xb8, 0x4b, 0xa7, 0x76, 0x7f, 0x7a, 0xf6, 0x36, 0x74, 0xc8, 0x60, - 0xe8, 0x90, 0xcf, 0xa1, 0x43, 0x1e, 0x47, 0x4e, 0x6e, 0x30, 0x72, 0x72, 0x1f, 0x23, 0x27, 0x77, - 0x55, 0x73, 0x3d, 0xec, 0x86, 0x2d, 0xde, 0x86, 0x6b, 0x31, 0xf9, 0x18, 0x8c, 0x9b, 0x9d, 0x2b, - 0x52, 0x6b, 0x71, 0x9b, 0x65, 0x63, 0x5f, 0x2b, 0xdb, 0x5a, 0x8c, 0x57, 0x58, 0xfb, 0x0e, 0x00, - 0x00, 0xff, 0xff, 0xa9, 0x02, 0x48, 0x0f, 0x18, 0x02, 0x00, 0x00, + proto.RegisterType((*QueryVersionTallyRequest)(nil), "celestia.signal.v1.QueryVersionTallyRequest") + proto.RegisterType((*QueryVersionTallyResponse)(nil), "celestia.signal.v1.QueryVersionTallyResponse") +} + +func init() { proto.RegisterFile("celestia/signal/v1/query.proto", fileDescriptor_7af24246367e432c) } + +var fileDescriptor_7af24246367e432c = []byte{ + // 337 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xcd, 0x4e, 0x3a, 0x31, + 0x14, 0xc5, 0x29, 0xff, 0x0f, 0x93, 0x4a, 0xd4, 0x74, 0x85, 0xa8, 0x13, 0xc5, 0x85, 0x2e, 0x60, + 0x1a, 0xd0, 0x27, 0x70, 0xed, 0x42, 0x89, 0x61, 0xe1, 0x86, 0x14, 0x68, 0x4a, 0x93, 0xda, 0x5b, + 0xda, 0xce, 0x28, 0x31, 0x6e, 0x7c, 0x02, 0x12, 0xe3, 0xc6, 0x27, 0x72, 0x49, 0xe2, 0xc6, 0xa5, + 0x01, 0x1f, 0xc4, 0xcc, 0x0c, 0x83, 0x1a, 0x35, 0x71, 0x37, 0x73, 0xee, 0xef, 0x9e, 0xde, 0x7b, + 0x0f, 0x0e, 0x7a, 0x5c, 0x71, 0xe7, 0x25, 0xa3, 0x4e, 0x0a, 0xcd, 0x14, 0x8d, 0x1b, 0x74, 0x18, + 0x71, 0x3b, 0x0a, 0x8d, 0x05, 0x0f, 0x84, 0xe4, 0xf5, 0x30, 0xab, 0x87, 0x71, 0xa3, 0xb2, 0x29, + 0x00, 0x84, 0xe2, 0x94, 0x19, 0x49, 0x99, 0xd6, 0xe0, 0x99, 0x97, 0xa0, 0x5d, 0xd6, 0x51, 0x3d, + 0xc4, 0xe5, 0xd3, 0xc4, 0xa0, 0xcd, 0xad, 0x93, 0xa0, 0xcf, 0x98, 0x52, 0xa3, 0x16, 0x1f, 0x46, + 0xdc, 0x79, 0x52, 0xc6, 0x4b, 0x71, 0x26, 0x97, 0xd1, 0x36, 0xda, 0xff, 0xdb, 0xca, 0x7f, 0xab, + 0xf7, 0x08, 0xaf, 0x7f, 0xd3, 0xe6, 0x0c, 0x68, 0xc7, 0xc9, 0x0e, 0x2e, 0xc5, 0xe0, 0xa5, 0x16, + 0x1d, 0x03, 0x97, 0xdc, 0xce, 0x9b, 0x97, 0x33, 0xed, 0x24, 0x91, 0xc8, 0x1e, 0x5e, 0xf5, 0x03, + 0xcb, 0xdd, 0x00, 0x54, 0x7f, 0x4e, 0x15, 0x53, 0x6a, 0x65, 0x21, 0x67, 0x60, 0x0d, 0x13, 0x0f, + 0x9e, 0xa9, 0xce, 0x27, 0xc7, 0x3f, 0x29, 0xbb, 0x96, 0x56, 0xda, 0xef, 0xb6, 0xcd, 0x07, 0x84, + 0xff, 0xa5, 0x73, 0x91, 0x31, 0xc2, 0xa5, 0x8f, 0xc3, 0x91, 0x5a, 0xf8, 0xf5, 0x36, 0xe1, 0x4f, + 0xab, 0x57, 0xea, 0xbf, 0xa4, 0xb3, 0x8d, 0xab, 0xbb, 0xb7, 0x4f, 0xaf, 0x77, 0xc5, 0x2d, 0xb2, + 0x41, 0x23, 0x23, 0x2c, 0xeb, 0xf3, 0x24, 0x18, 0x9f, 0x20, 0xf4, 0x7a, 0x7e, 0xb3, 0x9b, 0xa3, + 0xe3, 0xc7, 0x69, 0x80, 0x26, 0xd3, 0x00, 0xbd, 0x4c, 0x03, 0x34, 0x9e, 0x05, 0x85, 0xc9, 0x2c, + 0x28, 0x3c, 0xcf, 0x82, 0xc2, 0x79, 0x53, 0x48, 0x3f, 0x88, 0xba, 0x61, 0x0f, 0x2e, 0x68, 0xfe, + 0x2e, 0x58, 0xb1, 0xf8, 0xae, 0x33, 0x63, 0xe8, 0x55, 0x9e, 0xb9, 0x1f, 0x19, 0xee, 0xba, 0xff, + 0xd3, 0xfc, 0x0e, 0xde, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe7, 0x5f, 0x33, 0x08, 0x13, 0x02, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -193,7 +194,7 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { func (c *queryClient) VersionTally(ctx context.Context, in *QueryVersionTallyRequest, opts ...grpc.CallOption) (*QueryVersionTallyResponse, error) { out := new(QueryVersionTallyResponse) - err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Query/VersionTally", in, out, opts...) + err := c.cc.Invoke(ctx, "/celestia.signal.v1.Query/VersionTally", in, out, opts...) if err != nil { return nil, err } @@ -229,7 +230,7 @@ func _Query_VersionTally_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/celestia.upgrade.v1.Query/VersionTally", + FullMethod: "/celestia.signal.v1.Query/VersionTally", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).VersionTally(ctx, req.(*QueryVersionTallyRequest)) @@ -238,7 +239,7 @@ func _Query_VersionTally_Handler(srv interface{}, ctx context.Context, dec func( } var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "celestia.upgrade.v1.Query", + ServiceName: "celestia.signal.v1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { @@ -247,7 +248,7 @@ var _Query_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "celestia/upgrade/v1/query.proto", + Metadata: "celestia/signal/v1/query.proto", } func (m *QueryVersionTallyRequest) Marshal() (dAtA []byte, err error) { diff --git a/x/upgrade/types/query.pb.gw.go b/x/signal/types/query.pb.gw.go similarity index 99% rename from x/upgrade/types/query.pb.gw.go rename to x/signal/types/query.pb.gw.go index 03b777ca29..0fe22f5631 100644 --- a/x/upgrade/types/query.pb.gw.go +++ b/x/signal/types/query.pb.gw.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: celestia/upgrade/v1/query.proto +// source: celestia/signal/v1/query.proto /* Package types is a reverse proxy. diff --git a/x/upgrade/types/tx.pb.go b/x/signal/types/tx.pb.go similarity index 87% rename from x/upgrade/types/tx.pb.go rename to x/signal/types/tx.pb.go index bdcb1bd857..f58f90f9d5 100644 --- a/x/upgrade/types/tx.pb.go +++ b/x/signal/types/tx.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: celestia/upgrade/v1/tx.proto +// source: celestia/signal/v1/tx.proto package types @@ -38,7 +38,7 @@ func (m *MsgSignalVersion) Reset() { *m = MsgSignalVersion{} } func (m *MsgSignalVersion) String() string { return proto.CompactTextString(m) } func (*MsgSignalVersion) ProtoMessage() {} func (*MsgSignalVersion) Descriptor() ([]byte, []int) { - return fileDescriptor_ee2a0c754324bd13, []int{0} + return fileDescriptor_815f2cc162e6e27e, []int{0} } func (m *MsgSignalVersion) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -89,7 +89,7 @@ func (m *MsgSignalVersionResponse) Reset() { *m = MsgSignalVersionRespon func (m *MsgSignalVersionResponse) String() string { return proto.CompactTextString(m) } func (*MsgSignalVersionResponse) ProtoMessage() {} func (*MsgSignalVersionResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ee2a0c754324bd13, []int{1} + return fileDescriptor_815f2cc162e6e27e, []int{1} } func (m *MsgSignalVersionResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -127,7 +127,7 @@ func (m *MsgTryUpgrade) Reset() { *m = MsgTryUpgrade{} } func (m *MsgTryUpgrade) String() string { return proto.CompactTextString(m) } func (*MsgTryUpgrade) ProtoMessage() {} func (*MsgTryUpgrade) Descriptor() ([]byte, []int) { - return fileDescriptor_ee2a0c754324bd13, []int{2} + return fileDescriptor_815f2cc162e6e27e, []int{2} } func (m *MsgTryUpgrade) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -171,7 +171,7 @@ func (m *MsgTryUpgradeResponse) Reset() { *m = MsgTryUpgradeResponse{} } func (m *MsgTryUpgradeResponse) String() string { return proto.CompactTextString(m) } func (*MsgTryUpgradeResponse) ProtoMessage() {} func (*MsgTryUpgradeResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ee2a0c754324bd13, []int{3} + return fileDescriptor_815f2cc162e6e27e, []int{3} } func (m *MsgTryUpgradeResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -201,38 +201,38 @@ func (m *MsgTryUpgradeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgTryUpgradeResponse proto.InternalMessageInfo func init() { - proto.RegisterType((*MsgSignalVersion)(nil), "celestia.upgrade.v1.MsgSignalVersion") - proto.RegisterType((*MsgSignalVersionResponse)(nil), "celestia.upgrade.v1.MsgSignalVersionResponse") - proto.RegisterType((*MsgTryUpgrade)(nil), "celestia.upgrade.v1.MsgTryUpgrade") - proto.RegisterType((*MsgTryUpgradeResponse)(nil), "celestia.upgrade.v1.MsgTryUpgradeResponse") -} - -func init() { proto.RegisterFile("celestia/upgrade/v1/tx.proto", fileDescriptor_ee2a0c754324bd13) } - -var fileDescriptor_ee2a0c754324bd13 = []byte{ - // 343 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x4a, 0x33, 0x31, - 0x14, 0xed, 0xf4, 0xfb, 0xa8, 0x18, 0x28, 0xd4, 0xd4, 0xea, 0x30, 0x96, 0xa1, 0x04, 0xc4, 0xa2, - 0x74, 0x42, 0xed, 0x13, 0xe8, 0x7e, 0x36, 0xf5, 0x07, 0x74, 0x23, 0x69, 0x27, 0xc4, 0xc0, 0x98, - 0x84, 0x24, 0x1d, 0xda, 0xa5, 0xe2, 0x03, 0x08, 0xbe, 0x94, 0xcb, 0x82, 0x1b, 0x97, 0xd2, 0xfa, - 0x20, 0x42, 0xe7, 0xc7, 0xb6, 0x28, 0xba, 0xbb, 0x37, 0xe7, 0xdc, 0x73, 0x4e, 0x2e, 0x17, 0x34, - 0x87, 0x34, 0xa6, 0xc6, 0x72, 0x82, 0x47, 0x8a, 0x69, 0x12, 0x51, 0x9c, 0x74, 0xb1, 0x1d, 0x07, - 0x4a, 0x4b, 0x2b, 0x61, 0x3d, 0x47, 0x83, 0x0c, 0x0d, 0x92, 0xae, 0xd7, 0x64, 0x52, 0xb2, 0x98, - 0x62, 0xa2, 0x38, 0x26, 0x42, 0x48, 0x4b, 0x2c, 0x97, 0xc2, 0xa4, 0x23, 0xe8, 0x0a, 0xd4, 0x42, - 0xc3, 0xce, 0x38, 0x13, 0x24, 0xbe, 0xa4, 0xda, 0x70, 0x29, 0xe0, 0x11, 0xd8, 0x4a, 0x48, 0xcc, - 0x23, 0x62, 0xa5, 0xbe, 0x21, 0x51, 0xa4, 0xa9, 0x31, 0xae, 0xd3, 0x72, 0xda, 0x9b, 0xfd, 0x5a, - 0x01, 0x9c, 0xa4, 0xef, 0xd0, 0x05, 0x1b, 0x49, 0x3a, 0xe7, 0x96, 0x5b, 0x4e, 0xfb, 0x7f, 0x3f, - 0x6f, 0x91, 0x07, 0xdc, 0x75, 0xe9, 0x3e, 0x35, 0x4a, 0x0a, 0x43, 0xd1, 0x01, 0xa8, 0x86, 0x86, - 0x9d, 0xeb, 0xc9, 0x45, 0x1a, 0x14, 0xee, 0x80, 0x8a, 0xe1, 0x4c, 0x50, 0x9d, 0x19, 0x65, 0x1d, - 0xda, 0x05, 0x8d, 0x15, 0x62, 0xae, 0x70, 0xfc, 0x58, 0x06, 0xff, 0x42, 0xc3, 0xe0, 0xbd, 0x03, - 0xaa, 0xab, 0xf1, 0xf7, 0x83, 0x6f, 0xd6, 0x10, 0xac, 0x47, 0xf1, 0x3a, 0x7f, 0xa2, 0x15, 0x89, - 0xbd, 0x87, 0xd7, 0x8f, 0xe7, 0xf2, 0x36, 0x82, 0xcb, 0x9b, 0x37, 0x0b, 0x2a, 0x9c, 0x00, 0xb0, - 0xf4, 0x15, 0xf4, 0x93, 0xf0, 0x17, 0xc7, 0x3b, 0xfc, 0x9d, 0x53, 0x38, 0xef, 0x2d, 0x9c, 0x1b, - 0xa8, 0xbe, 0xec, 0x9c, 0x95, 0xa7, 0xe1, 0xcb, 0xcc, 0x77, 0xa6, 0x33, 0xdf, 0x79, 0x9f, 0xf9, - 0xce, 0xd3, 0xdc, 0x2f, 0x4d, 0xe7, 0x7e, 0xe9, 0x6d, 0xee, 0x97, 0xae, 0x7b, 0x8c, 0xdb, 0xdb, - 0xd1, 0x20, 0x18, 0xca, 0x3b, 0x9c, 0x9b, 0x49, 0xcd, 0x8a, 0xba, 0x43, 0x94, 0xc2, 0xe3, 0x42, - 0xd3, 0x4e, 0x14, 0x35, 0x83, 0xca, 0xe2, 0x2a, 0x7a, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe5, - 0xec, 0x2f, 0xdc, 0x68, 0x02, 0x00, 0x00, + proto.RegisterType((*MsgSignalVersion)(nil), "celestia.signal.v1.MsgSignalVersion") + proto.RegisterType((*MsgSignalVersionResponse)(nil), "celestia.signal.v1.MsgSignalVersionResponse") + proto.RegisterType((*MsgTryUpgrade)(nil), "celestia.signal.v1.MsgTryUpgrade") + proto.RegisterType((*MsgTryUpgradeResponse)(nil), "celestia.signal.v1.MsgTryUpgradeResponse") +} + +func init() { proto.RegisterFile("celestia/signal/v1/tx.proto", fileDescriptor_815f2cc162e6e27e) } + +var fileDescriptor_815f2cc162e6e27e = []byte{ + // 345 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xcd, 0x4a, 0x3b, 0x31, + 0x10, 0x6f, 0xfa, 0xff, 0x53, 0x31, 0x50, 0xa8, 0xd1, 0xea, 0xb2, 0x95, 0xa5, 0x2e, 0x82, 0x15, + 0x75, 0x43, 0xeb, 0x13, 0xe8, 0xd9, 0x5e, 0xea, 0x07, 0xe8, 0x45, 0xd2, 0x6e, 0x88, 0x81, 0x75, + 0x13, 0x92, 0x74, 0x6d, 0x4f, 0x82, 0x4f, 0x20, 0xf8, 0x52, 0x1e, 0x0b, 0x5e, 0x3c, 0x4a, 0xeb, + 0x7b, 0x28, 0x6d, 0xba, 0x6b, 0x5b, 0x11, 0xbd, 0xcd, 0x64, 0x7e, 0x5f, 0x19, 0x06, 0x56, 0x3a, + 0x34, 0xa2, 0xda, 0x70, 0x82, 0x35, 0x67, 0x31, 0x89, 0x70, 0x52, 0xc7, 0xa6, 0x17, 0x48, 0x25, + 0x8c, 0x40, 0x28, 0x1d, 0x06, 0x76, 0x18, 0x24, 0x75, 0x77, 0x93, 0x09, 0xc1, 0x22, 0x8a, 0x89, + 0xe4, 0x98, 0xc4, 0xb1, 0x30, 0xc4, 0x70, 0x11, 0x6b, 0xcb, 0xf0, 0x2f, 0x61, 0xa9, 0xa9, 0xd9, + 0xe9, 0x04, 0x7d, 0x41, 0x95, 0xe6, 0x22, 0x46, 0x7b, 0x70, 0x25, 0x21, 0x11, 0x0f, 0x89, 0x11, + 0xea, 0x9a, 0x84, 0xa1, 0xa2, 0x5a, 0x3b, 0xa0, 0x0a, 0x6a, 0xcb, 0xad, 0x52, 0x36, 0x38, 0xb2, + 0xef, 0xc8, 0x81, 0x4b, 0x89, 0xe5, 0x39, 0xf9, 0x2a, 0xa8, 0xfd, 0x6f, 0xa5, 0xad, 0xef, 0x42, + 0x67, 0x51, 0xba, 0x45, 0xb5, 0x14, 0xb1, 0xa6, 0xfe, 0x0e, 0x2c, 0x36, 0x35, 0x3b, 0x53, 0xfd, + 0x73, 0xc9, 0x14, 0x09, 0x29, 0x5a, 0x87, 0x85, 0x71, 0x64, 0xaa, 0xa6, 0x46, 0xd3, 0xce, 0xdf, + 0x80, 0xe5, 0x39, 0x60, 0xaa, 0xd0, 0xf8, 0x00, 0xf0, 0x5f, 0x53, 0x33, 0x74, 0x0f, 0x8b, 0xf3, + 0xe9, 0xb7, 0x83, 0xef, 0x4b, 0x08, 0x16, 0x83, 0xb8, 0xfb, 0x7f, 0x41, 0x65, 0x71, 0xdd, 0x87, + 0x97, 0xf7, 0xa7, 0xfc, 0x9a, 0x8f, 0x70, 0xd7, 0xc6, 0x18, 0x6f, 0xdd, 0xf2, 0xd0, 0x1d, 0x84, + 0x33, 0xff, 0xd8, 0xfa, 0x41, 0xf7, 0x0b, 0xe2, 0xee, 0xfe, 0x0a, 0xc9, 0x7c, 0x2b, 0x13, 0xdf, + 0xb2, 0xbf, 0x3a, 0xeb, 0x3b, 0x2d, 0x8f, 0x4f, 0x9e, 0x87, 0x1e, 0x18, 0x0c, 0x3d, 0xf0, 0x36, + 0xf4, 0xc0, 0xe3, 0xc8, 0xcb, 0x0d, 0x46, 0x5e, 0xee, 0x75, 0xe4, 0xe5, 0xae, 0x1a, 0x8c, 0x9b, + 0x9b, 0x6e, 0x3b, 0xe8, 0x88, 0x5b, 0x9c, 0x7a, 0x09, 0xc5, 0xb2, 0xfa, 0x80, 0x48, 0x89, 0x7b, + 0xe9, 0x01, 0x99, 0xbe, 0xa4, 0xba, 0x5d, 0x98, 0xdc, 0xc3, 0xe1, 0x67, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x6d, 0xc4, 0x11, 0x43, 0x60, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -264,7 +264,7 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { func (c *msgClient) SignalVersion(ctx context.Context, in *MsgSignalVersion, opts ...grpc.CallOption) (*MsgSignalVersionResponse, error) { out := new(MsgSignalVersionResponse) - err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Msg/SignalVersion", in, out, opts...) + err := c.cc.Invoke(ctx, "/celestia.signal.v1.Msg/SignalVersion", in, out, opts...) if err != nil { return nil, err } @@ -273,7 +273,7 @@ func (c *msgClient) SignalVersion(ctx context.Context, in *MsgSignalVersion, opt func (c *msgClient) TryUpgrade(ctx context.Context, in *MsgTryUpgrade, opts ...grpc.CallOption) (*MsgTryUpgradeResponse, error) { out := new(MsgTryUpgradeResponse) - err := c.cc.Invoke(ctx, "/celestia.upgrade.v1.Msg/TryUpgrade", in, out, opts...) + err := c.cc.Invoke(ctx, "/celestia.signal.v1.Msg/TryUpgrade", in, out, opts...) if err != nil { return nil, err } @@ -314,7 +314,7 @@ func _Msg_SignalVersion_Handler(srv interface{}, ctx context.Context, dec func(i } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/celestia.upgrade.v1.Msg/SignalVersion", + FullMethod: "/celestia.signal.v1.Msg/SignalVersion", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).SignalVersion(ctx, req.(*MsgSignalVersion)) @@ -332,7 +332,7 @@ func _Msg_TryUpgrade_Handler(srv interface{}, ctx context.Context, dec func(inte } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/celestia.upgrade.v1.Msg/TryUpgrade", + FullMethod: "/celestia.signal.v1.Msg/TryUpgrade", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(MsgServer).TryUpgrade(ctx, req.(*MsgTryUpgrade)) @@ -341,7 +341,7 @@ func _Msg_TryUpgrade_Handler(srv interface{}, ctx context.Context, dec func(inte } var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "celestia.upgrade.v1.Msg", + ServiceName: "celestia.signal.v1.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ { @@ -354,7 +354,7 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "celestia/upgrade/v1/tx.proto", + Metadata: "celestia/signal/v1/tx.proto", } func (m *MsgSignalVersion) Marshal() (dAtA []byte, err error) { diff --git a/x/upgrade/types/tx.pb.gw.go b/x/signal/types/tx.pb.gw.go similarity index 99% rename from x/upgrade/types/tx.pb.gw.go rename to x/signal/types/tx.pb.gw.go index 463c324c64..42461c7c16 100644 --- a/x/upgrade/types/tx.pb.gw.go +++ b/x/signal/types/tx.pb.gw.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: celestia/upgrade/v1/tx.proto +// source: celestia/signal/v1/tx.proto /* Package types is a reverse proxy. diff --git a/x/upgrade/ibc.go b/x/upgrade/ibc.go deleted file mode 100644 index 8b083821e9..0000000000 --- a/x/upgrade/ibc.go +++ /dev/null @@ -1,75 +0,0 @@ -package upgrade - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" - ibctypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" -) - -// We need compatibility with the way that IBC uses the upgrade module. This file -// ensures that we comply to the interface that IBC expects. -var _ ibctypes.UpgradeKeeper = (*Keeper)(nil) - -// ScheduleUpgrade implements the IBC upgrade keeper interface. This is a noop as -// no other process is allowed to schedule an upgrade but the upgrade keeper itself. -// This is kept around to support the interface. -func (k Keeper) ScheduleUpgrade(_ sdk.Context, _ types.Plan) error { - return nil -} - -// GetUpgradePlan implements the IBC upgrade keeper interface. This is used in BeginBlock -// to know when to write the upgraded consensus state. The IBC module needs to sign over -// the next consensus state to ensure a smooth transition for counterparty chains. This -// is implemented as a noop. Any IBC breaking change would be invoked by this upgrade module -// in end blocker. -func (k Keeper) GetUpgradePlan(_ sdk.Context) (plan types.Plan, havePlan bool) { - return types.Plan{}, false -} - -// SetUpgradedClient sets the expected upgraded client for the next version of -// this chain at the last height the current chain will commit. -func (k Keeper) SetUpgradedClient(ctx sdk.Context, planHeight int64, bz []byte) error { - store := ctx.KVStore(k.storeKey) - store.Set(types.UpgradedClientKey(planHeight), bz) - return nil -} - -// GetUpgradedClient gets the expected upgraded client for the next version of -// this chain. -func (k Keeper) GetUpgradedClient(ctx sdk.Context, height int64) ([]byte, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UpgradedClientKey(height)) - if len(bz) == 0 { - return nil, false - } - - return bz, true -} - -// SetUpgradedConsensusState sets the expected upgraded consensus state for the -// next version of this chain using the last height committed on this chain. -func (k Keeper) SetUpgradedConsensusState(ctx sdk.Context, planHeight int64, bz []byte) error { - store := ctx.KVStore(k.storeKey) - store.Set(types.UpgradedConsStateKey(planHeight), bz) - return nil -} - -// GetUpgradedConsensusState gets the expected upgraded consensus state for the -// next version of this chain. -func (k Keeper) GetUpgradedConsensusState(ctx sdk.Context, lastHeight int64) ([]byte, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UpgradedConsStateKey(lastHeight)) - if len(bz) == 0 { - return nil, false - } - - return bz, true -} - -// ClearIBCState clears any planned IBC state. -func (k Keeper) ClearIBCState(ctx sdk.Context, lastHeight int64) { - // delete IBC client and consensus state from store if this is IBC plan - store := ctx.KVStore(k.storeKey) - store.Delete(types.UpgradedClientKey(lastHeight)) - store.Delete(types.UpgradedConsStateKey(lastHeight)) -} diff --git a/x/upgrade/keeper_test.go b/x/upgrade/keeper_test.go deleted file mode 100644 index 44964e950b..0000000000 --- a/x/upgrade/keeper_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package upgrade_test - -import ( - "fmt" - "math" - "math/big" - "testing" - - sdkmath "cosmossdk.io/math" - "github.com/celestiaorg/celestia-app/v2/x/upgrade" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" -) - -func TestGetVotingPowerThreshold(t *testing.T) { - bigInt := big.NewInt(0) - bigInt.SetString("23058430092136939509", 10) - - type testCase struct { - name string - validators map[string]int64 - want sdkmath.Int - } - testCases := []testCase{ - { - name: "empty validators", - validators: map[string]int64{}, - want: sdkmath.NewInt(0), - }, - { - name: "one validator with 6 power returns 5 because the defaultSignalThreshold is 5/6", - validators: map[string]int64{"a": 6}, - want: sdkmath.NewInt(5), - }, - { - name: "one validator with 11 power (11 * 5/6 = 9.16666667) so should round up to 10", - validators: map[string]int64{"a": 11}, - want: sdkmath.NewInt(10), - }, - { - name: "one validator with voting power of math.MaxInt64", - validators: map[string]int64{"a": math.MaxInt64}, - want: sdkmath.NewInt(7686143364045646503), - }, - { - name: "multiple validators with voting power of math.MaxInt64", - validators: map[string]int64{"a": math.MaxInt64, "b": math.MaxInt64, "c": math.MaxInt64}, - want: sdkmath.NewIntFromBigInt(bigInt), - }, - } - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - stakingKeeper := newMockStakingKeeper(tc.validators) - k := upgrade.NewKeeper(nil, stakingKeeper) - got := k.GetVotingPowerThreshold(sdk.Context{}) - assert.Equal(t, tc.want, got, fmt.Sprintf("want %v, got %v", tc.want.String(), got.String())) - }) - } -} diff --git a/x/upgrade/upgrade_test.go b/x/upgrade/upgrade_test.go deleted file mode 100644 index c12bb82a30..0000000000 --- a/x/upgrade/upgrade_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package upgrade_test - -import ( - "encoding/json" - "testing" - "time" - - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" - v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" - "github.com/celestiaorg/celestia-app/v2/test/util" - "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" - dbm "github.com/tendermint/tm-db" -) - -func TestUpgradeAppVersion(t *testing.T) { - testApp, _ := setupTestApp(t, 3) - - supportedVersions := []uint64{v1.Version, v2.Version} - - require.Equal(t, supportedVersions, testApp.SupportedVersions()) - - testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ - Height: 2, - Version: tmversion.Consensus{App: 1}, - }}) - // app version should not have changed yet - require.EqualValues(t, 1, testApp.AppVersion()) - respEndBlock := testApp.EndBlock(abci.RequestEndBlock{Height: 2}) - // now the app version changes - require.NotNil(t, respEndBlock.ConsensusParamUpdates.Version) - require.EqualValues(t, 2, respEndBlock.ConsensusParamUpdates.Version.AppVersion) - require.EqualValues(t, 2, testApp.AppVersion()) -} - -func setupTestApp(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) { - t.Helper() - - db := dbm.NewMemDB() - chainID := "test_chain" - encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) - - genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account") - - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) - infoResp := testApp.Info(abci.RequestInfo{}) - require.EqualValues(t, 0, infoResp.AppVersion) - - cp := app.DefaultInitialConsensusParams() - abciParams := &abci.ConsensusParams{ - Block: &abci.BlockParams{ - MaxBytes: cp.Block.MaxBytes, - MaxGas: cp.Block.MaxGas, - }, - Evidence: &cp.Evidence, - Validator: &cp.Validator, - Version: &cp.Version, - } - - _ = testApp.InitChain( - abci.RequestInitChain{ - Time: time.Now(), - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: abciParams, - AppStateBytes: stateBytes, - ChainId: chainID, - }, - ) - - // assert that the chain starts with version provided in genesis - infoResp = testApp.Info(abci.RequestInfo{}) - require.EqualValues(t, app.DefaultInitialConsensusParams().Version.AppVersion, infoResp.AppVersion) - - _ = testApp.Commit() - return testApp, kr -} From 7822fb275aaf570fbd96d98a321c59054eaba493 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 10 Apr 2024 11:02:56 +0200 Subject: [PATCH 2/9] lint --- x/signal/keeper.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/signal/keeper.go b/x/signal/keeper.go index 36bb88cea2..5f79c89d58 100644 --- a/x/signal/keeper.go +++ b/x/signal/keeper.go @@ -20,12 +20,12 @@ var ( defaultSignalThreshold = sdk.NewDec(5).Quo(sdk.NewDec(6)) ) -// SignalThreshold is the fraction of voting power that is required +// Threshold is the fraction of voting power that is required // to signal for a version change. It is set to 5/6 as the middle point // between 2/3 and 3/3 providing 1/6 fault tolerance to halting the // network during an upgrade period. It can be modified through a // hard fork change that modified the app version -func SignalThreshold(_ uint64) sdk.Dec { +func Threshold(_ uint64) sdk.Dec { return defaultSignalThreshold } @@ -169,7 +169,7 @@ func (k Keeper) TallyVotingPower(ctx sdk.Context, threshold int64) (bool, uint64 // upgrade to a new version. func (k Keeper) GetVotingPowerThreshold(ctx sdk.Context) sdkmath.Int { totalVotingPower := k.stakingKeeper.GetLastTotalPower(ctx) - thresholdFraction := SignalThreshold(ctx.BlockHeader().Version.App) + thresholdFraction := Threshold(ctx.BlockHeader().Version.App) return thresholdFraction.MulInt(totalVotingPower).Ceil().TruncateInt() } From 18df55f777c44cbe28f3f268d79b5d9fad0c216f Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 15 Apr 2024 16:46:54 +0200 Subject: [PATCH 3/9] modify migration pattern to initialize and delete commit stores --- app/app.go | 224 +++++++++++++----- app/app_test.go | 3 +- app/module/module.go | 1 + app/test/ica_upgrade_test.go | 54 +---- app/test/upgrade_test.go | 3 +- cmd/celestia-appd/cmd/root.go | 6 +- go.mod | 2 +- go.sum | 2 - .../packetforward_upgrade_test.go | 50 +--- test/tokenfilter/setup.go | 2 +- test/util/malicious/app.go | 3 +- test/util/malicious/test_app.go | 2 +- test/util/test_app.go | 51 +++- x/minfee/upgrade_test.go | 2 +- 14 files changed, 226 insertions(+), 179 deletions(-) diff --git a/app/app.go b/app/app.go index d22ac03f97..587613a4c5 100644 --- a/app/app.go +++ b/app/app.go @@ -1,6 +1,7 @@ package app import ( + "fmt" "io" "github.com/celestiaorg/celestia-app/v2/app/module" @@ -181,29 +182,31 @@ type App struct { invCheckPeriod uint // keys to access the substores - keys map[string]*storetypes.KVStoreKey - tkeys map[string]*storetypes.TransientStoreKey - memKeys map[string]*storetypes.MemoryStoreKey + keyVersions map[uint64][]string + keys map[string]*storetypes.KVStoreKey + tkeys map[string]*storetypes.TransientStoreKey + memKeys map[string]*storetypes.MemoryStoreKey // keepers - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - AuthzKeeper authzkeeper.Keeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper // This is included purely for the IBC Keeper. It is not used for upgrading - SignalKeeper signal.Keeper - ParamsKeeper paramskeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBCKeeper must be a pointer in the app, so we can SetRouter on it correctly - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - ICAHostKeeper icahostkeeper.Keeper + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper // This is included purely for the IBC Keeper. It is not used for upgrading + SignalKeeper signal.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBCKeeper must be a pointer in the app, so we can SetRouter on it correctly + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + ICAHostKeeper icahostkeeper.Keeper + PacketForwardKeeper *packetforwardkeeper.Keeper ScopedIBCKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes ScopedTransferKeeper capabilitykeeper.ScopedKeeper // This keeper is public for test purposes @@ -218,8 +221,6 @@ type App struct { upgradeHeight int64 // used to define what messages are accepted for a given app version MsgGateKeeper *ante.MsgVersioningGateKeeper - - PacketForwardKeeper *packetforwardkeeper.Keeper } // New returns a reference to an initialized celestia app. @@ -231,7 +232,6 @@ func New( logger log.Logger, db dbm.DB, traceStore io.Writer, - loadLatest bool, invCheckPeriod uint, encodingConfig encoding.Config, upgradeHeight int64, @@ -247,18 +247,7 @@ func New( bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(interfaceRegistry) - keys := sdk.NewKVStoreKeys( - authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, capabilitytypes.StoreKey, - blobstreamtypes.StoreKey, - ibctransfertypes.StoreKey, - ibchost.StoreKey, - packetforwardtypes.StoreKey, - icahosttypes.StoreKey, - signaltypes.StoreKey, - ) + keys := sdk.NewKVStoreKeys(allStoreKeys()...) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -268,6 +257,7 @@ func New( interfaceRegistry: interfaceRegistry, txConfig: encodingConfig.TxConfig, invCheckPeriod: invCheckPeriod, + keyVersions: versionedStoreKeys(), keys: keys, tkeys: tkeys, memKeys: memKeys, @@ -639,8 +629,9 @@ func New( app.MsgGateKeeper = ante.NewMsgVersioningGateKeeper(app.configurator.GetAcceptedMessages()) app.MsgServiceRouter().SetCircuit(app.MsgGateKeeper) - // initialize stores - app.MountKVStores(keys) + // We only initialize the base stores that will be part of every version i.e. params + // (which contain the app version) + app.MountKVStores(app.baseKeys()) app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) @@ -661,10 +652,13 @@ func New( )) app.SetPostHandler(posthandler.New()) - if loadLatest { - if err := app.LoadLatestVersion(); err != nil { - tmos.Exit(err.Error()) - } + app.SetMigrateStoreFn(app.migrateCommitStore) + app.SetMigrateModuleFn(app.migrateModules) + + // we don't seal the store until the app version has been initailised + // this will just initialize the base keys (i.e. the param store) + if err := app.CommitMultiStore().LoadLatestVersion(); err != nil { + tmos.Exit(err.Error()) } return app @@ -686,41 +680,68 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo if currentVersion == v1 { // check that we are at the height before the upgrade if req.Height == app.upgradeHeight-1 { - if err := app.Upgrade(ctx, currentVersion, currentVersion+1); err != nil { - panic(err) - } + app.SetInitialAppVersionInConsensusParams(ctx, v2) + app.SetAppVersion(ctx, v2) } // from v2 to v3 and onwards we use a signalling mechanism } else if shouldUpgrade, newVersion := app.SignalKeeper.ShouldUpgrade(); shouldUpgrade { // Version changes must be increasing. Downgrades are not permitted if newVersion > currentVersion { - if err := app.Upgrade(ctx, currentVersion, newVersion); err != nil { - panic(err) - } + app.SetAppVersion(ctx, newVersion) } } return res } -func (app *App) Upgrade(ctx sdk.Context, fromVersion, toVersion uint64) error { - if err := app.mm.RunMigrations(ctx, app.configurator, fromVersion, toVersion); err != nil { - return err +func (app *App) migrateCommitStore(fromVersion, toVersion uint64) (baseapp.StoreMigrations, error) { + oldStoreKeys := app.keyVersions[fromVersion] + newStoreKeys := app.keyVersions[toVersion] + newMap := make(map[string]bool) + output := baseapp.StoreMigrations{ + Added: make(map[string]*storetypes.KVStoreKey), + Deleted: make(map[string]*storetypes.KVStoreKey), } - if toVersion == v2 { - // we need to set the app version in the param store for the first time - app.SetInitialAppVersionInConsensusParams(ctx, toVersion) + for _, storeKey := range newStoreKeys { + newMap[storeKey] = false } - app.SetAppVersion(ctx, toVersion) - return nil + for _, storeKey := range oldStoreKeys { + if _, ok := newMap[storeKey]; !ok { + output.Deleted[storeKey] = app.keys[storeKey] + } else { + // this module exists in both the old and new modules + newMap[storeKey] = true + } + } + for storeKey, existsInOldModule := range newMap { + if !existsInOldModule { + output.Added[storeKey] = app.keys[storeKey] + } + } + return output, nil } -// InitChainer application update at chain initialization -func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - var genesisState GenesisState - if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { - panic(err) +func (app *App) migrateModules(ctx sdk.Context, fromVersion, toVersion uint64) error { + return app.mm.RunMigrations(ctx, app.configurator, fromVersion, toVersion) +} + +// We wrap Info around baseapp so we can take the app version and +// setup the multicommit store. +func (app *App) Info(req abci.RequestInfo) abci.ResponseInfo { + resp := app.BaseApp.Info(req) + // mount the stores for the provided app version + if resp.AppVersion > 0 && !app.IsSealed() { + app.MountKVStores(app.versionedKeys(resp.AppVersion)) + if err := app.LoadLatestVersion(); err != nil { + panic(fmt.Sprintf("loading latest version: %s", err.Error())) + } } - // genesis must always contain the consensus params. The validator set howerver is derived from the + return resp +} + +// We wrap InitChain around baseapp so we can take the app version and +// setup the multicommit store. +func (app *App) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { + // genesis must always contain the consensus params. The validator set however is derived from the // initial genesis state. The genesis must always contain a non zero app version which is the initial // version that the chain starts on if req.ConsensusParams == nil || req.ConsensusParams.Version == nil { @@ -729,6 +750,25 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res if req.ConsensusParams.Version.AppVersion == 0 { panic("app version 0 is not accepted. Please set an app version in the genesis") } + + // mount the stores for the provided app version if it has not already been mounted + if app.AppVersion() == 0 && !app.IsSealed() { + app.MountKVStores(app.versionedKeys(req.ConsensusParams.Version.AppVersion)) + if err := app.LoadLatestVersion(); err != nil { + panic(fmt.Sprintf("loading latest version: %s", err.Error())) + } + } + + return app.BaseApp.InitChain(req) +} + +// InitChainer application update at chain initialization +func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { + var genesisState GenesisState + if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil { + panic(err) + } + return app.mm.InitGenesis(ctx, app.appCodec, genesisState, req.ConsensusParams.Version.AppVersion) } @@ -743,6 +783,28 @@ func (app *App) SupportedVersions() []uint64 { return app.mm.SupportedVersions() } +// versionedKeys returns the keys for the kv stores for a given app version +func (app *App) versionedKeys(appVersion uint64) map[string]*storetypes.KVStoreKey { + output := make(map[string]*storetypes.KVStoreKey) + if keys, exists := app.keyVersions[appVersion]; exists { + for _, moduleName := range keys { + if key, exists := app.keys[moduleName]; exists { + output[moduleName] = key + } + } + } + return output +} + +// baseKeys returns the base keys that are mounted to every version +func (app *App) baseKeys() map[string]*storetypes.KVStoreKey { + return map[string]*storetypes.KVStoreKey{ + // we need to know the app version to know what stores to mount + // thus the paramstore must always be a store that is mounted + paramstypes.StoreKey: app.keys[paramstypes.StoreKey], + } +} + // ModuleAccountAddrs returns all the app's module account addresses. func (app *App) ModuleAccountAddrs() map[string]bool { modAccAddrs := make(map[string]bool) @@ -911,3 +973,41 @@ func extractRegisters(m sdkmodule.BasicManager, soloRegisters ...encoding.Module } return s } + +func allStoreKeys() []string { + return []string{ + authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, capabilitytypes.StoreKey, + blobstreamtypes.StoreKey, + ibctransfertypes.StoreKey, + ibchost.StoreKey, + packetforwardtypes.StoreKey, + icahosttypes.StoreKey, + signaltypes.StoreKey, + } +} + +// versionedStoreKeys returns the store keys for each app version +// ... I wish there was an easier way than this (like using the modules which are already versioned) +func versionedStoreKeys() map[uint64][]string { + return map[uint64][]string{ + 1: { + authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, capabilitytypes.StoreKey, + blobstreamtypes.StoreKey, ibctransfertypes.StoreKey, ibchost.StoreKey, + blobtypes.StoreKey, + }, + 2: { + authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, capabilitytypes.StoreKey, + blobstreamtypes.StoreKey, ibctransfertypes.StoreKey, ibchost.StoreKey, + packetforwardtypes.StoreKey, icahosttypes.StoreKey, signaltypes.StoreKey, + }, + } +} diff --git a/app/app_test.go b/app/app_test.go index 10fae52405..b83a0f9c68 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -14,13 +14,12 @@ func TestNew(t *testing.T) { logger := log.NewNopLogger() db := tmdb.NewMemDB() traceStore := &NoopWriter{} - loadLatest := true invCheckPeriod := uint(1) encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...) upgradeHeight := int64(0) appOptions := NoopAppOptions{} - got := app.New(logger, db, traceStore, loadLatest, invCheckPeriod, encodingConfig, upgradeHeight, appOptions) + got := app.New(logger, db, traceStore, invCheckPeriod, encodingConfig, upgradeHeight, appOptions) t.Run("initializes ICAHostKeeper", func(t *testing.T) { assert.NotNil(t, got.ICAHostKeeper) diff --git a/app/module/module.go b/app/module/module.go index ce782e7728..6e457bbf42 100644 --- a/app/module/module.go +++ b/app/module/module.go @@ -351,6 +351,7 @@ func (m *Manager) ModuleNames(version uint64) []string { return ms } +// SupportedVersions returns all the supported versions for the module manager func (m *Manager) SupportedVersions() []uint64 { output := make([]uint64, 0, m.lastVersion-m.firstVersion+1) for version := m.firstVersion; version <= m.lastVersion; version++ { diff --git a/app/test/ica_upgrade_test.go b/app/test/ica_upgrade_test.go index 5a1fc8e022..6a86ba42b1 100644 --- a/app/test/ica_upgrade_test.go +++ b/app/test/ica_upgrade_test.go @@ -1,30 +1,21 @@ package app_test import ( - "encoding/json" "testing" - "time" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" - v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" - v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/v2/test/util" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" version "github.com/tendermint/tendermint/proto/tendermint/version" - dbm "github.com/tendermint/tm-db" ) // TestICA verifies that the ICA module's params are overridden during an // upgrade from v1 -> v2. func TestICA(t *testing.T) { - testApp, _ := setupTestApp(t, 3) + testApp, _ := util.SetupTestAppWithUpgradeHeight(t, 3) ctx := testApp.NewContext(true, tmproto.Header{ Version: version.Consensus{ App: 1, @@ -57,46 +48,3 @@ func TestICA(t *testing.T) { require.NoError(t, err) require.Equal(t, "true", got.Param.Value) } - -func setupTestApp(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) { - t.Helper() - - db := dbm.NewMemDB() - chainID := "test_chain" - encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) - genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account") - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) - infoResp := testApp.Info(abci.RequestInfo{}) - require.EqualValues(t, 0, infoResp.AppVersion) - cp := app.DefaultInitialConsensusParams() - abciParams := &abci.ConsensusParams{ - Block: &abci.BlockParams{ - MaxBytes: cp.Block.MaxBytes, - MaxGas: cp.Block.MaxGas, - }, - Evidence: &cp.Evidence, - Validator: &cp.Validator, - Version: &cp.Version, - } - - _ = testApp.InitChain( - abci.RequestInitChain{ - Time: time.Now(), - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: abciParams, - AppStateBytes: stateBytes, - ChainId: chainID, - }, - ) - - // assert that the chain starts with version provided in genesis - infoResp = testApp.Info(abci.RequestInfo{}) - require.EqualValues(t, app.DefaultInitialConsensusParams().Version.AppVersion, infoResp.AppVersion) - - _ = testApp.Commit() - supportedVersions := []uint64{v1.Version, v2.Version} - require.Equal(t, supportedVersions, testApp.SupportedVersions()) - return testApp, kr -} diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index 4cea521252..441586c9ad 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -5,6 +5,7 @@ import ( v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" + "github.com/celestiaorg/celestia-app/v2/test/util" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -12,7 +13,7 @@ import ( ) func TestUpgradeAppVersion(t *testing.T) { - testApp, _ := setupTestApp(t, 3) + testApp, _ := util.SetupTestAppWithUpgradeHeight(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} diff --git a/cmd/celestia-appd/cmd/root.go b/cmd/celestia-appd/cmd/root.go index 533724c7d2..96a6044ebc 100644 --- a/cmd/celestia-appd/cmd/root.go +++ b/cmd/celestia-appd/cmd/root.go @@ -237,7 +237,7 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts se } return app.New( - logger, db, traceStore, true, + logger, db, traceStore, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encoding.MakeConfig(app.ModuleEncodingRegisters...), // Ideally, we would reuse the one created by NewRootCmd. cast.ToInt64(appOpts.Get(UpgradeHeightFlag)), @@ -263,13 +263,13 @@ func createAppAndExport( encCfg.Codec = codec.NewProtoCodec(encCfg.InterfaceRegistry) var capp *app.App if height != -1 { - capp = app.New(logger, db, traceStore, false, uint(1), encCfg, 0, appOpts) + capp = app.New(logger, db, traceStore, uint(1), encCfg, 0, appOpts) if err := capp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - capp = app.New(logger, db, traceStore, true, uint(1), encCfg, 0, appOpts) + capp = app.New(logger, db, traceStore, uint(1), encCfg, 0, appOpts) } return capp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) diff --git a/go.mod b/go.mod index 27a6a27512..9a3aa036a2 100644 --- a/go.mod +++ b/go.mod @@ -253,7 +253,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.20.2-sdk-v0.46.16 + github.com/cosmos/cosmos-sdk => /Users/callum/Developer/go/src/github.com/celestiaorg/cosmos-sdk // Pin to ledger-cosmos-go v0.12.4 to avoid a breaking change introduced in v0.13.0 // The following replace statement can be removed when we upgrade to cosmos-sdk >= v0.50.0 github.com/cosmos/ledger-cosmos-go => github.com/cosmos/ledger-cosmos-go v0.12.4 diff --git a/go.sum b/go.sum index ff8b96224a..3c2c9ba83c 100644 --- a/go.sum +++ b/go.sum @@ -326,8 +326,6 @@ github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZI github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= github.com/celestiaorg/celestia-core v1.35.0-tm-v0.34.29 h1:sXERzNXgyHyqTKNQx4S29C/NMDzgav62DaQDNF49HUQ= github.com/celestiaorg/celestia-core v1.35.0-tm-v0.34.29/go.mod h1:weZR4wYx1Vcw3g1Jc5G8VipG4M+KUDSqeIzyyWszmsQ= -github.com/celestiaorg/cosmos-sdk v1.20.2-sdk-v0.46.16 h1:EmzwDx64oG8eKZPar50VCkpzxDNqjjtt7rOBJsMQY8E= -github.com/celestiaorg/cosmos-sdk v1.20.2-sdk-v0.46.16/go.mod h1:AmuR63HTlX8vNV3+NGWNPIZa95J1UweTUmWDHSdTGj0= github.com/celestiaorg/go-square v1.0.1 h1:LEG1zrw4i03VBMElQF8GAbKYgh1bT1uGzWxasU2ePuo= github.com/celestiaorg/go-square v1.0.1/go.mod h1:XMv5SGCeGSkynW2OOsedugaW/rQlvzxGzWGxTKsyYOU= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= diff --git a/test/packetforward/packetforward_upgrade_test.go b/test/packetforward/packetforward_upgrade_test.go index a9972a515e..b6c16f95d1 100644 --- a/test/packetforward/packetforward_upgrade_test.go +++ b/test/packetforward/packetforward_upgrade_test.go @@ -1,31 +1,24 @@ package packetforward_test import ( - "encoding/json" "strings" "testing" - "time" - "github.com/celestiaorg/celestia-app/v2/app" - "github.com/celestiaorg/celestia-app/v2/app/encoding" v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/v2/test/util" - "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/x/params/types/proposal" packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/router/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" version "github.com/tendermint/tendermint/proto/tendermint/version" - dbm "github.com/tendermint/tm-db" ) // TestPacketForwardMiddlewareAgainstAppUpgrades verifies that the PFM module's params are overridden during an // upgrade from v1 -> v2. func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { - testApp, _ := setupTestApp(t, 3) + testApp, _ := util.SetupTestAppWithUpgradeHeight(t, 3) supportedVersions := []uint64{v1.Version, v2.Version} require.Equal(t, supportedVersions, testApp.SupportedVersions()) @@ -74,44 +67,3 @@ func TestPacketForwardMiddlewareAgainstAppUpgrades(t *testing.T) { require.NoError(t, err) require.Equal(t, "0.000000000000000000", strings.Trim(got.Param.Value, "\"")) } - -func setupTestApp(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) { - t.Helper() - - db := dbm.NewMemDB() - chainID := "test_chain" - encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) - genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account") - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) - infoResp := testApp.Info(abci.RequestInfo{}) - require.EqualValues(t, 0, infoResp.AppVersion) - cp := app.DefaultInitialConsensusParams() - abciParams := &abci.ConsensusParams{ - Block: &abci.BlockParams{ - MaxBytes: cp.Block.MaxBytes, - MaxGas: cp.Block.MaxGas, - }, - Evidence: &cp.Evidence, - Validator: &cp.Validator, - Version: &cp.Version, - } - - _ = testApp.InitChain( - abci.RequestInitChain{ - Time: time.Now(), - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: abciParams, - AppStateBytes: stateBytes, - ChainId: chainID, - }, - ) - - // assert that the chain starts with version provided in genesis - infoResp = testApp.Info(abci.RequestInfo{}) - require.EqualValues(t, app.DefaultInitialConsensusParams().Version.AppVersion, infoResp.AppVersion) - - _ = testApp.Commit() - return testApp, kr -} diff --git a/test/tokenfilter/setup.go b/test/tokenfilter/setup.go index a900004262..aea94a1fc6 100644 --- a/test/tokenfilter/setup.go +++ b/test/tokenfilter/setup.go @@ -146,7 +146,7 @@ func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs encCdc := encoding.MakeConfig(app.ModuleEncodingRegisters...) genesisState := app.NewDefaultGenesisState(encCdc.Codec) app := app.New( - log.NewNopLogger(), db, nil, true, 5, encCdc, 0, simapp.EmptyAppOptions{}, + log.NewNopLogger(), db, nil, 5, encCdc, 0, simapp.EmptyAppOptions{}, ) // set genesis accounts diff --git a/test/util/malicious/app.go b/test/util/malicious/app.go index fdd0263abc..9212e966d7 100644 --- a/test/util/malicious/app.go +++ b/test/util/malicious/app.go @@ -51,13 +51,12 @@ func New( logger log.Logger, db dbm.DB, traceStore io.Writer, - loadLatest bool, invCheckPeriod uint, encodingConfig encoding.Config, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { - goodApp := app.New(logger, db, traceStore, loadLatest, invCheckPeriod, encodingConfig, 0, appOpts, baseAppOptions...) + goodApp := app.New(logger, db, traceStore, invCheckPeriod, encodingConfig, 0, appOpts, baseAppOptions...) badApp := &App{App: goodApp} // set the malicious prepare proposal handler if it is set in the app options diff --git a/test/util/malicious/test_app.go b/test/util/malicious/test_app.go index 24b3f652c5..35943f611f 100644 --- a/test/util/malicious/test_app.go +++ b/test/util/malicious/test_app.go @@ -77,7 +77,7 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts se } return New( - logger, db, traceStore, true, + logger, db, traceStore, cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), encoding.MakeConfig(app.ModuleEncodingRegisters...), // Ideally, we would reuse the one created by NewRootCmd. appOpts, diff --git a/test/util/test_app.go b/test/util/test_app.go index 59b7f3cb26..765b53d326 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -3,11 +3,14 @@ package util import ( "encoding/json" "fmt" + "testing" "time" "github.com/celestiaorg/celestia-app/v2/app" "github.com/celestiaorg/celestia-app/v2/app/encoding" "github.com/celestiaorg/celestia-app/v2/pkg/appconsts" + v1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" + v2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/v2/test/util/testfactory" "github.com/celestiaorg/celestia-app/v2/test/util/testnode" "github.com/cosmos/cosmos-sdk/codec" @@ -22,6 +25,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/spf13/cast" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -79,7 +83,7 @@ func NewTestAppWithGenesisSet(cparams *tmproto.ConsensusParams, genAccounts ...s encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) testApp := app.New( - log.NewNopLogger(), db, nil, true, + log.NewNopLogger(), db, nil, cast.ToUint(emptyOpts.Get(server.FlagInvCheckPeriod)), encCfg, 0, @@ -107,6 +111,8 @@ func NewTestAppWithGenesisSet(cparams *tmproto.ConsensusParams, genAccounts ...s genesisTime := time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC).UTC() + _ = testApp.Info(abci.RequestInfo{}) + // init chain will set the validator set and initialize the genesis accounts testApp.InitChain( abci.RequestInitChain{ @@ -293,3 +299,46 @@ func genesisStateWithValSet( func NewDefaultGenesisState(cdc codec.JSONCodec) app.GenesisState { return app.ModuleBasics.DefaultGenesis(cdc) } + +func SetupTestAppWithUpgradeHeight(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) { + t.Helper() + + db := dbm.NewMemDB() + chainID := "test_chain" + encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) + testApp := app.New(log.NewNopLogger(), db, nil, 0, encCfg, upgradeHeight, EmptyAppOptions{}) + genesisState, _, kr := GenesisStateWithSingleValidator(testApp, "account") + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + infoResp := testApp.Info(abci.RequestInfo{}) + require.EqualValues(t, 0, infoResp.AppVersion) + cp := app.DefaultInitialConsensusParams() + abciParams := &abci.ConsensusParams{ + Block: &abci.BlockParams{ + MaxBytes: cp.Block.MaxBytes, + MaxGas: cp.Block.MaxGas, + }, + Evidence: &cp.Evidence, + Validator: &cp.Validator, + Version: &cp.Version, + } + + _ = testApp.InitChain( + abci.RequestInitChain{ + Time: time.Now(), + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: abciParams, + AppStateBytes: stateBytes, + ChainId: chainID, + }, + ) + + // assert that the chain starts with version provided in genesis + infoResp = testApp.Info(abci.RequestInfo{}) + require.EqualValues(t, app.DefaultInitialConsensusParams().Version.AppVersion, infoResp.AppVersion) + + _ = testApp.Commit() + supportedVersions := []uint64{v1.Version, v2.Version} + require.Equal(t, supportedVersions, testApp.SupportedVersions()) + return testApp, kr +} diff --git a/x/minfee/upgrade_test.go b/x/minfee/upgrade_test.go index 7ce3566fdb..3fb5c02c84 100644 --- a/x/minfee/upgrade_test.go +++ b/x/minfee/upgrade_test.go @@ -89,7 +89,7 @@ func setupTestApp(t *testing.T, upgradeHeight int64) (*app.App, keyring.Keyring) db := dbm.NewMemDB() chainID := "test_chain" encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) - testApp := app.New(log.NewNopLogger(), db, nil, true, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) + testApp := app.New(log.NewNopLogger(), db, nil, 0, encCfg, upgradeHeight, util.EmptyAppOptions{}) genesisState, _, kr := util.GenesisStateWithSingleValidator(testApp, "account") From 7f71a8f490e5234b13b28264d472305ea7e3de21 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Mon, 15 Apr 2024 19:45:36 +0200 Subject: [PATCH 4/9] set the module version map in the upgrade keeper --- app/app.go | 2 ++ app/module/module.go | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/app.go b/app/app.go index 587613a4c5..00a5c8c68d 100644 --- a/app/app.go +++ b/app/app.go @@ -769,6 +769,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res panic(err) } + app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap(req.ConsensusParams.Version.AppVersion)) return app.mm.InitGenesis(ctx, app.appCodec, genesisState, req.ConsensusParams.Version.AppVersion) } @@ -986,6 +987,7 @@ func allStoreKeys() []string { packetforwardtypes.StoreKey, icahosttypes.StoreKey, signaltypes.StoreKey, + blobtypes.StoreKey, } } diff --git a/app/module/module.go b/app/module/module.go index 6e457bbf42..506d622c08 100644 --- a/app/module/module.go +++ b/app/module/module.go @@ -223,9 +223,6 @@ func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames [] // MigrationHandler is the migration function that each module registers. type MigrationHandler func(sdk.Context) error -// VersionMap is a map of moduleName -> version -type VersionMap map[string]uint64 - // RunMigrations performs in-place store migrations for all modules. This // function MUST be called when the state machine changes appVersion func (m Manager) RunMigrations(ctx sdk.Context, cfg sdkmodule.Configurator, fromVersion, toVersion uint64) error { @@ -335,6 +332,22 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo } } +// GetVersionMap gets consensus version from all modules +func (m *Manager) GetVersionMap(version uint64) sdkmodule.VersionMap { + vermap := make(sdkmodule.VersionMap) + if version > m.lastVersion || version < m.firstVersion { + return vermap + } + + for _, v := range m.versionedModules[version] { + version := v.ConsensusVersion() + name := v.Name() + vermap[name] = version + } + + return vermap +} + // ModuleNames returns list of all module names, without any particular order. func (m *Manager) ModuleNames(version uint64) []string { modules, ok := m.versionedModules[version] From bea9815d867e4f373eabd2b666757d13cee6574a Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 16 Apr 2024 10:44:24 +0200 Subject: [PATCH 5/9] use latest cosmos-sdk version --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 605b247940..2f8f8a8df7 100644 --- a/go.mod +++ b/go.mod @@ -257,7 +257,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => /Users/callum/Developer/go/src/github.com/celestiaorg/cosmos-sdk + github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.21.0-sdk-v0.46.16 // Pin to ledger-cosmos-go v0.12.4 to avoid a breaking change introduced in v0.13.0 // The following replace statement can be removed when we upgrade to cosmos-sdk >= v0.50.0 github.com/cosmos/ledger-cosmos-go => github.com/cosmos/ledger-cosmos-go v0.12.4 diff --git a/go.sum b/go.sum index d77a8b2d5b..8f7668b686 100644 --- a/go.sum +++ b/go.sum @@ -326,6 +326,8 @@ github.com/celestiaorg/blobstream-contracts/v3 v3.1.0 h1:h1Y4V3EMQ2mFmNtWt2sIhZI github.com/celestiaorg/blobstream-contracts/v3 v3.1.0/go.mod h1:x4DKyfKOSv1ZJM9NwV+Pw01kH2CD7N5zTFclXIVJ6GQ= github.com/celestiaorg/celestia-core v1.35.0-tm-v0.34.29 h1:sXERzNXgyHyqTKNQx4S29C/NMDzgav62DaQDNF49HUQ= github.com/celestiaorg/celestia-core v1.35.0-tm-v0.34.29/go.mod h1:weZR4wYx1Vcw3g1Jc5G8VipG4M+KUDSqeIzyyWszmsQ= +github.com/celestiaorg/cosmos-sdk v1.21.0-sdk-v0.46.16 h1:P44npoIUuortDf0nQSUpTwO8zsWoHufbDD/doU+CtxY= +github.com/celestiaorg/cosmos-sdk v1.21.0-sdk-v0.46.16/go.mod h1:AmuR63HTlX8vNV3+NGWNPIZa95J1UweTUmWDHSdTGj0= github.com/celestiaorg/go-square v1.0.1 h1:LEG1zrw4i03VBMElQF8GAbKYgh1bT1uGzWxasU2ePuo= github.com/celestiaorg/go-square v1.0.1/go.mod h1:XMv5SGCeGSkynW2OOsedugaW/rQlvzxGzWGxTKsyYOU= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= From 226d04facb236fdeb32760277fd7c1da5970e5f8 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Tue, 16 Apr 2024 11:41:34 -0400 Subject: [PATCH 6/9] chore(deps): bump cosmos-sdk in testground --- test/testground/go.mod | 2 +- test/testground/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/testground/go.mod b/test/testground/go.mod index 1cf9752814..b646318b92 100644 --- a/test/testground/go.mod +++ b/test/testground/go.mod @@ -223,7 +223,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.20.2-sdk-v0.46.16 + github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.21.0-sdk-v0.46.16 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.0 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 diff --git a/test/testground/go.sum b/test/testground/go.sum index 8f835f8a68..8795825282 100644 --- a/test/testground/go.sum +++ b/test/testground/go.sum @@ -340,8 +340,8 @@ github.com/celestiaorg/celestia-app v1.0.0-rc0.0.20240304150808-f0a1f87c0253 h1: github.com/celestiaorg/celestia-app v1.0.0-rc0.0.20240304150808-f0a1f87c0253/go.mod h1:z3gMQZkUUe2MYrQQGnrYy+gDP0QpX0f5EPWtVNM0u/E= github.com/celestiaorg/celestia-core v1.35.0-tm-v0.34.29 h1:sXERzNXgyHyqTKNQx4S29C/NMDzgav62DaQDNF49HUQ= github.com/celestiaorg/celestia-core v1.35.0-tm-v0.34.29/go.mod h1:weZR4wYx1Vcw3g1Jc5G8VipG4M+KUDSqeIzyyWszmsQ= -github.com/celestiaorg/cosmos-sdk v1.20.2-sdk-v0.46.16 h1:EmzwDx64oG8eKZPar50VCkpzxDNqjjtt7rOBJsMQY8E= -github.com/celestiaorg/cosmos-sdk v1.20.2-sdk-v0.46.16/go.mod h1:AmuR63HTlX8vNV3+NGWNPIZa95J1UweTUmWDHSdTGj0= +github.com/celestiaorg/cosmos-sdk v1.21.0-sdk-v0.46.16 h1:P44npoIUuortDf0nQSUpTwO8zsWoHufbDD/doU+CtxY= +github.com/celestiaorg/cosmos-sdk v1.21.0-sdk-v0.46.16/go.mod h1:AmuR63HTlX8vNV3+NGWNPIZa95J1UweTUmWDHSdTGj0= github.com/celestiaorg/go-square v1.0.1 h1:LEG1zrw4i03VBMElQF8GAbKYgh1bT1uGzWxasU2ePuo= github.com/celestiaorg/go-square v1.0.1/go.mod h1:XMv5SGCeGSkynW2OOsedugaW/rQlvzxGzWGxTKsyYOU= github.com/celestiaorg/go-square/merkle v0.0.0-20240117232118-fd78256df076 h1:PYInrsYzrDIsZW9Yb86OTi2aEKuPcpgJt6Mc0Jlc/yg= From 50da4836d4a658d6ed99c75e7d68847bbc1cfb9e Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Tue, 16 Apr 2024 18:17:43 +0200 Subject: [PATCH 7/9] gofumpt --- app/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index f137d915ff..278c9f2975 100644 --- a/app/app.go +++ b/app/app.go @@ -688,7 +688,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // Version changes must be increasing. Downgrades are not permitted if newVersion > currentVersion { app.SetAppVersion(ctx, newVersion) - app.SignalKeeper.ResetTally(ctx) + app.SignalKeeper.ResetTally(ctx) } } return res From 18b1199ddfd10954de76eb079f901fce289718e9 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 17 Apr 2024 10:42:40 +0200 Subject: [PATCH 8/9] Update app/app.go Co-authored-by: Rootul P --- app/app.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 278c9f2975..7de8a5ab6b 100644 --- a/app/app.go +++ b/app/app.go @@ -629,8 +629,7 @@ func New( app.MsgGateKeeper = ante.NewMsgVersioningGateKeeper(app.configurator.GetAcceptedMessages()) app.MsgServiceRouter().SetCircuit(app.MsgGateKeeper) - // We only initialize the base stores that will be part of every version i.e. params - // (which contain the app version) + // Initialize the KV stores for the base modules (e.g. params). The base modules will be included in every app version. app.MountKVStores(app.baseKeys()) app.MountTransientStores(tkeys) app.MountMemoryStores(memKeys) From afa909713a8bca5167d736947fb5bc75f3534db9 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Wed, 17 Apr 2024 11:39:43 +0200 Subject: [PATCH 9/9] add some sanity checks to make sure modules are correctly added --- app/app.go | 343 ++++----------------------------------- app/module/module.go | 11 ++ app/modules.go | 373 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 417 insertions(+), 310 deletions(-) create mode 100644 app/modules.go diff --git a/app/app.go b/app/app.go index a0f3db1a98..10b232fa94 100644 --- a/app/app.go +++ b/app/app.go @@ -3,11 +3,11 @@ package app import ( "fmt" "io" + "slices" "github.com/celestiaorg/celestia-app/v2/app/module" "github.com/celestiaorg/celestia-app/v2/app/posthandler" "github.com/celestiaorg/celestia-app/v2/x/minfee" - "github.com/celestiaorg/celestia-app/v2/x/mint" mintkeeper "github.com/celestiaorg/celestia-app/v2/x/mint/keeper" minttypes "github.com/celestiaorg/celestia-app/v2/x/mint/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -23,19 +23,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkmodule "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" - "github.com/cosmos/cosmos-sdk/x/auth" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" 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" "github.com/cosmos/cosmos-sdk/x/crisis" @@ -44,27 +37,19 @@ import ( 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" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - "github.com/cosmos/cosmos-sdk/x/gov" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta2 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" oldgovtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/cosmos/cosmos-sdk/x/params" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - "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" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" @@ -72,7 +57,6 @@ import ( "github.com/cosmos/ibc-go/v6/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - ibc "github.com/cosmos/ibc-go/v6/modules/core" ibcclienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" ibcporttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" @@ -89,13 +73,11 @@ import ( appv1 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v1" appv2 "github.com/celestiaorg/celestia-app/v2/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/v2/pkg/proof" - "github.com/celestiaorg/celestia-app/v2/x/blob" blobkeeper "github.com/celestiaorg/celestia-app/v2/x/blob/keeper" blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" "github.com/celestiaorg/celestia-app/v2/x/paramfilter" "github.com/celestiaorg/celestia-app/v2/x/tokenfilter" - "github.com/celestiaorg/celestia-app/v2/x/blobstream" blobstreamkeeper "github.com/celestiaorg/celestia-app/v2/x/blobstream/keeper" blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types" "github.com/celestiaorg/celestia-app/v2/x/signal" @@ -106,59 +88,23 @@ import ( packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/keeper" packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" - ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" icahost "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host" icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" ) -var ( - // ModuleBasics defines the module BasicManager is in charge of setting up basic, - // non-dependant module elements, such as codec registration - // and genesis verification. - ModuleBasics = sdkmodule.NewBasicManager( - auth.AppModuleBasic{}, - genutil.AppModuleBasic{}, - bankModule{}, - capability.AppModuleBasic{}, - stakingModule{}, - mintModule{}, - distributionModule{}, - newGovModule(), - params.AppModuleBasic{}, - crisisModule{}, - slashingModule{}, - authzmodule.AppModuleBasic{}, - feegrantmodule.AppModuleBasic{}, - ibcModule{}, - evidence.AppModuleBasic{}, - transfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, - blob.AppModuleBasic{}, - blobstream.AppModuleBasic{}, - signal.AppModuleBasic{}, - minfee.AppModuleBasic{}, - packetforward.AppModuleBasic{}, - icaModule{}, - ) - - // ModuleEncodingRegisters keeps track of all the module methods needed to - // register interfaces and specific type to encoding config - ModuleEncodingRegisters = extractRegisters(ModuleBasics) - - // maccPerms is short for module account permissions. - maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - govtypes.ModuleName: {authtypes.Burner}, - minttypes.ModuleName: {authtypes.Minter}, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - icatypes.ModuleName: nil, - } -) +// maccPerms is short for module account permissions. +var maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + govtypes.ModuleName: {authtypes.Burner}, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + icatypes.ModuleName: nil, +} const ( v1 = appv1.Version @@ -426,195 +372,14 @@ func New( // we prefer to be more strict in what arguments the modules expect. skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) - // NOTE: Any module instantiated in the module manager that is later modified - // must be passed by reference here. - var err error - app.mm, err = module.NewManager([]module.VersionedModule{ - { - Module: genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, encodingConfig.TxConfig), - FromVersion: v1, ToVersion: v2, - }, - { - Module: auth.NewAppModule(appCodec, app.AccountKeeper, nil), - FromVersion: v1, ToVersion: v2, - }, - { - Module: vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: capability.NewAppModule(appCodec, *app.CapabilityKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - FromVersion: v1, ToVersion: v2, - }, - { - Module: crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), - FromVersion: v1, ToVersion: v2, - }, - { - Module: gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: evidence.NewAppModule(app.EvidenceKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), - FromVersion: v1, ToVersion: v2, - }, - { - Module: ibc.NewAppModule(app.IBCKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: params.NewAppModule(app.ParamsKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: transfer.NewAppModule(app.TransferKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: blob.NewAppModule(appCodec, app.BlobKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: blobstream.NewAppModule(appCodec, app.BlobstreamKeeper), - FromVersion: v1, ToVersion: v2, - }, - { - Module: signal.NewAppModule(app.SignalKeeper), - FromVersion: v2, ToVersion: v2, - }, - { - Module: minfee.NewAppModule(app.ParamsKeeper), - FromVersion: v2, ToVersion: v2, - }, - { - Module: packetforward.NewAppModule(app.PacketForwardKeeper), - FromVersion: v2, ToVersion: v2, - }, - { - Module: ica.NewAppModule(nil, &app.ICAHostKeeper), - FromVersion: v2, ToVersion: v2, - }, - }) + // NOTE: Modules can't be modified or else must be passed by reference to the module manager + err := app.setupModuleManager(skipGenesisInvariants) if err != nil { panic(err) } - // During begin block slashing happens after distr.BeginBlocker so that - // there is nothing left over in the validator fee pool, so as to keep the - // CanWithdrawInvariant invariant. - // NOTE: staking module is required if HistoricalEntries param > 0 - app.mm.SetOrderBeginBlockers( - capabilitytypes.ModuleName, - minttypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - evidencetypes.ModuleName, - stakingtypes.ModuleName, - ibchost.ModuleName, - ibctransfertypes.ModuleName, - feegrant.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - crisistypes.ModuleName, - govtypes.ModuleName, - genutiltypes.ModuleName, - blobtypes.ModuleName, - blobstreamtypes.ModuleName, - paramstypes.ModuleName, - authz.ModuleName, - vestingtypes.ModuleName, - signaltypes.ModuleName, - minfee.ModuleName, - icatypes.ModuleName, - packetforwardtypes.ModuleName, - ) - - app.mm.SetOrderEndBlockers( - crisistypes.ModuleName, - govtypes.ModuleName, - stakingtypes.ModuleName, - capabilitytypes.ModuleName, - minttypes.ModuleName, - distrtypes.ModuleName, - slashingtypes.ModuleName, - evidencetypes.ModuleName, - ibchost.ModuleName, - ibctransfertypes.ModuleName, - feegrant.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - genutiltypes.ModuleName, - blobtypes.ModuleName, - blobstreamtypes.ModuleName, - paramstypes.ModuleName, - authz.ModuleName, - vestingtypes.ModuleName, - signaltypes.ModuleName, - minfee.ModuleName, - packetforwardtypes.ModuleName, - icatypes.ModuleName, - ) - - // NOTE: The genutils module must occur after staking so that pools are - // properly initialized with tokens from genesis accounts. - // 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. - // NOTE: The minfee module must occur before genutil so DeliverTx can - // successfully pass the fee checking logic - app.mm.SetOrderInitGenesis( - capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - stakingtypes.ModuleName, - slashingtypes.ModuleName, - govtypes.ModuleName, - minttypes.ModuleName, - crisistypes.ModuleName, - ibchost.ModuleName, - minfee.ModuleName, - genutiltypes.ModuleName, - evidencetypes.ModuleName, - ibctransfertypes.ModuleName, - blobtypes.ModuleName, - blobstreamtypes.ModuleName, - vestingtypes.ModuleName, - feegrant.ModuleName, - paramstypes.ModuleName, - authz.ModuleName, - signaltypes.ModuleName, - packetforwardtypes.ModuleName, - icatypes.ModuleName, - ) + // order begin block, end block and init genesis + app.setModuleOrder() app.QueryRouter().AddRoute(proof.TxInclusionQueryPath, proof.QueryTxInclusionProof) app.QueryRouter().AddRoute(proof.ShareInclusionQueryPath, proof.QueryShareInclusionProof) @@ -654,6 +419,9 @@ func New( app.SetMigrateStoreFn(app.migrateCommitStore) app.SetMigrateModuleFn(app.migrateModules) + // assert that keys are present for all supported versions + app.assertAllKeysArePresent() + // we don't seal the store until the app version has been initailised // this will just initialize the base keys (i.e. the param store) if err := app.CommitMultiStore().LoadLatestVersion(); err != nil { @@ -693,33 +461,30 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo return res } +// migrateCommitStore tells the baseapp during a version upgrade, which stores to add and which +// stores to remove func (app *App) migrateCommitStore(fromVersion, toVersion uint64) (baseapp.StoreMigrations, error) { oldStoreKeys := app.keyVersions[fromVersion] newStoreKeys := app.keyVersions[toVersion] - newMap := make(map[string]bool) - output := baseapp.StoreMigrations{ + result := baseapp.StoreMigrations{ Added: make(map[string]*storetypes.KVStoreKey), Deleted: make(map[string]*storetypes.KVStoreKey), } - for _, storeKey := range newStoreKeys { - newMap[storeKey] = false - } - for _, storeKey := range oldStoreKeys { - if _, ok := newMap[storeKey]; !ok { - output.Deleted[storeKey] = app.keys[storeKey] - } else { - // this module exists in both the old and new modules - newMap[storeKey] = true + for _, oldKey := range oldStoreKeys { + if !slices.Contains(newStoreKeys, oldKey) { + result.Deleted[oldKey] = app.keys[oldKey] } } - for storeKey, existsInOldModule := range newMap { - if !existsInOldModule { - output.Added[storeKey] = app.keys[storeKey] + for _, newKey := range newStoreKeys { + if !slices.Contains(oldStoreKeys, newKey) { + result.Added[newKey] = app.keys[newKey] } } - return output, nil + return result, nil } +// migrateModules performs migrations on existing modules that have registered migrations +// between versions and initializes the state of new modules for the specified app version. func (app *App) migrateModules(ctx sdk.Context, fromVersion, toVersion uint64) error { return app.mm.RunMigrations(ctx, app.configurator, fromVersion, toVersion) } @@ -961,55 +726,13 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino // extractRegisters isolates the encoding module registers from the module // manager, and appends any solo registers. -func extractRegisters(m sdkmodule.BasicManager, soloRegisters ...encoding.ModuleRegister) []encoding.ModuleRegister { +func extractRegisters(m sdkmodule.BasicManager) []encoding.ModuleRegister { // TODO: might be able to use some standard generics in go 1.18 - s := make([]encoding.ModuleRegister, len(m)+len(soloRegisters)) + s := make([]encoding.ModuleRegister, len(m)) i := 0 for _, v := range m { s[i] = v i++ } - for i, v := range soloRegisters { - s[i+len(m)] = v - } return s } - -func allStoreKeys() []string { - return []string{ - authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, capabilitytypes.StoreKey, - blobstreamtypes.StoreKey, - ibctransfertypes.StoreKey, - ibchost.StoreKey, - packetforwardtypes.StoreKey, - icahosttypes.StoreKey, - signaltypes.StoreKey, - blobtypes.StoreKey, - } -} - -// versionedStoreKeys returns the store keys for each app version -// ... I wish there was an easier way than this (like using the modules which are already versioned) -func versionedStoreKeys() map[uint64][]string { - return map[uint64][]string{ - 1: { - authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, capabilitytypes.StoreKey, - blobstreamtypes.StoreKey, ibctransfertypes.StoreKey, ibchost.StoreKey, - blobtypes.StoreKey, - }, - 2: { - authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, - evidencetypes.StoreKey, capabilitytypes.StoreKey, - blobstreamtypes.StoreKey, ibctransfertypes.StoreKey, ibchost.StoreKey, - packetforwardtypes.StoreKey, icahosttypes.StoreKey, signaltypes.StoreKey, - }, - } -} diff --git a/app/module/module.go b/app/module/module.go index 506d622c08..ac986533c0 100644 --- a/app/module/module.go +++ b/app/module/module.go @@ -399,6 +399,17 @@ func (m *Manager) checkUpgradeSchedule() error { return nil } +// assertMatchingModules performs a sanity check that the basic module manager +// contains all the same modules present in the module manager +func (m *Manager) AssertMatchingModules(basicModuleManager sdkmodule.BasicManager) error { + for _, module := range m.allModules { + if _, exists := basicModuleManager[module.Name()]; !exists { + return fmt.Errorf("module %s not found in basic module manager", module.Name()) + } + } + return nil +} + // DefaultMigrationsOrder returns a default migrations order: ascending alphabetical by module name, // except x/auth which will run last, see: // https://github.com/cosmos/cosmos-sdk/issues/10591 diff --git a/app/modules.go b/app/modules.go new file mode 100644 index 0000000000..210d0f75cd --- /dev/null +++ b/app/modules.go @@ -0,0 +1,373 @@ +package app + +import ( + "fmt" + + "github.com/celestiaorg/celestia-app/v2/app/module" + "github.com/celestiaorg/celestia-app/v2/x/blob" + blobtypes "github.com/celestiaorg/celestia-app/v2/x/blob/types" + "github.com/celestiaorg/celestia-app/v2/x/blobstream" + blobstreamtypes "github.com/celestiaorg/celestia-app/v2/x/blobstream/types" + "github.com/celestiaorg/celestia-app/v2/x/minfee" + "github.com/celestiaorg/celestia-app/v2/x/mint" + minttypes "github.com/celestiaorg/celestia-app/v2/x/mint/types" + "github.com/celestiaorg/celestia-app/v2/x/signal" + signaltypes "github.com/celestiaorg/celestia-app/v2/x/signal/types" + sdkmodule "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/x/auth" + 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" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/capability" + capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/evidence" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + "github.com/cosmos/cosmos-sdk/x/feegrant" + feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/gov" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/params" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v6/packetforward/types" + ica "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts" + icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types" + icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types" + "github.com/cosmos/ibc-go/v6/modules/apps/transfer" + ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v6/modules/core" + ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" +) + +var ( + // ModuleBasics defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration + // and genesis verification. + ModuleBasics = sdkmodule.NewBasicManager( + auth.AppModuleBasic{}, + genutil.AppModuleBasic{}, + bankModule{}, + capability.AppModuleBasic{}, + stakingModule{}, + mintModule{}, + distributionModule{}, + newGovModule(), + params.AppModuleBasic{}, + crisisModule{}, + slashingModule{}, + authzmodule.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + ibcModule{}, + evidence.AppModuleBasic{}, + transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + blob.AppModuleBasic{}, + blobstream.AppModuleBasic{}, + signal.AppModuleBasic{}, + minfee.AppModuleBasic{}, + packetforward.AppModuleBasic{}, + icaModule{}, + ) + + // ModuleEncodingRegisters keeps track of all the module methods needed to + // register interfaces and specific type to encoding config + ModuleEncodingRegisters = extractRegisters(ModuleBasics) +) + +func (app *App) setupModuleManager(skipGenesisInvariants bool) error { + var err error + app.mm, err = module.NewManager([]module.VersionedModule{ + { + Module: genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, app.txConfig), + FromVersion: v1, ToVersion: v2, + }, + { + Module: auth.NewAppModule(app.appCodec, app.AccountKeeper, nil), + FromVersion: v1, ToVersion: v2, + }, + { + Module: vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: bank.NewAppModule(app.appCodec, app.BankKeeper, app.AccountKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: capability.NewAppModule(app.appCodec, *app.CapabilityKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: feegrantmodule.NewAppModule(app.appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + FromVersion: v1, ToVersion: v2, + }, + { + Module: crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), + FromVersion: v1, ToVersion: v2, + }, + { + Module: gov.NewAppModule(app.appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: mint.NewAppModule(app.appCodec, app.MintKeeper, app.AccountKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: slashing.NewAppModule(app.appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: distr.NewAppModule(app.appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: staking.NewAppModule(app.appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: evidence.NewAppModule(app.EvidenceKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: authzmodule.NewAppModule(app.appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + FromVersion: v1, ToVersion: v2, + }, + { + Module: ibc.NewAppModule(app.IBCKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: params.NewAppModule(app.ParamsKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: transfer.NewAppModule(app.TransferKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: blob.NewAppModule(app.appCodec, app.BlobKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: blobstream.NewAppModule(app.appCodec, app.BlobstreamKeeper), + FromVersion: v1, ToVersion: v2, + }, + { + Module: signal.NewAppModule(app.SignalKeeper), + FromVersion: v2, ToVersion: v2, + }, + { + Module: minfee.NewAppModule(app.ParamsKeeper), + FromVersion: v2, ToVersion: v2, + }, + { + Module: packetforward.NewAppModule(app.PacketForwardKeeper), + FromVersion: v2, ToVersion: v2, + }, + { + Module: ica.NewAppModule(nil, &app.ICAHostKeeper), + FromVersion: v2, ToVersion: v2, + }, + }) + if err != nil { + return err + } + return app.mm.AssertMatchingModules(ModuleBasics) +} + +func (app *App) setModuleOrder() { + // During begin block slashing happens after distr.BeginBlocker so that + // there is nothing left over in the validator fee pool, so as to keep the + // CanWithdrawInvariant invariant. + // NOTE: staking module is required if HistoricalEntries param > 0 + app.mm.SetOrderBeginBlockers( + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + ibchost.ModuleName, + ibctransfertypes.ModuleName, + feegrant.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + crisistypes.ModuleName, + govtypes.ModuleName, + genutiltypes.ModuleName, + blobtypes.ModuleName, + blobstreamtypes.ModuleName, + paramstypes.ModuleName, + authz.ModuleName, + vestingtypes.ModuleName, + signaltypes.ModuleName, + minfee.ModuleName, + icatypes.ModuleName, + packetforwardtypes.ModuleName, + ) + + app.mm.SetOrderEndBlockers( + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + ibchost.ModuleName, + ibctransfertypes.ModuleName, + feegrant.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + genutiltypes.ModuleName, + blobtypes.ModuleName, + blobstreamtypes.ModuleName, + paramstypes.ModuleName, + authz.ModuleName, + vestingtypes.ModuleName, + signaltypes.ModuleName, + minfee.ModuleName, + packetforwardtypes.ModuleName, + icatypes.ModuleName, + ) + + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // 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. + // NOTE: The minfee module must occur before genutil so DeliverTx can + // successfully pass the fee checking logic + app.mm.SetOrderInitGenesis( + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + minttypes.ModuleName, + crisistypes.ModuleName, + ibchost.ModuleName, + minfee.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + ibctransfertypes.ModuleName, + blobtypes.ModuleName, + blobstreamtypes.ModuleName, + vestingtypes.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + authz.ModuleName, + signaltypes.ModuleName, + packetforwardtypes.ModuleName, + icatypes.ModuleName, + ) +} + +func allStoreKeys() []string { + return []string{ + authtypes.StoreKey, authzkeeper.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, capabilitytypes.StoreKey, + blobstreamtypes.StoreKey, + ibctransfertypes.StoreKey, + ibchost.StoreKey, + packetforwardtypes.StoreKey, + icahosttypes.StoreKey, + signaltypes.StoreKey, + blobtypes.StoreKey, + } +} + +// versionedStoreKeys returns the store keys for each app version +// ... I wish there was an easier way than this (like using the modules which are already versioned) +func versionedStoreKeys() map[uint64][]string { + return map[uint64][]string{ + 1: { + authtypes.StoreKey, + authzkeeper.StoreKey, + banktypes.StoreKey, + stakingtypes.StoreKey, + minttypes.StoreKey, + distrtypes.StoreKey, + slashingtypes.StoreKey, + govtypes.StoreKey, + upgradetypes.StoreKey, + feegrant.StoreKey, + evidencetypes.StoreKey, + capabilitytypes.StoreKey, + blobstreamtypes.StoreKey, + ibctransfertypes.StoreKey, + ibchost.StoreKey, + blobtypes.StoreKey, + }, + 2: { + authtypes.StoreKey, + authzkeeper.StoreKey, + banktypes.StoreKey, + stakingtypes.StoreKey, + minttypes.StoreKey, + distrtypes.StoreKey, + slashingtypes.StoreKey, + govtypes.StoreKey, + upgradetypes.StoreKey, + feegrant.StoreKey, + evidencetypes.StoreKey, + capabilitytypes.StoreKey, + blobstreamtypes.StoreKey, + ibctransfertypes.StoreKey, + ibchost.StoreKey, + packetforwardtypes.StoreKey, + icahosttypes.StoreKey, + signaltypes.StoreKey, + }, + } +} + +// assertAllKeysArePresent performs a couple sanity checks on startup to ensure each versions key names have +// a key and that all versions supported by the module manager have a respective versioned key +func (app *App) assertAllKeysArePresent() { + supportedAppVersions := app.SupportedVersions() + supportedVersionsMap := make(map[uint64]bool, len(supportedAppVersions)) + for _, version := range supportedAppVersions { + supportedVersionsMap[version] = false + } + + for appVersion, keys := range app.keyVersions { + if _, exists := supportedVersionsMap[appVersion]; exists { + supportedVersionsMap[appVersion] = true + } else { + panic(fmt.Sprintf("keys %v for app version %d are not supported by the module manager", keys, appVersion)) + } + for _, key := range keys { + if _, ok := app.keys[key]; !ok { + panic(fmt.Sprintf("key %s is not present", key)) + } + } + } + for appVersion, supported := range supportedVersionsMap { + if !supported { + panic(fmt.Sprintf("app version %d is supported by the module manager but has no keys", appVersion)) + } + } +}