Skip to content
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

Properly Account for slash_query_in_progress in Unbondings #981

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion x/stakeibc/keeper/unbonding_records.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,16 @@ func (k Keeper) UnbondFromHostZone(ctx sdk.Context, hostZone types.HostZone) err
// Determine the ideal balanced delegation for each validator after the unbonding
// (as if we were to unbond and then rebalance)
// This will serve as the starting point for determining how much to unbond each validator
delegationAfterUnbonding := hostZone.TotalDelegations.Sub(totalUnbondAmount)
// first, get the total delegations _excluding_ validators with slash_query_in_progress
totalValidDelegationBeforeUnbonding := sdkmath.ZeroInt()
for _, validator := range hostZone.Validators {
if !validator.SlashQueryInProgress {
totalValidDelegationBeforeUnbonding = totalValidDelegationBeforeUnbonding.Add(validator.Delegation)
}
}
// then subtract out the amount to unbond
delegationAfterUnbonding := totalValidDelegationBeforeUnbonding.Sub(totalUnbondAmount)
shellvish marked this conversation as resolved.
Show resolved Hide resolved

balancedDelegationsAfterUnbonding, err := k.GetTargetValAmtsForHostZone(ctx, hostZone, delegationAfterUnbonding)
if err != nil {
return errorsmod.Wrapf(err, "unable to get target val amounts for host zone %s", hostZone.ChainId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,44 @@ func (s *KeeperTestSuite) TestUnbondFromHostZone_Successful_UnbondOnlyZeroWeight
s.CheckUnbondingMessages(tc, expectedUnbondings)
}

func (s *KeeperTestSuite) TestUnbondFromHostZone_Successful_UnbondIgnoresSlashQueryInProgress() {
// Native Stake: 100
// LSM Stake: 0
// Total Stake: 100
//
// Slash Query In Progress Stake: 25
// Eligible Stake: 75
//
// Unbond Amount: 20
// Stake After Unbond: 80
// Eligible Stake After Unbond 45
totalUnbondAmount := sdkmath.NewInt(20)
totalStake := sdkmath.NewInt(100)
totalWeight := int64(100)

validators := []*types.Validator{
// Current: 25, Weight: 15%, Balanced: (15/75) * 55= 11, Capacity: 25-11 = 14 > 0
{Address: "valA", Weight: 15, Delegation: sdkmath.NewInt(25)},
// Current: 25, Weight: 20%, Balanced: (20/75) * 55 = 14.66, Capacity: 25-14.66 = 10.44 > 0
{Address: "valB", Weight: 20, Delegation: sdkmath.NewInt(25)},
// Current: 25, Weight: 40%, Balanced: (40/75) * 55 = 29.33, Capacity: 25-29.33 < 0
{Address: "valC", Weight: 40, Delegation: sdkmath.NewInt(25)},
// Current: 25, Weight: 25%, Slash-Query-In-Progress so ignored
{Address: "valD", Weight: 25, Delegation: sdkmath.NewInt(25), SlashQueryInProgress: true},
}

expectedUnbondings := []ValidatorUnbonding{
// valA has #1 priority - unbond up to 14
{Validator: "valA", UnbondAmount: sdkmath.NewInt(14)},
// 20 - 14 = 6 unbond remaining
// valB has #2 priority - unbond up to remaining
{Validator: "valB", UnbondAmount: sdkmath.NewInt(6)},
}

tc := s.SetupTestUnbondFromHostZone(totalWeight, totalStake, totalUnbondAmount, validators)
s.CheckUnbondingMessages(tc, expectedUnbondings)
}

func (s *KeeperTestSuite) TestUnbondFromHostZone_Successful_UnbondTotalLessThanTotalLSM() {
// Native Stake: 1000
// LSM Stake: 250
Expand Down
Loading