mod raft¶
- module raft¶
Leader consensus over exploration decrees between server brains. Leader consensus over exploration decrees.
The per-chain server brains need one of themselves to decide where the ensemble goes next: which seam gets a bridge, which community each chain works, when an exploration policy changes. A decree is only safe to act on when a majority agrees it is part of the shared history, which is the raft guarantee: elected leadership, an append-only replicated log, and commitment by majority match with the current-term restriction that closes the stale-commit hazard.
The node here is pure state and arithmetic: no clock, no socket, no randomness. The caller supplies logical time to
RaftNode::tickand delivers messages toRaftNode::receive; both return the messages to send, and any transport that carries them faithfully (an in-memory bus in tests, nng between processes) yields the same transcripts. Election timeouts stagger deterministically by node identity, so a quiet cluster elects the same leader every replay.Modules
Types
- type NodeId¶
Node identity inside one consensus group.
- type Term¶
Election term.
Functions
- fn decree_members(local: NodeId, peers: &[NodeId]) -> Vec<NodeId>¶
Sorted identities participating in one consensus group.
Peer lists exclude the local node and may use absolute campaign replica identities, so group membership cannot be reconstructed as
0..len.
Enums
- enum RaftMessage¶
Messages between raft nodes.
- RequestVote¶
A candidate asks for a vote.
- last_log_index: u64¶
Index of the candidate’s last log entry.
- enum Role¶
The three raft roles.
- Follower¶
Accepts decrees from the current leader.
- Candidate¶
Standing for election.
- Leader¶
Replicates decrees and answers proposals.
Structs and Unions
- struct Decree¶
One replicated decree: an opaque payload the state machine above interprets (the wire format is the capnp decree, never inspected here).
- payload: Vec<u8>¶
Opaque decree payload.
- struct NotLeader¶
Proposing on a node that is not the leader.
- struct RaftNode¶
One raft node’s complete state.
Implementations
- impl RaftNode¶
Functions
- fn new(id: NodeId, mut peers: Vec<NodeId>, base_timeout: u64, stagger: u64) -> Self¶
A follower with a deterministic, identity-staggered election timeout:
base + id * staggerticks of silence start an election, so no two quiet nodes fire together and the same configuration elects the same first leader on every replay. The supplied peer roster is normalized as a set excludingid.
- fn propose(&mut self, payload: Vec<u8>) -> Result<u64, NotLeader>¶
Propose a decree; only the leader accepts. Returns the log index the decree occupies.
- fn receive(&mut self, from: NodeId, message: RaftMessage, now: u64) -> Vec<(NodeId, RaftMessage)>¶
Deliver one message; returns messages to send.
Senders outside the immutable peer roster are ignored before their term, vote, or log contents can affect the replicated state machine.
- fn take_committed(&mut self) -> Vec<Decree>¶
Committed decrees not yet handed to the state machine. Each decree is delivered exactly once, in log order.
- fn tick(&mut self, now: u64) -> Vec<(NodeId, RaftMessage)>¶
Advance logical time; returns messages to send.