Database Atomicity and State Integrity
WAproxy requires atomic state transitions during wallet_send execution.
Execution must never result in:
- partial balance deduction
- duplicate idempotency entries
- inconsistent transaction records
- orphaned broadcast states
------------------------------------------------------------
ATOMIC EXECUTION MODEL
------------------------------------------------------------
A wallet_send operation must execute as a single atomic unit:
- Validate request
- Lock wallet state
- Verify balance >= amount_sat + safety_margin
- Compute protocol_fee
- Broadcast transaction
- Persist tx result
- Persist idempotency record
- Commit state
If any step fails before commit:
- Rollback entire operation.
------------------------------------------------------------
STATE COMMIT RULE
------------------------------------------------------------
State must be committed only after:
- Broadcast success confirmed
- txid recorded
- idempotency key bound to result
No partial commits allowed.
------------------------------------------------------------
RESTART SAFETY
------------------------------------------------------------
If node restarts:
- Idempotency mapping must persist.
- Confirmed broadcasts must not repeat.
- Pending state must remain consistent.
------------------------------------------------------------
CONCURRENCY CONTROL
------------------------------------------------------------
Concurrent sends on same WID must:
- serialize execution
- prevent race condition
- prevent double spending attempts
------------------------------------------------------------
DATA INTEGRITY GUARANTEES
------------------------------------------------------------
Database must ensure:
- ACID properties
- durable idempotency records
- wallet-level locking discipline
WAproxy does not allow:
- eventual consistency for execution layer
- async state mutation without confirmation
- speculative balance deduction
------------------------------------------------------------
ARCHITECTURAL STATEMENT
------------------------------------------------------------
Atomic execution preserves economic integrity.
WAproxy treats state mutation
as a critical financial operation,
not a casual API call.
