Skip to content

Commit

Permalink
feat: v2.0.0 upgrade (#629)
Browse files Browse the repository at this point in the history
## Description
Adds the on-chain upgrade handler for the upcoming version 2.0 of Desmos

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [x] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
RiccardoM authored Sep 27, 2021
1 parent 1a22342 commit d6e42b6
Show file tree
Hide file tree
Showing 14 changed files with 4,262 additions and 36 deletions.
19 changes: 4 additions & 15 deletions .github/workflows/on-chain-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
GENESIS_DESMOS_VERSION: "v0.17.2"
GENESIS_URL: "https://raw.githubusercontent.com/desmos-labs/morpheus/master/morpheus-apollo-2/genesis.json"
UPGRADE_NAME: "desmos-v0.17.4-upgrade"
GENESIS_DESMOS_VERSION: "v1.0.4"
GENESIS_URL: "https://raw.githubusercontent.com/RiccardoM/desmos-states/master/morpheus-apollo-22003141.json"
UPGRADE_NAME: "v2.0.0"
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
Expand All @@ -34,27 +34,16 @@ jobs:
with:
go-version: 1.15

- name: Compute diff 📜
uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Install Desmos 🔧
run: make clean install
if: env.GIT_DIFF

- name: Start testnet ⛓
run: |
make upgrade-testnet-start \
GENESIS_VERSION="$GENESIS_DESMOS_VERSION" \
GENESIS_URL="$GENESIS_URL" \
UPGRADE_NAME="$UPGRADE_NAME"
if: env.GIT_DIFF
- name: Submit upgrade ✅
run: |
./contrib/upgrade_testnet/submit_upgrade_proposal.sh 4 $UPGRADE_NAME 50
if: env.GIT_DIFF
./contrib/upgrade_testnet/submit_upgrade_proposal.sh 4 $UPGRADE_NAME 50
50 changes: 48 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ import (
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand Down Expand Up @@ -324,6 +326,7 @@ func NewDesmosApp(

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.upgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
app.registerUpgradeHandlers()

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand Down Expand Up @@ -369,7 +372,7 @@ func NewDesmosApp(
&app.IBCKeeper.PortKeeper,
scopedProfilesKeeper,
)
profilesModule := profiles.NewAppModule(appCodec, app.ProfileKeeper, app.AccountKeeper, app.BankKeeper)
profilesModule := profiles.NewAppModule(appCodec, legacyAmino, app.ProfileKeeper, app.AccountKeeper, app.BankKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
Expand Down Expand Up @@ -500,7 +503,7 @@ func NewDesmosApp(
// Custom modules
//fees.NewAppModule(app.FeesKeeper, app.AccountKeeper),
//posts.NewAppModule(app.appCodec, app.postsKeeper, app.AccountKeeper, app.BankKeeper),
profiles.NewAppModule(app.appCodec, app.ProfileKeeper, app.AccountKeeper, app.BankKeeper),
profiles.NewAppModule(app.appCodec, legacyAmino, app.ProfileKeeper, app.AccountKeeper, app.BankKeeper),
//subspaces.NewAppModule(app.appCodec, app.SubspaceKeeper, app.AccountKeeper, app.BankKeeper),
)

Expand Down Expand Up @@ -686,6 +689,49 @@ func (app *DesmosApp) RegisterTendermintService(clientCtx client.Context) {
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
}

func (app *DesmosApp) registerUpgradeHandlers() {
app.upgradeKeeper.SetUpgradeHandler("v2.0.0", func(ctx sdk.Context, plan upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) {
// 1st-time running in-store migrations, using 1 as fromVersion to
// avoid running InitGenesis.
fromVM := map[string]uint64{
authtypes.ModuleName: 1,
banktypes.ModuleName: 1,
capabilitytypes.ModuleName: 1,
crisistypes.ModuleName: 1,
distrtypes.ModuleName: 1,
evidencetypes.ModuleName: 1,
govtypes.ModuleName: 1,
minttypes.ModuleName: 1,
paramstypes.ModuleName: 1,
slashingtypes.ModuleName: 1,
stakingtypes.ModuleName: 1,
upgradetypes.ModuleName: 1,
vestingtypes.ModuleName: 1,
ibchost.ModuleName: 1,
genutiltypes.ModuleName: 1,
ibctransfertypes.ModuleName: 1,

profilestypes.ModuleName: 1,
}

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if upgradeInfo.Name == "v2.0.0" && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{authz.ModuleName, feegrant.ModuleName},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
Expand Down
8 changes: 4 additions & 4 deletions contrib/upgrade_testnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
desmosnode0:
container_name: desmosnode0
image: "desmoslabs/desmos-cosmovisor:v0.17.2"
image: "desmoslabs/desmos-cosmovisor:v1.0.4"
command: "start"
ports:
- "26656-26657:26656-26657"
Expand All @@ -19,7 +19,7 @@ services:

desmosnode1:
container_name: desmosnode1
image: "desmoslabs/desmos-cosmovisor:v0.17.2"
image: "desmoslabs/desmos-cosmovisor:v1.0.4"
command: "start"
ports:
- "26666-26667:26656-26657"
Expand All @@ -35,7 +35,7 @@ services:

desmosnode2:
container_name: desmosnode2
image: "desmoslabs/desmos-cosmovisor:v0.17.2"
image: "desmoslabs/desmos-cosmovisor:v1.0.4"
command: "start"
ports:
- "26676-26677:26656-26657"
Expand All @@ -51,7 +51,7 @@ services:

desmosnode3:
container_name: desmosnode3
image: "desmoslabs/desmos-cosmovisor:v0.17.2"
image: "desmoslabs/desmos-cosmovisor:v1.0.4"
command: "start"
ports:
- "26686-26687:26656-26657"
Expand Down
4 changes: 2 additions & 2 deletions contrib/upgrade_testnet/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rm -r -f $BUILDDIR

# Create the 4 nodes folders with the correct denom
echo "===> Creating $NODES nodes localnet"
make setup-localnet COIN_DENOM="udaric" NODES=$NODES > /dev/null > 2 &> 1
make setup-localnet COIN_DENOM="udaric" NODES=$NODES > /dev/null > /dev/null

# Run the Python script to setup the genesis
echo "===> Setting up the genesis file"
Expand All @@ -34,7 +34,7 @@ sed -i "s|image: \".*\"|image: \"desmoslabs/desmos-cosmovisor:$GENESIS_VERSION\"

# Build the current code using Alpine to make sure it's later compatible with the devnet
echo "===> Building Desmos"
docker run --rm --user $ID:$GID -v $(pwd):/desmos desmoslabs/desmos-build make build-linux > /dev/null > 2 &> 1
docker run --rm --user $ID:$GID -v $(pwd):/desmos desmoslabs/desmos-build make build-linux > /dev/null

# Copy the Desmos binary into the proper folders
UPGRADE_FOLDER="$BUILDDIR/node0/desmos/cosmovisor/upgrades/$UPGRADE_NAME/bin"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (

replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

replace github.com/cosmos/cosmos-sdk => github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210906075223-32780842edff
replace github.com/cosmos/cosmos-sdk => github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210927075512-e26bf1014f50

replace google.golang.org/grpc => google.golang.org/grpc v1.33.2

Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x
github.com/cosmos/iavl v0.15.0-rc3.0.20201009144442-230e9bdf52cd/go.mod h1:3xOIaNNX19p0QrX0VqWa6voPRoJRGGYtny+DH8NEPvE=
github.com/cosmos/iavl v0.15.0-rc5/go.mod h1:WqoPL9yPTQ85QBMT45OOUzPxG/U/JcJoN7uMjgxke/I=
github.com/cosmos/iavl v0.15.3/go.mod h1:OLjQiAQ4fGD2KDZooyJG9yz+p2ao2IAYSbke8mVvSA4=
github.com/cosmos/iavl v0.16.0 h1:ICIOB8xysirTX27GmVAaoeSpeozzgSu9d49w36xkVJA=
github.com/cosmos/iavl v0.16.0/go.mod h1:2A8O/Jz9YwtjqXMO0CjnnbTYEEaovE8jWcwrakH3PoE=
github.com/cosmos/iavl v0.17.1 h1:b/Cl8h1PRMvsu24+TYNlKchIu7W6tmxIBGe6E9u2Ybw=
github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwROUxFk=
github.com/cosmos/ibc-go v1.2.0 h1:0RgxmKzCzIH9SwDp4ckL5VrzlO1KJ5hO0AsOAzOiWE4=
github.com/cosmos/ibc-go v1.2.0/go.mod h1:wGjeNd+T4kpGrt0OC8DTiE/qXLrlmTPNpdoYsBZUjKI=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
Expand All @@ -213,8 +213,8 @@ github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE=
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f h1:gUywWy8Pw1ROmF4o/qLy/FP1bEyEtjPg6a/RgdXmcCA=
github.com/desmos-labs/Go-Emoji-Utils v1.1.1-0.20210623064146-c30bc8196d0f/go.mod h1:5TMhouV+kDGQZZrBK+rzBP+Jmeyu0V7WvrBHqukiTv8=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210906075223-32780842edff h1:qU2BNu0sp6lQq3HoMT96cpj3M3Qyo/UGRqlM7T8Kw1E=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210906075223-32780842edff/go.mod h1:orG0jzFJ2KsDfzLd/X0JSOMzF4Oxc/BQz2GkcYF4gRE=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210927075512-e26bf1014f50 h1:aHMy8n0itEDKqMIAnjdNJ2L8SMzBgqTx0TXzDVYKCOc=
github.com/desmos-labs/cosmos-sdk v0.43.0-alpha1.0.20210927075512-e26bf1014f50/go.mod h1:2Gy2237TJhvo7vcn+r8hovzipVaLj51Mjtuw9eyzWEU=
github.com/desmos-labs/ledger-desmos-go v0.11.2-0.20210814121638-5d87e392e8a9 h1:b77qmphsyX3+hjJraaqLyzjt9eKqbosy4LaYScPvTAs=
github.com/desmos-labs/ledger-desmos-go v0.11.2-0.20210814121638-5d87e392e8a9/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/dgraph-io/badger/v2 v2.2007.1/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE=
Expand Down Expand Up @@ -826,8 +826,6 @@ github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoM
github.com/tendermint/tendermint v0.34.0-rc4/go.mod h1:yotsojf2C1QBOw4dZrTcxbyxmPUrT4hNuOQWX9XUwB4=
github.com/tendermint/tendermint v0.34.0-rc6/go.mod h1:ugzyZO5foutZImv0Iyx/gOFCX6mjJTgbLHTwi17VDVg=
github.com/tendermint/tendermint v0.34.0/go.mod h1:Aj3PIipBFSNO21r+Lq3TtzQ+uKESxkbA3yo/INM4QwQ=
github.com/tendermint/tendermint v0.34.10/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
github.com/tendermint/tendermint v0.34.12/go.mod h1:aeHL7alPh4uTBIJQ8mgFEE8VwJLXI1VD3rVOmH2Mcy0=
github.com/tendermint/tendermint v0.34.13 h1:fu+tsHudbOr5PvepjH0q47Jae59hQAvn3IqAHv2EbC8=
github.com/tendermint/tendermint v0.34.13/go.mod h1:6RVVRBqwtKhA+H59APKumO+B7Nye4QXSFc6+TYxAxCI=
github.com/tendermint/tm-db v0.6.2/go.mod h1:GYtQ67SUvATOcoY8/+x6ylk8Qo02BQyLrAs+yAcLvGI=
Expand Down
155 changes: 155 additions & 0 deletions proto/desmos/profiles/legacy/v100/models_app_links.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
syntax = "proto3";
package desmos.profiles.legacy.v100;

option go_package = "github.com/desmos-labs/desmos/x/profiles/legacy/v100";

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";

// ApplicationLink contains the data of a link to a centralized application
message ApplicationLink {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

// User to which the link is associated
string user = 1 [ (gogoproto.moretags) = "yaml:\"user\"" ];

// Data contains the details of this specific link
Data data = 2
[ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"data\"" ];

// State of the link
ApplicationLinkState state = 3 [ (gogoproto.moretags) = "yaml:\"state\"" ];

// OracleRequest represents the request that has been made to the oracle
OracleRequest oracle_request = 4 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"oracle_request\""
];

// Data coming from the result of the verification.
// Only available when the state is STATE_SUCCESS
Result result = 5 [ (gogoproto.moretags) = "yaml:\"result\"" ];

// CreationTime represents the time in which the link was created
google.protobuf.Timestamp creation_time = 6 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"creation_time\""
];
}

// Data contains the data associated to a specific user of a
// generic centralized application
message Data {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

// The application name (eg. Twitter, GitHub, etc)
string application = 1 [ (gogoproto.moretags) = "yaml:\"application\"" ];
// Username on the application (eg. Twitter tag, GitHub profile, etc)
string username = 2 [ (gogoproto.moretags) = "yaml:\"username\"" ];
}

// OracleRequest represents a generic oracle request used to
// verify the ownership of a centralized application account
message OracleRequest {
option (gogoproto.goproto_getters) = false;

option (gogoproto.equal) = true;

// ID is the ID of the request
int64 id = 1
[ (gogoproto.customname) = "ID", (gogoproto.moretags) = "yaml:\"id\"" ];

// OracleScriptID is ID of an oracle script
int64 oracle_script_id = 2 [
(gogoproto.customname) = "OracleScriptID",
(gogoproto.moretags) = "yaml:\"oracle_script_id\""
];

// CallData contains the data used to perform the oracle request
CallData call_data = 3 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"call_data\""
];

// ClientID represents the ID of the client that has called the oracle script
string client_id = 4 [
(gogoproto.customname) = "ClientID",
(gogoproto.moretags) = "yaml:\"client_id\""
];

// CallData contains the data sent to a single oracle request in order to
// verify the ownership of a centralized application by a Desmos profile
message CallData {
option (gogoproto.equal) = true;

// The application for which the ownership should be verified
string application = 1 [ (gogoproto.moretags) = "yaml:\"application\"" ];

// The hex encoded call data that should be used to verify the application
// account ownership
string call_data = 2 [ (gogoproto.moretags) = "yaml:\"call_data\"" ];
}
}

// ApplicationLinkState defines if an application link is in the following
// states: STARTED, ERRORED, SUCCESSFUL, TIMED_OUT
enum ApplicationLinkState {
option (gogoproto.goproto_enum_prefix) = false;

// A link has just been initialized
APPLICATION_LINK_STATE_INITIALIZED_UNSPECIFIED = 0
[ (gogoproto.enumvalue_customname) = "ApplicationLinkStateInitialized" ];
// A link has just started being verified
APPLICATION_LINK_STATE_VERIFICATION_STARTED = 1
[ (gogoproto.enumvalue_customname) = "AppLinkStateVerificationStarted" ];
// A link has errored during the verification process
APPLICATION_LINK_STATE_VERIFICATION_ERROR = 2
[ (gogoproto.enumvalue_customname) = "AppLinkStateVerificationError" ];
// A link has being verified successfully
APPLICATION_LINK_STATE_VERIFICATION_SUCCESS = 3
[ (gogoproto.enumvalue_customname) = "AppLinkStateVerificationSuccess" ];
// A link has timed out while waiting for the verification
APPLICATION_LINK_STATE_TIMED_OUT = 4
[ (gogoproto.enumvalue_customname) = "AppLinkStateVerificationTimedOut" ];
}

// Result represents a verification result
message Result {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

// sum is the oneof that specifies whether this represents a success or
// failure result
oneof sum {
// Success represents a successful verification
Success success = 1;

// Failed represents a failed verification
Failed failed = 2;
}

// Success is the result of an application link that has been successfully
// verified
message Success {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

// Value that has be signed by the profile
string value = 1 [ (gogoproto.moretags) = "yaml:\"value\"" ];
// Signature that has been produced by signing the value
string signature = 2 [ (gogoproto.moretags) = "yaml:\"signature\"" ];
}

// Failed is the result of an application link that has not been verified
// successfully
message Failed {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

// Error that is associated with the failure
string error = 1 [ (gogoproto.moretags) = "yaml:\"error\"" ];
}
}
Loading

0 comments on commit d6e42b6

Please sign in to comment.