From c17202bbad35f535594a9af9b80abfbbb0cdb506 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Fri, 5 Jul 2024 11:39:04 +0200 Subject: [PATCH 01/14] basic upgrade handler for v23 --- app/app.go | 7 ++- .../testnet/v23.0.0-alpha.1/constants.go | 51 +++++++++++++++++++ .../testnet/v23.0.0-alpha.1/upgrade_test.go | 40 +++++++++++++++ app/upgrades/v23/constants.go | 22 ++++++++ app/upgrades/v23/upgrade_test.go | 39 ++++++++++++++ app/upgrades/v23/upgrades.go | 35 +++++++++++++ interchaintest/chain_upgrade_test.go | 4 +- 7 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 app/upgrades/testnet/v23.0.0-alpha.1/constants.go create mode 100644 app/upgrades/testnet/v23.0.0-alpha.1/upgrade_test.go create mode 100644 app/upgrades/v23/constants.go create mode 100644 app/upgrades/v23/upgrade_test.go create mode 100644 app/upgrades/v23/upgrades.go diff --git a/app/app.go b/app/app.go index ec28ea9c8..b5f13a0b0 100644 --- a/app/app.go +++ b/app/app.go @@ -73,6 +73,8 @@ import ( testnetV19alpha3 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v19.0.0-alpha.3" testnetV21alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v21.0.0-alpha.1" testnetV22alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v22.0.0-alpha.1" + testnetV23alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v23.0.0-alpha.1" + v10 "github.com/CosmosContracts/juno/v23/app/upgrades/v10" v11 "github.com/CosmosContracts/juno/v23/app/upgrades/v11" v12 "github.com/CosmosContracts/juno/v23/app/upgrades/v12" @@ -85,6 +87,7 @@ import ( v19 "github.com/CosmosContracts/juno/v23/app/upgrades/v19" v21 "github.com/CosmosContracts/juno/v23/app/upgrades/v21" v22 "github.com/CosmosContracts/juno/v23/app/upgrades/v22" + v23 "github.com/CosmosContracts/juno/v23/app/upgrades/v23" "github.com/CosmosContracts/juno/v23/docs" ) @@ -114,7 +117,8 @@ var ( testnetV19alpha3.Upgrade, testnetV21alpha1.Upgrade, testnetV22alpha1.Upgrade, - + testnetV23alpha1.Upgrade, + v10.Upgrade, v11.Upgrade, v12.Upgrade, @@ -127,6 +131,7 @@ var ( v19.Upgrade, v21.Upgrade, v22.Upgrade, + v23.Upgrade, } ) diff --git a/app/upgrades/testnet/v23.0.0-alpha.1/constants.go b/app/upgrades/testnet/v23.0.0-alpha.1/constants.go new file mode 100644 index 000000000..0109ac6b2 --- /dev/null +++ b/app/upgrades/testnet/v23.0.0-alpha.1/constants.go @@ -0,0 +1,51 @@ +package v23 + +import ( + "fmt" + + store "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" + + "github.com/CosmosContracts/juno/v23/app/keepers" + "github.com/CosmosContracts/juno/v23/app/upgrades" +) + +// UpgradeName defines the on-chain upgrade name for the upgrade. +const UpgradeName = "v2300alpha1" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: v2300Alpha1UpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{ + // updated modules + icqtypes.ModuleName, + }, + }, +} + +func v2300Alpha1UpgradeHandler( + mm *module.Manager, + cfg module.Configurator, + _ *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := ctx.Logger().With("upgrade", UpgradeName) + + nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID()) + logger.Info(fmt.Sprintf("With native denom %s", nativeDenom)) + + // Run migrations + logger.Info(fmt.Sprintf("pre migrate version map: %v", vm)) + versionMap, err := mm.RunMigrations(ctx, cfg, vm) + if err != nil { + return nil, err + } + logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) + + return versionMap, err + } +} diff --git a/app/upgrades/testnet/v23.0.0-alpha.1/upgrade_test.go b/app/upgrades/testnet/v23.0.0-alpha.1/upgrade_test.go new file mode 100644 index 000000000..d16e773b6 --- /dev/null +++ b/app/upgrades/testnet/v23.0.0-alpha.1/upgrade_test.go @@ -0,0 +1,40 @@ +package v23_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/CosmosContracts/juno/v23/app/apptesting" + v23alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v22.0.0-alpha.1" +) + +type UpgradeTestSuite struct { + apptesting.KeeperTestHelper +} + +func (s *UpgradeTestSuite) SetupTest() { + s.Setup() +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +// Ensures the test does not error out. +func (s *UpgradeTestSuite) TestUpgrade() { + s.Setup() + + preUpgradeChecks(s) + + upgradeHeight := int64(5) + s.ConfirmUpgradeSucceeded(v23alpha1.UpgradeName, upgradeHeight) + + postUpgradeChecks(s) +} + +func preUpgradeChecks(_ *UpgradeTestSuite) { +} + +func postUpgradeChecks(_ *UpgradeTestSuite) { +} diff --git a/app/upgrades/v23/constants.go b/app/upgrades/v23/constants.go new file mode 100644 index 000000000..20dd90437 --- /dev/null +++ b/app/upgrades/v23/constants.go @@ -0,0 +1,22 @@ +package v23 + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" + + "github.com/CosmosContracts/juno/v23/app/upgrades" +) + +// UpgradeName defines the on-chain upgrade name for the upgrade. +const UpgradeName = "v23" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateV23UpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{ + // updated modules + icqtypes.ModuleName, + }, + }, +} diff --git a/app/upgrades/v23/upgrade_test.go b/app/upgrades/v23/upgrade_test.go new file mode 100644 index 000000000..5117f212f --- /dev/null +++ b/app/upgrades/v23/upgrade_test.go @@ -0,0 +1,39 @@ +package v23_test + +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/CosmosContracts/juno/v23/app/apptesting" + v23 "github.com/CosmosContracts/juno/v23/app/upgrades/v23" +) + +type UpgradeTestSuite struct { + apptesting.KeeperTestHelper +} + +func (s *UpgradeTestSuite) SetupTest() { + s.Setup() +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +// Ensures the test does not error out. +func (s *UpgradeTestSuite) TestUpgrade() { + s.Setup() + preUpgradeChecks(s) + + upgradeHeight := int64(5) + s.ConfirmUpgradeSucceeded(v23.UpgradeName, upgradeHeight) + + postUpgradeChecks(s) +} + +func preUpgradeChecks(_ *UpgradeTestSuite) { +} + +func postUpgradeChecks(_ *UpgradeTestSuite) { +} diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go new file mode 100644 index 000000000..e7ae32159 --- /dev/null +++ b/app/upgrades/v23/upgrades.go @@ -0,0 +1,35 @@ +package v23 + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/CosmosContracts/juno/v23/app/keepers" + "github.com/CosmosContracts/juno/v23/app/upgrades" +) + +func CreateV23UpgradeHandler( + mm *module.Manager, + cfg module.Configurator, + _ *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + logger := ctx.Logger().With("upgrade", UpgradeName) + + nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID()) + logger.Info(fmt.Sprintf("With native denom %s", nativeDenom)) + + // Run migrations + logger.Info(fmt.Sprintf("pre migrate version map: %v", vm)) + versionMap, err := mm.RunMigrations(ctx, cfg, vm) + if err != nil { + return nil, err + } + logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) + + return versionMap, err + } +} diff --git a/interchaintest/chain_upgrade_test.go b/interchaintest/chain_upgrade_test.go index 8d4616e8f..ac674bcb0 100644 --- a/interchaintest/chain_upgrade_test.go +++ b/interchaintest/chain_upgrade_test.go @@ -24,7 +24,7 @@ import ( const ( chainName = "juno" - upgradeName = "v21" + upgradeName = "v23" haltHeightDelta = int64(9) // will propose upgrade this many blocks in the future blocksAfterUpgrade = int64(7) @@ -34,7 +34,7 @@ var ( // baseChain is the current version of the chain that will be upgraded from baseChain = ibc.DockerImage{ Repository: JunoMainRepo, - Version: "v20.0.0", + Version: "v22.0.1", UidGid: "1025:1025", } ) From 18621fbef44b255d5bd691b9699f14793872f06d Mon Sep 17 00:00:00 2001 From: dimiandre Date: Fri, 5 Jul 2024 13:15:42 +0200 Subject: [PATCH 02/14] remove icq from store upgrades --- app/upgrades/v23/constants.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/upgrades/v23/constants.go b/app/upgrades/v23/constants.go index 20dd90437..58f0ea08c 100644 --- a/app/upgrades/v23/constants.go +++ b/app/upgrades/v23/constants.go @@ -2,7 +2,6 @@ package v23 import ( store "github.com/cosmos/cosmos-sdk/store/types" - icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" "github.com/CosmosContracts/juno/v23/app/upgrades" ) @@ -13,10 +12,5 @@ const UpgradeName = "v23" var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateV23UpgradeHandler, - StoreUpgrades: store.StoreUpgrades{ - Added: []string{ - // updated modules - icqtypes.ModuleName, - }, - }, + StoreUpgrades: store.StoreUpgrades{}, } From 85098916c5cf442cc69d957b44c7349e97f5e09f Mon Sep 17 00:00:00 2001 From: dimiandre Date: Fri, 5 Jul 2024 16:50:01 +0200 Subject: [PATCH 03/14] migrate icq params in upgrade handler --- app/upgrades/v23/upgrades.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index e7ae32159..dcc0963cd 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -3,18 +3,20 @@ package v23 import ( "fmt" + "github.com/CosmosContracts/juno/v23/app/keepers" + "github.com/CosmosContracts/juno/v23/app/upgrades" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - "github.com/CosmosContracts/juno/v23/app/keepers" - "github.com/CosmosContracts/juno/v23/app/upgrades" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" ) func CreateV23UpgradeHandler( mm *module.Manager, cfg module.Configurator, - _ *keepers.AppKeepers, + keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) @@ -22,12 +24,34 @@ func CreateV23UpgradeHandler( nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID()) logger.Info(fmt.Sprintf("With native denom %s", nativeDenom)) + // migrate ICQ params + for _, subspace := range keepers.ParamsKeeper.GetSubspaces() { + subspace := subspace + + var keyTable paramstypes.KeyTable + if subspace.Name() == icqtypes.ModuleName { + keyTable = icqtypes.ParamKeyTable() + } else { + continue + } + + if !subspace.HasKeyTable() { + subspace.WithKeyTable(keyTable) + } + } + + // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. + // The old params module is required to still be imported in your app.go in order to handle this migration. + baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper) + // Run migrations logger.Info(fmt.Sprintf("pre migrate version map: %v", vm)) versionMap, err := mm.RunMigrations(ctx, cfg, vm) if err != nil { return nil, err } + logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) return versionMap, err From 5a99d083adbc9238d3dd191accdca7f02381a237 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Fri, 5 Jul 2024 19:05:30 +0200 Subject: [PATCH 04/14] builder module account conversion --- app/upgrades/v23/upgrades.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index dcc0963cd..0105bdadf 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" @@ -54,6 +55,26 @@ func CreateV23UpgradeHandler( logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) + // convert pob builder account to an actual module account + // during upgrade from v15 to v16 it wasn't correctly created, and since it received tokens on mainnet is not a base account + // it's like this on both mainnet and uni + if ctx.ChainID() == "juno-1" || ctx.ChainID() == "uni-6" { + logger.Info("converting x/pob builder module account") + + address := sdk.MustAccAddressFromBech32("juno1ma4sw9m2nvtucny6lsjhh4qywvh86zdh5dlkd4") + + acc := keepers.AccountKeeper.NewAccount( + ctx, + authtypes.NewModuleAccount( + authtypes.NewBaseAccountWithAddress(address), + "builder", + ), + ) + keepers.AccountKeeper.SetAccount(ctx, acc) + + logger.Info("x/pob builder module address is now a module account") + } + return versionMap, err } } From 3791ff2a2809074612bda32dcf3fb52ffb4f6df0 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Fri, 5 Jul 2024 19:28:41 +0200 Subject: [PATCH 05/14] port back tf patch from mainnet with a better implementation --- x/tokenfactory/keeper/bankactions.go | 31 +++++++++++++++------------- x/tokenfactory/keeper/keeper.go | 7 ++++++- x/tokenfactory/types/errors.go | 1 + 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 92b34f165..62733944b 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -1,7 +1,6 @@ package keeper import ( - "fmt" "sort" "google.golang.org/grpc/codes" @@ -29,8 +28,8 @@ func (k Keeper) mintTo(ctx sdk.Context, amount sdk.Coin, mintTo string) error { return err } - if k.bankKeeper.BlockedAddr(addr) { - return fmt.Errorf("failed to mint to blocked address: %s", addr) + if k.IsModuleAcc(ctx, addr) { + return types.ErrModuleAccount } return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, @@ -50,8 +49,8 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return err } - if k.bankKeeper.BlockedAddr(addr) { - return fmt.Errorf("failed to burn from blocked address: %s", addr) + if k.IsModuleAcc(ctx, addr) { + return types.ErrModuleAccount } err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, @@ -77,6 +76,10 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string, return err } + if k.IsModuleAcc(ctx, fromAcc) { + return types.ErrModuleAccount + } + sortedPermAddrs := make([]string, 0, len(k.permAddrs)) for moduleName := range k.permAddrs { sortedPermAddrs = append(sortedPermAddrs, moduleName) @@ -94,19 +97,19 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string, } } - fromSdkAddr, err := sdk.AccAddressFromBech32(fromAddr) + toAcc, err := sdk.AccAddressFromBech32(toAddr) if err != nil { return err } - toSdkAddr, err := sdk.AccAddressFromBech32(toAddr) - if err != nil { - return err + if k.IsModuleAcc(ctx, toAcc) { + return types.ErrModuleAccount } - if k.bankKeeper.BlockedAddr(toSdkAddr) { - return fmt.Errorf("failed to force transfer to blocked address: %s", toSdkAddr) - } - - return k.bankKeeper.SendCoins(ctx, fromSdkAddr, toSdkAddr, sdk.NewCoins(amount)) + return k.bankKeeper.SendCoins(ctx, fromAcc, toAcc, sdk.NewCoins(amount)) } + +// IsModuleAcc checks if a given address is restricted +func (k Keeper) IsModuleAcc(ctx sdk.Context, addr sdk.AccAddress) bool { + return k.permAddrMap[addr.String()] +} \ No newline at end of file diff --git a/x/tokenfactory/keeper/keeper.go b/x/tokenfactory/keeper/keeper.go index 7ee3bcc1e..b53388e42 100644 --- a/x/tokenfactory/keeper/keeper.go +++ b/x/tokenfactory/keeper/keeper.go @@ -19,6 +19,7 @@ type ( cdc codec.BinaryCodec storeKey storetypes.StoreKey permAddrs map[string]authtypes.PermissionsForAddress + permAddrMap map[string]bool accountKeeper types.AccountKeeper bankKeeper types.BankKeeper @@ -44,8 +45,11 @@ func NewKeeper( authority string, ) Keeper { permAddrs := make(map[string]authtypes.PermissionsForAddress) + permAddrMap := make(map[string]bool) for name, perms := range maccPerms { - permAddrs[name] = authtypes.NewPermissionsForAddress(name, perms) + permsForAddr := authtypes.NewPermissionsForAddress(name, perms) + permAddrs[name] = permsForAddr + permAddrMap[permsForAddr.GetAddress().String()] = true } return Keeper{ @@ -53,6 +57,7 @@ func NewKeeper( storeKey: storeKey, permAddrs: permAddrs, + permAddrMap: permAddrMap, accountKeeper: accountKeeper, bankKeeper: bankKeeper, communityPoolKeeper: communityPoolKeeper, diff --git a/x/tokenfactory/types/errors.go b/x/tokenfactory/types/errors.go index 5a3c587d0..8337d7b55 100644 --- a/x/tokenfactory/types/errors.go +++ b/x/tokenfactory/types/errors.go @@ -20,4 +20,5 @@ var ( ErrCreatorTooLong = errorsmod.Register(ModuleName, 9, fmt.Sprintf("creator too long, max length is %d bytes", MaxCreatorLength)) ErrDenomDoesNotExist = errorsmod.Register(ModuleName, 10, "denom does not exist") ErrCapabilityNotEnabled = errorsmod.Register(ModuleName, 11, "this capability is not enabled on chain") + ErrModuleAccount = errorsmod.Register(ModuleName, 12, "interacting with module accounts not allowed") ) From bbb4280ad024176d52351725a53ae31ac9b55d6e Mon Sep 17 00:00:00 2001 From: dimiandre Date: Fri, 5 Jul 2024 19:30:18 +0200 Subject: [PATCH 06/14] lint --- app/app.go | 3 +-- app/upgrades/testnet/v23.0.0-alpha.1/constants.go | 5 +++-- app/upgrades/v23/upgrades.go | 10 ++++++---- x/tokenfactory/keeper/bankactions.go | 4 ++-- x/tokenfactory/keeper/keeper.go | 6 +++--- x/tokenfactory/types/errors.go | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/app.go b/app/app.go index b5f13a0b0..149c2f24b 100644 --- a/app/app.go +++ b/app/app.go @@ -74,7 +74,6 @@ import ( testnetV21alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v21.0.0-alpha.1" testnetV22alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v22.0.0-alpha.1" testnetV23alpha1 "github.com/CosmosContracts/juno/v23/app/upgrades/testnet/v23.0.0-alpha.1" - v10 "github.com/CosmosContracts/juno/v23/app/upgrades/v10" v11 "github.com/CosmosContracts/juno/v23/app/upgrades/v11" v12 "github.com/CosmosContracts/juno/v23/app/upgrades/v12" @@ -118,7 +117,7 @@ var ( testnetV21alpha1.Upgrade, testnetV22alpha1.Upgrade, testnetV23alpha1.Upgrade, - + v10.Upgrade, v11.Upgrade, v12.Upgrade, diff --git a/app/upgrades/testnet/v23.0.0-alpha.1/constants.go b/app/upgrades/testnet/v23.0.0-alpha.1/constants.go index 0109ac6b2..955dac81f 100644 --- a/app/upgrades/testnet/v23.0.0-alpha.1/constants.go +++ b/app/upgrades/testnet/v23.0.0-alpha.1/constants.go @@ -3,11 +3,12 @@ package v23 import ( "fmt" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" + store "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" "github.com/CosmosContracts/juno/v23/app/keepers" "github.com/CosmosContracts/juno/v23/app/upgrades" @@ -19,7 +20,7 @@ const UpgradeName = "v2300alpha1" var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: v2300Alpha1UpgradeHandler, - StoreUpgrades: store.StoreUpgrades{ + StoreUpgrades: store.StoreUpgrades{ Added: []string{ // updated modules icqtypes.ModuleName, diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index 0105bdadf..3c22af71a 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -3,15 +3,17 @@ package v23 import ( "fmt" - "github.com/CosmosContracts/juno/v23/app/keepers" - "github.com/CosmosContracts/juno/v23/app/upgrades" + icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" + "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" + + "github.com/CosmosContracts/juno/v23/app/keepers" + "github.com/CosmosContracts/juno/v23/app/upgrades" ) func CreateV23UpgradeHandler( @@ -52,7 +54,7 @@ func CreateV23UpgradeHandler( if err != nil { return nil, err } - + logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) // convert pob builder account to an actual module account diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 62733944b..051984841 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -110,6 +110,6 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string, } // IsModuleAcc checks if a given address is restricted -func (k Keeper) IsModuleAcc(ctx sdk.Context, addr sdk.AccAddress) bool { +func (k Keeper) IsModuleAcc(_ sdk.Context, addr sdk.AccAddress) bool { return k.permAddrMap[addr.String()] -} \ No newline at end of file +} diff --git a/x/tokenfactory/keeper/keeper.go b/x/tokenfactory/keeper/keeper.go index b53388e42..30d2fb053 100644 --- a/x/tokenfactory/keeper/keeper.go +++ b/x/tokenfactory/keeper/keeper.go @@ -16,9 +16,9 @@ import ( type ( Keeper struct { - cdc codec.BinaryCodec - storeKey storetypes.StoreKey - permAddrs map[string]authtypes.PermissionsForAddress + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + permAddrs map[string]authtypes.PermissionsForAddress permAddrMap map[string]bool accountKeeper types.AccountKeeper diff --git a/x/tokenfactory/types/errors.go b/x/tokenfactory/types/errors.go index 8337d7b55..c04cc008c 100644 --- a/x/tokenfactory/types/errors.go +++ b/x/tokenfactory/types/errors.go @@ -20,5 +20,5 @@ var ( ErrCreatorTooLong = errorsmod.Register(ModuleName, 9, fmt.Sprintf("creator too long, max length is %d bytes", MaxCreatorLength)) ErrDenomDoesNotExist = errorsmod.Register(ModuleName, 10, "denom does not exist") ErrCapabilityNotEnabled = errorsmod.Register(ModuleName, 11, "this capability is not enabled on chain") - ErrModuleAccount = errorsmod.Register(ModuleName, 12, "interacting with module accounts not allowed") + ErrModuleAccount = errorsmod.Register(ModuleName, 12, "interacting with module accounts not allowed") ) From c46204efcf57d51eab36f0bf562fbc943c045664 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Sun, 7 Jul 2024 11:21:56 +0200 Subject: [PATCH 07/14] refuse in tf update --- x/tokenfactory/keeper/bankactions.go | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index 051984841..636d979b8 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -1,11 +1,6 @@ package keeper import ( - "sort" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/CosmosContracts/juno/v23/x/tokenfactory/types" @@ -80,23 +75,6 @@ func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string, return types.ErrModuleAccount } - sortedPermAddrs := make([]string, 0, len(k.permAddrs)) - for moduleName := range k.permAddrs { - sortedPermAddrs = append(sortedPermAddrs, moduleName) - } - sort.Strings(sortedPermAddrs) - - for _, moduleName := range sortedPermAddrs { - account := k.accountKeeper.GetModuleAccount(ctx, moduleName) - if account == nil { - return status.Errorf(codes.NotFound, "account %s not found", moduleName) - } - - if account.GetAddress().Equals(fromAcc) { - return status.Errorf(codes.Internal, "send from module acc not available") - } - } - toAcc, err := sdk.AccAddressFromBech32(toAddr) if err != nil { return err From 04eda81ccc74138274ba7de067d8d1e0aca9da3b Mon Sep 17 00:00:00 2001 From: dimiandre Date: Sun, 7 Jul 2024 11:42:43 +0200 Subject: [PATCH 08/14] core1 vesting migration --- app/upgrades/v23/upgrades.go | 48 +++++++++- app/upgrades/v23/vesting.go | 181 +++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 app/upgrades/v23/vesting.go diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index 3c22af71a..04a7b1ad8 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -16,6 +16,29 @@ import ( "github.com/CosmosContracts/juno/v23/app/upgrades" ) + +type IndividualAccount struct { + Owner string + Address string +} + +// Core1VestingAccounts https://daodao.zone/dao/juno1j6glql3xmrcnga0gytecsucq3kd88jexxamxg3yn2xnqhunyvflqr7lxx3/members +// we are including only lobo, dimi and jake because the other ones do not agree on giving up their vesting +var Core1VestingAccounts = []IndividualAccount{ + { + Owner: "dimi", + Address: "juno1s33zct2zhhaf60x4a90cpe9yquw99jj0zen8pt", + }, + { + Owner: "jake", + Address: "juno18qw9ydpewh405w4lvmuhlg9gtaep79vy2gmtr2", + }, + { + Owner: "wolf", + Address: "juno1a8u47ggy964tv9trjxfjcldutau5ls705djqyu", + }, +} + func CreateV23UpgradeHandler( mm *module.Manager, cfg module.Configurator, @@ -58,7 +81,7 @@ func CreateV23UpgradeHandler( logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap)) // convert pob builder account to an actual module account - // during upgrade from v15 to v16 it wasn't correctly created, and since it received tokens on mainnet is not a base account + // during upgrade from v15 to v16 it wasn't correctly created, and since it received tokens on mainnet is now a base account // it's like this on both mainnet and uni if ctx.ChainID() == "juno-1" || ctx.ChainID() == "uni-6" { logger.Info("converting x/pob builder module account") @@ -77,6 +100,29 @@ func CreateV23UpgradeHandler( logger.Info("x/pob builder module address is now a module account") } + // only on mainnet and uni, migrate core1 vesting accounts + if ctx.ChainID() == "juno-1" || ctx.ChainID() == "uni-6" { + if err := migrateCore1VestingAccounts(ctx, keepers, nativeDenom); err != nil { + return nil, err + } + } + return versionMap, err } } + + +// Migrate balances from the Core-1 vesting accounts to the Council SubDAO. +func migrateCore1VestingAccounts(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string) error { + for _, account := range Core1VestingAccounts { + if err := MoveVestingCoinFromVestingAccount(ctx, + keepers, + bondDenom, + account.Owner, + sdk.MustAccAddressFromBech32(account.Address), + ); err != nil { + return err + } + } + return nil +} diff --git a/app/upgrades/v23/vesting.go b/app/upgrades/v23/vesting.go new file mode 100644 index 000000000..37d9ea380 --- /dev/null +++ b/app/upgrades/v23/vesting.go @@ -0,0 +1,181 @@ +package v23 + +import ( + "fmt" + "time" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + authvestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + + "github.com/CosmosContracts/juno/v23/app/keepers" +) + +// Stops a vesting account and returns all tokens back to the community pool +func MoveVestingCoinFromVestingAccount(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string, owner string, accAddr sdk.AccAddress) error { + now := ctx.BlockHeader().Time + + stdAcc := keepers.AccountKeeper.GetAccount(ctx, accAddr) + vacc, ok := stdAcc.(*authvestingtypes.PeriodicVestingAccount) + if !ok { + // For e2e testing + fmt.Printf("account " + accAddr.String() + " is not a vesting account.\n") + return nil + } + + fmt.Printf("\n\n== Vesting Account Address: %s (%s) ==\n", vacc.GetAddress().String(), owner) + + // Gets vesting coins (These get returned back to community pool) + // we should filter vesting coins to only include the bondDenom + vestingCoins := vacc.GetVestingCoins(now) + fmt.Printf("All Vesting Coins: %v\n", vestingCoins) + vestingJuno := vestingCoins.AmountOf(bondDenom) + fmt.Printf("Vesting Junos: %v\n", vestingJuno) + + // Display locked & spendable funds + lockedCoins := keepers.BankKeeper.LockedCoins(ctx, accAddr) + fmt.Printf("Locked Coins: %v\n", lockedCoins) + spendableCoins := keepers.BankKeeper.SpendableCoins(ctx, accAddr) + fmt.Printf("Spendable Coins: %v\n", spendableCoins) + + // Instantly complete any re-deleations. + amt, err := completeAllRedelegations(ctx, now, keepers, accAddr) + if err != nil { + return err + } + fmt.Println("Redelegated Amount: ", amt) + + // Instantly unbond all delegations. + amt, err = unbondAllAndFinish(ctx, now, keepers, accAddr) + if err != nil { + return err + } + fmt.Println("Unbonded Amount: ", amt) + + // Community pool balance before transfer + cpoolBeforeBal := keepers.DistrKeeper.GetFeePool(ctx).CommunityPool + + // Set the vesting account to a base account + keepers.AccountKeeper.SetAccount(ctx, vacc.BaseAccount) + + // Moves vesting tokens to the council. + if err := transferUnvestedTokensToCommunityPool(ctx, keepers, accAddr, sdk.NewCoin(bondDenom, vestingJuno)); err != nil { + return err + } + + // Log new council balance + cpoolAfterBal := keepers.DistrKeeper.GetFeePool(ctx).CommunityPool + + fmt.Printf("Community Pool Balance Before: %v\n", cpoolBeforeBal) + fmt.Printf("Community Pool Balance After: %v\n", cpoolAfterBal) + + // Ensure the post validation checks are met. + err = postValidation(ctx, keepers, bondDenom, accAddr, vestingCoins, cpoolBeforeBal) + return err +} + +func postValidation(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string, accAddr sdk.AccAddress, vestingCoins sdk.Coins, cpoolBeforeBal sdk.DecCoins) error { + // Community pool juno balance should only increase by exactly the vestedCoins + cpoolAfterBal := keepers.DistrKeeper.GetFeePool(ctx).CommunityPool + + // only count vesting junos + vestingJuno := vestingCoins.AmountOf(bondDenom) + + if !cpoolBeforeBal.AmountOf(bondDenom).Add(vestingJuno.ToLegacyDec()).Equal(cpoolAfterBal.AmountOf(bondDenom)) { + return fmt.Errorf("ERROR: community pool balance before (%v) + unvested juno (%v) from unvestedCoins (%v) != core1BalAfter (%v)", cpoolBeforeBal, vestingJuno, vestingCoins, cpoolAfterBal) + } + + // vesting account should have no future vesting periods + newVacc := keepers.AccountKeeper.GetAccount(ctx, accAddr) + if _, ok := newVacc.(*authvestingtypes.PeriodicVestingAccount); ok { + return fmt.Errorf("ERROR: account %s still is a vesting account", accAddr.String()) + } + + // ensure the account has 0 delegations, redelegations, or unbonding delegations, + delegations := keepers.StakingKeeper.GetAllDelegatorDelegations(ctx, accAddr) + if !(len(delegations) == 0) { + return fmt.Errorf("ERROR: account %s still has delegations", accAddr.String()) + } + + redelegations := keepers.StakingKeeper.GetRedelegations(ctx, accAddr, 65535) + if len(redelegations) != 0 { + return fmt.Errorf("ERROR: account %s still has redelegations", accAddr.String()) + } + + unbondingDelegations := keepers.StakingKeeper.GetAllUnbondingDelegations(ctx, accAddr) + if len(unbondingDelegations) != 0 { + return fmt.Errorf("ERROR: account %s still has unbonding delegations", accAddr.String()) + } + + return nil +} + +// Transfer funds from the vesting account to the Council SubDAO. +func transferUnvestedTokensToCommunityPool(ctx sdk.Context, keepers *keepers.AppKeepers, accAddr sdk.AccAddress, vestingJuno sdk.Coin) error { + fmt.Printf("Sending Vesting Juno to Community pool: %v\n", vestingJuno) + err := keepers.DistrKeeper.FundCommunityPool(ctx, sdk.NewCoins(vestingJuno), accAddr); + return err +} + +// Completes all re-delegations and returns the amount of tokens which were re-delegated. +func completeAllRedelegations(ctx sdk.Context, now time.Time, keepers *keepers.AppKeepers, accAddr sdk.AccAddress) (math.Int, error) { + redelegatedAmt := math.ZeroInt() + + for _, activeRedelegation := range keepers.StakingKeeper.GetRedelegations(ctx, accAddr, 65535) { + redelegationSrc, _ := sdk.ValAddressFromBech32(activeRedelegation.ValidatorSrcAddress) + redelegationDst, _ := sdk.ValAddressFromBech32(activeRedelegation.ValidatorDstAddress) + + // set all entry completionTime to now so we can complete re-delegation + for i := range activeRedelegation.Entries { + activeRedelegation.Entries[i].CompletionTime = now + redelegatedAmt = redelegatedAmt.Add(math.Int(activeRedelegation.Entries[i].SharesDst)) + } + + keepers.StakingKeeper.SetRedelegation(ctx, activeRedelegation) + _, err := keepers.StakingKeeper.CompleteRedelegation(ctx, accAddr, redelegationSrc, redelegationDst) + if err != nil { + return redelegatedAmt, err + } + } + + return redelegatedAmt, nil +} + +// Returns the amount of tokens which were unbonded (not rewards) +func unbondAllAndFinish(ctx sdk.Context, now time.Time, keepers *keepers.AppKeepers, accAddr sdk.AccAddress) (math.Int, error) { + unbondedAmt := math.ZeroInt() + + // Unbond all delegations from the account + for _, delegation := range keepers.StakingKeeper.GetAllDelegatorDelegations(ctx, accAddr) { + validatorValAddr := delegation.GetValidatorAddr() + if _, found := keepers.StakingKeeper.GetValidator(ctx, validatorValAddr); !found { + continue + } + + _, err := keepers.StakingKeeper.Undelegate(ctx, accAddr, validatorValAddr, delegation.GetShares()) + if err != nil { + return math.ZeroInt(), err + } + } + + // Take all unbonding and complete them. + for _, unbondingDelegation := range keepers.StakingKeeper.GetAllUnbondingDelegations(ctx, accAddr) { + validatorStringAddr := unbondingDelegation.ValidatorAddress + validatorValAddr, _ := sdk.ValAddressFromBech32(validatorStringAddr) + + // Complete unbonding delegation + for i := range unbondingDelegation.Entries { + unbondingDelegation.Entries[i].CompletionTime = now + unbondedAmt = unbondedAmt.Add(unbondingDelegation.Entries[i].Balance) + } + + keepers.StakingKeeper.SetUnbondingDelegation(ctx, unbondingDelegation) + _, err := keepers.StakingKeeper.CompleteUnbonding(ctx, accAddr, validatorValAddr) + if err != nil { + return math.ZeroInt(), err + } + } + + return unbondedAmt, nil +} \ No newline at end of file From b7c4914434183bb3be57211f536216bd469ecdc8 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Sun, 7 Jul 2024 12:02:16 +0200 Subject: [PATCH 09/14] lint --- app/upgrades/v23/upgrades.go | 3 --- app/upgrades/v23/vesting.go | 8 ++++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index 04a7b1ad8..db944cc15 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -15,8 +15,6 @@ import ( "github.com/CosmosContracts/juno/v23/app/keepers" "github.com/CosmosContracts/juno/v23/app/upgrades" ) - - type IndividualAccount struct { Owner string Address string @@ -111,7 +109,6 @@ func CreateV23UpgradeHandler( } } - // Migrate balances from the Core-1 vesting accounts to the Council SubDAO. func migrateCore1VestingAccounts(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string) error { for _, account := range Core1VestingAccounts { diff --git a/app/upgrades/v23/vesting.go b/app/upgrades/v23/vesting.go index 37d9ea380..18b794f84 100644 --- a/app/upgrades/v23/vesting.go +++ b/app/upgrades/v23/vesting.go @@ -75,10 +75,10 @@ func MoveVestingCoinFromVestingAccount(ctx sdk.Context, keepers *keepers.AppKeep return err } -func postValidation(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string, accAddr sdk.AccAddress, vestingCoins sdk.Coins, cpoolBeforeBal sdk.DecCoins) error { +func postValidation(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string, accAddr sdk.AccAddress, vestingCoins sdk.Coins, cpoolBeforeBal sdk.DecCoins) error { // Community pool juno balance should only increase by exactly the vestedCoins cpoolAfterBal := keepers.DistrKeeper.GetFeePool(ctx).CommunityPool - + // only count vesting junos vestingJuno := vestingCoins.AmountOf(bondDenom) @@ -114,7 +114,7 @@ func postValidation(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom stri // Transfer funds from the vesting account to the Council SubDAO. func transferUnvestedTokensToCommunityPool(ctx sdk.Context, keepers *keepers.AppKeepers, accAddr sdk.AccAddress, vestingJuno sdk.Coin) error { fmt.Printf("Sending Vesting Juno to Community pool: %v\n", vestingJuno) - err := keepers.DistrKeeper.FundCommunityPool(ctx, sdk.NewCoins(vestingJuno), accAddr); + err := keepers.DistrKeeper.FundCommunityPool(ctx, sdk.NewCoins(vestingJuno), accAddr) return err } @@ -178,4 +178,4 @@ func unbondAllAndFinish(ctx sdk.Context, now time.Time, keepers *keepers.AppKeep } return unbondedAmt, nil -} \ No newline at end of file +} From e055089ad1bd9f0c684d12c4b2ff57d3cb51ff87 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Sun, 7 Jul 2024 12:14:44 +0200 Subject: [PATCH 10/14] lint 2 --- app/upgrades/v23/upgrades.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index db944cc15..aa6f4db76 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -15,6 +15,7 @@ import ( "github.com/CosmosContracts/juno/v23/app/keepers" "github.com/CosmosContracts/juno/v23/app/upgrades" ) + type IndividualAccount struct { Owner string Address string From a40e23bb0bf0eab732b0819cffe7a9de120f8215 Mon Sep 17 00:00:00 2001 From: dimiandre Date: Sun, 7 Jul 2024 17:24:27 +0200 Subject: [PATCH 11/14] remove uneccessary consensus params migration --- app/upgrades/v23/upgrades.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/upgrades/v23/upgrades.go b/app/upgrades/v23/upgrades.go index aa6f4db76..344b9a5c6 100644 --- a/app/upgrades/v23/upgrades.go +++ b/app/upgrades/v23/upgrades.go @@ -5,7 +5,6 @@ import ( icqtypes "github.com/cosmos/ibc-apps/modules/async-icq/v7/types" - "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -65,11 +64,6 @@ func CreateV23UpgradeHandler( } } - // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. - // The old params module is required to still be imported in your app.go in order to handle this migration. - baseAppLegacySS := keepers.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) - baseapp.MigrateParams(ctx, baseAppLegacySS, &keepers.ConsensusParamsKeeper) - // Run migrations logger.Info(fmt.Sprintf("pre migrate version map: %v", vm)) versionMap, err := mm.RunMigrations(ctx, cfg, vm) From 47e5de2f630b75d3d89f8872cce50b439d2147d9 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sun, 7 Jul 2024 23:27:58 +0700 Subject: [PATCH 12/14] add retryable --- interchaintest/go.mod | 3 +- interchaintest/helpers/cosmwasm.go | 21 ++++++++++++-- interchaintest/setup.go | 45 +++++++++++++++++++----------- 3 files changed, 49 insertions(+), 20 deletions(-) diff --git a/interchaintest/go.mod b/interchaintest/go.mod index 3fe641520..a302e8f5b 100644 --- a/interchaintest/go.mod +++ b/interchaintest/go.mod @@ -16,6 +16,7 @@ require ( cosmossdk.io/math v1.3.0 github.com/CosmWasm/wasmd v0.45.0 github.com/CosmosContracts/juno/v23 v23.0.0-00010101000000-000000000000 + github.com/cenkalti/backoff v2.2.1+incompatible github.com/cosmos/cosmos-sdk v0.47.12 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.6.0 @@ -78,7 +79,7 @@ require ( github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/bufbuild/protocompile v0.5.1 // indirect - github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cockroachdb/errors v1.11.1 // indirect diff --git a/interchaintest/helpers/cosmwasm.go b/interchaintest/helpers/cosmwasm.go index 54d363375..9e1997b6c 100644 --- a/interchaintest/helpers/cosmwasm.go +++ b/interchaintest/helpers/cosmwasm.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "testing" + "time" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v7/ibc" @@ -12,9 +13,17 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cenkalti/backoff/v4" "github.com/cosmos/cosmos-sdk/crypto/keyring" ) +var backoffPolicy = &backoff.ExponentialBackOff{ + MaxElapsedTime: time.Minute, + InitialInterval: 500 * time.Millisecond, + Multiplier: 1.5, + MaxInterval: 10 * time.Second, +} + func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error { var jsonMap map[string]interface{} if err := json.Unmarshal([]byte(queryMsg), &jsonMap); err != nil { @@ -24,10 +33,16 @@ func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosCha return err } -func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname string, fileLoc string) (codeId string) { - codeId, err := chain.StoreContract(ctx, keyname, fileLoc) +func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname, fileLoc string) string { + var codeId string + err := backoff.Retry(func() error { + var err error + codeId, err = chain.StoreContract(ctx, keyname, fileLoc) + return err + }, backoffPolicy) + if err != nil { - t.Fatal(err) + t.Fatalf("Failed to store contract: %v", err) } return codeId } diff --git a/interchaintest/setup.go b/interchaintest/setup.go index 4cf2eb428..904d7816f 100644 --- a/interchaintest/setup.go +++ b/interchaintest/setup.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "testing" + "time" sdkmath "cosmossdk.io/math" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/cenkalti/backoff" "github.com/docker/docker/client" interchaintest "github.com/strangelove-ventures/interchaintest/v7" "github.com/strangelove-ventures/interchaintest/v7/chain/cosmos" @@ -26,6 +28,13 @@ import ( tokenfactorytypes "github.com/CosmosContracts/juno/v23/x/tokenfactory/types" ) +var backoffPolicy = &backoff.ExponentialBackOff{ + MaxElapsedTime: 5 * time.Minute, + InitialInterval: 1 * time.Second, + Multiplier: 2, + MaxInterval: 30 * time.Second, +} + var ( VotingPeriod = "15s" MaxDepositPeriod = "10s" @@ -123,22 +132,26 @@ func CreateThisBranchChain(t *testing.T, numVals, numFull int) []ibc.Chain { } func CreateChainWithCustomConfig(t *testing.T, numVals, numFull int, config ibc.ChainConfig) []ibc.Chain { - cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ - { - Name: "juno", - ChainName: "juno", - Version: config.Images[0].Version, - ChainConfig: config, - NumValidators: &numVals, - NumFullNodes: &numFull, - }, - }) - - // Get chains from the chain factory - chains, err := cf.Chains(t.Name()) - require.NoError(t, err) - - // chain := chains[0].(*cosmos.CosmosChain) + var chains []ibc.Chain + + err := backoff.Retry(func() error { + cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ + { + Name: "juno", + ChainName: "juno", + Version: config.Images[0].Version, + ChainConfig: config, + NumValidators: &numVals, + NumFullNodes: &numFull, + }, + }) + + var err error + chains, err = cf.Chains(t.Name()) + return err + }, backoffPolicy) + + require.NoError(t, err, "Failed to create chain after multiple attempts") return chains } From 7a4d911f0794a21b5a4c0f1cfcd2c51d3de9fc60 Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sun, 7 Jul 2024 23:44:50 +0700 Subject: [PATCH 13/14] refactor backoff --- interchaintest/helpers/cosmwasm.go | 15 +++++++++------ interchaintest/setup.go | 14 +++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/interchaintest/helpers/cosmwasm.go b/interchaintest/helpers/cosmwasm.go index 9e1997b6c..e3e813399 100644 --- a/interchaintest/helpers/cosmwasm.go +++ b/interchaintest/helpers/cosmwasm.go @@ -17,11 +17,13 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" ) -var backoffPolicy = &backoff.ExponentialBackOff{ - MaxElapsedTime: time.Minute, - InitialInterval: 500 * time.Millisecond, - Multiplier: 1.5, - MaxInterval: 10 * time.Second, +func newBackoffPolicy() *backoff.ExponentialBackOff { + b := backoff.NewExponentialBackOff() + b.MaxElapsedTime = time.Minute + b.InitialInterval = 500 * time.Millisecond + b.Multiplier = 1.5 + b.MaxInterval = 10 * time.Second + return b } func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error { @@ -35,11 +37,12 @@ func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosCha func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname, fileLoc string) string { var codeId string + err := backoff.Retry(func() error { var err error codeId, err = chain.StoreContract(ctx, keyname, fileLoc) return err - }, backoffPolicy) + }, newBackoffPolicy()) if err != nil { t.Fatalf("Failed to store contract: %v", err) diff --git a/interchaintest/setup.go b/interchaintest/setup.go index 904d7816f..f894e05a6 100644 --- a/interchaintest/setup.go +++ b/interchaintest/setup.go @@ -28,13 +28,6 @@ import ( tokenfactorytypes "github.com/CosmosContracts/juno/v23/x/tokenfactory/types" ) -var backoffPolicy = &backoff.ExponentialBackOff{ - MaxElapsedTime: 5 * time.Minute, - InitialInterval: 1 * time.Second, - Multiplier: 2, - MaxInterval: 30 * time.Second, -} - var ( VotingPeriod = "15s" MaxDepositPeriod = "10s" @@ -132,6 +125,13 @@ func CreateThisBranchChain(t *testing.T, numVals, numFull int) []ibc.Chain { } func CreateChainWithCustomConfig(t *testing.T, numVals, numFull int, config ibc.ChainConfig) []ibc.Chain { + + backoffPolicy := backoff.NewExponentialBackOff() + backoffPolicy.MaxElapsedTime = 5 * time.Minute + backoffPolicy.InitialInterval = 500 * time.Millisecond + backoffPolicy.Multiplier = 1.5 + backoffPolicy.MaxInterval = 10 * time.Second + var chains []ibc.Chain err := backoff.Retry(func() error { From ea7220a21886afa2ee5f36946b2c1f123a848e7b Mon Sep 17 00:00:00 2001 From: Tuan Tran Date: Sun, 7 Jul 2024 23:55:50 +0700 Subject: [PATCH 14/14] longer max elapsed time --- interchaintest/helpers/cosmwasm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interchaintest/helpers/cosmwasm.go b/interchaintest/helpers/cosmwasm.go index e3e813399..d5f4e8eaa 100644 --- a/interchaintest/helpers/cosmwasm.go +++ b/interchaintest/helpers/cosmwasm.go @@ -19,7 +19,7 @@ import ( func newBackoffPolicy() *backoff.ExponentialBackOff { b := backoff.NewExponentialBackOff() - b.MaxElapsedTime = time.Minute + b.MaxElapsedTime = 5 * time.Minute b.InitialInterval = 500 * time.Millisecond b.Multiplier = 1.5 b.MaxInterval = 10 * time.Second