Skip to content

Commit

Permalink
Migration for v1.0.3 upgrade (#115)
Browse files Browse the repository at this point in the history
* Setup chain upgrade handler

* Set store loader with default upgrades

* Add migrator

* Resolve cycle import

* Missing interface

* Remove unused code

* Refactor issuer creator, return issuer creator in query response

* Remove unused variable
  • Loading branch information
deep-quality-dev authored Jul 17, 2024
1 parent 1ac9c78 commit 765aa23
Show file tree
Hide file tree
Showing 32 changed files with 4,080 additions and 537 deletions.
97 changes: 58 additions & 39 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,35 @@ import (

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"github.com/cosmos/cosmos-sdk/runtime"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"

"swisstronik/x/evm"
"swisstronik/x/feemarket"

"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
"github.com/cosmos/cosmos-sdk/x/group"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"

simappparams "cosmossdk.io/simapp/params"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
"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"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"
"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"
Expand All @@ -54,6 +47,9 @@ import (
"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/consensus"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
Expand All @@ -74,7 +70,7 @@ 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"

"github.com/cosmos/cosmos-sdk/x/group"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand Down Expand Up @@ -114,36 +110,30 @@ import (
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

vestingmodule "swisstronik/x/vesting"
vestingmodulekeeper "swisstronik/x/vesting/keeper"
vestingmoduletypes "swisstronik/x/vesting/types"

compliancemodule "swisstronik/x/compliance"
compliancemoduleclient "swisstronik/x/compliance/client"
compliancemodulekeeper "swisstronik/x/compliance/keeper"
compliancemoduletypes "swisstronik/x/compliance/types"

evmante "swisstronik/app/ante"
"swisstronik/app/upgrades/v1_0_3"
"swisstronik/docs"
"swisstronik/encoding"

simappparams "cosmossdk.io/simapp/params"

evmante "swisstronik/app/ante"
"swisstronik/ethereum/eip712"
srvflags "swisstronik/server/flags"
evmcommontypes "swisstronik/types"
compliancemodule "swisstronik/x/compliance"
compliancemoduleclient "swisstronik/x/compliance/client"
compliancemodulekeeper "swisstronik/x/compliance/keeper"
compliancemoduletypes "swisstronik/x/compliance/types"
"swisstronik/x/evm"
evmkeeper "swisstronik/x/evm/keeper"
evmtypes "swisstronik/x/evm/types"
"swisstronik/x/feemarket"
feemarketkeeper "swisstronik/x/feemarket/keeper"
feemarkettypes "swisstronik/x/feemarket/types"

"swisstronik/ethereum/eip712"

"github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
vestingmodule "swisstronik/x/vesting"
vestingmodulekeeper "swisstronik/x/vesting/keeper"
vestingmoduletypes "swisstronik/x/vesting/types"
)

const (
Expand Down Expand Up @@ -803,7 +793,7 @@ func New(
app.setAnteHandler(encodingConfig.TxConfig, maxGasWanted)
app.setPostHandler()
app.SetEndBlocker(app.EndBlocker)
SetupHandlers(app, app.EvmKeeper, app.IBCKeeper.ClientKeeper, app.ParamsKeeper, appCodec)
app.setupUpgradeHandlers()

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
Expand Down Expand Up @@ -1068,6 +1058,35 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
return paramsKeeper
}

func (app *App) setupUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler(
v1_0_3.UpgradeName,
v1_0_3.CreateUpgradeHandler(
app.mm, app.configurator,
),
)

// 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))
}

if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

if upgradeInfo.Name == v1_0_3.UpgradeName {
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
// so that new stores start with the correct version (the current height of chain),
// instead the default which is the latest version that store last committed i.e 0 for new stores.
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storetypes.StoreUpgrades{}))
}
}

// SimulationManager implements runtime.AppI
func (*App) SimulationManager() *module.SimulationManager {
panic("unimplemented")
Expand Down
153 changes: 0 additions & 153 deletions app/setup_handler.go

This file was deleted.

5 changes: 5 additions & 0 deletions app/upgrades/v1_0_3/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v1_0_3

const (
UpgradeName = "v1.0.3"
)
24 changes: 24 additions & 0 deletions app/upgrades/v1_0_3/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v1_0_3

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Starting module migrations...")

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("Upgrade complete")
return vm, err
}
}
3 changes: 3 additions & 0 deletions proto/swisstronik/compliance/entities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ message OperatorDetails {
message IssuerDetails {
// Allows to easily understand
// what entity can be associated with issuer address.
// Issuer name
string name = 1;
// Basic issuer description
string description = 2;
Expand All @@ -49,6 +50,8 @@ message IssuerDetails {
string logo = 4;
// Legal entity name
string legalEntity = 5;
// Issuer creator who created current issuer
string creator = 6;
}

message AddressDetails {
Expand Down
3 changes: 1 addition & 2 deletions proto/swisstronik/compliance/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ message GenesisState {

message GenesisIssuerDetails {
string address = 1;
string creator = 2;
IssuerDetails details = 3;
IssuerDetails details = 2;
}

message GenesisAddressDetails {
Expand Down
1 change: 1 addition & 0 deletions proto/swisstronik/compliance/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ message QueryIssuersDetailsResponse {
string url = 4;
string logo = 5;
string legalEntity = 6;
string creator = 7;
}

// issuers is a slice of registered issuers for the compliance module
Expand Down
Loading

0 comments on commit 765aa23

Please sign in to comment.