Skip to content

feat(wallet): UTXO pool management for high-frequency transactions#492

Merged
sgbett merged 11 commits intomasterfrom
feat/474-utxo-pool-management
Apr 18, 2026
Merged

feat(wallet): UTXO pool management for high-frequency transactions#492
sgbett merged 11 commits intomasterfrom
feat/474-utxo-pool-management

Conversation

@sgbett
Copy link
Copy Markdown
Owner

@sgbett sgbett commented Apr 17, 2026

Summary

  • Implement BRC-122 two-zone basket validation (flat zone unchanged, structured zone for colon-delimited namespaces like pool:doom)
  • Add UTXOPool interface module + LocalPool concrete implementation with acquire/release/status/shutdown
  • Add ReplenishmentWorker background thread with inlined BRC-29 derivation for pool output creation
  • Add update_output_basket to StorageAdapter for metadata-only basket reassignment
  • Fix store_tracked_outputs to persist derivation metadata for basket outputs
  • Wire utxo_pool factory into WalletClient
  • 84 new specs with regression coverage for all 9 bugs from the previous implementation attempt

Round-1 bug regressions (all covered by specs)

  1. Pool locks use no_send: true — exempt from 300s stale recovery
  2. Basket validator accepts pool:doom via BRC-122 structured zone
  3. Replenisher signalled at <= watermark (not <)
  4. store_tracked_outputs persists derivation metadata
  5. create_action called with explicit Hash literal
  6. Split outputs include output_description (25 chars)
  7. Split uses auto_fund: true
  8. pool.storage exposed via attr_reader
  9. Scavenge TOCTOU race documented (benign, self-corrects)

Test plan

Closes #474

Generated with Claude Code

sgbett and others added 9 commits April 17, 2026 23:57
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Metadata-only basket reassignment (BRC-66 principle). Raises WalletError
if outpoint not found. TOCTOU race documented in StorageAdapter YARD docs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
#489)

Background thread that monitors a LocalPool and calls create_action to
fund new outputs when the pool falls below its target count. Inlines
BRC-29 derivation logic (prefix/suffix/key_id) to avoid coupling to
ChangeGenerator's private build_output method. Applies all round-1 bug
fixes: auto_fund: true, hex locking_script, derivation metadata fields,
structured-zone basket, and explicit Hash wrapping on create_action call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…on coverage (#491)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sgbett sgbett force-pushed the feat/474-utxo-pool-management branch from 3bb344a to 6817a88 Compare April 17, 2026 22:57
sgbett and others added 2 commits April 18, 2026 00:31
…er validation

- ReplenishmentWorker now replenishes immediately on start before
  entering the wait loop. Previously, run_loop slept up to 60s before
  the first cycle, leaving newly created pools empty (chicken-and-egg:
  acquire raises PoolDepletedError, signal path never reached).

- Structured basket validator now rejects non-normalised input (mixed
  case, leading/trailing whitespace). Previously it normalised internally
  but callers stored the original string, causing lookup mismatches.

- utxo_pool factory eagerly validates the basket name and checks
  broadcast_enabled? before creating the pool. Previously, invalid names
  or missing broadcasters caused silent replenishment failures caught by
  the worker's rescue block.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements the new StorageAdapter method added in the UTXO pool work.
Updates both the basket column and the JSONB data blob. Follows the
same pattern as update_output_state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2026

Codecov Report

❌ Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...sv-wallet/lib/bsv/wallet_interface/memory_store.rb 16.66% 5 Missing ⚠️
...wallet/lib/bsv/wallet_interface/storage_adapter.rb 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@sgbett sgbett merged commit 8d5cafa into master Apr 18, 2026
10 checks passed
@sgbett sgbett deleted the feat/474-utxo-pool-management branch April 18, 2026 01:30
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.

[HLR] UTXO Pool Management for High-Frequency Transactions

1 participant