-
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
Merged
+885
−104
Merged
Inflation Fix #951
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
005c24e
update inflation fix
shellvish 624d924
add halting to LSM
shellvish 2a0f911
add resume host zone func
shellvish 7b4eb66
add rate limit change
shellvish f144dbd
pr comments
shellvish c759b6f
iterate blacklist
shellvish 95b5c5b
update upgrade handler to remove stuatom
shellvish a51600c
updated github readme
sampocs 3b063d8
threw error if host zone not found in upgrade handler
sampocs 8544454
update v16 tests
shellvish 3ac58a6
Merge branch 'inflation-fix' of https://github.com/Stride-Labs/stride…
shellvish 4544ea1
gosec changes
shellvish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) { | ||
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 | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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