Skip to content

Enhancement: StreamsModule._addrCache and FactoryModule.addressCache … - #581

Open
Emoji-dot wants to merge 2 commits into
conduit-protocol:mainfrom
Emoji-dot:streamFi-skd
Open

Enhancement: StreamsModule._addrCache and FactoryModule.addressCache …#581
Emoji-dot wants to merge 2 commits into
conduit-protocol:mainfrom
Emoji-dot:streamFi-skd

Conversation

@Emoji-dot

Copy link
Copy Markdown

…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

  • Bug fix
  • New feature / method
  • Refactor
  • Test coverage
  • Documentation
  • Dependency update

Related issue

Closes #

Changes

File Change

Checklist

  • npm run typecheck — no errors
  • npm run lint — no warnings
  • npm test — all tests pass
  • npm run build — bundle compiles cleanly
  • No any types introduced
  • New public methods documented in docs/api.md
  • All on-chain amounts kept as bigint — no Number() conversion in arithmetic
  • New methods mock-tested in src/tests/
  • CHANGELOG.md updated under [Unreleased]
  • src/index.ts updated if new exports added

Breaking changes?

  • No
  • Yes — describe below and add BREAKING CHANGE: footer to relevant commit

Notes 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

…are two uncoordinated, unbounded id->address maps, Bug: normalizeTransactions dedup key collapses multiple events of one stream when id/hash are absent
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Jaydbrown

Copy link
Copy Markdown
Contributor

FactoryModule conflicts substantively with #568/#570/#578 (all merged): this branch adds an LruMemoCache-based addressCache, while main now has a Map + negative-cache-TTL + wallet-adapter design for the same layer, and src/dashboard/transaction-history.ts has competing direction-derivation logic. Needs a rebase and a decision on which cache design to keep. Leaving open per instruction.

@Jaydbrown

Copy link
Copy Markdown
Contributor

Rechecked against current main: conflicts in src/factory.ts, src/streams.ts and src/dashboard/transaction-history.ts. The core issue is that #568/#570 (merged) replaced FactoryModule's address cache with a Map + negative-cache-TTL + wallet-adapter design, while this branch enhances the older LruMemoCache-based _addrCache/addressCache. As an enhancement (not a regression fix) it needs a rebase onto the new cache design to land. Leaving open per instruction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants