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

multi: v2 reputation and client bond refactor #2501

Merged
merged 16 commits into from Oct 3, 2023

Conversation

buck54321
Copy link
Member

@buck54321 buck54321 commented Sep 5, 2023

Server

  1. Eliminate "bonus tiers". They weren't doing anything.
  2. Server sends updates for score changes too.
  3. Reverse scoring signage to match common convention.

Client

  1. Simplify asset.Bonder. There was a lot of tracking going on in our Bonder 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.
  2. Add Strength field to various Bond 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.
  3. Penalties are not auto-compensated by default. User will need to set a non-zero PenaltyComps value for the account in order for penalties to be compensated. PenaltyComps works in conjunction with MaxBondedAmt, but specifically applies to limiting penalties.
  4. Parallel tracks will now merge. This is accomplished by shortening the lifetime of a new bond if there is an existing live bond with which this bond can be merged upon expiration.
  5. For v1 rep servers, we will periodically re-auth since the ConnectResult is the only place we can get our score.

Replaces #2471

@buck54321 buck54321 mentioned this pull request Sep 6, 2023
Copy link
Contributor

@martonp martonp left a 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.

server/account/account.go Outdated Show resolved Hide resolved
server/auth/auth.go Outdated Show resolved Hide resolved
server/auth/auth.go Outdated Show resolved Hide resolved
inBonds, _ := dc.bondTotalInternal(bondAssetID)
totalReserves := bondOverlap * bondAssetAmt * targetTier // this dexConnection
if totalReserves > inBonds {
nominalReserves += totalReserves - inBonds
Copy link
Contributor

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?

Copy link
Member Author

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.

client/core/types.go Outdated Show resolved Hide resolved
// 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"`
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it now.

if targetTier == 0 {
return 0
}
// Keep a list of tuples of [weakTime, bondStrength]. Later, we'll checks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supported.
Consider

// 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]
Copy link
Contributor

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.

Comment on lines 298 to 300
// 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
Copy link
Contributor

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.

@martonp
Copy link
Contributor

martonp commented Sep 13, 2023

I didn't mean to approve yet, I'm still planning to test it.

@JoeGruffins
Copy link
Member

This does not appear to solve #2461 which is fine just mentioning in case it is intended to as #2471 was.

Copy link
Member

@JoeGruffins JoeGruffins left a 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.

Comment on lines +3934 to +3935
// 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)
Copy link
Member

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).

Comment on lines 3937 to 3938
// Using <= though acknowledging that this ignore the possibility that
// an existing revoked bond could be ressurected.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

Comment on lines -3948 to +3942
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)
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah. Good catch.

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// postbond. This means if ther server doubles the bond size for an
// postbond. This means if the server doubles the bond size for an

Comment on lines 8694 to 8695
// TODO: notify sub consumers e.g. frontend
c.notify(newReputationNote(dc.acct.host, rep))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove TODO?

// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// BondedTier is the tier indicated by the users active bonds. BondedTier
// BondedTier is the tier indicated by the user's active bonds. BondedTier

@buck54321 buck54321 merged commit a407baa into decred:master Oct 3, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants