Skip to content

feat(events): add event deduplication primitive, stream driver, and r… - #90

Merged
N-thnI merged 2 commits into
Vero-protocol:mainfrom
Osuochasam:fix/event-deduplication
Aug 29, 2026
Merged

N-thnI merged 2 commits into
Vero-protocol:mainfrom
Osuochasam:fix/event-deduplication

Conversation

@Osuochasam

Copy link
Copy Markdown
Contributor

SummaryThis PR resolves event processing vulnerabilities across the SDK by introducing a deduplication primitive (ProcessedSet), a managed polling stream driver (EventStream), and ledger-reorg rewind capabilities. It guarantees idempotent event processing and eliminates per-repository polling loop divergence.Key Changes1. Deduplication Primitive (src/events/processed-set.ts)Introduced the ProcessedSet interface and an InMemoryProcessedSet implementation.Uses an $O(1)$ FIFO-evicting strategy with a default capacity of 10,000 entries to prevent memory leaks while blocking duplicate event execution.2. Stream Driver & Reorg Handling (src/events/stream.ts)Created the EventStream class to own polling loops, pagination, and backoff logic.Features exponential back-off with 10% random jitter and native AbortSignal support.Detects unresolvable cursors during ledger reorganizations and rewinds to the last known-good state.Guarantees zero active timer handles when stop() is invoked.3. Cursor & Deduplication Integration (src/events/cursor.ts)Added optional StreamEvent.id field and integrated ProcessedSet checks into EventCursor.process().Preserves strict no-skip ordering: execution proceeds only if unprocessed, followed by store.set() and then processedSet.add().Added a reset() method to support cursor rewinds during reorgs.4. Public Exports & Test Coverage (src/events/index.ts, src/tests/events.test.ts)Re-exported ProcessedSet, InMemoryProcessedSet, and EventStream.Added 16 new unit tests across 5 describe blocks validating deduplication, timer cleanup, throw safety, and reorg rewinds.Quality GatesUnit Tests: npm test $\rightarrow$ 214/214 passed (100%)TypeScript: npm run typecheck $\rightarrow$ 0 errorsLinter: npm run lint $\rightarrow$ 0 errorsBuild: npm run build $\rightarrow$ Clean CJS & ESM outputs

Closes #87

@N-thnI
N-thnI merged commit fc97f3b into Vero-protocol:main Aug 29, 2026
3 checks passed
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.

Add event deduplication, a stream driver, and reorg handling

2 participants