Skip to content

Use copy-on-write in driver.set to avoid ghost updates #140

@duelingbenjos

Description

@duelingbenjos

Title: Use copy-on-write in driver.set to avoid ghost updates

Summary

  • driver.set stores mutable values by reference in pending_writes/transaction_writes, so later in-place mutations by callers change the write intent and can leak stale/mutated data.

Problem

95:100:xian-contracting/src/contracting/storage/driver.py
if type(value) in [decimal.Decimal, float]:
    value = ContractingDecimal(str(value))
self.pending_writes[key] = value
if is_txn_write:
    self.transaction_writes[key] = value
  • No defensive copy for dict/list.

Proposed Fix

  • Deepcopy mutable inputs (dict/list) in driver.set before storing.
  • Optionally store an immutable snapshot for transaction_writes used in API outputs.

Acceptance Criteria

  • Mutating the original dict after set() does not affect what is committed or reported as writes.
  • Unit tests demonstrate isolation of write intent from later mutations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions