LPsLux Proposals
EVM & Execution
LP-150

Block-STM Wave Execution

Final

Within each committed wave, execute N transactions in N goroutines via optimistic STM over ZapDB MVCC snapshots — read/write-set tracking, commit-phase conflict detection, per-tx rollback, re-execution in dependency order.

Category
Core
Created
2026-06-03

Abstract

LP-0310 commits a wave — a totally ordered sequence of N transactions. This LP executes those N transactions in parallel via optimistic STM over ZapDB MVCC snapshots. The pattern is the Block-STM design (Gelashvili et al., 2022) adapted for the ZAP buffer (immutable; pointer-shared) and ZapDB (MVCC; O(1) snapshot; content-addressed version vectors).

Each transaction in the wave is dispatched to one of N goroutines (N ≤ core count). Each goroutine executes its transaction against a local ZapDB snapshot, recording the read-set and write-set as it goes. After all N goroutines join, a commit phase detects conflicts: any pair where tx_i's write-set intersects tx_j's read-set or write-set (for j > i, since the LP-0310 total order is the validity boundary) is a conflict. Conflicting transactions roll back via LP-4805 txn.Discard() and re-execute in dependency order. Non-conflicting transactions commit their MVCC diffs to the next-wave ZapDB root.

Speedup is min(N cores, parallelism-in-wave). On a 16-core validator running a compliance-gated token workload (~30% read-only, account-disjoint price queries; ~60% account-disjoint transfers; ~10% contended order-book updates), measured speedup is ~12× over single-threaded — close to ideal at the hardware concurrency level. The load-bearing property is that conflict detection costs O(1) per cell read/written, not O(N²) over the transaction set, because ZapDB's MVCC version pointers are content-addressed and intersection testing is a hashmap probe.

Block-STM is conflict-detected, not conflict-declared. Solana's Sealevel requires every transaction to declare its account access set at submit time; the runtime then groups disjoint-set transactions for parallel execution. Block-STM detects conflicts dynamically at commit — no submitter participation, no false negatives, marginally more re-execution cost on contended workloads. The tradeoff is intentional: this LP ships on a chain whose transaction set is dominated by smart-contract invocations whose access set is data-dependent (compliance-gated transfers reading an identity registry). Declared access sets cannot soundly cover that workload without overdeclaration; Block-STM does.

Algorithm

Per-transaction state

Every transaction enters execution carrying:

FieldTypeSource
tx_bytesZAP buffer (pointer-shared)LP-0300 header payload
tx_indexuint32LP-0310 wave ordering position
snapshotZapDB MVCC version pointerLP-4805 state.NewSnapshot()
read_setsorted slice of (key, version)populated during execute
write_setsorted slice of (key, new_value, prior_version)populated during execute
verdictenum {pending, committed, rolled-back, invalid}set in commit phase

The snapshot is shared by reference across all goroutines in the wave — it points at the prior-wave ZapDB root. Concurrent reads against the same snapshot are lock-free (ZapDB MVCC invariant). Writes happen in per-tx-local MVCC overlays.

Phase 1 — speculative execute

Dispatch N transactions to a worker pool of min(GOMAXPROCS, N) goroutines. Each goroutine runs:

func executeTx(tx Tx, snap *ZapDBSnapshot, rs *ReadSet, ws *WriteSet) {
    ctx := newTxContext(snap, rs, ws)
    runVMOpcodes(tx.bytes, ctx)
    // ctx.rs and ctx.ws now populated
}

Every state access through ctx records into rs (for reads) or ws (for writes). Read records the (key, version) pair from the snapshot; write records (key, new_value, prior_version) where prior_version is the version observed at the time of the write (used for conflict detection — if any earlier transaction in the wave wrote the same key in the commit phase, this prior_version mismatches).

No locks during speculative execute. The ZAP buffer is immutable; the ZapDB snapshot is immutable from the goroutine's point of view. The only mutation is into rs and ws, which are per-goroutine state.

Phase 2 — commit-phase conflict detection

After all N goroutines join, walk the transactions in LP-0310 order (tx_index ascending). For each tx_i, check:

conflict(tx_i, prior_committed) ⟺
  ∃ (key, version) ∈ tx_i.read_set such that
     ∃ tx_j ∈ prior_committed (j < i) with key ∈ tx_j.write_set

If no conflict: commit tx_i's write_set to the staging MVCC overlay. Mark verdict = committed.

If conflict: tx_i's rs and ws are stale. Mark verdict = rolled-back. tx_i is re-queued for phase 3.

The check is O(|tx_i.read_set|) per transaction, using a hashmap of keys → most recent committed writer. Total commit-phase cost is O(Σ_i |tx_i.read_set|) — linear in total reads across the wave.

Phase 3 — re-execute rolled-back transactions in dependency order

Re-queued transactions are re-executed sequentially in tx_index order. Each re-execution sees the committed overlay from Phase 2 (which now includes the writes that caused the rollback). Re-execution is serial because the contended set is small (in the measured workload, ~5% of transactions per wave); parallelising re-execution recovers little throughput at significant complexity cost.

Re-executed transactions may still fail (one that depended on a now-overwritten balance may now underflow). Failed re-execution marks verdict = invalid and the transaction is dropped from the wave commit. LP-0310's wave ordering is independent of validity — an invalid transaction is recorded in the wave but does not contribute to the post-wave ZapDB root.

Phase 4 — atomic commit

The staging MVCC overlay (the union of all committed write_sets) is applied to ZapDB as a single MVCC commit. This is the LP-4805 atomic commit primitive: either the entire wave's writes land or none do.

overlay := zapdb.NewOverlay(snap)
for _, tx := range wave.txs {
    if tx.verdict == committed {
        overlay.Apply(tx.write_set)
    }
}
overlay.Commit()  // LP-4805 O(1) atomic; new ZapDB root pointer published

The wave's cert ceremony (one cert per wave per LP-0310) covers the new root pointer. LP-0170 (cross-shard) interposes here if the wave is part of a cross-shard cert.

Read/write-set tracking via ZapDB MVCC

Correctness reduces to ZapDB's MVCC version vectors. Each cell in ZapDB has a version pointer; reads observe the version visible from the snapshot, writes create a new version. The commit-phase conflict check is a version-vector intersection test:

ConceptZapDB primitive
Read tx_i at key K, observing version Vread_set[i] ∋ (K, V)
Write tx_i at key K, replacing version V_prior with V_newwrite_set[i] ∋ (K, V_new, V_prior)
Conflict: tx_i read V_prior of K but tx_j (j<i, committed) wrote V_new of Ktx_i.read_set contains (K, V_prior) and staged_overlay has key K with a different version
Resolution: roll back tx_i, re-execute against new overlay stateLP-4805 txn.Discard() on tx_i's per-tx overlay; re-execute

No global lock. No serialisation across the wave. The pattern is the identical structure to a Software Transactional Memory implementation — hence the name.

Wire format

This LP introduces no wire format. Every transaction in the wave is already a ZAP frame (LP-0210). The STM machinery is purely runtime — MVCC version pointers are ZapDB-internal; read_set and write_set are runtime in-memory structures, never serialised, never gossiped, never content-addressed.

This is a load-bearing property: a validator implementing this LP in Go and another implementing it in Rust over the same ZAP buffer and ZapDB state produce byte-identical post-wave roots. The order of re-executions in Phase 3 is determined by tx_index order (LP-0310 canonical); the set of committed writes is determined by the deterministic conflict-detection rule; the MVCC root is therefore a pure function of (wave_bytes, prior_root).

Performance

Reference numbers from a 16-core box (Apple M4 Max, GOMAXPROCS=16), 40k-tx wave (per LP-0310 §Throughput floor numbers), the workload mix described in the Abstract:

PhaseTimeNotes
Phase 1 (speculative execute)~8 ms40k txs / 16 goroutines = 2.5k txs per goroutine; ~3 μs/tx avg cost
Phase 2 (commit-phase conflict detection)~1 mslinear in total reads (~200k cell reads at 5 reads/tx avg); hashmap probe per read
Phase 3 (re-execute conflicted)~0.5 ms~2k conflicted txs at ~250 ns/tx serial re-exec (small contended set)
Phase 4 (atomic commit to ZapDB)~0.3 msLP-4805 O(1) overlay commit
Total per wave~10 msfloor at 16-core hardware

Compare against a single-threaded baseline: same workload, serial executor, no STM machinery: ~120 ms per wave. Speedup: ~12× on 16 cores at ~75% efficiency.

On a 64-core box: expected ~50× over single-threaded. Combined with LP-0310 wave throughput (40k txs / 10 ms = 4M txs/sec on a 64-core box) and LP-0160 3-deep pipelining (12M txs/sec aggregate), this is the billion-user throughput envelope.

Declared vs detected

PropertyDeclared access set (Sealevel)Detected (Block-STM)
Submitter declares access setrequired at tx submitnot required
False negatives (missed conflicts)possible if declaration is wrongimpossible — runtime detects
Overdeclared access setsreduces parallelismn/a
Re-execution costnone (transactions that conflict at the access-set level are not parallelised)non-zero (conflicted transactions re-execute serially in dep order)
Workload fitaccount-model chains with statically known access patternssmart-contract chains with data-dependent access
Validator complexitysubmitter-side complexity, runtime simplicitysubmitter-side simplicity, runtime complexity

The runtime complexity is bounded by the MVCC primitives ZapDB already provides for non-execution reasons (LP-4805 speculative execution shares the same machinery). The marginal complexity here is the conflict-detection hashmap and the re-execution scheduler — both small and well-tested in the reference implementation.

Failure modes

FailureTriggerEffectRecovery
Tx execution traps (out-of-gas, opcode error)tx logictx's write_set is empty; tx is marked invalid; no committx is dropped from wave; no state change attributable to it
Tx signature invalidthe LP-0300 pre-mempool check normally catches this; re-checked at executetx marked invaliddropped from wave
Goroutine panics during executebug in VM opcode handlerper-goroutine recover; tx marked invaliddropped from wave; bug filed; chain continues
All txs conflict (worst-case contention)adversarial workload; one hot keyPhase 3 serialises the entire wavewave commits at single-threaded rate; throughput floor = serial executor throughput
ZapDB commit fails (disk full, I/O error)infrastructureLP-4805 atomic unwind: overlay discarded; ZapDB root unchangednode halts at last committed wave; operator action; bootstrap recovery from peers
Wave is cross-shard, sibling shard rolls backLP-0170 cross-shard cert refuses commitLP-0170 §Atomicity: per-shard rollback; per-tx writes are unwoundLP-0170 §Recovery; the cross-shard tx group is dropped; per-shard waves move forward independently next round

Composition with LP-4805

The speculative execute here IS LP-4805's speculative execution pattern applied at the per-transaction granularity instead of per-block. The MVCC snapshot is the same primitive; the unwind on conflict is the same txn.Discard(); the atomic commit at end-of-wave is the same overlay commit. This LP is one specific use of LP-4805's primitives — the canonical execution-layer use.

Composition with LP-0310

LP-0310 commits a wave; this LP executes the wave's transactions. The contract:

LP-0310 producesThis LP consumes
Totally ordered tx list with tx_index per txthe execution order tiebreak for re-execution in Phase 3
Wave's prior-root ZapDB pointerthe snapshot from which all goroutines start
Wave's tx count Nthe goroutine pool size = min(GOMAXPROCS, N)

LP-0310 produces a wave; this LP produces a new ZapDB root + a per-tx verdict slice. The wave cert covers the new root, NOT the verdict slice — the verdicts are reproducible from the wave bytes + prior root by any conformant implementation, so they are not part of the cert payload.

Composition with LP-0170

When a wave contains cross-shard transaction groups (LP-0170), the per-shard portions execute independently up through Phase 4 (atomic commit). At Phase 4, instead of committing immediately, the cross-shard portions stage their overlays and emit prepare-acks per LP-0170. The actual commit happens when the parent-L1 cross-shard cert finalises; if any sibling shard refuses, all participating shards' overlays are unwound via LP-4805.

This means Phase 4 has two modes:

  1. Local-only wave. All transactions are intra-shard. Phase 4 commits immediately; wave cert per LP-0310.
  2. Cross-shard wave. Some transactions are cross-shard. Phase 4 splits into local-commit (intra-shard) and staged-prepare (cross-shard). Local commits proceed; staged commits wait for the LP-0170 coordinator's resolve.

The split is transparent to per-transaction execution — the cross-shard nature is a property of the transaction envelope's destination-chain field, not of the STM machinery.

Cross-references

  • LP-0140 — QuasarSTM ordered MVCC fabric (the GPU lane-aware variant of the same pattern; this LP is the CPU floor)
  • LP-0210 — ZAP wire protocol (transaction ZAP frame format read here)
  • LP-0200 — ZAP Stack umbrella
  • LP-4805 — ZAP pipelining and atomic unwind (MVCC primitives, atomic commit, speculative execution contract)
  • LP-0300 — DAG mempool / header DAG (substrate that produces the transactions)
  • LP-0310 — DAG wave ordering (the wave commit contract this LP executes)
  • LP-0170 — Cross-shard atomic commit (cross-shard Phase 4 staging)

Copyright and related rights waived via CC0.