diff --git a/app/app.go b/app/app.go index fa7128090..c92b67ac8 100644 --- a/app/app.go +++ b/app/app.go @@ -2,7 +2,6 @@ package app import ( "encoding/json" - "fmt" "io" "math/big" "net/http" @@ -72,7 +71,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - clientkeeper "github.com/cosmos/ibc-go/v6/modules/core/02-client/keeper" "github.com/cosmos/cosmos-sdk/x/mint" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" @@ -113,7 +111,6 @@ import ( ante "github.com/dymensionxyz/dymension/app/ante" appparams "github.com/dymensionxyz/dymension/app/params" - v2upgrade "github.com/dymensionxyz/dymension/app/upgrades/v2" rollappmodule "github.com/dymensionxyz/dymension/x/rollapp" rollappmodulekeeper "github.com/dymensionxyz/dymension/x/rollapp/keeper" rollappmoduletypes "github.com/dymensionxyz/dymension/x/rollapp/types" @@ -895,7 +892,6 @@ func New( app.SetAnteHandler(anteHandler) app.SetEndBlocker(app.EndBlocker) - app.setupUpgradeHandlers() if loadLatest { if err := app.LoadLatestVersion(); err != nil { @@ -1128,38 +1124,3 @@ func (app *App) GetTxConfig() client.TxConfig { func (app *App) ExportState(ctx sdk.Context) map[string]json.RawMessage { return app.mm.ExportGenesis(ctx, app.AppCodec()) } - -// TODO: Create upgrade interface and setup generic upgrades handling a la osmosis -func (app *App) setupUpgradeHandlers() { - UpgradeName := "v2" - - app.UpgradeKeeper.SetUpgradeHandler( - UpgradeName, - v2upgrade.CreateUpgradeHandler( - app.mm, app.configurator, - app.BankKeeper, - app.IBCKeeper.ClientKeeper.(clientkeeper.Keeper), - app.RollappKeeper, - app.StakingKeeper, - app.appCodec, - ), - ) - - // When a planned update height is reached, the old binary will panic - // writing on disk the height and name of the update that triggered it - // This will read that value, and execute the preparations for the upgrade. - upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() - if err != nil { - panic(fmt.Errorf("failed to read upgrade info from disk: %w", err)) - } - - // Pre upgrade handler - switch upgradeInfo.Name { - // do nothing - } - - if upgradeInfo.Name == "v2" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - // configure store loader with the store upgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, v2upgrade.GetStoreUpgrades())) - } -} diff --git a/app/upgrades/v2/constants.go b/app/upgrades/v2/constants.go deleted file mode 100644 index 6c6133c28..000000000 --- a/app/upgrades/v2/constants.go +++ /dev/null @@ -1,33 +0,0 @@ -package rc - -import ( - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -const ( - UpgradeName = "v2" -) - -var ( - DYMTokenMetata = banktypes.Metadata{ - Description: "Denom metadata for DYM (udym)", - DenomUnits: []*banktypes.DenomUnit{ - { - Denom: "udym", - Exponent: 0, - Aliases: []string{}, - }, - { - Denom: "DYM", - Exponent: 18, - Aliases: []string{}, - }, - }, - Base: "udym", - Display: "DYM", - Name: "DYM", - Symbol: "DYM", - URI: "", - URIHash: "", - } -) diff --git a/app/upgrades/v2/upgrade.go b/app/upgrades/v2/upgrade.go deleted file mode 100644 index 1f49282ba..000000000 --- a/app/upgrades/v2/upgrade.go +++ /dev/null @@ -1,214 +0,0 @@ -package rc - -import ( - "fmt" - "math/big" - - "github.com/tendermint/tendermint/libs/log" - - "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - clientkeeper "github.com/cosmos/ibc-go/v6/modules/core/02-client/keeper" - clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v6/modules/core/exported" - dmtypes "github.com/cosmos/ibc-go/v6/modules/light-clients/01-dymint/types" - tmtypes "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint/types" - rollappKeeper "github.com/dymensionxyz/dymension/x/rollapp/keeper" - rollapptypes "github.com/dymensionxyz/dymension/x/rollapp/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v2 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - bankKeeper bankkeeper.Keeper, - clientKeeper clientkeeper.Keeper, - rollappKeeper rollappKeeper.Keeper, - stakingKeeper stakingKeeper.Keeper, - cdc codec.BinaryCodec, - -) upgradetypes.UpgradeHandler { - - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - - logger := ctx.Logger().With("upgrade", UpgradeName) - - // Create a map from client id to status where the statuses will be saved - clientStatuses := updateClientStates(ctx, clientKeeper, logger, cdc) - - // Update the consensus states - updateConsensusStates(ctx, clientKeeper, logger) - - // Verify the client statuses are the same after the upgrade - verifyClientStatus(ctx, clientKeeper, clientStatuses, logger, cdc) - - // Update delegations - updateDelegation(ctx, stakingKeeper, logger) - - // Update the denom metadata for DYM token - bankKeeper.SetDenomMetaData(ctx, DYMTokenMetata) - - // Update the params for rolllapp to init the new param enable_rollapps - rollappKeeper.SetParams(ctx, rollapptypes.DefaultParams()) - - // Iterate over all rollapps and set PermissionedAddresses to empty as the migration - // Caused the PermissionedAddresses to be set to "" - rollappsList := rollappKeeper.GetAllRollapp(ctx) - for _, rollapp := range rollappsList { - rollapp.PermissionedAddresses = []string{} - rollappKeeper.SetRollapp(ctx, rollapp) - } - - // Start running the module migrations - logger.Debug("running module migrations ...") - return mm.RunMigrations(ctx, configurator, vm) - } -} - -// updateClientState updates the client state from Dymint client state to Tendermint client state -func updateClientStates(ctx sdk.Context, clientKeeper clientkeeper.Keeper, logger log.Logger, cdc codec.BinaryCodec) map[string]exported.Status { - // Create a map from client id to status where the statuses will be saved - clientStatuses := make(map[string]exported.Status) - - // Iterate over all clients and change their client state to Tendermint client state - clientKeeper.IterateClients(ctx, func(clientID string, clientState exported.ClientState) bool { - logger.Info("Trying to upgrade client", "clientID", clientID, "clientState", clientState) - dmClientState, ok := clientState.(*dmtypes.ClientState) - if !ok { - logger.Info("Not a Dymint client state. Skipping", "clientID", clientID, "clientState", clientState) - return false - } - logger.Info("Found dymint state. Upgrading client", "clientID", clientID, "clientState", clientState) - prevStatus := dmClientState.Status(ctx, clientKeeper.ClientStore(ctx, clientID), cdc) - clientStatuses[clientID] = prevStatus - newClientState := tmtypes.NewClientState( - dmClientState.ChainId, - tmtypes.DefaultTrustLevel, - dmClientState.TrustingPeriod, - dmClientState.UnbondingPeriod, - dmClientState.MaxClockDrift, - dmClientState.LatestHeight, - dmClientState.GetProofSpecs(), - dmClientState.UpgradePath, - true, - true, - ) - clientKeeper.SetClientState(ctx, clientID, newClientState) - - return false - }) - - logger.Info("Upgraded all clients Successfully") - return clientStatuses -} - -func updateConsensusStates(ctx sdk.Context, clientKeeper clientkeeper.Keeper, logger log.Logger) { - // Iterate over all consensus states and change them to Tendermint consensus state - clientKeeper.IterateConsensusStates(ctx, func(clientID string, consensusStateWithHeight clienttypes.ConsensusStateWithHeight) bool { - // Get the consensus state - logger.Info("Trying to upgrade consensus state", "clientID", clientID) - exportedConsensusState, found := clientKeeper.GetClientConsensusState(ctx, clientID, consensusStateWithHeight.Height) - dmConsensusState, ok := exportedConsensusState.(*dmtypes.ConsensusState) - if !ok { - logger.Info("Not a Dymint consensus state. Skipping", "clientID", clientID) - return false - } - if !found { - logger.Info("Consensus state not found. Skipping", "clientID", clientID) - return false - } - // Convert to Tendermint consensus state - tmConsensusState := &tmtypes.ConsensusState{ - Timestamp: dmConsensusState.Timestamp, - Root: dmConsensusState.Root, - NextValidatorsHash: dmConsensusState.NextValidatorsHash, - } - - clientKeeper.SetClientConsensusState(ctx, clientID, consensusStateWithHeight.Height, tmConsensusState) - logger.Info("Upgraded consensus state", "clientID", clientID, "consensusStateHeight", consensusStateWithHeight.Height) - return false - }) - - logger.Info("Upgraded all consensus states successfully") - -} - -func verifyClientStatus(ctx sdk.Context, clientKeeper clientkeeper.Keeper, clientStatuses map[string]exported.Status, logger log.Logger, cdc codec.BinaryCodec) { - // Iterate over all clients and change their client state to Tendermint client state - clientKeeper.IterateClients(ctx, func(clientID string, clientState exported.ClientState) bool { - // Check the status of the client is active after the upgrade - logger.Info("Checking client status after upgrade", "clientID", clientID) - status := clientState.Status(ctx, clientKeeper.ClientStore(ctx, clientID), cdc) - if _, ok := clientStatuses[clientID]; ok { - if status != clientStatuses[clientID] { - msg := fmt.Sprintf("client status has changed after upgrade. Expected: %s, got: %s", clientStatuses[clientID], status) - panic(msg) - } - } else { - fmt.Printf("client status not found for clientID: %s", clientID) - } - return false - }) - - logger.Info("Client status verification passed successfully") -} - -// updateDelegation updates the delegation for a single node in order to overcome the froopyland chain halt. -// this is a hotfix and should be removed after the chain is upgraded to v2 and enough nodes migrated. -func updateDelegation(ctx sdk.Context, stakingKeeper stakingKeeper.Keeper, logger log.Logger) { - - const ( - // SilkNode validator address - valBech32Addr = "dymvaloper1kkmputh26f6tyjtdajvwgpjztgcvls7t797jn5" - // Dymension delegator address - delBech32Addr = "dym1g3djlajjyqe6lcfz4lphc97csdgnnw249vru73" - ) - - valAddr, valErr := sdk.ValAddressFromBech32(valBech32Addr) - if valErr != nil { - logger.Error("error while converting validator address from bech32", "error", valErr) - panic(valErr) - } - - validator, found := stakingKeeper.GetValidator(ctx, valAddr) - if !found { - logger.Error("validator not found") - panic("validator not found") - } - - delegatorAddress, err := sdk.AccAddressFromBech32(delBech32Addr) - if err != nil { - logger.Error("error while converting delegator address from bech32", "error", err) - panic(err) - } - - bondDenom := stakingKeeper.BondDenom(ctx) - bigIntValue, ok := big.NewInt(0).SetString("27384040000000000000000000", 10) - if !ok { - logger.Error("error while converting string to big.Int") - panic("error while converting string to big.Int") - } - amount := sdk.NewCoin(bondDenom, sdk.NewIntFromBigInt(bigIntValue)) - - // NOTE: source funds are always unbonded - _, err = stakingKeeper.Delegate(ctx, delegatorAddress, amount.Amount, stakingtypes.Unbonded, validator, true) - if err != nil { - logger.Error("error while delegating", "error", err) - panic(err) - } - -} - -func GetStoreUpgrades() *storetypes.StoreUpgrades { - storeUpgrades := storetypes.StoreUpgrades{ - // Set migrations for all new modules - Added: []string{"poolmanager", "delayedack", "denommetadata", "gamm", "incentives", "lockup", "streamer", "epochs", "txfees"}, - } - return &storeUpgrades -} diff --git a/cmd/dymd/cmd/hotfix.go b/cmd/dymd/cmd/hotfix.go deleted file mode 100644 index 7e22fdc7d..000000000 --- a/cmd/dymd/cmd/hotfix.go +++ /dev/null @@ -1,57 +0,0 @@ -package cmd - -import ( - "errors" - "fmt" - - "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/server/types" - "github.com/spf13/cobra" -) - -// InspectCmd dumps app state to JSON. - -func HotfixCmd(appExporter types.AppExporter, appCreator types.AppCreator, defaultNodeHome string) *cobra.Command { - cmd := &cobra.Command{ - Use: "hotfix", - Short: "hotfix db state", - RunE: func(cmd *cobra.Command, args []string) error { - cmd.SetOut(cmd.OutOrStdout()) - cmd.SetErr(cmd.OutOrStderr()) - - serverCtx := server.GetServerContextFromCmd(cmd) - - // use the parsed config to load the block and state store - blockStore, stateStore, err := loadStateAndBlockStore(serverCtx.Config) - if err != nil { - return err - } - defer func() { - _ = blockStore.Close() - _ = stateStore.Close() - }() - - // Read the data from the KVStore - fmt.Println("LOADING STATE") - - state, err := stateStore.Load() - if err != nil { - return err - } - if state.IsEmpty() { - return errors.New("no state found") - } - fmt.Printf("%+v\n", state) - - state.Validators = state.NextValidators.Copy() - - if err := stateStore.Save(state); err != nil { - return fmt.Errorf("failed to save rolled back state: %w", err) - } - - return nil - }, - } - - return cmd -} diff --git a/cmd/dymd/cmd/root.go b/cmd/dymd/cmd/root.go index 03ae1301a..93c331522 100644 --- a/cmd/dymd/cmd/root.go +++ b/cmd/dymd/cmd/root.go @@ -151,7 +151,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig ) rootCmd.AddCommand(InspectCmd(a.appExport, a.newApp, app.DefaultNodeHome)) - rootCmd.AddCommand(HotfixCmd(a.appExport, a.newApp, app.DefaultNodeHome)) // add keybase, auxiliary RPC, query, and tx child commands rootCmd.AddCommand( diff --git a/go.mod b/go.mod index db4b23e94..2e4462512 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.19 require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.2.0 + github.com/cometbft/cometbft-db v0.7.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.15 github.com/cosmos/ibc-go/v6 v6.2.1 @@ -58,7 +59,6 @@ require ( github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/cockroachdb/apd/v2 v2.0.2 // indirect github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect - github.com/cometbft/cometbft-db v0.7.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect @@ -208,7 +208,6 @@ replace ( github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 // use dymension forks - github.com/cosmos/ibc-go/v6 => github.com/dymensionxyz/ibc-go/v6 v6.0.0-rc0.0.20231123152216-df3f798086fa github.com/evmos/ethermint => github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 github.com/osmosis-labs/osmosis/osmomath => github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1 diff --git a/go.sum b/go.sum index 07ed60f1c..abc315a40 100644 --- a/go.sum +++ b/go.sum @@ -388,6 +388,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.6 h1:XY78yEeNPrEYyNCKlqr9chrwoeSDJ0bV2VjocTk//OU= github.com/cosmos/iavl v0.19.6/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/ibc-go/v6 v6.2.1 h1:NiaDXTRhKwf3n9kELD4VRIe5zby1yk1jBvaz9tXTQ6k= +github.com/cosmos/ibc-go/v6 v6.2.1/go.mod h1:XLsARy4Y7+GtAqzMcxNdlQf6lx+ti1e8KcMGv5NIK7A= github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA= github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI= github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= @@ -452,8 +454,6 @@ github.com/dvsekhvalnov/jose2go v1.5.0 h1:3j8ya4Z4kMCwT5nXIKFSV84YS+HdqSSO0VsTQx github.com/dvsekhvalnov/jose2go v1.5.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU= github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3 h1:iAtAivMtJh2Ublnq2KasC7EIa5/gfsff5EJ7kUlnd9A= github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.3/go.mod h1:O2J61ZwM0Vdms6pRa1fb43pwmCuNRctro3AB90WlOc0= -github.com/dymensionxyz/ibc-go/v6 v6.0.0-rc0.0.20231123152216-df3f798086fa h1:LVNWH4Fm3yaaQY+jEhVCZ0zvWen7V5YSNeNF7ZfzECk= -github.com/dymensionxyz/ibc-go/v6 v6.0.0-rc0.0.20231123152216-df3f798086fa/go.mod h1:CY3zh2HLfetRiW8LY6kVHMATe90Wj/UOoY8T6cuB0is= github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1 h1:7Q31g2/pRpyAbxRBlv1hMI5bfOvoCRUtPzdqPhaBDQU= github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1/go.mod h1:2idySYJxP5YfMAEeSeqD8e7fSchfsI4jn7XFHJgNUsM= github.com/dymensionxyz/osmosis/v15 v15.2.0-dymension-v0.4 h1:lDEcbcNvrbvMwrL5ckzGpfAzihc7CFGxZkFtqHNq/hI=