-
Notifications
You must be signed in to change notification settings - Fork 137
garbage collect zero-value UTXOs #1832
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
base: 0-8-0-staging
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 19360804740Details
💛 - Coveralls |
f3a3bff to
f55b6c5
Compare
3bd769d to
6fe11a5
Compare
a8f3ce4 to
afbfebf
Compare
bf3e3ee to
d812a8e
Compare
d812a8e to
0ceaf76
Compare
|
I like |
ef93717 to
d9383ba
Compare
GeorgeTsagk
left a comment
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.
last nits, 99% there
d9383ba to
773c448
Compare
GeorgeTsagk
left a comment
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.
LGTM
773c448 to
4fb0135
Compare
1cf422a to
66faf3f
Compare
2b3ac4f to
035a840
Compare
This includes the addition of a "swept" field in the "managed_utxos" table with the corresponding migration and the "MarkManagedUTXOAsSwept" function.
…ng family and index
66faf3f to
61a19e9
Compare
|
@ffranr: review reminder |
ffranr
left a comment
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 we should double check our logic around coin release but otherwise just nits.
| LeaseExpiry: sql.NullTime{ | ||
| Time: finalLeaseExpiry.UTC(), | ||
| Valid: true, | ||
| }, |
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.
Could be a helper like sqlInt16
| err := readOutPoint( | ||
| bytes.NewReader(u.Outpoint), 0, 0, &anchorPoint) |
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.
trailing ) should be on a new line
| err = q.MarkManagedUTXOAsSwept(ctx, | ||
| MarkManagedUTXOAsSweptParams{ | ||
| Outpoint: outpointBytes, | ||
| SweepingTxid: conf.AnchorTXID[:], | ||
| }) |
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.
trailing ) should be on a new line
| len(pkg.InputCommitments) > 0 { | ||
| // Also unlock any zero-value UTXOs that were leased for this package. | ||
| if pkg.SendState < SendStateStorePreBroadcast { | ||
| // Gather all outpoints to unlock in a single array |
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.
Punctuation missing for comments here and below.
| // We now need to lock/lease/reserve those selected coins so | ||
| // that they can't be used by other processes. | ||
| if len(zeroValueInputs) > 0 { | ||
| expiry := time.Now().Add(defaultCoinLeaseDuration) |
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.
Worth using time.Now().UTC() here IMO so every time as much as possible is UTC at every point.
tapfreighter/wallet.go
Outdated
| zeroValueInputs, err := f.cfg.CoinSelector.SelectOrphanCoins(ctx) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to select zero-value "+ | ||
| "UTXOs: %w", err) | ||
| } |
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.
Same here. If we return an error at this point then we wont release all coins.
| // Send full amount of the new asset. This should sweep Alice's | ||
| // first tombstone and create a new one. | ||
| bobAddr2, err := secondTapd.NewAddr(ctxb, &taprpc.NewAddrRequest{ | ||
| AssetId: genInfo2.AssetId, | ||
| Amt: assetAmount, | ||
| AssetVersion: rpcAssets2[0].Version, | ||
| }) | ||
| require.NoError(t.t, err) | ||
|
|
||
| sendResp2, _ := sendAssetsToAddr(t, t.tapd, bobAddr2) | ||
|
|
||
| ConfirmAndAssertOutboundTransfer( | ||
| t.t, t.lndHarness.Miner().Client, t.tapd, sendResp2, | ||
| genInfo2.AssetId, | ||
| []uint64{0, assetAmount}, 1, 2, | ||
| ) | ||
| AssertNonInteractiveRecvComplete(t.t, secondTapd, 2) |
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.
Maybe we can inspect this transaction to ensure that the additional zero-value tombstone input is present.
| // Wait for the node to fully sync after restart. | ||
| time.Sleep(2 * time.Second) | ||
|
|
||
| // Verify that the zero-value UTXOs are still present after restart. | ||
| //nolint:lll | ||
| tombstoneUtxosAfterRestart, err := t.tapd.ListUtxos(ctxb, &taprpc.ListUtxosRequest{ |
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.
Instead of this sleep you could possibly use ListUtxosRPC itest helper. Sleep can cause flakes.
| require.NoError(t, err) | ||
|
|
||
| transferResp, err := sender.ListTransfers( | ||
| ctxb, &taprpc.ListTransfersRequest{}, | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| transferRespJSON, err := formatProtoJSON(transferResp) | ||
| require.NoError(t, err) | ||
| t.Logf("Got response from list transfers: %v", transferRespJSON) |
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.
Why remove these lines? That doesn't seem to fix under the commit subject. Same further above also.
itest/test_list_on_test.go
Outdated
| test: testZeroValueAnchorSweep, | ||
| tapdOptions: []Option{ | ||
| WithSweepOrphanUtxos(), | ||
| }, | ||
| }, |
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.
hmm I don't think I'm a fan of this change. I think it was clearer if t.tapd had the default options and we just create a new tapd instance if we need to specify configuration. I think we should remove the proofCourierType field also.
I don't think we should consult this list to see how the primary tapd node is configured. But I won't block on this change, we can revisit later.
Garbage collect the residue orphaned UTXOs when creating transactions. Orphaned UTXOs occur when creating tombstones or full burns.
Currently, these UTXOs accumulate in the DB and are never cleaned. This PR introduces a garbage collection mechanism to collect these UTXOs and use them as inputs of transactions initiated by
tapd:The PR adds a new
sweptflag to themanaged_utxotable because UTXOs are not removed from the table when spent. This flag is also returned by theListUtxosRPC endpoint.The mechanism preserves the liveness and safety properties, ensuring that zero-value UTXOs can never accumulate in the DB. Adding garbage collection to Mint transactions is not necessary to ensure these properties.
Fixes #514
Note to reviewers
unspent, keeping the spent outputs in a table calledmanage_utxosseems like a contradiction, same logic applies for the need of asweptflag in that table. We should either rename the table or store spent utxos somewhere else?