-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package v1_4 | ||
|
||
const ( | ||
UpgradeName = "v1_4" | ||
) |
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,41 @@ | ||
package v1_4 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
stakingkeeper "github.com/xpladev/xpla/x/staking/keeper" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
stakingKeeper *stakingkeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
|
||
validators := stakingKeeper.GetAllValidators(ctx) | ||
for _, validator := range validators { | ||
tolerance, err := validator.SharesFromTokens(sdk.OneInt()) | ||
if err != nil { | ||
return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "validator must have valid share") | ||
} | ||
|
||
delegations := stakingKeeper.GetValidatorDelegations(ctx, validator.GetOperator()) | ||
for _, delegation := range delegations { | ||
if delegation.Shares.GTE(tolerance) { | ||
continue | ||
} | ||
|
||
_, err := stakingKeeper.Unbond(ctx, delegation.GetDelegatorAddr(), validator.GetOperator(), delegation.GetShares()) | ||
if err != nil { | ||
return nil, sdkerrors.Wrapf(sdkerrors.ErrLogic, "dust delegation must be unbond") | ||
} | ||
} | ||
} | ||
|
||
return mm.RunMigrations(ctx, configurator, fromVM) | ||
} | ||
} |