Skip to main content

Module store

Module store 

Source
Expand description

The StateStore trait and the in-memory reference implementation.

Structs§

InMemoryStore
Single-node in-memory store: atomic counters behind a short transaction mutex that serializes check-and-spend so multi-key spends stay atomic.
Refund
One key/amount entry in an atomic multi-dimensional refund. Twin to Spend. Introduced in R67 to close R66 F2: the previous shape issued 3 independent store.refund calls (total_calls, per-tool, payout), each its own Redis round-trip. Crash/reconnect between steps left partial refund state; concurrent try_tool_call under InMemoryStore could observe partially-refunded state (fresh total_calls headroom but still-charged per-tool) — an ordering result impossible under a single-Lua refund and a cross-backend divergence with RedisStore (which has zero serialization between the 3 refunds).
Spend
One key/amount/limit entry in an atomic multi-dimensional spend.

Enums§

StateError
State-layer errors.
TrySpendOutcome
Outcome of an atomic multi-dimensional spend. Carries the post- commit min-headroom across the spent keys on success — a value that CANNOT race with a concurrent spend/refund because it is computed inside the same atomic Lua (RedisStore) / mutex-critical section (InMemoryStore) that commits the spend.

Traits§

StateStore
Atomic counter operations. Every mutation is atomic with respect to concurrent callers; try_spend is a single check-and-spend (never a read-then-write).