Enhancement: StreamsModule._addrCache and FactoryModule.addressCache … - #581
Enhancement: StreamsModule._addrCache and FactoryModule.addressCache …#581Emoji-dot wants to merge 2 commits into
Conversation
…are two uncoordinated, unbounded id->address maps, Bug: normalizeTransactions dedup key collapses multiple events of one stream when id/hash are absent
|
@Emoji-dot 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! 🚀 |
|
|
|
Rechecked against current |
…are two uncoordinated, unbounded id->address maps, Bug: normalizeTransactions dedup key collapses multiple events of one stream when id/hash are absent
What does this PR do?
Type of change
Related issue
Closes #
Changes
Checklist
npm run typecheck— no errorsnpm run lint— no warningsnpm test— all tests passnpm run build— bundle compiles cleanlyanytypes introduceddocs/api.mdbigint— noNumber()conversion in arithmeticsrc/tests/CHANGELOG.mdupdated under[Unreleased]src/index.tsupdated if new exports addedBreaking changes?
BREAKING CHANGE:footer to relevant commitNotes for reviewers
Task 1: Transaction History Bug Fix
Problem: The normalizeTransactions function collapsed multiple events of the same stream when id/hash were absent, because it fell back to streamId as the dedup key. This meant a pause + resume + withdraw on stream 5 would show as a single row.
Solution: Modified normalizeTransaction() to synthesize a composite key ${streamId}:${kind}:${timestamp} when neither id nor hash is present. This ensures distinct events on the same stream get unique IDs and aren't treated as duplicates.
Changes:
transaction-history.ts: Updated ID generation logic
transaction-history-crash.test.ts: Added test case for composite key synthesis
Task 2: Address Cache Consolidation
Problem: Two separate unbounded caches existed for the same data:
StreamsModule._addrCache (keyed by bigint)
FactoryModule.addressCache (keyed by string) This caused doubled memory usage, unbounded growth, and no coordination between modules.
Solution: Consolidated into a single bounded LRU cache in FactoryModule with capacity of 1000 entries. StreamsModule now delegates to its internal factory's cache instead of maintaining its own.
Changes:
factory.ts: Replaced Map with LruMemoCache, added clearAddressCache() method
streams.ts: Removed _addrCache, updated _resolveAddr() to use factory cache, added clearAddressCache() method
client.ts: Added clearAddressCache() method for public API
factory.test.ts: Added tests for cache clearing, LRU eviction, and consolidation
Both fixes are fully tested and verified to pass typecheck, lint, and all relevant tests.
close #564 close #575