Skip to content

Commit

Permalink
Merge branch 'main' into cleanup_v15
Browse files Browse the repository at this point in the history
  • Loading branch information
riley-stride authored Dec 6, 2023
2 parents 06144f3 + 5a7b105 commit 5ba3c7a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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)

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

0 comments on commit 5ba3c7a

Please sign in to comment.