Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions contracts/data_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ impl DataStore {
}

/// Add `delta` (signed) to existing u128 value. Panics on underflow.
///
/// # Issue #261 — write-ordering guarantee
///
/// Soroban executes all contract invocations within a transaction sequentially
/// and deterministically. Invocation N always sees the committed state from
/// invocations 1 … N-1 within the same transaction. This means a multicall
/// that includes both `deposit_handler::execute_deposit` and
/// `fee_handler::claim_fees` is safe: the second invocation reads the value
/// written by the first, so both deltas accumulate correctly.
///
/// True concurrent writes (two independent transactions mutating the same key
/// in the same ledger) are prevented by Soroban's transaction footprint model:
/// conflicting footprints cause one transaction to be rejected before execution.
///
/// Therefore **no additional version/nonce guard is required** on this method.
/// Callers MUST use `apply_delta_to_u128` (not separate get + set_u128) for
/// pool-amount updates so the atomic read-modify-write is preserved within a
/// single data_store invocation.
pub fn apply_delta_to_u128(env: Env, caller: Address, key: BytesN<32>, delta: i128) -> u128 {
caller.require_auth();
require_controller(&env, &caller);
Expand Down
Loading
Loading