Skip to content

Comments

feat(bitcoin): Add indexing UTXO on event#42

Open
Azzurriii wants to merge 6 commits intomainfrom
feat/index-utxo
Open

feat(bitcoin): Add indexing UTXO on event#42
Azzurriii wants to merge 6 commits intomainfrom
feat/index-utxo

Conversation

@Azzurriii
Copy link
Collaborator

  • Added UTXO event structure and related methods for tracking created and spent UTXOs.
  • Enhanced BitcoinIndexer to extract UTXO events from transactions and include them in block metadata.
  • Updated MempoolWorker to process and emit UTXO events for monitored addresses.
  • Modified emitter to support UTXO event emission to NATS.
  • Refactored Block type to include metadata for better extensibility.

- Added UTXO event structure and related methods for tracking created and spent UTXOs.
- Enhanced BitcoinIndexer to extract UTXO events from transactions and include them in block metadata.
- Updated MempoolWorker to process and emit UTXO events for monitored addresses.
- Modified emitter to support UTXO event emission to NATS.
- Refactored Block type to include metadata for better extensibility.
@Azzurriii Azzurriii requested a review from anhthii February 10, 2026 06:00
@anhthii
Copy link
Contributor

anhthii commented Feb 19, 2026

revert c24bb6e , not necessary

Additional feedback:

Mempool should not emit UTXOs. UTXOs are used for balance calculation and spending decisions. Mempool txs can be dropped or replaced (RBF), making mempool
UTXOs unreliable. If a consumer spends a UTXO from a mempool tx that never confirms, the spending tx fails. Mempool worker should only emit transfer events
(for UI notifications), not UTXOs.

Adding UTXO subjects to the existing transfer stream causes a NATS
subject overlap error, and deleting the stream to recreate it would
lose unconsumed messages. Use a separate "utxo" stream instead.
@anhthii
Copy link
Contributor

anhthii commented Feb 19, 2026

❯ go run cmd/indexer/main.go index --chains=bitcoin_testnet --debug --manual
2026-02-19T18:16:29+07:00 INF Config loaded environment=development
2026-02-19T18:16:29+07:00 INF Connecting to redis url=localhost:6379 environment=development mtls=false
2026-02-19T18:16:29+07:00 INF Connected to Redis pong=PONG
2026-02-19T18:16:29+07:00 INF Redis connection established
2026-02-19T18:16:29+07:00 INF Database connection skipped - not configured
2026-02-19T18:16:29+07:00 INF Connecting to kvstore url=127.0.0.1:8500
2026-02-19T18:16:29+07:00 INF Connecting to NATS url=nats://localhost:4222
2026-02-19T18:16:29+07:00 INF NATS connection established
2026-02-19T18:16:29+07:00 INF Stream found name=transfer subjects=[transfer.event.*] state=0
2026-02-19T18:16:29+07:00 ERR Error creating JetStream stream: !BADKEY="nats: API error: code=400 err_code=10065 description=subjects overlap with an

NATS JetStream is rejecting a stream creation because the subjects it wants to use are already claimed by another existing stream.

Fix create a separate stream for utxo without deleting and recreating transfer stream that can cause lost of unconsumed messages
a19577d

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.

2 participants