-
Notifications
You must be signed in to change notification settings - Fork 101
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
multi: v2 reputation and client bond refactor #2501
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice improvements.. I'm glad the code in the wallets got simplified.
client/core/bond.go
Outdated
inBonds, _ := dc.bondTotalInternal(bondAssetID) | ||
totalReserves := bondOverlap * bondAssetAmt * targetTier // this dexConnection | ||
if totalReserves > inBonds { | ||
nominalReserves += totalReserves - inBonds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have 2 bonds active, but the user setting is to maintain 1 bond, wouldn't we have insufficient reserves for the overlap period?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way I'm doing it with minBondReserves
in 402ddee resolves this and actually makes reserves much more accurate.
server/account/account.go
Outdated
// Reputation is a part of a number of server-originating messages. It was | ||
// introduced with the v2 ConnectResult. | ||
type Reputation struct { | ||
BondedTier int64 `json:"bondedTier"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the server not only sent the BondTier
, but also the list of bond IDs it knows about. This would allow the client to know about any mismatches between bonds it thinks have been posted vs bonds the server knows about.
expectedServerTier++ | ||
} | ||
reportedServerTier := state.Rep.EffectiveTier() | ||
if reportedServerTier < expectedServerTier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reportedServerTier < expectedServerTier
could be true because the client thinks the server knows about some bonds that it actually does not know about. Not just due to penalties. If the BondIDs are added to the Reputation
, those existing bonds could be reposted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you're getting at is handled on connection in authDEX
. By this point, any discrepancy is likely unresolvable, and the user should rely on their configuration (PenaltyComps
, MaxBondedAmt
) to prevent a malicious server from forcing a bunch of bonds they refuse to recognize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it now.
17d9168
to
402ddee
Compare
client/core/bond.go
Outdated
if targetTier == 0 { | ||
return 0 | ||
} | ||
// Keep a list of tuples of [weakTime, bondStrength]. Later, we'll checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checks
client/core/bond.go
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
supported.
Consider
client/core/bond.go
Outdated
// we need to add the missing bond strength. | ||
reserveTiers := targetTier - tierSum | ||
sort.Slice(activeTiers, func(i, j int) bool { | ||
return activeTiers[i][0] < activeTiers[j][1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sort is comparing the weak time to the strength.
client/core/bond.go
Outdated
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be double counted? Since we need this amount of tiers now, and then the same amount when the ones we need to submit now become weak.
I didn't mean to approve yet, I'm still planning to test it. |
402ddee
to
323d4c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of changes but looks good to me. Will continue to test.
// DRAFT NOTE: This was wrong? Isn't account suspended at tier 0? | ||
// cannotTrade := dc.acct.effectiveTier < 0 || (dc.acct.effectiveTier == 0 && dc.apiVersion() < serverdex.BondAPIVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Suspended", but maybe just no longer bonded? effectiveTier
of zero may not indicate penalties. So it would not make a new account unless there was surely a penalty (<0 effective tier).
client/core/core.go
Outdated
// Using <= though acknowledging that this ignore the possibility that | ||
// an existing revoked bond could be ressurected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Using <= though acknowledging that this ignore the possibility that | |
// an existing revoked bond could be ressurected. | |
// Using <= though acknowledging that this ignores the possibility that | |
// an existing revoked bond could be resurrected. |
keyIndex++ | ||
c.log.Infof("HD account key for %s has tier %d, but %d penalties (not able to trade). Deriving another account key.", | ||
dc.acct.host, rep.BondedTier, rep.Penalties) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to increment key index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah. Good catch.
client/core/core.go
Outdated
// On the server, they do | ||
// bondTier += int64(bond.Strength) | ||
// where bond.Strength is a value stored in the database during | ||
// postbond. This means if ther server doubles the bond size for an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// postbond. This means if ther server doubles the bond size for an | |
// postbond. This means if the server doubles the bond size for an |
client/core/core.go
Outdated
// TODO: notify sub consumers e.g. frontend | ||
c.notify(newReputationNote(dc.acct.host, rep)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove TODO?
server/account/account.go
Outdated
// Reputation is a part of a number of server-originating messages. It was | ||
// introduced with the v2 ConnectResult. | ||
type Reputation struct { | ||
// BondedTier is the tier indicated by the users active bonds. BondedTier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// BondedTier is the tier indicated by the users active bonds. BondedTier | |
// BondedTier is the tier indicated by the user's active bonds. BondedTier |
323d4c3
to
e4860c6
Compare
e4860c6
to
d77aee6
Compare
Server
Client
asset.Bonder
. There was a lot of tracking going on in ourBonder
implementations that was used exclusively for logging. I can see an argument being made that the wallet should know about outstanding bond value, but the wallet didn't even know the bond IDs, so the wallets weren't really managing bonds in any way that added security. There was really nothing happening that couldn't be logged by the caller. Also swaps out the diff-based approach to reserves management, which is tedious and error-prone, to a simpler idempotent setter pattern.Strength
field to variousBond
structs. That's how the server calculates tier already. Client was using a different calc. Changes to bond asset configuration could have gotten client and server out of sync.PenaltyComps
value for the account in order for penalties to be compensated.PenaltyComps
works in conjunction withMaxBondedAmt
, but specifically applies to limiting penalties.ConnectResult
is the only place we can get our score.Replaces #2471