Skip to content

Commit

Permalink
add v7 upgrade handler (#2106)
Browse files Browse the repository at this point in the history
(cherry picked from commit fedf6e4)

# Conflicts:
#	protocol/testing/version/VERSION_CURRENT
#	protocol/testing/version/VERSION_FULL_NAME_PREUPGRADE
#	protocol/testing/version/VERSION_PREUPGRADE
  • Loading branch information
affanv14 authored and mergify[bot] committed Aug 20, 2024
1 parent 39e1921 commit f22cc2f
Show file tree
Hide file tree
Showing 9 changed files with 2,442 additions and 534 deletions.
17 changes: 6 additions & 11 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package app
import (
"fmt"

v6_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v6.0.0"
v7_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.0.0"

upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,27 +14,22 @@ 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{
v6_0_0.Upgrade,
v7_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(v6_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v6_0_0.UpgradeName))
if app.UpgradeKeeper.HasHandler(v7_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v7_0_0.UpgradeName))
}
app.UpgradeKeeper.SetUpgradeHandler(
v6_0_0.UpgradeName,
v6_0_0.CreateUpgradeHandler(
v7_0_0.UpgradeName,
v7_0_0.CreateUpgradeHandler(
app.ModuleManager,
app.configurator,
app.ClobKeeper,
app.PricesKeeper,
app.MarketMapKeeper,
app.RevShareKeeper,
app.VaultKeeper,
),
)
}
Expand Down
266 changes: 0 additions & 266 deletions protocol/app/upgrades/v6.0.0/upgrade_container_test.go

This file was deleted.

13 changes: 13 additions & 0 deletions protocol/app/upgrades/v7.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package v_7_0_0

import (
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
)

const (
UpgradeName = "v7.0.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
}
17 changes: 17 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v_7_0_0

import (
"context"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/types/module"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}
47 changes: 47 additions & 0 deletions protocol/app/upgrades/v7.0.0/upgrade_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//go:build all || container_test

package v_7_0_0_test

import (
"testing"

v_7_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.0.0"
"github.com/dydxprotocol/v4-chain/protocol/testing/containertest"
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
"github.com/stretchr/testify/require"
)

const (
AliceBobBTCQuantums = 1_000_000
CarlDaveBTCQuantums = 2_000_000
CarlDaveETHQuantums = 4_000_000
)

func TestStateUpgrade(t *testing.T) {
testnet, err := containertest.NewTestnetWithPreupgradeGenesis()
require.NoError(t, err, "failed to create testnet - is docker daemon running?")
err = testnet.Start()
require.NoError(t, err)
defer testnet.MustCleanUp()
node := testnet.Nodes["alice"]
nodeAddress := constants.AliceAccAddress.String()

preUpgradeSetups(node, t)
preUpgradeChecks(node, t)

err = containertest.UpgradeTestnet(nodeAddress, t, node, v_7_0_0.UpgradeName)
require.NoError(t, err)

postUpgradeChecks(node, t)
}

func preUpgradeSetups(node *containertest.Node, t *testing.T) {
}

func preUpgradeChecks(node *containertest.Node, t *testing.T) {
// Add test for your upgrade handler logic below
}

func postUpgradeChecks(node *containertest.Node, t *testing.T) {
// Add test for your upgrade handler logic below
}
Loading

0 comments on commit f22cc2f

Please sign in to comment.