Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA-654] add upgrade handler for v8.0.0 #2395

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 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"

v7_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.0.0"
v7_1_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.1.0"

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

This file was deleted.

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

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

const (
UpgradeName = "v7.1.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
},
}
46 changes: 46 additions & 0 deletions protocol/app/upgrades/v7.1.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v_7_1_0

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types"

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

func initListingModuleState(ctx sdk.Context, listingKeeper listingkeeper.Keeper) {
// Set hard cap on listed markets
err := listingKeeper.SetMarketsHardCap(ctx, 500)
if err != nil {
panic(fmt.Sprintf("failed to set markets hard cap: %s", err))
}

// Set listing vault deposit params
err = listingKeeper.SetListingVaultDepositParams(
ctx,
listingtypes.DefaultParams(),
)
if err != nil {
panic(fmt.Sprintf("failed to set listing vault deposit params: %s", err))
}
}
shrenujb marked this conversation as resolved.
Show resolved Hide resolved

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
listingKeeper listingkeeper.Keeper,
) 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))

initListingModuleState(sdkCtx, listingKeeper)

return mm.RunMigrations(ctx, configurator, vm)
}
}
80 changes: 80 additions & 0 deletions protocol/app/upgrades/v7.1.0/upgrade_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package v_7_1_0_test

import (
"testing"

v_7_1_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.1.0"
listingtypes "github.com/dydxprotocol/v4-chain/protocol/x/listing/types"

"github.com/cosmos/gogoproto/proto"

"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
)
shrenujb marked this conversation as resolved.
Show resolved Hide resolved

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_1_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
postUpgradeListingModuleStateCheck(node, t)
}

func postUpgradeListingModuleStateCheck(node *containertest.Node, t *testing.T) {
// Check that the listing module state has been initialized with the hard cap and default deposit params.
resp, err := containertest.Query(
node,
listingtypes.NewQueryClient,
listingtypes.QueryClient.ListingVaultDepositParams,
&listingtypes.QueryListingVaultDepositParams{},
)
require.NoError(t, err)
require.NotNil(t, resp)

listingVaultDepositParamsResp := listingtypes.QueryListingVaultDepositParamsResponse{}
err = proto.UnmarshalText(resp.String(), &listingVaultDepositParamsResp)
require.NoError(t, err)
require.Equal(t, listingtypes.DefaultParams(), listingVaultDepositParamsResp.Params)

resp, err = containertest.Query(
node,
listingtypes.NewQueryClient,
listingtypes.QueryClient.MarketsHardCap,
&listingtypes.QueryMarketsHardCap{},
)
require.NoError(t, err)
require.NotNil(t, resp)

marketsHardCapResp := listingtypes.QueryMarketsHardCapResponse{}
err = proto.UnmarshalText(resp.String(), &marketsHardCapResp)
require.NoError(t, err)
require.Equal(t, uint32(500), marketsHardCapResp.HardCap)
}
Loading