Skip to content

Commit

Permalink
Add v5 upgrade handler and set up container upgrade test (dydxproto…
Browse files Browse the repository at this point in the history
…col#1153)

* wip

* update preupgrade_genesis

* fix preupgrade_genesis.json

* nit

* setupUpgradeStoreLoaders for v5.0.0

Signed-off-by: Eric <eric.warehime@gmail.com>
  • Loading branch information
teddyding authored and Eric-Warehime committed Mar 12, 2024
1 parent b7942b3 commit 2a062b1
Show file tree
Hide file tree
Showing 8 changed files with 2,155 additions and 2,155 deletions.
13 changes: 6 additions & 7 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,29 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
v4_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v4.0.0"
v5_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v5.0.0"
)

var (
// `Upgrades` defines the upgrade handlers and store loaders for the application.
// New upgrades should be added to this slice after they are implemented.
Upgrades = []upgrades.Upgrade{
v4_0_0.Upgrade,
v5_0_0.Upgrade,
}
Forks = []upgrades.Fork{}
)

// setupUpgradeHandlers registers the upgrade handlers to perform custom upgrade
// logic and state migrations for software upgrades.
func (app *App) setupUpgradeHandlers() {
if app.UpgradeKeeper.HasHandler(v4_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v4_0_0.UpgradeName))
if app.UpgradeKeeper.HasHandler(v5_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v5_0_0.UpgradeName))
}
app.UpgradeKeeper.SetUpgradeHandler(
v4_0_0.UpgradeName,
v4_0_0.CreateUpgradeHandler(
v5_0_0.UpgradeName,
v5_0_0.CreateUpgradeHandler(
app.ModuleManager,
app.configurator,
app.RatelimitKeeper,
),
)
}
Expand Down
21 changes: 21 additions & 0 deletions protocol/app/upgrades/v5.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v_5_0_0

import (
store "cosmossdk.io/store/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"

vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
)

const (
UpgradeName = "v5.0.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
vaulttypes.StoreKey,
},
},
}
24 changes: 24 additions & 0 deletions protocol/app/upgrades/v5.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v_5_0_0

import (
"context"
"fmt"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/dydxprotocol/v4-chain/protocol/lib"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades")
sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName))

// TODO(TRA-93): Initialize `x/vault` module.

return mm.RunMigrations(ctx, configurator, vm)
}
}
18 changes: 12 additions & 6 deletions protocol/testing/containertest/containertest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set -eo pipefail
source "./genesis.sh"

CHAIN_ID="localdydxprotocol"
PREUPGRADE_VERSION="v4.0.0-rc1"

# Define mnemonics for all validators.
MNEMONICS=(
Expand Down Expand Up @@ -153,22 +154,27 @@ setup_cosmovisor() {
done
}

copy_preupgrade_binary_arch() {
download_preupgrade_binary() {
arch="$(apk --print-arch)"
file_arch=""
url_arch=""
case "$arch" in
'x86_64')
file_arch='amd64'
url_arch='amd64'
;;
'aarch64')
file_arch='arm64'
url_arch='arm64'
;;
*)
echo >&2 "unexpected architecture '$arch'"
exit 1
;;
esac
cp /bin/dydxprotocold_preupgrade_${file_arch} /bin/dydxprotocold_preupgrade
tar_url="https://github.com/dydxprotocol/v4-chain/releases/download/protocol%2F$PREUPGRADE_VERSION/dydxprotocold-$PREUPGRADE_VERSION-linux-$url_arch.tar.gz"
tar_path='/tmp/dydxprotocold/dydxprotocold.tar.gz'
mkdir -p /tmp/dydxprotocold
curl -vL $tar_url -o $tar_path
dydxprotocold_path=$(tar -xvf $tar_path --directory /tmp/dydxprotocold)
cp /tmp/dydxprotocold/$dydxprotocold_path /bin/dydxprotocold_preupgrade
}

# TODO(DEC-1894): remove this function once we migrate off of persistent peers.
Expand All @@ -187,5 +193,5 @@ edit_config() {

install_prerequisites
setup_cosmovisor
copy_preupgrade_binary_arch
download_preupgrade_binary
create_validators
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 2a062b1

Please sign in to comment.