-
Notifications
You must be signed in to change notification settings - Fork 208
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
Inflation Fix #951
Inflation Fix #951
Changes from 5 commits
005c24e
624d924
2a0f911
7b4eb66
f144dbd
c759b6f
95b5c5b
a51600c
3b063d8
8544454
3ac58a6
4544ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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" | ||
) | ||
|
||
var ( | ||
UpgradeName = "v16" | ||
|
||
CosmosHubChainId = "cosmoshub-4" | ||
) | ||
|
||
// 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 { | ||
ctx.Logger().Error("Cosmos Hub host zone not found!") | ||
} else { | ||
hostZone.Halted = false | ||
stakeibcKeeper.SetHostZone(ctx, hostZone) | ||
} | ||
|
||
// remove stuatom from rate limits | ||
ctx.Logger().Info("Removing stuatom as a blacklisted asset...") | ||
ratelimitKeeper.RemoveDenomFromBlacklist(ctx, "stuatom") | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package v16_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"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, | ||
} | ||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) | ||
} | ||
// create Cosmos Hub Host Zone | ||
hostZone := stakeibctypes.HostZone{ | ||
ChainId: CosmosHubChainIdTest, | ||
Halted: true, | ||
} | ||
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, "host zone should not be halted") | ||
} | ||
// 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") | ||
} | ||
} |
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 | ||
} |
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) { | ||
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. We also need to remove the blacklisted denom right? |
||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
_ "github.com/stretchr/testify/suite" | ||
|
||
stakeibctypes "github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
) | ||
|
||
type ResumeHostZoneTestCase struct { | ||
validMsg stakeibctypes.MsgResumeHostZone | ||
zone stakeibctypes.HostZone | ||
} | ||
|
||
func (s *KeeperTestSuite) SetupResumeHostZone() ResumeHostZoneTestCase { | ||
// Register a host zone | ||
hostZone := stakeibctypes.HostZone{ | ||
ChainId: HostChainId, | ||
HostDenom: Atom, | ||
IbcDenom: IbcAtom, | ||
RedemptionRate: sdk.NewDec(1.0), | ||
MinRedemptionRate: sdk.NewDec(9).Quo(sdk.NewDec(10)), | ||
MaxRedemptionRate: sdk.NewDec(15).Quo(sdk.NewDec(10)), | ||
Halted: true, | ||
} | ||
|
||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) | ||
|
||
defaultMsg := stakeibctypes.MsgResumeHostZone{ | ||
Creator: s.TestAccs[0].String(), | ||
ChainId: HostChainId, | ||
} | ||
|
||
return ResumeHostZoneTestCase{ | ||
validMsg: defaultMsg, | ||
zone: hostZone, | ||
} | ||
} | ||
|
||
// Verify that bounds can be set successfully | ||
func (s *KeeperTestSuite) TestResumeHostZone_Success() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().ResumeHostZone(s.Ctx, &tc.validMsg) | ||
s.Require().NoError(err, "should not throw an error") | ||
|
||
// Confirm the inner bounds were set | ||
zone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, HostChainId) | ||
s.Require().True(found, "host zone should be in the store") | ||
|
||
s.Require().False(zone.Halted, "host zone should not be halted") | ||
} | ||
|
||
// verify that non-admins can't call the tx | ||
func (s *KeeperTestSuite) TestResumeHostZone_NonAdmin() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
invalidMsg := tc.validMsg | ||
invalidMsg.Creator = s.TestAccs[1].String() | ||
|
||
err := invalidMsg.ValidateBasic() | ||
s.Require().Error(err, "nonadmins shouldn't be able to call this tx") | ||
} | ||
|
||
// verify that the function can't be called on missing zones | ||
func (s *KeeperTestSuite) TestResumeHostZone_MissingZones() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
invalidMsg := tc.validMsg | ||
invalidChainId := "invalid-chain" | ||
invalidMsg.ChainId = invalidChainId | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().ResumeHostZone(s.Ctx, &invalidMsg) | ||
|
||
s.Require().Error(err, "shouldn't be able to call tx on missing zones") | ||
expectedErrorMsg := fmt.Sprintf("invalid chain id, zone for %s not found: host zone not found", invalidChainId) | ||
s.Require().Equal(expectedErrorMsg, err.Error(), "should return correct error msg") | ||
} | ||
|
||
// verify that the function can't be called on unhalted zones | ||
func (s *KeeperTestSuite) TestResumeHostZone_UnhaltedZones() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
zone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, HostChainId) | ||
s.Require().True(found, "host zone should be in the store") | ||
s.Require().True(zone.Halted, "host zone should be halted") | ||
zone.Halted = false | ||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, zone) | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().ResumeHostZone(s.Ctx, &tc.validMsg) | ||
s.Require().Error(err, "shouldn't be able to call tx on unhalted zones") | ||
expectedErrorMsg := fmt.Sprintf("invalid chain id, zone for %s not halted: host zone is not halted", HostChainId) | ||
s.Require().Equal(expectedErrorMsg, err.Error(), "should return correct error msg") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) { | |
cdc.RegisterConcrete(&MsgUndelegateHost{}, "stakeibc/UndelegateHost", nil) | ||
cdc.RegisterConcrete(&MsgCalibrateDelegation{}, "stakeibc/CalibrateDelegation", nil) | ||
cdc.RegisterConcrete(&MsgUpdateInnerRedemptionRateBounds{}, "stakeibc/UpdateInnerRedemptionRateBounds", nil) | ||
cdc.RegisterConcrete(&MsgResumeHostZone{}, "stakeibc/ResumeHostZone", nil) | ||
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. Should we test this with ledger? 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. It's a good point, let's test it in Dockernet |
||
// this line is used by starport scaffolding # 2 | ||
} | ||
|
||
|
@@ -45,6 +46,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { | |
&MsgUndelegateHost{}, | ||
&MsgCalibrateDelegation{}, | ||
&MsgUpdateInnerRedemptionRateBounds{}, | ||
&MsgResumeHostZone{}, | ||
) | ||
|
||
registry.RegisterImplementations((*govtypes.Content)(nil), | ||
|
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.
Should we test this on dockernet as well?
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.
Definitely