Skip to content

Rewrite replay worker for per-author DAG buffering #26

@intendednull

Description

@intendednull

Context

The replay node (crates/replay/src/role.rs) currently uses a flat VecDeque<Event> FIFO buffer with apply_lenient(). It needs to be rewritten for the per-author DAG model.

What needs to change

ServerData struct

// Old
struct ServerData {
    state: ServerState,
    events: VecDeque<Event>,  // bounded FIFO
}

// New
struct ServerData {
    dag: EventDag,
    state: ServerState,       // cached, maintained incrementally
    pending: PendingBuffer,
    max_events_per_author: usize,
}

Key changes

  • Per-author bounded chains instead of single FIFO (prevents chatty peer from evicting quiet peer's history)
  • Sync via HeadsSummary comparison instead of StateHash linear scan
  • on_event() uses dag.insert() + apply_incremental() + pending.resolve()
  • Snapshot fallback when peer is too far behind
  • Handle InsertError variants (SeqGap → buffer, Duplicate → skip)

Depends on

  • Wire protocol update (WorkerRequest/WorkerResponse changes)

References

  • Spec: docs/specs/2026-04-01-per-author-merkle-dag-state-design.md (Section 8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions