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

client/db: active and archived match buckets #1263

Merged
merged 4 commits into from Nov 11, 2021

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Nov 2, 2021

This builds on #957. @itswisdomagain's commits will be merged without squashing into this. I've added his v5 test db generator app as well, just with an added cancel order match.

This redefines the v6 client db upgrade to introduce a new active matches bucket instead of creating a Retired flag on each match.

The db and upgrade code is modeled after the active/archived orders buckets changes in #1071, whereby existing matches remain in what is to be the archived bucket, and only active ones are moved into the new active matches bucket.

client/db.MatchIsActive is updated to detect cancel matches as inactive. This is detected as MatchComplete and len(proof.Auth.InitSig) == 0 since cancel matches begin as complete and have no init/redeem data set in the Auth field.
The Address field is only empty for the maker/trade match with a cancel, but for the taker/cancel's match with the trade it has to this point contained the canceled maker order's address.

This also updates client/core to clear the Address field for both sides of a cancel match because it is pointless to store. Removing this useless data from a MetaMatch will save a bit of storage space, but previous cancel matches are not updated by the v6 upgrade. Similarly, the server's swapper is updated to not send the maker address with a cancel msgjson.Match.

Shut down the db tests properly.

Maybe 0.3

@chappjc chappjc marked this pull request as ready for review November 3, 2021 02:13
client/db/types.go Outdated Show resolved Hide resolved
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.

Works well. Some of the code looks really good to.

I didn't realized the UI was updated until just now. Looks good.

client/db/bolt/upgrades.go Outdated Show resolved Hide resolved
client/db/bolt/upgrades.go Outdated Show resolved Hide resolved
@@ -4673,7 +4673,7 @@ func (c *Core) dbTrackers(dc *dexConnection) (map[order.OrderID]*trackedTrade, e
for _, dbMatch := range dbMatches {
// Only trade matches are added to the matches map. Detect and skip
// cancel order matches, which have an empty Address field.
if dbMatch.Address == "" {
if dbMatch.Address == "" { // only correct for maker's cancel match
Copy link
Member Author

@chappjc chappjc Nov 3, 2021

Choose a reason for hiding this comment

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

This is a sorta redundant check anyway since MatchesForOrder a few lines up should screen them out, but if it fails to do so, then this check is effective for screening out this trade order's cancel match, which was a problem in the past.

Comment on lines -95 to -96
byteEpoch = uint16Bytes(uint16(order.OrderStatusEpoch))
byteBooked = uint16Bytes(uint16(order.OrderStatusBooked))
Copy link
Member Author

Choose a reason for hiding this comment

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

Were used before the orders bucket was split.

@chappjc chappjc force-pushed the active-matchs branch 2 times, most recently from 2fb45ae to 0ea934e Compare November 3, 2021 20:36
Comment on lines +18 to +24
// TODO: consider changing upgradefunc to accept a bbolt.DB so it may create its
// own transactions. The individual upgrades have to happen in separate
// transactions because they get too big for a single transaction. Plus we
// should consider switching certain upgrades from ForEach to a more cumbersome
// Cursor()-based iteration that will facilitate partitioning updates into
// smaller batches of buckets.
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines +130 to +135
matchesBucket := []byte("matches")
return reloadMatchProofs(dbtx, skipCancels, matchesBucket)
Copy link
Member

Choose a reason for hiding this comment

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

archivedMatchesBucket? Or would that be confusing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just trying to make these older upgrades more robust to future changes to package level variables by defining the bucket/key names as they are known to be at that particular version.

Comment on lines +302 to +307
oldMatchesBucket := []byte("matches")
newActiveMatchesBucket := []byte("activeMatches")
Copy link
Member

Choose a reason for hiding this comment

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

Not using activeMatchesBucket and archivedMatchesBucket because this is better semantics?

Copy link
Member Author

Choose a reason for hiding this comment

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

Missed this comment, sorry. Same consideration as other comment - a v7+ upgrade might change the package-level variables, but this v6 upgrade will always need to work with a specific key as it was in v5

@chappjc chappjc force-pushed the active-matchs branch 2 times, most recently from d5fc628 to 57c65da Compare November 10, 2021 16:02
client/db: add v3upgrade to set match retired field for existing matches

merge (*trackedTrade).matchIsActive and db.isRetiredMatch

There is now one single function with the heuristics for determining
a match's activeness, used by both trackedTrade and db.
This redefines the v5 client db upgrade to introduce a new active
matches bucket instead of creating a Retired flag on each match.

The db and upgrade code is modeled after the active/archived
orders buckets changes.

client/db.MatchIsActive is updated to detect cancel matches as
inactive. This is detected as MatchComplete and
len(proof.Auth.InitSig) == 0 since cancel matches begin as complete
and have no init/redeem data set in the Auth field.
The Address field is only empty for the maker/trade match with a
cancel, but for the taker/cancel's match with the trade it has to
this point contained the canceled maker order's address.

This also updates client/core to clear the Address field for both
sides of a cancel match. Removing this useless data from a MetaMatch
will save a bit of storage space, but previous cancel matches are not
updated by the v6 upgrade.

Shut down the db tests properly.

upgrade logger, log matches upgrade outcome
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

4 participants