Skip to content

Commit

Permalink
work around bonus tier bug
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Aug 4, 2023
1 parent 95e0e58 commit 5051e26
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions client/core/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,41 @@ func (c *Core) bondStateOfDEX(dc *dexConnection, bondCfg *dexBondCfg) *dexAcctBo
}
}

tierDeficit := int64(state.targetTier) - state.tier
state.mustPost = tierDeficit + state.weakStrength - state.pendingStrength
// This old way is bugged because we have no way of knowing how many bonus
// tiers the server has assigned us, because it is not directly reported in
// any comms and to calculate it locally, we would need to know the
// server's ban score, which is configurable and not reported. We would also
// need to know our own score, but after the ConnectResult, the server
// doesn't send score updates.
//
// The old way
// -----------
// tierDeficit := int64(state.targetTier) - state.tier
// state.mustPost = tierDeficit + state.weakStrength - state.pendingStrength
// -----------
//
// Instead, if the server says we're short, we assume that we have zero
// bonus tiers and use the old calculation.
serverTierDeficit := int64(state.targetTier) - state.tier + state.weakStrength - state.pendingStrength
if serverTierDeficit > 0 {
state.mustPost = serverTierDeficit
} else {
// But if the server says we're tiered up, we may be so because we have
// bonus tiers, which ultimately causes us to ignore weak bonds. In
// that case, just make sure that our local bond data is sufficient to
// get our target tier. For clients with low targetTier and good trading
// history, this will be the primary route through which weak bonds are
// renewed.
// Note: For users with targetTier > 1, unknown bonus tiers can also
// cause us to broadcast renewal bonds that are too small, resulting
// in split bonds that cost the user unnecessary tx fees. This solution
// is only a stop-gap. A proper solution will require more data from the
// API so we can know our bonus tiers.
bondTierDeficit := int64(state.targetTier) - state.liveStrength - state.pendingStrength + state.weakStrength
if bondTierDeficit > 0 {
state.mustPost = bondTierDeficit
}
}

return state
}
Expand Down

0 comments on commit 5051e26

Please sign in to comment.