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 4 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"
v8_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v8.0.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,
v8_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(v7_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v7_0_0.UpgradeName))
if app.UpgradeKeeper.HasHandler(v8_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v8_0_0.UpgradeName))
}
app.UpgradeKeeper.SetUpgradeHandler(
v7_0_0.UpgradeName,
v7_0_0.CreateUpgradeHandler(
v8_0_0.UpgradeName,
v8_0_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/v8.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v_8_0_0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Inconsistent Upgrade Version in constants.go

The UpgradeName constant in protocol/app/upgrades/v8.0.0/constants.go is set to "v7.1.0", which does not align with the package name v_8_0_0 and the directory path v8.0.0. Please update the UpgradeName to "v8.0.0" to ensure consistency across the codebase.

🔗 Analysis chain

Verify package name consistency with upgrade version

The package name v_8_0_0 and file path v8.0.0 suggest this is for version 8.0.0, but the UpgradeName constant (line 9) is set to "v7.1.0". Please ensure that the package name, file path, and upgrade version are consistent throughout the file and the entire upgrade process.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for inconsistencies in upgrade version across the codebase

# Test 1: Search for occurrences of both v7.1.0 and v8.0.0 in the upgrades directory
echo "Searching for v7.1.0 and v8.0.0 in upgrades directory:"
rg --type go -e "v7\.1\.0" -e "v8\.0\.0" protocol/app/upgrades

# Test 2: Check if there's a v7.1.0 directory in the upgrades folder
echo "Checking for v7.1.0 directory:"
fd -t d "v7.1.0" protocol/app/upgrades

# Test 3: Verify the upgrade name in other files referencing this upgrade
echo "Checking upgrade name references:"
rg --type go "UpgradeName.*v[78]\.1\.0" protocol/app

Length of output: 784


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

const (
UpgradeName = "v7.1.0"
)
shrenujb marked this conversation as resolved.
Show resolved Hide resolved

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
},
}
46 changes: 46 additions & 0 deletions protocol/app/upgrades/v8.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v_8_0_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))
}
}

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)
}
}
82 changes: 82 additions & 0 deletions protocol/app/upgrades/v8.0.0/upgrade_container_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//go:build all || container_test

package v_8_0_0_test

import (
"testing"

v_8_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v7.1.0"
shrenujb marked this conversation as resolved.
Show resolved Hide resolved
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
)

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_8_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
postUpgradeListingModuleStateCheck(node, t)
}
shrenujb marked this conversation as resolved.
Show resolved Hide resolved

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