Fix/event pagination tx watch ttl#431
Merged
hman38705 merged 2 commits intosolutions-plug:mainfrom Mar 30, 2026
Merged
Conversation
Event sync:
- Replace fixed limit:100 with a paginating loop in fetch_events_since;
continues fetching while page == EVENTS_PAGE_SIZE and cursor is present
- Add EVENTS_PAGE_SIZE = 100 constant
watched_txs:
- Replace HashSet<String> with HashMap<String, Instant> to track insertion time
- Add MAX_WATCHED_TXS = 1000 cap; oldest entry evicted on overflow
- Add WATCHED_TX_TTL = 1h; stale entries purged each monitor tick
- Evictions increment cache_invalidations_total{scope=tx_watch_eviction}
and emit a warn! log
Tests:
- Update existing tx-monitor tests for HashMap API
- Add TTL eviction unit tests
- Add cap/memory-growth tests (>MAX_WATCHED_TXS insertions stay bounded)
- Add pagination accumulation tests (>100 events, partial page, no duplicates)
|
@joel-metal Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #387
closes #388
Problem 1 — Event sync misses events on busy ledgers
fetch_events_since used a single RPC call with limit:100. On ledgers
with >100 contract events the excess events were silently dropped,
causing the sync cursor to advance past un-processed data.
Fix:
· First iteration uses startLedger = from_ledger.
· Subsequent iterations use the opaque
cursorreturned by the RPC.· Loop exits when page length < EVENTS_PAGE_SIZE (last page reached)
or when the RPC returns no cursor.
increment, preserving the existing resilience behaviour.
Problem 2 — watched_txs grows without bound for never-finalized hashes
watched_txs was a HashSet with no eviction policy. Hashes for
transactions that never reach a terminal status (network drop, reorg,
stuck mempool) accumulated indefinitely, causing unbounded memory growth.
Fix:
insertion timestamp of each hash.
· watch_transaction checks the cap before inserting.
· When at capacity the entry with the oldest Instant is evicted first.
· run_transaction_monitor calls retain() each tick.
· Any entry whose age exceeds WATCHED_TX_TTL is removed.
· Emit tracing::warn! with the evicted hash and reason.
· Increment cache_invalidations_total{scope="tx_watch_eviction"} so
operators can alert on unexpected eviction rates.
Tests added
Pagination:
TTL eviction:
Cap / memory growth:
never exceed cap
Existing tx-monitor tests updated to use the new HashMap<String, Instant>
API (contains_key / insert with Instant instead of HashSet::contains /
insert).