Open
Conversation
Mapping<String, bool> -> Mapping<String, ()>. The value was always true; unit reflects the set semantics and drops one byte per entry. Switch the guard to .contains() for readability. Entries cannot be removed on confirm/timeout: swaps.remove(swap_id) wipes the only other on-chain record of a consumed source tx, so used_from_tx is the sole replay guard at initiate. Comment documents this. Storage-layout change; requires fresh deploy. Refs: entrius#174 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f3e1a47 to
06a6e00
Compare
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
Fixes #174 —
used_from_txstorage leak.Mapping<String, bool>→Mapping<String, ()>. The value was alwaystrue; unit reflects the set semantics and drops one byte per entry.get(&k).unwrap_or(false)with.contains(&k)at the guard site for readability.Why not delete entries on confirm / timeout
The issue report suggests cleaning entries in
confirm_swap/timeout_swap, analogous to therequest_votescleanup in #149. That approach is unsafe here:swaps.remove(swap_id)already runs on both confirm (lib.rs:804) and timeout (lib.rs:861).used_from_txis the only on-chain record that a given source tx hash has already been consumed.vote_initiatefrom replaying the same user payment to pay a miner twice.Removing entries on completion would reopen that replay vector, so this PR keeps the dedup permanent and takes the modest win of shrinking each entry's storage footprint.
The
request_votescase in #149 is different — request IDs are monotonic, so cleaned-up entries can never collide with a future round.Caveats
used_from_txentries. Halt first if upgrading a live instance.Test plan
cargo check --releasepassescargo contract build --releaseproduces optimized wasmDuplicateSourceTx