Skip to content

fix(p2p/sensor): improve transaction writing consistency#909

Merged
minhd-vu merged 8 commits intomainfrom
fix/p2p-sensor-tx-writing
May 6, 2026
Merged

fix(p2p/sensor): improve transaction writing consistency#909
minhd-vu merged 8 commits intomainfrom
fix/p2p-sensor-tx-writing

Conversation

@minhd-vu
Copy link
Copy Markdown
Contributor

@minhd-vu minhd-vu commented May 1, 2026

Description

  • Change handleNewPooledTransactionHashes condition from || to && so transactions are requested when either --write-txs or --write-tx-events is enabled (previously required both)
  • Preserve earliest TimeFirstSeen for transactions by checking existing records before writing, matching block behavior
  • Add --write-first-tx-event flag for write-first-event-only behavior
  • Add SensorFirstSeen field to DatastoreTransaction for sensor attribution

Jira / Linear Tickets

Testing

  • Test A
  • Test B

- Change handleNewPooledTransactionHashes condition from || to && so
  transactions are requested when either --write-txs or --write-tx-events
  is enabled (previously required both)
- Preserve earliest TimeFirstSeen for transactions by checking existing
  records before writing, matching block behavior
- Skip writing transactions that already exist with earlier timestamp
- Add --write-first-tx-event flag for write-first-event-only behavior
- Add SensorFirstSeen field to DatastoreTransaction for sensor attribution
@minhd-vu minhd-vu force-pushed the fix/p2p-sensor-tx-writing branch from 009338e to 87a5e26 Compare May 5, 2026 00:19
minhd-vu and others added 7 commits May 4, 2026 20:42
…ation

- Add fixed worker pool (default 100 workers) for transaction and
  transaction event writes using unbounded linked list queue
- Check transaction cache before writing to deduplicate across peers
- Add Close() method to Database interface for graceful shutdown
- Add --write-workers flag to configure worker count
- Keep semaphore pattern for block writes (lower volume)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove the worker pool implementation and revert to the original semaphore
pattern for database writes. The cache-first transaction deduplication
(added in previous commit) should significantly reduce write volume,
making the simpler semaphore pattern sufficient.

Changes:
- Remove worker pool types, queue, and worker goroutines from datastore.go
- Remove WriteWorkers from DatastoreOptions
- Remove --write-workers flag from sensor command
- Keep using runAsync() semaphore pattern for all database writes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Close() method was added for the worker pool implementation but is
no longer needed after reverting to the semaphore pattern. With the
semaphore pattern, in-flight goroutines complete on their own without
needing explicit shutdown coordination.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract common transaction processing logic into processTransactions()
- Consolidates duplicate code from handleTransactions and handlePooledTransactions
- Remove orphaned comment about Close() method
- Remove duplicate WriteTransactions comment

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

@minhd-vu minhd-vu marked this pull request as ready for review May 6, 2026 14:09
@minhd-vu minhd-vu merged commit 8ecdb0f into main May 6, 2026
25 of 27 checks passed
@minhd-vu minhd-vu deleted the fix/p2p-sensor-tx-writing branch May 6, 2026 15:22
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