Repository navigation
Fix: Fix: record_snapshot overwrites the oldest entry silently with no event - #1849
Merged
Merged
Conversation
Co-authored-by: Simple Agent <agent@simple.dev>
|
@Joshua13-stack 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.
Closes #1768
Issues
#1768 Fix:
record_snapshotoverwrites the oldest entry silently with no eventSummary
The overwrite condition can be detected by checking
index >= MAX_SNAPSHOTS_PER_MATCHbefore writing, since the slot is only reused after the first wrap. Read the existing snapshot atDataKey::Snapshot(m.id, slot)to obtain the overwritten index for the event payload. Ensure the event topic usesSymbol::new(env, "match")andsymbol_short!("snapshot_overwritten")(or a suitable short symbol) consistent with existing event conventions.Changes
record_snapshot, before writing the new snapshot, check whether the target slot already holds a snapshot (i.e.,index >= MAX_SNAPSHOTS_PER_MATCHor the slot key exists). If so, read the existing snapshot to capture itsindex, then publish amatch/snapshot_overwrittenevent with(match_id, overwritten_index, new_index)before overwriting the slot. Keep the existingmatch/snapshotevent. Update the doc comment onrecord_snapshotto state that overwrites now emit an event. (contracts/escrow/src/lib.rs)test_snapshot_ring_buffer_emits_overwrite_eventthat creates a match, drivesrecord_snapshotpastMAX_SNAPSHOTS_PER_MATCHviaenv.as_contract, and asserts that amatch/snapshot_overwrittenevent is emitted on the first wrap-around write with the correct match id, overwritten index, and new index. Useenv.events().all()to inspect emitted events. (contracts/escrow/src/tests/snapshots.rs)MAX_SNAPSHOTS_PER_MATCH = 8), wrap-around semantics, and the newmatch/snapshot_overwrittenevent (payload: match id, overwritten snapshot index, new snapshot index) so off-chain indexers can detect data loss. (docs/architecture.md)