feat: add per-topic replay nonce to EventEmitter - #959
Merged
greatest0fallt1me merged 1 commit intoJul 24, 2026
Merged
Conversation
|
@probablyABug 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! 🚀 |
Contributor
|
Merged — thanks for jumping on this one! |
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.
Pull Request Description
📋 Basic Information
Type of Change
Related Issues
Closes #674
Priority Level
📝 Detailed Description
What does this PR do?
Adds replay-protection support to
EventEmitterby introducing a monotonic per-topic nonce. Every emitted event now includes anonce: u64field that increments independently for each event topic, allowing downstream consumers to safely deduplicate events when cross-contract retries or fallback execution paths emit the same logical event multiple times.Why is this change needed?
Cross-contract retries and batch fallback mechanisms may legitimately execute the same event emission logic more than once. Without a deterministic replay identifier, downstream indexers and applications cannot reliably distinguish duplicate emissions from new events.
This change provides an efficient, deterministic replay-protection mechanism while maintaining topic isolation and minimal storage overhead.
How was this tested?
cargo test -p predictify-hybrid event_replay_nonceAlternative Solutions Considered
Alternative approaches such as timestamp-based identifiers and transaction-hash-based deduplication were considered. These approaches either cannot guarantee monotonic ordering or depend on external execution context.
A persistent per-topic counter provides deterministic ordering, low storage overhead, and straightforward consumer-side deduplication.
🏗️ Smart Contract Specific
Contract Changes
Oracle Integration
Market Resolution Logic
Security Considerations
🧪 Testing
Test Coverage
Test Results
Manual Testing Steps
📚 Documentation
Documentation Updates
Breaking Changes
Breaking Changes:
None.
Migration Guide:
No migration is required. Event consumers may optionally begin using the new
noncefield for replay detection and deduplication.Documentation notes that nonce state is reset only after a contract upgrade.
🔍 Code Quality
Code Review Checklist
Performance Impact
EventNonce(topic)entry maintained per event topic.O(1)) nonce lookup and increment.Security Review
🚀 Deployment & Integration
Deployment Notes
noncefield.Integration Points
📊 Impact Assessment
User Impact
Business Impact
✅ Final Checklist
Pre-Submission
Review Readiness
📸 Screenshots (if applicable)
N/A
🔗 Additional Resources
💬 Notes for Reviewers
Please pay special attention to:
DataKey::EventNonce(topic).Questions for reviewers:
Thank you for your contribution to Predictify!