fix(slashing): implement deduplication for real-time slashing event feed#88
Open
Mona-i wants to merge 1 commit into
Open
Conversation
- Add SlashingEvent types with id, nodeId, timestamp, amount, slot, epoch fields - Implement useWebSocketReconnect hook with automatic reconnection and catch-up support * Tracks last event ID for server-side deduplication headers * Implements exponential backoff reconnection strategy * Sends x-last-event-id header on reconnect for catch-up logic * Handles WebSocket header parsing for catch-up burst identification - Implement useSlashingStream hook with triple-layer deduplication * Layer 1: Hook-level Map<eventId, timestamp> with TTL (5 minutes) * Layer 2: Array filter to prevent duplicates in setEvents callback * Layer 3: React key reconciliation using event.id as key * Periodic cleanup of expired event IDs every 60 seconds - Create SlashingEventFeed component for displaying real-time slashing events * Displays events in chronological order (newest first) * Uses useRef<Set<string>> for component-level dedup layer * Shows connection status and error states * Limits displayed events to 50 and total in memory to 1000 - Add comprehensive test suite for WebSocket reconnection scenarios * Tests deduplication across reconnections * Verifies catch-up burst handling with partial overlaps * Tests TTL expiration for event ID tracking * Validates rapid duplicate arrivals are filtered Ensures invariant: ∀ event_id: count(feed_events[event_id]) ≤ 1 Fixes VeriNode-Labs#39
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.
Real-Time Slashing Event Feed Duplicate Display Under WebSocket Reconnection
Closes #39
Summary
This PR implements comprehensive deduplication logic to prevent duplicate slashing events in the real-time feed when the WebSocket reconnects and the server sends a catch-up burst of events.
Changes
1. New Types (src/types/slashing.ts)
2. WebSocket Reconnect Hook (src/hooks/useWebSocketReconnect.ts)
3. Slashing Stream Hook (src/hooks/useSlashingStream.ts)
4. Slashing Event Feed Component (src/components/slashing/SlashingEventFeed.tsx)
5. Comprehensive Test Suite (src/hooks/tests/useSlashingStream.test.ts)
Deduplication Invariant
The implementation ensures: ∀ event_id: count(feed_events[event_id]) ≤ 1
Testing
All tests pass. The implementation handles:
Architecture