Skip to content

Conversation

@darioAnongba
Copy link
Contributor

@darioAnongba darioAnongba commented Oct 1, 2025

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

  1. UTXO meaning unspent, keeping the spent outputs in a table called manage_utxos seems like a contradiction, same logic applies for the need of a swept flag in that table. We should either rename the table or store spent utxos somewhere else?

@darioAnongba darioAnongba self-assigned this Oct 1, 2025
@coveralls
Copy link

coveralls commented Oct 1, 2025

Pull Request Test Coverage Report for Build 18382547235

Details

  • 21 of 354 (5.93%) changed or added relevant lines in 10 files are covered.
  • 28020 unchanged lines in 195 files lost coverage.
  • Overall coverage decreased (-15.2%) to 34.469%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapfreighter/parcel.go 0 4 0.0%
tapdb/sqlc/assets.sql.go 0 6 0.0%
rpcserver.go 0 11 0.0%
tapfreighter/coin_select.go 0 29 0.0%
tapfreighter/chain_porter.go 0 40 0.0%
tapfreighter/wallet.go 0 70 0.0%
tapdb/assets_store.go 3 176 1.7%
Files with Coverage Reduction New Missed Lines %
universe/supplyverifier/util.go 1 98.75%
proof/util.go 2 81.63%
tapdb/migrations.go 2 76.19%
address/log.go 3 0.0%
commitment/log.go 3 0.0%
internal/pedersen/commitment.go 3 95.31%
lndservices/log.go 3 0.0%
rfq/log.go 3 0.0%
tapchannel/log.go 3 0.0%
tapdb/supply_syncer.go 3 73.85%
Totals Coverage Status
Change from base Build 18359865357: -15.2%
Covered Lines: 30524
Relevant Lines: 88554

💛 - Coveralls

@levmi levmi moved this from 🆕 New to 🏗 In progress in Taproot-Assets Project Board Oct 2, 2025
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from f3a3bff to f55b6c5 Compare October 3, 2025 16:21
@darioAnongba darioAnongba changed the base branch from main to 0-8-0-staging October 6, 2025 09:43
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 3 times, most recently from 3bd769d to 6fe11a5 Compare October 6, 2025 15:03
@darioAnongba darioAnongba changed the base branch from 0-8-0-staging to main October 6, 2025 15:03
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 10 times, most recently from a8f3ce4 to afbfebf Compare October 9, 2025 13:04
@darioAnongba darioAnongba marked this pull request as ready for review October 9, 2025 13:09
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 4 times, most recently from bf3e3ee to d812a8e Compare October 9, 2025 16:04
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from d812a8e to 0ceaf76 Compare October 9, 2025 16:32
@darioAnongba darioAnongba moved this from 🏗 In progress to 👀 In review in Taproot-Assets Project Board Oct 9, 2025
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from f4fb800 to 127946d Compare October 16, 2025 14:17
@darioAnongba darioAnongba requested review from ffranr and removed request for Roasbeef October 16, 2025 14:18
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

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

awesome work!

// Bip32Derivation is the BIP32 derivation info for the internal key.
// This is used to preserve the key derivation through the allocation
// flow so that PSBTs can be properly signed.
Bip32Derivation []*psbt.Bip32Derivation
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, we were not persisting the necessary information in the DB to be able to sign the input for zero value UTXOs. Laolu described the bug here: https://github.com/lightninglabs/taproot-assets/blob/main/docs/debug-handbook/psbt-finalization-failures.md#a-bip32-key-derivation-mismatch.

Specifically the KeyFamily or KeyIndex not preserved when storing keys.

@GeorgeTsagk
Copy link
Member

also needs a rebase

@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 4 times, most recently from faf184a to d52a498 Compare October 27, 2025 15:29
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from d52a498 to 6edd03c Compare October 27, 2025 18:04
@ffranr
Copy link
Contributor

ffranr commented Oct 28, 2025

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.

@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 3 times, most recently from 5635183 to 0b60ce3 Compare October 28, 2025 17:41
@darioAnongba
Copy link
Contributor Author

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.

@darioAnongba darioAnongba requested a review from ffranr October 28, 2025 17:43
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch 3 times, most recently from cdac2f2 to ef93717 Compare October 28, 2025 18:57
@darioAnongba darioAnongba force-pushed the feat/zero-value-utxo-selection branch from ef93717 to d9383ba Compare October 28, 2025 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

wallet: garbage collect tombstone UTXOs

5 participants