taproot-assets
taproot-assets copied to clipboard
garbage collect zero-value UTXOs
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:
- Transfers
- Burns
The PR adds a new swept flag to the managed_utxo table because UTXOs are not removed from the table when spent. This flag is also returned by the ListUtxos RPC 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
- UTXO meaning
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?
Pull Request Test Coverage Report for Build 19575345571
Details
- 293 of 382 (76.7%) changed or added relevant lines in 16 files are covered.
- 388 unchanged lines in 29 files lost coverage.
- Overall coverage increased (+6.7%) to 56.271%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| asset/asset.go | 3 | 5 | 60.0% |
| itest/assertions.go | 0 | 3 | 0.0% |
| itest/test_harness.go | 1 | 5 | 20.0% |
| rpcserver.go | 10 | 15 | 66.67% |
| tapfreighter/chain_porter.go | 40 | 45 | 88.89% |
| tapfreighter/coin_select.go | 23 | 29 | 79.31% |
| tapfreighter/wallet.go | 59 | 80 | 73.75% |
| tapdb/assets_store.go | 106 | 149 | 71.14% |
| <!-- | Total: | 293 | 382 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| fn/context_guard.go | 1 | 91.94% |
| fn/func.go | 2 | 58.82% |
| tapdb/assets_common.go | 2 | 77.97% |
| tapdb/migrations.go | 2 | 76.19% |
| tapdb/sqlc/transfers.sql.go | 2 | 82.65% |
| tapdb/universe_federation.go | 2 | 88.55% |
| itest/assertions.go | 3 | 87.33% |
| itest/multisig.go | 3 | 97.94% |
| proof/courier.go | 3 | 79.57% |
| tapdb/sqlc/db_custom.go | 3 | 70.83% |
| <!-- | Total: | 388 |
| Totals | |
|---|---|
| Change from base Build 19360481010: | 6.7% |
| Covered Lines: | 64244 |
| Relevant Lines: | 114169 |
💛 - Coveralls
Please rebase on to the latest in [0-8-0-staging](https://github.com/lightninglabs/taproot-assets/tree/0-8-0-staging). Might get you more PSBT funding test coverage now that https://github.com/lightninglabs/taproot-assets/pull/1418 is merged.
also needs a rebase
Non-blocking, but for the sweepZeroValueAnchorUtxos config field: “sweep orphaned UTXOs” might be clearer. “Anchor” is implied by UTXO, and “zero-value” isn’t accurate since they contain 1000 sats. If they were zero value there would be nothing to sweep.
I like SweepOrphanUtxos better as well. I renamed it everywhere at the config level, let me know if you think we should rename all the way down to the DB layer. In the context of assets, zero-value is correct though, but more verbose and uglier.
@ffranr: review reminder