feat: add contract event archival layer for historical analytics - #532
Merged
Just-Bamford merged 1 commit intoAug 30, 2026
Merged
Conversation
Implements Sorokit#504 - Add EventArchiveStorage interface for pluggable storage backends - Implement InMemoryEventArchiveStorage for testing/development - Add EventArchivalManager to coordinate event persistence - Support historical queries with filters, pagination, and ordering - Provide time-series aggregation and event rate calculations - Handle deduplication and storage failures gracefully - Separate event ingestion from storage concerns - Include comprehensive tests for all archival functionality Acceptance Criteria: ✅ Contract events can be persisted through a storage adapter ✅ Archived records retain event type, contract, topics, ledger, and timestamp ✅ queryContractEvents supports historical retrieval ✅ Queries support time ranges, contract IDs, topics, and event types ✅ Results support deterministic pagination and ordering ✅ Aggregation utilities calculate event counts and rates over time ✅ Storage failures do not corrupt the live event stream ✅ Tests cover persistence, duplicate events, pagination, filtering, and recovery ✅ Storage implementation remains replaceable
|
@lajay-faith 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.
Summary
Implements #504
Adds a persistent archival layer for contract events, enabling long-term analytics beyond live event subscriptions.
Features
✅ Persistent Storage - Archive events from live subscriptions to any storage backend
✅ Historical Queries - Search archived events with filters, pagination, and ordering
✅ Time Series Analytics - Aggregate events over time intervals
✅ Pluggable Storage - Replaceable storage adapters for any database or object storage
✅ Deduplication - Automatic handling of duplicate events
✅ Error Isolation - Storage failures don't corrupt live event streams
✅ Comprehensive Tests - Full coverage of archival functionality
Implementation Details
Architecture
Components
Key Features
Acceptance Criteria
✅ Contract events can be persisted through a storage adapter
✅ Archived records retain event type, contract, topics, ledger, and timestamp
✅ queryContractEvents(filters) supports historical retrieval
✅ Queries support time ranges, contract IDs, topics, and event types
✅ Results support deterministic pagination and ordering
✅ Aggregation utilities can calculate event counts and rates over time
✅ Storage failures do not silently corrupt the live event stream
✅ Tests cover persistence, duplicate events, pagination, filtering, and recovery
✅ Storage implementation remains replaceable
Files Changed
New Files
src/soroban/eventArchival/types.ts- Type definitions and interfacessrc/soroban/eventArchival/inMemoryStorage.ts- In-memory storage implementationsrc/soroban/eventArchival/eventArchivalManager.ts- Main archival coordinatorsrc/soroban/eventArchival/index.ts- Public API exportssrc/tests/contractEventArchival.test.ts- Comprehensive testsdocs/contract-event-archival.md- Complete documentationModified Files
src/soroban/index.ts- Export archival moduleUsage Example
Custom Storage Adapters
Applications can implement the
EventArchiveStorageinterface for production use:Recommended backends:
Testing
All tests pass with comprehensive coverage:
npm test -- contractEventArchival.test.tsDocumentation
Complete documentation added:
docs/contract-event-archival.md- Full usage guide, API reference, examplesBenefits
Before (Live Subscriptions Only)
After (With Archival)
Use Cases
Design Principles
Notes for Reviewers
Closes #504