-
Notifications
You must be signed in to change notification settings - Fork 170
Upgrade handler 9.4 #3164
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
base: main
Are you sure you want to change the base?
Upgrade handler 9.4 #3164
Changes from 6 commits
1f887cf
4317e31
b9f1c87
2853bc6
8b25fad
17ff22e
5ab4846
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package v_9_4 | ||
|
|
||
| import ( | ||
| store "cosmossdk.io/store/types" | ||
| "github.com/dydxprotocol/v4-chain/protocol/app/upgrades" | ||
| affiliatetypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types" | ||
| ) | ||
|
|
||
| const ( | ||
| UpgradeName = "v9.4" | ||
| ) | ||
|
|
||
| var ( | ||
| Upgrade = upgrades.Upgrade{ | ||
| UpgradeName: UpgradeName, | ||
| StoreUpgrades: store.StoreUpgrades{}, | ||
| } | ||
|
|
||
| PreviousAffilliateTiers = affiliatetypes.AffiliateTiers{ | ||
| Tiers: []affiliatetypes.AffiliateTiers_Tier{ | ||
| { | ||
| ReqReferredVolumeQuoteQuantums: 0, | ||
| ReqStakedWholeCoins: 0, | ||
| TakerFeeSharePpm: 50_000, | ||
| }, | ||
| { | ||
| ReqReferredVolumeQuoteQuantums: 1_000_000_000_000, // 1M volume | ||
| ReqStakedWholeCoins: 200, | ||
| TakerFeeSharePpm: 100_000, | ||
| }, | ||
| { | ||
| ReqReferredVolumeQuoteQuantums: 5_000_000_000_000, // 5M volume | ||
| ReqStakedWholeCoins: 1_000, | ||
| TakerFeeSharePpm: 125_000, | ||
| }, | ||
| { | ||
| ReqReferredVolumeQuoteQuantums: 25_000_000_000_000, // 25M volume | ||
| ReqStakedWholeCoins: 5_000, | ||
| TakerFeeSharePpm: 150_000, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| PreviousAffiliateParameters = affiliatetypes.AffiliateParameters{ | ||
| Maximum_30DAffiliateRevenuePerReferredUserQuoteQuantums: 1_000_000_000_000, // 10M volume | ||
| RefereeMinimumFeeTierIdx: 1, | ||
| Maximum_30DAttributableVolumePerReferredUserQuoteQuantums: 1_000_000_000, // 10k volume | ||
| } | ||
|
Comment on lines
+44
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainAlign numeric literals with comments and units (quote quantums). “10M volume” vs 1_000_000_000_000 and “10k volume” vs 1_000_000_000 are inconsistent if 1 unit = 1e6 quote quantums. Pick one:
- Maximum_30DAffiliateRevenuePerReferredUserQuoteQuantums: 1_000_000_000_000, // 10M volume
+ Maximum_30DAffiliateRevenuePerReferredUserQuoteQuantums: 10_000_000_000_000, // 10M
- Maximum_30DAttributableVolumePerReferredUserQuoteQuantums: 1_000_000_000, // 10k volume
+ Maximum_30DAttributableVolumePerReferredUserQuoteQuantums: 10_000_000_000, // 10k
Also, confirm RefereeMinimumFeeTierIdx = 1 is intentional given Default uses 2. 🏁 Script executed: #!/bin/bash
# Inspect fee tier indices and ensure 0-based indexing and bounds.
rg -n 'RefereeMinimumFeeTierIdx' -C3
rg -nP '(Fee|Trading).*Tier(s)?\b.*\[' -C2 --type goLength of output: 17977 Align numeric literals with comments or vice versa in PreviousAffiliateParameters. The values 1_000_000_000_000 and 1_000_000_000 do not match their comments if quote quantums are scaled (1e6 base units). The new defaults correctly use 10_000_000_000_000 and 10_000_000_000 for "10M" and "10k" respectively. Either scale the previous values up by 10× or adjust comments to "1M" and "1k". RefereeMinimumFeeTierIdx = 1 in the previous state vs 2 in the new default appears intentional as part of the upgrade migration. 🤖 Prompt for AI Agents |
||
|
|
||
| PreviousAffiliateWhitelist = affiliatetypes.AffiliateWhitelist{ | ||
| Tiers: []affiliatetypes.AffiliateWhitelist_Tier{ | ||
| { | ||
| Addresses: []string{ | ||
| "dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4", // Carl | ||
| "dydx10fx7sy6ywd5senxae9dwytf8jxek3t2gcen2vs", // Dave | ||
| }, | ||
| TakerFeeSharePpm: 200_000, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| DefaultAffiliateTiers = affiliatetypes.AffiliateTiers{ | ||
| Tiers: []affiliatetypes.AffiliateTiers_Tier{ | ||
| { | ||
| ReqReferredVolumeQuoteQuantums: 0, | ||
| ReqStakedWholeCoins: 0, | ||
| TakerFeeSharePpm: 400_000, | ||
| }, | ||
| { | ||
| ReqReferredVolumeQuoteQuantums: 1_000_000_000_000, // 1M volume | ||
| ReqStakedWholeCoins: 200, | ||
| TakerFeeSharePpm: 400_000, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| DefaultAffiliateParameters = affiliatetypes.AffiliateParameters{ | ||
| Maximum_30DAffiliateRevenuePerReferredUserQuoteQuantums: 10_000_000_000_000, // 10M volume | ||
| RefereeMinimumFeeTierIdx: 2, | ||
| Maximum_30DAttributableVolumePerReferredUserQuoteQuantums: 10_000_000_000, // 10k volume | ||
| } | ||
| ) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| package v_9_4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| upgradetypes "cosmossdk.io/x/upgrade/types" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/cosmos/cosmos-sdk/types/module" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/dydxprotocol/v4-chain/protocol/lib" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| affiliatekeeper "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/keeper" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| affiliatetypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| func setDefaultAffiliateTiersForSlidingAffiliates(ctx sdk.Context, affiliateKeeper affiliatekeeper.Keeper) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| err := affiliateKeeper.UpdateAffiliateTiers(ctx, DefaultAffiliateTiers) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| panic(fmt.Sprintf("failed to set default affiliate tiers: %s", err)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| func setDefaultAffiliateParameters(ctx sdk.Context, affiliateKeeper affiliatekeeper.Keeper) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| err := affiliateKeeper.UpdateAffiliateParameters(ctx, &affiliatetypes.MsgUpdateAffiliateParameters{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| AffiliateParameters: DefaultAffiliateParameters, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| panic(fmt.Sprintf("failed to set default affiliate parameters: %s", err)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RefereeMinimumFeeTierIdx likely out of range (will fail upgrade). Per constants.go, DefaultAffiliateTiers defines 2 tiers (idx 0–1) while DefaultAffiliateParameters sets RefereeMinimumFeeTierIdx = 2. This mismatches and will cause UpdateAffiliateParameters to error, triggering a panic here. Add a guard and fix constants to align (preferred: set idx to 1 or add a third tier). Based on relevant_code_snippets. Apply this guard locally to fail fast with a clear message: func setDefaultAffiliateParameters(ctx sdk.Context, affiliateKeeper affiliatekeeper.Keeper) {
- err := affiliateKeeper.UpdateAffiliateParameters(ctx, &affiliatetypes.MsgUpdateAffiliateParameters{
+ // Sanity check: ensure referee tier index is within bounds of DefaultAffiliateTiers.
+ if int(DefaultAffiliateParameters.RefereeMinimumFeeTierIdx) >= len(DefaultAffiliateTiers.Tiers) {
+ panic(fmt.Sprintf(
+ "invalid RefereeMinimumFeeTierIdx=%d for %d tiers",
+ DefaultAffiliateParameters.RefereeMinimumFeeTierIdx, len(DefaultAffiliateTiers.Tiers),
+ ))
+ }
+ err := affiliateKeeper.UpdateAffiliateParameters(ctx, &affiliatetypes.MsgUpdateAffiliateParameters{
AffiliateParameters: DefaultAffiliateParameters,
})📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| func migrateAffiliateOverrides(ctx sdk.Context, affiliateKeeper affiliatekeeper.Keeper) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Get all whitelist | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| whitelist, err := affiliateKeeper.GetAffiliateWhitelist(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| panic(fmt.Sprintf("failed to get affiliate whitelist: %s", err)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Create overrides for all whitelist addresses | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| overrides := affiliatetypes.AffiliateOverrides{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var overridesList []string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, addr := range whitelist.Tiers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| overridesList = append(overridesList, addr.Addresses...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| overrides.Addresses = overridesList | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Update affiliate overrides | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| err = affiliateKeeper.SetAffiliateOverrides(ctx, overrides) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| panic(fmt.Sprintf("failed to set affiliate overrides: %s", err)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| func CreateUpgradeHandler( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| mm *module.Manager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| affiliateKeeper affiliatekeeper.Keeper, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Set default affiliate tiers and parameters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| setDefaultAffiliateTiersForSlidingAffiliates(sdkCtx, affiliateKeeper) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Set default affiliate parameters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| setDefaultAffiliateParameters(sdkCtx, affiliateKeeper) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Migrate affiliate overrides. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| migrateAffiliateOverrides(sdkCtx, affiliateKeeper) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return mm.RunMigrations(ctx, configurator, vm) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| //go:build all || container_test | ||
|
|
||
| package v_9_4_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/cosmos/gogoproto/proto" | ||
| v_9_4 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v9.4" | ||
| "github.com/dydxprotocol/v4-chain/protocol/testing/containertest" | ||
| "github.com/dydxprotocol/v4-chain/protocol/testutil/constants" | ||
| affiliatetypes "github.com/dydxprotocol/v4-chain/protocol/x/affiliates/types" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| 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_9_4.UpgradeName) | ||
| require.NoError(t, err) | ||
|
|
||
| postUpgradeChecks(node, t) | ||
| } | ||
|
|
||
| func preUpgradeSetups(node *containertest.Node, t *testing.T) {} | ||
|
|
||
| func preUpgradeChecks(node *containertest.Node, t *testing.T) { | ||
| // Verify affiliate tiers are set to default values | ||
| tiersResp := &affiliatetypes.AllAffiliateTiersResponse{} | ||
| resp, err := containertest.Query( | ||
| node, | ||
| affiliatetypes.NewQueryClient, | ||
| affiliatetypes.QueryClient.AllAffiliateTiers, | ||
| &affiliatetypes.AllAffiliateTiersRequest{}, | ||
| ) | ||
| require.NoError(t, err) | ||
| err = proto.UnmarshalText(resp.String(), tiersResp) | ||
| require.NoError(t, err) | ||
| require.Equal(t, v_9_4.PreviousAffilliateTiers, tiersResp.Tiers) | ||
| } | ||
|
|
||
| func postUpgradeChecks(node *containertest.Node, t *testing.T) { | ||
| // Verify affiliate tiers are set to default values | ||
| tiersResp := &affiliatetypes.AllAffiliateTiersResponse{} | ||
| resp, err := containertest.Query( | ||
| node, | ||
| affiliatetypes.NewQueryClient, | ||
| affiliatetypes.QueryClient.AllAffiliateTiers, | ||
| &affiliatetypes.AllAffiliateTiersRequest{}, | ||
| ) | ||
| require.NoError(t, err) | ||
| err = proto.UnmarshalText(resp.String(), tiersResp) | ||
| require.NoError(t, err) | ||
| require.Equal(t, v_9_4.DefaultAffiliateTiers, tiersResp.Tiers) | ||
|
|
||
| // Verify affiliate parameters are set to default values | ||
| paramsResp := &affiliatetypes.AffiliateParametersResponse{} | ||
| resp, err = containertest.Query( | ||
| node, | ||
| affiliatetypes.NewQueryClient, | ||
| affiliatetypes.QueryClient.AffiliateParameters, | ||
| &affiliatetypes.AffiliateParametersRequest{}, | ||
| ) | ||
| require.NoError(t, err) | ||
| err = proto.UnmarshalText(resp.String(), paramsResp) | ||
| require.NoError(t, err) | ||
| require.Equal(t, v_9_4.DefaultAffiliateParameters, paramsResp.Parameters) | ||
|
|
||
| // Verify affiliate overrides were migrated from whitelist | ||
| overridesResp := &affiliatetypes.AffiliateOverridesResponse{} | ||
| resp, err = containertest.Query( | ||
| node, | ||
| affiliatetypes.NewQueryClient, | ||
| affiliatetypes.QueryClient.AffiliateOverrides, | ||
| &affiliatetypes.AffiliateOverridesRequest{}, | ||
| ) | ||
| require.NoError(t, err) | ||
| err = proto.UnmarshalText(resp.String(), overridesResp) | ||
| require.NoError(t, err) | ||
| // Overrides should contain addresses from the pre-upgrade whitelist | ||
| expectedOverrides := affiliatetypes.AffiliateOverrides{ | ||
| Addresses: []string{ | ||
| "dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4", // Carl | ||
| "dydx10fx7sy6ywd5senxae9dwytf8jxek3t2gcen2vs", // Dave | ||
| }, | ||
| } | ||
| require.Equal(t, expectedOverrides, overridesResp.Overrides) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v9.3 | ||
| v9.4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v9.2.1 | ||
| v9.3 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v9.2 | ||
| v9.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify units and indices in AffiliateParameters.
Run this to locate definitions and usages:
Also applies to: 67-71
🏁 Script executed:
Length of output: 59
I need to correct the shell script—
rgdoesn't recognize "proto" as a valid file type. Let me search more broadly to find the AffiliateParameters definition, fee tier configuration, and verify the indices and magnitudes.🏁 Script executed:
Length of output: 129859
I found critical issues. Let me search for fee tier configuration to verify the index validity.
🏁 Script executed:
Length of output: 262144
Fix unit comments and fee‑tier index in AffiliateParameters (upgrade constants)
🤖 Prompt for AI Agents