Skip to content

Commit

Permalink
review followup
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Sep 17, 2023
1 parent 0b80792 commit 323d4c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 9 additions & 7 deletions client/core/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ func (c *Core) updateBondReserves(balanceCheckID ...uint32) {
}
}

// minBondReserveTiers calculates the minimum number of tiers that we need to
// minBondReserves calculates the minimum number of tiers that we need to
// reserve funds for. minBondReserveTiers must be called with the authMtx
// RLocked.
func (c *Core) minBondReserves(dc *dexConnection, bondAsset *BondAsset) uint64 {
acct, targetTier := dc.acct, dc.acct.targetTier
if targetTier == 0 {
return 0
}
// Keep a list of tuples of [weakTime, bondStrength]. Later, we'll checks
// Keep a list of tuples of [weakTime, bondStrength]. Later, we'll check
// these against expired bonds, to see how many tiers we can expect to have
// refunded funds avilable for.
activeTiers := make([][2]uint64, 0)
Expand All @@ -278,8 +278,8 @@ func (c *Core) minBondReserves(dc *dexConnection, bondAsset *BondAsset) uint64 {
weakTime := bond.LockTime - bondExpiry - pBuffer
ba := dexCfg.BondAssets[dex.BipIDSymbol(bond.AssetID)]
if ba == nil {
// Bond asset no longer supported Can't calculate strength. Consdier
// it strength one.
// Bond asset no longer supported. Can't calculate strength.
// Consider it strength one.
activeTiers = append(activeTiers, [2]uint64{weakTime, 1})
continue
}
Expand All @@ -295,11 +295,13 @@ func (c *Core) minBondReserves(dc *dexConnection, bondAsset *BondAsset) uint64 {
break
}
}

// If our active+pending bonds don't cover our target tier for some reason,
// we need to add the missing bond strength.
reserveTiers := targetTier - tierSum
// we need to add the missing bond strength. Double-count because we
// needed to renew these bonds too.
reserveTiers := (targetTier - tierSum) * 2
sort.Slice(activeTiers, func(i, j int) bool {
return activeTiers[i][0] < activeTiers[j][1]
return activeTiers[i][0] < activeTiers[j][0]
})
sort.Slice(acct.expiredBonds, func(i, j int) bool { // probably already is sorted, but whatever
return acct.expiredBonds[i].LockTime < acct.expiredBonds[j].LockTime
Expand Down
4 changes: 3 additions & 1 deletion client/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10513,7 +10513,9 @@ func TestUpdateBondOptions(t *testing.T) {
var targetTierZero uint64 = 0
defaultMaxBondedAmt := maxBondedMult * bondAsset.Amt * targetTier
tooLowMaxBonded := defaultMaxBondedAmt - 1
singlyBondedReserves := bondAsset.Amt*targetTier + bondFeeBuffer
// Double because we will reserve for the bond that's about to be posted
// in rotateBonds too.
singlyBondedReserves := bondAsset.Amt*targetTier*2 + bondFeeBuffer

type acctState struct {
targetTier uint64
Expand Down

0 comments on commit 323d4c3

Please sign in to comment.