diff --git a/app/app.go b/app/app.go index 05546e284..9e4f84fe8 100644 --- a/app/app.go +++ b/app/app.go @@ -29,7 +29,7 @@ import ( v044 "github.com/neutron-org/neutron/v3/app/upgrades/v0.4.4" v200 "github.com/neutron-org/neutron/v3/app/upgrades/v2.0.0" v202 "github.com/neutron-org/neutron/v3/app/upgrades/v2.0.2" - v300 "github.com/neutron-org/neutron/v3/app/upgrades/v3.0.0" + v301 "github.com/neutron-org/neutron/v3/app/upgrades/v3.0.1" "github.com/neutron-org/neutron/v3/x/cron" @@ -183,7 +183,7 @@ const ( ) var ( - Upgrades = []upgrades.Upgrade{v030.Upgrade, v044.Upgrade, v200.Upgrade, v202.Upgrade, v300.Upgrade} + Upgrades = []upgrades.Upgrade{v030.Upgrade, v044.Upgrade, v200.Upgrade, v202.Upgrade, v301.Upgrade} // DefaultNodeHome default home directories for the application daemon DefaultNodeHome string @@ -1134,6 +1134,8 @@ func (app *App) setupUpgradeHandlers() { &upgrades.UpgradeKeepers{ AccountKeeper: app.AccountKeeper, FeeBurnerKeeper: app.FeeBurnerKeeper, + BankKeeper: app.BankKeeper, + TransferKeeper: app.TransferKeeper.Keeper, CronKeeper: app.CronKeeper, IcqKeeper: app.InterchainQueriesKeeper, TokenFactoryKeeper: app.TokenFactoryKeeper, diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 9c86c14af..6153ff59f 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -6,6 +6,7 @@ import ( store "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" @@ -21,6 +22,7 @@ import ( tokenfactorykeeper "github.com/neutron-org/neutron/v3/x/tokenfactory/keeper" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + transferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal @@ -41,6 +43,8 @@ type Upgrade struct { type UpgradeKeepers struct { // keepers AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + TransferKeeper transferkeeper.Keeper IcqKeeper icqkeeper.Keeper CronKeeper cronkeeper.Keeper TokenFactoryKeeper *tokenfactorykeeper.Keeper diff --git a/app/upgrades/v3.0.0/constants.go b/app/upgrades/v3.0.1/constants.go similarity index 86% rename from app/upgrades/v3.0.0/constants.go rename to app/upgrades/v3.0.1/constants.go index ea2caed83..f5b034a4c 100644 --- a/app/upgrades/v3.0.0/constants.go +++ b/app/upgrades/v3.0.1/constants.go @@ -1,4 +1,4 @@ -package v300 +package v301 import ( "cosmossdk.io/math" @@ -12,10 +12,10 @@ import ( const ( // UpgradeName defines the on-chain upgrade name. - UpgradeName = "v3.0.0" + UpgradeName = "v3.0.1" - AuctionParamsMaxBundleSize = 2 - AuctionParamsFrontRunningProtection = true + AuctionParamsMaxBundleSize = 4 + AuctionParamsFrontRunningProtection = false ) var ( diff --git a/app/upgrades/v3.0.0/upgrades.go b/app/upgrades/v3.0.1/upgrades.go similarity index 56% rename from app/upgrades/v3.0.0/upgrades.go rename to app/upgrades/v3.0.1/upgrades.go index 20397c3fd..1db554cca 100644 --- a/app/upgrades/v3.0.0/upgrades.go +++ b/app/upgrades/v3.0.1/upgrades.go @@ -1,8 +1,15 @@ -package v300 +package v301 import ( "fmt" + "cosmossdk.io/math" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + transferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper" + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + consumerkeeper "github.com/cosmos/interchain-security/v4/x/ccv/consumer/keeper" + ccvtypes "github.com/cosmos/interchain-security/v4/x/ccv/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" @@ -19,6 +26,10 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) +// CreateUpgradeHandler is an upgrade major version 2 -> 3 +// Upgrade v3.0.0 was applied on pion-1 chain and later renamed to v3.0.1 +// Upgrade v3.0.1 is in a nutshell the same v3.0.0 but with additional storage migrations +// specially for neutron-1 chain - setICSParams and removeDiscrepancies func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, @@ -43,9 +54,18 @@ func CreateUpgradeHandler( return vm, fmt.Errorf("failed to migrate ICS outstanding downtime: %w", err) } + setICSParams(ctx, keepers.ConsumerKeeper) + recalculateSlashingMissedBlocksCounter(ctx, keepers) + if ctx.ChainID() == "neutron-1" { + if err := removeDiscrepancies(ctx, keepers.BankKeeper, keepers.TransferKeeper); err != nil { + return vm, fmt.Errorf("failed to remove discrepancy: %w", err) + } + } + ctx.Logger().Info(fmt.Sprintf("Migration {%s} applied", UpgradeName)) + return vm, nil } } @@ -68,6 +88,28 @@ func setAuctionParams(ctx sdk.Context, feeBurnerKeeper *feeburnerkeeper.Keeper, return auctionKeeper.SetParams(ctx, auctionParams) } +func setICSParams(ctx sdk.Context, consumerKeeper *consumerkeeper.Keeper) { + newParams := ccvtypes.NewParams( + consumerKeeper.GetEnabled(ctx), + consumerKeeper.GetBlocksPerDistributionTransmission(ctx), + consumerKeeper.GetDistributionTransmissionChannel(ctx), + consumerKeeper.GetProviderFeePoolAddrStr(ctx), + consumerKeeper.GetCCVTimeoutPeriod(ctx), + consumerKeeper.GetTransferTimeoutPeriod(ctx), + consumerKeeper.GetConsumerRedistributionFrac(ctx), + consumerKeeper.GetHistoricalEntries(ctx), + consumerKeeper.GetUnbondingPeriod(ctx), + consumerKeeper.GetSoftOptOutThreshold(ctx), + consumerKeeper.GetRewardDenoms(ctx), + consumerKeeper.GetProviderRewardDenoms(ctx), + + // Currently it's an empty string, we need to set to default value + ccvtypes.DefaultRetryDelayPeriod, + ) + + consumerKeeper.SetParams(ctx, newParams) +} + // Sometime long ago we decreased SlashWindow to 36k on pion-1 testnet (the param is untouched on neutron-1 mainnet), // from that time MissedBlockCounter is wrong // We need to set to a proper value. @@ -122,3 +164,40 @@ func migrateICSOutstandingDowntime(ctx sdk.Context, keepers *upgrades.UpgradeKee return nil } + +// There is a discrepancy happens due to bug in PFM module. +// Check all disrepencies you can with a tool - https://github.com/strangelove-ventures/escrow-checker, only one found for `neutron-1` +// ``` +// Discrepancy found! +// Counterparty Chain ID: osmosis-1 +// Escrow Account Address: neutron1fp9wuhq58pz53wxvv3tnrxkw8m8s6swpf2fkv9 +// Asset Base Denom: stuatom +// Asset IBC Denom: ibc/B7864B03E1B9FD4F049243E92ABD691586F682137037A9F3FCA5222815620B3C +// Escrow Balance: 10481 +// Counterparty Total Supply: 2447077ibc/8FCFAF3AE6BA4C5BDFF85B41449FBACE547E2BAC23895E839230404FB0EC3837 +// ^^^ +// bug was already fixed in releases v2.0.3/v3.0.0 +// the aim of the function is to remove the discrepancy +func removeDiscrepancies(ctx sdk.Context, bankKeeper bankkeeper.Keeper, transferKeeper transferkeeper.Keeper) error { + coin := sdk.Coin{ + Denom: "ibc/B7864B03E1B9FD4F049243E92ABD691586F682137037A9F3FCA5222815620B3C", + Amount: math.NewInt(2436596), + } + EscrowAddress := sdk.MustAccAddressFromBech32("neutron1fp9wuhq58pz53wxvv3tnrxkw8m8s6swpf2fkv9") + coins := sdk.NewCoins(coin) + + if err := bankKeeper.MintCoins(ctx, transfertypes.ModuleName, coins); err != nil { + return err + } + + if err := bankKeeper.SendCoinsFromModuleToAccount(ctx, transfertypes.ModuleName, EscrowAddress, coins); err != nil { + return err + } + + // For ibc-go v7+ you will also need to update the transfer module's store for the total escrow amounts. + currentTotalEscrow := transferKeeper.GetTotalEscrowForDenom(ctx, coin.GetDenom()) + newTotalEscrow := currentTotalEscrow.Add(coin) + transferKeeper.SetTotalEscrowForDenom(ctx, newTotalEscrow) + + return nil +} diff --git a/app/upgrades/v3.0.0/upgrades_test.go b/app/upgrades/v3.0.1/upgrades_test.go similarity index 97% rename from app/upgrades/v3.0.0/upgrades_test.go rename to app/upgrades/v3.0.1/upgrades_test.go index e7d5275af..5b906a439 100644 --- a/app/upgrades/v3.0.0/upgrades_test.go +++ b/app/upgrades/v3.0.1/upgrades_test.go @@ -1,4 +1,4 @@ -package v300_test +package v301_test import ( "testing" @@ -13,7 +13,7 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/stretchr/testify/require" - v300 "github.com/neutron-org/neutron/v3/app/upgrades/v3.0.0" + v300 "github.com/neutron-org/neutron/v3/app/upgrades/v3.0.1" "github.com/neutron-org/neutron/v3/testutil" )