Skip to content

Wallet coinselection #928

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

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft

Conversation

nodech
Copy link
Contributor

@nodech nodech commented Apr 24, 2025

Wallet Coin Selection

This PR adds new coin indexes to the txdb and uses them inside wallet for
coinselection instead of selecting every coin for in memory sorting.
This should allow wallet to scale for these specific selections regardless of
the number of coins. Also this reduces the search space to only spendable coins
from the beginning.
The wallet's coin selection now offers two optimized methods,
dbvalue and dbage, alongside existing options (all, value, age,
random). Unlike previous methods that load and process all coins from the
database in memory, these new variations stream coins directly to the selector,
potentially improving performance.

Name for dbvalue and dbage is not final, can be changed. Alternatives
include but not limited to: streamvalue, queryvalue...

MTX

MTX Coinselection has been moved outside to allow for replacable coin sources.

TXDB Layout

  • By Height
    • Sh[height:uint32][coin-hash:hash256][coin-index:uint32] - Coin by height/age for wallet.
    • SH[account:uint32][height:uint32][coin-hash:hash256][coin-index:uint32] - Coin by height/age per account.
  • By value
    • Sv[value:uint64][coin-hash:hash256][coin-index:uint32] - Confirmed coins by value for wallet.
    • SV[account:uint32[value:uint64][coin-hash:hash256][coin-index:uint32] - Confirmed by value per account.
    • Su[value:uint64][coin-hash:hash256][coin-index:uint32] - Unconfirmed coins by value for wallet.
    • SU[account:uint32[value:uint64][coin-hash:hash256][coin-index:uint32] - Unconfirmed coins by value per account.

Other prefixes can also be considered for the TXDB: q or Q.

TODO:

  • Add layout indexes for By Height + Account (Useful for AGE sort)
  • Add layout indexes for By Value + Account
  • Wallet coinselector
  • Benchmarks
  • Migration
  • Migration test
  • Migration test \w data

@coveralls
Copy link

coveralls commented Apr 24, 2025

Coverage Status

coverage: 71.477% (+0.2%) from 71.269%
when pulling dded017 on nodech:wallet-coinselection
into 5f11d62 on handshake-org:master.

@nodech nodech force-pushed the wallet-coinselection branch from fa1d30d to 40a083a Compare May 15, 2025 10:18
@nodech nodech added this to the hsd 8.0.0 milestone May 21, 2025
@nodech nodech added feature general - adding feature wallet part of the codebase breaking-minor Backwards compatible - Release version labels May 21, 2025
@nodech nodech self-assigned this May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-minor Backwards compatible - Release version feature general - adding feature wallet part of the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants