-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: sampocs <[email protected]>
- Loading branch information
Showing
18 changed files
with
885 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package v16 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
ratelimitkeeper "github.com/Stride-Labs/stride/v15/x/ratelimit/keeper" | ||
stakeibckeeper "github.com/Stride-Labs/stride/v15/x/stakeibc/keeper" | ||
stakeibctypes "github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
) | ||
|
||
var ( | ||
UpgradeName = "v16" | ||
|
||
CosmosHubChainId = "cosmoshub-4" | ||
CosmosHubStToken = "stuatom" | ||
) | ||
|
||
// CreateUpgradeHandler creates an SDK upgrade handler for v15 | ||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
stakeibcKeeper stakeibckeeper.Keeper, | ||
ratelimitKeeper ratelimitkeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
ctx.Logger().Info("Starting upgrade v16...") | ||
|
||
// unhalt Cosmos Hub host zone | ||
ctx.Logger().Info("Unhalting Cosmos Hub...") | ||
hostZone, found := stakeibcKeeper.GetHostZone(ctx, CosmosHubChainId) | ||
if !found { | ||
return vm, stakeibctypes.ErrHostZoneNotFound.Wrap(CosmosHubChainId) | ||
} | ||
|
||
hostZone.Halted = false | ||
stakeibcKeeper.SetHostZone(ctx, hostZone) | ||
|
||
// remove stuatom from rate limits | ||
ctx.Logger().Info("Removing stuatom as a blacklisted asset...") | ||
ratelimitKeeper.RemoveDenomFromBlacklist(ctx, CosmosHubStToken) | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package v16_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/Stride-Labs/stride/v15/app/apptesting" | ||
stakeibctypes "github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
apptesting.AppTestHelper | ||
} | ||
|
||
func (s *UpgradeTestSuite) SetupTest() { | ||
s.Setup() | ||
} | ||
|
||
var ( | ||
CosmosHubChainIdTest = "cosmoshub-4" | ||
) | ||
|
||
func TestKeeperTestSuite(t *testing.T) { | ||
suite.Run(t, new(UpgradeTestSuite)) | ||
} | ||
|
||
func (s *UpgradeTestSuite) TestUpgrade() { | ||
dummyUpgradeHeight := int64(5) | ||
|
||
// Setup the store before the ugprade | ||
checkCosmosHubAfterUpgrade := s.SetupHostZonesBeforeUpgrade() | ||
|
||
// Run the upgrade to set the bounds and clear pending queries | ||
s.ConfirmUpgradeSucceededs("v16", dummyUpgradeHeight) | ||
|
||
// Check the store after the upgrade | ||
checkCosmosHubAfterUpgrade() | ||
} | ||
|
||
func (s *UpgradeTestSuite) SetupHostZonesBeforeUpgrade() func() { | ||
|
||
// Create 10 dummy host zones | ||
for i := 0; i < 10; i++ { | ||
chainId := fmt.Sprintf("chain-%d", i) | ||
|
||
hostZone := stakeibctypes.HostZone{ | ||
ChainId: chainId, | ||
Halted: false, | ||
RedemptionRate: sdk.MustNewDecFromStr("1.0"), | ||
MinInnerRedemptionRate: sdk.MustNewDecFromStr("0.95"), | ||
MinRedemptionRate: sdk.MustNewDecFromStr("0.97"), | ||
MaxInnerRedemptionRate: sdk.MustNewDecFromStr("1.05"), | ||
MaxRedemptionRate: sdk.MustNewDecFromStr("1.10"), | ||
} | ||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) | ||
} | ||
// create Cosmos Hub Host Zone | ||
hostZone := stakeibctypes.HostZone{ | ||
ChainId: CosmosHubChainIdTest, | ||
Halted: true, | ||
RedemptionRate: sdk.MustNewDecFromStr("1.0"), | ||
MinInnerRedemptionRate: sdk.MustNewDecFromStr("0.95"), | ||
MinRedemptionRate: sdk.MustNewDecFromStr("0.97"), | ||
MaxInnerRedemptionRate: sdk.MustNewDecFromStr("1.05"), | ||
MaxRedemptionRate: sdk.MustNewDecFromStr("1.10"), | ||
} | ||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) | ||
|
||
return func() { | ||
|
||
hostZones := s.App.StakeibcKeeper.GetAllHostZone(s.Ctx) | ||
|
||
for _, hostZone := range hostZones { | ||
s.Require().False(hostZone.Halted, fmt.Sprintf("host zone %s should not be halted: %v", hostZone.ChainId, hostZone)) | ||
} | ||
// Confirm Cosmos Hub host zone is not unhalted | ||
cosmosHubHostZone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, CosmosHubChainIdTest) | ||
s.Require().True(found, "Cosmos Hub host zone not found!") | ||
s.Require().False(cosmosHubHostZone.Halted, "Cosmos Hub host zone should not be halted") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
) | ||
|
||
func CmdResumeHostZone() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "resume-host-zone [chainid]", | ||
Short: "Broadcast message resume-host-zone", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argChainId := args[0] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgResumeHostZone( | ||
clientCtx.GetFromAddress().String(), | ||
argChainId, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k msgServer) ResumeHostZone(goCtx context.Context, msg *types.MsgResumeHostZone) (*types.MsgResumeHostZoneResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// Get Host Zone | ||
hostZone, found := k.GetHostZone(ctx, msg.ChainId) | ||
if !found { | ||
errMsg := fmt.Sprintf("invalid chain id, zone for %s not found", msg.ChainId) | ||
k.Logger(ctx).Error(errMsg) | ||
return nil, errorsmod.Wrapf(types.ErrHostZoneNotFound, errMsg) | ||
} | ||
|
||
// Check the zone is halted | ||
if !hostZone.Halted { | ||
errMsg := fmt.Sprintf("invalid chain id, zone for %s not halted", msg.ChainId) | ||
k.Logger(ctx).Error(errMsg) | ||
return nil, errorsmod.Wrapf(types.ErrHostZoneNotHalted, errMsg) | ||
} | ||
|
||
// remove from blacklist | ||
stDenom := types.StAssetDenomFromHostZoneDenom(hostZone.HostDenom) | ||
k.RatelimitKeeper.RemoveDenomFromBlacklist(ctx, stDenom) | ||
|
||
// Resume zone | ||
hostZone.Halted = false | ||
k.SetHostZone(ctx, hostZone) | ||
|
||
return &types.MsgResumeHostZoneResponse{}, nil | ||
} |
Oops, something went wrong.