Skip to content

Commit

Permalink
feat: added testnet upgrade handler for v1.0.4 (#625)
Browse files Browse the repository at this point in the history
## Description
This PR adds an on-chain upgrade handler for the upcoming version `1.0.4`. 
This will be used inside the Morpheus testnet to upgrade it to the same version of the current Desmos mainnet, so that we can later test future mainnet upgrades there as well. 

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### 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)
- [x] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] 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 20, 2021
1 parent 5a82f04 commit e0f404a
Show file tree
Hide file tree
Showing 20 changed files with 540 additions and 32 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/on-chain-upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Test on chain upgrade
# On chain upgrade workflow tests the on-chain upgrade procedure.
# This workflow is run on pushes to master & every Pull Requests where a .go, .mod, .sum have been changed
on:
pull_request:
push:
branches:
- master
jobs:
Cleanup-runs:
runs-on: ubuntu-latest
steps:
- name: Cleanup 🧹
uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"

Perform-upgrade:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
GENESIS_DESMOS_VERSION: "v0.17.7"
GENESIS_URL: "https://raw.githubusercontent.com/RiccardoM/desmos-states/master/morpheus-apollo-22003141.json"
UPGRADE_NAME: "v1.0.4"
UPGRADE_HEIGHT: 50
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Setup Go 🧰
uses: actions/[email protected]
with:
go-version: 1.15

- name: Compute diff 📜
uses: technote-space/get-diff-action@v4
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 $UPGRADE_HEIGHT
if: env.GIT_DIFF
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,4 @@ jobs:
run: |
./contrib/localnet_liveness.sh 100 5 50 localhost
if: env.GIT_DIFF

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# Build
vendor
venv
build
tools/bin/*
examples/build/*
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
-->

# Changelog
## Version 1.0.4
### Changes
- Added the on-chain upgrade handler

## Version 1.0.3
### Bug fixes
- Fixed the help of the `desmos tx profiles save` command
Expand All @@ -28,10 +32,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changes
- Fixed tags not being fetched correctly inside `release` workflow

## Version 0.17.7
### Changes
- Fixed tags not being fetched correctly inside `release` workflow

## Version 0.17.6
### Bug fixes
- Fixed the Cosmos capability issue ([cosmos\#9835](https://github.com/cosmos/cosmos-sdk/pull/9835))
Expand Down
38 changes: 27 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ build: BUILD_ARGS=-o $(BUILDDIR)/
build-linux: go.sum
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build

build-386:go.sum
GOOS=linux GOARCH=386 LEDGER_ENABLED=false $(MAKE) build

build-arm32:go.sum
GOOS=linux GOARCH=arm GOARM=7 LEDGER_ENABLED=false $(MAKE) build

Expand Down Expand Up @@ -261,9 +264,9 @@ lint-fix:
.PHONY: lint lint-fix

format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/desmos-labs/desmos
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -path "./venv" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -path "./venv" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -path "./venv" | xargs goimports -w -local github.com/desmos-labs/desmos
.PHONY: format

###############################################################################
Expand Down Expand Up @@ -379,16 +382,29 @@ proto-update-deps:
build-docker-desmosnode:
$(MAKE) -C networks/local

# Setups 4 folders representing each one the genesis state of a testnet node
setup-localnet: build-linux
if ! [ -f build/node0/desmos/config/genesis.json ]; then $(BUILDDIR)/desmos testnet \
-o ./build --starting-ip-address 192.168.10.2 --keyring-backend=test \
--v=$(if $(NODES),$(NODES),4) \
--gentx-coin-denom=$(if $(COIN_DENOM),$(COIN_DENOM),"stake") \
--minimum-gas-prices="0.000006$(if $(COIN_DENOM),$(COIN_DENOM),"stake")"; fi

# Starts a local 4-nodes testnet that should be used to test on-chain upgrades.
# It requires 3 arguments to work:
# 1. GENESIS_VERSION, which represents the Desmos version to be used when starting the testnet
# 2. GENESIS_URL, which represents the URL from where to download the testnet genesis status
# 3. UPGRADE_NAME, which represents the name of the upgrade to perform
upgrade-testnet-start: upgrade-testnet-stop
$(CURDIR)/contrib/upgrade_testnet/start.sh 4 $(GENESIS_VERSION) $(GENESIS_URL) $(UPGRADE_NAME)

# Stops the 4-nodes testnet that should be used to test on-chain upgrades.
upgrade-testnet-stop:
$(CURDIR)/contrib/upgrade_testnet/stop.sh

# Run a 4-node testnet locally
localnet-start: build-linux localnet-stop
localnet-start: localnet-stop setup-localnet
$(if $(shell docker inspect -f '{{ .Id }}' desmoslabs/desmos-env 2>/dev/null),$(info found image desmoslabs/desmos-env),$(MAKE) -C contrib/images desmos-env)
if ! [ -f build/node0/desmos/config/genesis.json ]; then docker run --rm \
--user $(shell id -u):$(shell id -g) \
-v $(BUILDDIR):/desmos:Z \
-v /etc/group:/etc/group:ro \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/shadow:/etc/shadow:ro \
desmoslabs/desmos-env testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
docker-compose up -d

# Stop testnet
Expand Down
12 changes: 10 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ import (
const (
appName = "Desmos"
Bech32MainPrefix = "desmos"

CoinType = 852
FullFundraiserPath = "44'/852'/0'/0/0"
)

var (
Expand Down Expand Up @@ -302,6 +305,11 @@ func NewDesmosApp(
)
app.upgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath)

// Register the upgrade
app.upgradeKeeper.SetUpgradeHandler("v1.0.4", func(ctx sdk.Context, plan upgradetypes.Plan) {

})

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand Down Expand Up @@ -520,8 +528,8 @@ func SetupConfig(config *sdk.Config) {

// 852 is the international dialing code of Hong Kong
// Following the coin type registered at https://github.com/satoshilabs/slips/blob/master/slip-0044.md
config.SetCoinType(852)
config.SetFullFundraiserPath("44'/852'/0'/0/0")
config.SetCoinType(CoinType)
config.SetFullFundraiserPath(FullFundraiserPath)
}

// MakeCodecs constructs the *std.Codec and *codec.LegacyAmino instances used by
Expand Down
26 changes: 19 additions & 7 deletions app/desmos/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"os"
"path/filepath"

"github.com/desmos-labs/desmos/app"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/spf13/cobra"
tmconfig "github.com/tendermint/tendermint/config"
Expand Down Expand Up @@ -40,6 +42,7 @@ var (
flagOutputDir = "output-dir"
flagNodeDaemonHome = "node-daemon-home"
flagStartingIPAddress = "starting-ip-address"
flagGenTxCoinDenom = "gentx-coin-denom"
)

// get cmd to initialize all files for tendermint testnet and application
Expand All @@ -56,7 +59,10 @@ Example:
desmos testnet --v 4 --output-dir ./output --starting-ip-address 192.168.10.2
`,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

serverCtx := server.GetServerContextFromCmd(cmd)
config := serverCtx.Config
Expand All @@ -68,12 +74,13 @@ Example:
nodeDirPrefix, _ := cmd.Flags().GetString(flagNodeDirPrefix)
nodeDaemonHome, _ := cmd.Flags().GetString(flagNodeDaemonHome)
startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress)
gentxCoinDenom, _ := cmd.Flags().GetString(flagGenTxCoinDenom)
numValidators, _ := cmd.Flags().GetInt(flagNumValidators)
algo, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm)

return InitTestnet(
clientCtx, cmd, config, mbm, genBalIterator, outputDir, chainID, minGasPrices,
nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo, numValidators,
nodeDirPrefix, nodeDaemonHome, startingIPAddress, gentxCoinDenom, keyringBackend, algo, numValidators,
)
},
}
Expand All @@ -83,6 +90,7 @@ Example:
cmd.Flags().String(flagNodeDirPrefix, "node", "Prefix the directory name for each node with (node results in node0, node1, ...)")
cmd.Flags().String(flagNodeDaemonHome, "desmos", "Home directory of the node's daemon configuration")
cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list [email protected]:46656, [email protected]:46656, ...)")
cmd.Flags().String(flagGenTxCoinDenom, sdk.DefaultBondDenom, "Denomination of the coin to be used when generating genesis transactions")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)")
cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|test)")
Expand All @@ -106,6 +114,7 @@ func InitTestnet(
nodeDirPrefix,
nodeDaemonHome,
startingIPAddress,
gentxCoinDenom,
keyringBackend,
algoStr string,
numValidators int,
Expand Down Expand Up @@ -175,7 +184,7 @@ func InitTestnet(
return err
}

addr, secret, err := server.GenerateSaveCoinKey(kb, nodeDirName, true, algo)
addr, secret, err := server.GenerateSaveCoinKeyFromPath(kb, nodeDirName, true, algo, app.FullFundraiserPath)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
Expand All @@ -197,7 +206,7 @@ func InitTestnet(
accStakingTokens := sdk.TokensFromConsensusPower(500)
coins := sdk.Coins{
sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), accTokens),
sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens),
sdk.NewCoin(gentxCoinDenom, accStakingTokens),
}

genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
Expand All @@ -207,7 +216,7 @@ func InitTestnet(
createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
sdk.NewCoin(gentxCoinDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
Expand All @@ -230,7 +239,7 @@ func InitTestnet(
WithKeybase(kb).
WithTxConfig(clientCtx.TxConfig)

if err := tx.Sign(txFactory, nodeDirName, txBuilder, false); err != nil {
if err := tx.Sign(txFactory, nodeDirName, txBuilder, true); err != nil {
return err
}

Expand Down Expand Up @@ -286,7 +295,10 @@ func initGenFiles(
var bankGenState banktypes.GenesisState
clientCtx.JSONMarshaler.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)

bankGenState.Balances = genBalances
bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances)
for _, bal := range bankGenState.Balances {
bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...)
}
appGenState[banktypes.ModuleName] = clientCtx.JSONMarshaler.MustMarshalJSON(&bankGenState)

appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")
Expand Down
19 changes: 16 additions & 3 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
all: desmos-env

desmos-env:
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag desmoslabs/desmos-env desmos-env

.PHONY: all desmos-env
desmos-build:
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag desmoslabs/desmos-build desmos-build

desmos-python:
docker build --tag desmoslabs/desmos-python desmos-python

desmos-cosmovisor:
docker build \
--build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) \
--build-arg DESMOS_VERSION=$(DESMOS_VERSION) \
--tag desmoslabs/desmos-cosmovisor:$(DESMOS_VERSION) \
desmos-cosmovisor

all: desmos-env desmos-python desmos-cosmovisor desmos-build

.PHONY: all desmos-env desmos-python desmos-cosmovisor desmos-build
18 changes: 18 additions & 0 deletions contrib/images/desmos-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.15-alpine

# Set up dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --no-cache $PACKAGES

ARG UID=1000
ARG GID=1000
USER ${UID}:${GID}

# Fixes build errors. Required since Go 1.12 (https://github.com/golang/go/issues/26280#issuecomment-445294378)
ENV GOPATH /tmp/go
ENV GOCACHE /tmp/.cache

VOLUME [ "/desmos" ]
WORKDIR /desmos

CMD ["sh"]
30 changes: 30 additions & 0 deletions contrib/images/desmos-cosmovisor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG DESMOS_VERSION="v0.17.2"
FROM golang:1.15-alpine AS build-env

ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --no-cache $PACKAGES

ENV GOBIN /go/bin

# Set working directory for the build
WORKDIR /go/src/github.com/cosmos/cosmos-sdk
RUN git clone https://github.com/cosmos/cosmos-sdk.git /go/src/github.com/cosmos/cosmos-sdk
RUN cd /go/src/github.com/cosmos/cosmos-sdk
RUN make cosmovisor

# Final image
FROM desmoslabs/desmos:$DESMOS_VERSION

# Copy over binaries from the build-env
COPY --from=build-env /go/src/github.com/cosmos/cosmos-sdk/cosmovisor/cosmovisor /usr/bin/cosmovisor

ARG UID=1000
ARG GID=1000
USER ${UID}:${GID}

COPY wrapper.sh /usr/bin/wrapper.sh
ENTRYPOINT ["bash", "/usr/bin/wrapper.sh"]

# Run cosmovisor by default, omit entrypoint to ease using container with Desmos
CMD ["cosmovisor"]
STOPSIGNAL SIGTERM
Loading

0 comments on commit e0f404a

Please sign in to comment.