diff --git a/.changes/cft-trace-entry-and-term-history.added.md b/.changes/cft-trace-entry-and-term-history.added.md new file mode 100644 index 00000000000..bd5a8b44800 --- /dev/null +++ b/.changes/cft-trace-entry-and-term-history.added.md @@ -0,0 +1,2 @@ +In the `ccf.cft` consensus trace records defined in [cft_trace_msgpack.h](src/consensus/aft/cft_trace_msgpack.h), `execute_append_entries_sync` now records the view (`vw`), seqno (`sn`) and signature flag (`gc`) of its entry, and so is traced only once the entry has applied, and `init_as_backup` records the snapshot's term history (`th`), the first seqno of each view. +The [consensus trace replayer](lean/consensus/replay/README.md#replay-contract) requires these fields, and uses them to check that a node applies the entries it was sent and that a joiner's snapshot agrees with the committed prefix it starts from. diff --git a/lean/consensus/Consensus/Replay/Groups.lean b/lean/consensus/Consensus/Replay/Groups.lean index a8c4e55fdf1..62cfe180486 100644 --- a/lean/consensus/Consensus/Replay/Groups.lean +++ b/lean/consensus/Consensus/Replay/Groups.lean @@ -70,7 +70,6 @@ def Reduced.watermark (reduced : Reduced) (ran : Array Nat) : Float := /-- Prepare replay identities and reduce each node's events into its queue of groups. -Request IDs continue across nodes, so they are unique in the trace. If `lenient`, a node's groups end before its first event that no rule consumes. -/ def reduce (streams : Array (Array Event)) (declared : List String) (lenient := false) @@ -79,10 +78,9 @@ def reduce (streams : Array (Array Event)) (declared : List String) (lenient := let mut bootstrap := none let mut queues := #[] let mut counts := #[] - let mut nextRequestId := 1 for events in streams do let ((found, consumed), state) ← - (CCF.Parsec.run events ((node lenient).run { header, nextRequestId })).mapError + (CCF.Parsec.run events ((node lenient).run { header })).mapError fun error => match events.back? with | some last => @@ -97,7 +95,6 @@ def reduce (streams : Array (Array Event)) (declared : List String) (lenient := bootstrap := some leader queues := queues.push found counts := counts.push (events.size, consumed) - nextRequestId := state.nextRequestId let some leader := bootstrap | throw "no node bootstraps the network" let header := { header with bootstrap := {← header.nodeId leader} } return { header, queues, events := counts } diff --git a/lean/consensus/Consensus/Replay/Interpreter.lean b/lean/consensus/Consensus/Replay/Interpreter.lean index 24775bf5ac9..840a5a205cb 100644 --- a/lean/consensus/Consensus/Replay/Interpreter.lean +++ b/lean/consensus/Consensus/Replay/Interpreter.lean @@ -46,16 +46,16 @@ def Header.initial (header : Header) : Model.State := inductive Step where | local (node : String) (input : Input) + /-- `applied` holds the entries, by index, which the node traced applying from the packet. -/ | receive (source destination : String) (packet : Packet) - /-- Initialize from a node's committed prefix ending at `index` in term `view`. -/ - | initAsBackup (node : String) (index view : Nat) + (applied : List (Nat × Entry) := []) def Step.name : Step → String | .local _ (.append _) => "append" | .local _ (.sendEntries ..) => "sendEntries" | .local _ (.timeout _) => "timeout" | .local _ .nominateSuccessor => "nominateSuccessor" - | .local _ (.initAsBackup _) | .initAsBackup .. => "initAsBackup" + | .local _ (.initAsBackup _) => "initAsBackup" | .receive .. => "receive" structure ReplayState where @@ -244,25 +244,46 @@ private def missing (header : Header) (pending : List Envelope) | .error error => s!"{error}; {queued}" | .ok _ => queued -/-- Deliver any matching queued envelope; loss is non-delivery. -/ +/-- Whether a message has each of the `applied` entries at its index. -/ +private def carries (applied : List (Nat × Entry)) : Model.Node.Message → Bool + | .appendEntriesRequest request => + applied.all + fun (index, entry) => + request.prevLogIndex < index + && request.entries[index - request.prevLogIndex - 1]? == some entry + | _ => applied.isEmpty + +/-- +Deliver any matching queued envelope which carries the `applied` entries; loss is +non-delivery. +-/ private def selectPacket (replay : ReplayState) (source destination : NodeID) - (packet : Packet) + (packet : Packet) (applied : List (Nat × Entry)) : Except String Envelope := do let pending := pendingBetween replay source destination let some envelope := closest packet pending <|> pending.head? | throw s!"no pending packet from '{source}' to '{destination}'" checkPacket packet envelope.payload - unless pending.all - fun other => - !(checkPacket packet other.payload).isOk - || other.payload == envelope.payload do + let matching := + pending.filter + fun other => + (checkPacket packet other.payload).isOk && carries applied other.payload + let some envelope := matching.head? + | throw + s!"no matching packet from '{source}' to '{destination}' carries the entries applied at {applied.map (·.1)}" + unless matching.all (·.payload == envelope.payload) do throw s!"ambiguous delivery from '{source}' to '{destination}': matching packets differ in model payload" return envelope -/-- A node whose committed prefix has a signature at `index` in term `view`. -/ -private def initSource (replay : ReplayState) (index view : Nat) +/-- +A node whose committed prefix has the length of `entries`, the log of a snapshot as its node +traced it, and ends as it does: at a signature, in the same term. +-/ +private def initSource (replay : ReplayState) (entries : List Entry) : Except String NodeState := do + let index := entries.length + let view := termAt entries index -- Committed prefixes in a reachable state are comparable, so any such node will do. let some (_, source) := replay.state.nodes.find? @@ -273,6 +294,25 @@ private def initSource (replay : ReplayState) (index view : Nat) | throw s!"no node has a committed signature at {index} in term {view}" return source +/-- +Check a committed prefix against `entries`, the log of a snapshot as its node traced it: +the term of each entry, the configuration in force and the retirements. A snapshot traces +neither a configuration which a later one replaced, nor a retirement since removed, nor +which entries before its last are signatures. +-/ +private def checkSnapshot (committed entries : List Entry) : Except String Unit := do + let configuration (log : List Entry) := + (log.filterMap (·.content.metadata.configuration)).getLast? + let retired (log : List Entry) := + log.foldl (· ∪ ·.content.metadata.retirementConfirmations) (∅ : Finset NodeID) + unless committed.map Entry.term == entries.map Entry.term do + throw + s!"term history: observed terms {entries.map Entry.term}, model {committed.map Entry.term}" + unless configuration committed == configuration entries do + throw "snapshot configuration differs from the model's" + unless (retired entries).sort.all (· ∈ retired committed) do + throw "snapshot retirement which the model has not confirmed" + /-- Run one model action, recording the envelopes it queues. -/ private def ReplayState.run (replay : ReplayState) (header : Header) (action : Model.Action) (name : String) @@ -304,6 +344,11 @@ def runInstruction (header : Header) (replay : ReplayState) (instruction : Instr throw s!"model queued {render (Packet.ofMessage envelope.payload)} to '{target}' with no native send" return { replay with queued := [] } + | .action (step@(.local node (.initAsBackup entries))) _ => + let joiner ← header.nodeId node + let committed := (← initSource replay entries).log.take entries.length + checkSnapshot committed entries + replay.run header (.local joiner (.initAsBackup committed)) step.name | .action (step@(.local node input)) _ => let node ← header.nodeId node match input with @@ -323,15 +368,20 @@ def runInstruction (header : Header) (replay : ReplayState) (instruction : Instr throw s!"undeclared model node {destination}" | _ => pure () replay.run header (.local node input) step.name - | .action (.receive source destination packet) _ => - let source ← header.nodeId source - let destination ← header.nodeId destination - let envelope ← selectPacket replay source destination packet - replay.run header (.deliver envelope) "receive" - | .action (step@(.initAsBackup node index view)) _ => - let joiner ← header.nodeId node - let source ← initSource replay index view - replay.run header (.local joiner (.initAsBackup (source.log.take index))) step.name + | .action (.receive source destination packet applied) _ => + let before := (← lookup header replay destination).log + let envelope ← + selectPacket replay (← header.nodeId source) (← header.nodeId destination) packet + applied + let next ← replay.run header (.deliver envelope) "receive" + -- The model applies the entries after those the node keeps. + let after := (← lookup header next destination).log + let kept := ((before.zip after).takeWhile fun (a, b) => a == b).length + let model := ((after.zipIdx 1).drop kept).map fun (entry, index) => (index, entry) + unless model == applied do + throw + s!"the model applied the entries at {model.map (·.1)}, the node traced applying {applied.map (·.1)}" + return next /-- Why a step must wait: a receive has no matching queued packet, or an initialization has no @@ -341,15 +391,15 @@ The reason is built only on demand: a waiting group is retried after every other -/ private def Step.waiting (header : Header) (replay : ReplayState) : Step → Except String (Option (Unit → String)) - | .receive source destination packet => do + | .receive source destination packet _ => do let source ← header.nodeId source let destination ← header.nodeId destination let pending := pendingBetween replay source destination if pending.any fun envelope => (checkPacket packet envelope.payload).isOk then return none return some fun _ => missing header pending source destination packet - | .initAsBackup _ index view => - match initSource replay index view with + | .local _ (.initAsBackup entries) => + match initSource replay entries with | .ok _ => return none | .error reason => return some fun _ => reason | .local .. => pure none @@ -400,7 +450,7 @@ private def stuck (rest : Array Group) (blocked : Array (Group × (Unit → Stri fun (group, reason) => let waiting := s!"node '{group.node}' waits at {reason ()}" match group.instructions.find? (· matches .action ..) with - | some (.action (.receive source destination packet) _) => + | some (.action (.receive source destination packet _) _) => let sender := rest.filter (·.node == source) match sender.findSome? (·.send? destination packet) with | none => .inl s!"{waiting}; '{source}' sends no such packet later" diff --git a/lean/consensus/Consensus/Replay/Reduction.lean b/lean/consensus/Consensus/Replay/Reduction.lean index 713b5156292..948836d3714 100644 --- a/lean/consensus/Consensus/Replay/Reduction.lean +++ b/lean/consensus/Consensus/Replay/Reduction.lean @@ -26,7 +26,6 @@ open CCF.Parsec (failure validated attempt many_ optional_) structure ReductionState where header : Header - nextRequestId : ReqID := 1 instructions : Array Instruction := #[] /-- The node, if its events start by bootstrapping the network. -/ bootstrap : Option String := none @@ -132,16 +131,12 @@ private def readAppendContent (head : Event) (seqno : Nat) (signature : Bool) some <$> modelMembers config fields.nodes | none => pure none let retirementConfirmations ← modelMembers head retiredNodes - let request := (← get).nextRequestId - modify fun s => { s with nextRequestId := request + 1 } - return .transaction request { configuration, retirementConfirmations } + -- Named by position, so every node names an entry alike; genesis, at index 1, is zero. + return .transaction (seqno - 1) { configuration, retirementConfirmations } -/-- One entry of a batch: its replicate event, retirements, configuration and flush. -/ -private def readReplicateEntry (head : Event) : Reduction AppendEntryInput := do - let .replicateEntry entry := head.body | mismatch head - let some seqno := entry.seqno | liftExcept head (throw "seqno: missing") - -- consume - event head "replicate_entry" +/-- The retirements and configuration that the ledger hooks of entry `seqno` trace. -/ +private def readEntryHooks (head : Event) (seqno : Nat) + : Reduction (List String × Option (Event × AddConfiguration)) := do let retiredNodes ← CCF.Parsec.many do let retirement ← peek @@ -157,6 +152,15 @@ private def readReplicateEntry (head : Event) : Reduction AppendEntryInput := do let .addConfiguration fields := config.body | mismatch config many_ (event head "send_append_entries") return (config, fields) + return (retiredNodes, config) + +/-- One entry of a batch: its replicate event, retirements, configuration and flush. -/ +private def readReplicateEntry (head : Event) : Reduction AppendEntryInput := do + let .replicateEntry entry := head.body | mismatch head + let some seqno := entry.seqno | liftExcept head (throw "seqno: missing") + -- consume + event head "replicate_entry" + let (retiredNodes, config) ← readEntryHooks head seqno let flushes ← CCF.Parsec.optionalRule do event head "batch_flush" @@ -202,27 +206,39 @@ private def readReceive (head : Event) (families : List String) : Reduction Step (require (families.contains packet.msg) "receive function/packet mismatch") return .receive from_node_id head.node packet +/-- An entry of the packet received from `source`, which the node traced applying. -/ +private def readAppliedEntry (head : Event) (source : String) + : Reduction (Nat × Entry) := do + let next ← peek + event head "execute_append_entries_sync" + let .executeAppendEntries entry := next.body | mismatch next + liftExcept next + (require (entry.from_node_id == source) s!"expected an entry from {source}") + let (retiredNodes, config) ← readEntryHooks head entry.seqno + let content ← + readAppendContent next entry.seqno entry.globally_committable config retiredNodes + return (entry.seqno, ⟨entry.view, content⟩) + private def ruleRecvAppendEntries : Reduction Unit := do let head ← peek - let action ← readReceive head ["append_entries"] + let .receive source destination packet _ ← readReceive head ["append_entries"] + | mismatch head -- consume let start ← position event head "recv_append_entries" optional_ (event head "become_follower") - many_ - ((do - event head "execute_append_entries_sync" - many_ (event head "retired_committed_tx")) - <|> (do - event head "add_configuration" - many_ (event head "send_append_entries")) - <|> (do - event head "commit" - optional_ (nominate head))) + let applied ← + CCF.Parsec.many + ((some <$> readAppliedEntry head source) + <|> (do + event head "commit" + optional_ (nominate head) + return none)) optional_ (event head "send_append_entries_response") -- emit emitObserve head "recv-append-entries" - emitAction head "recv-append-entries" action + emitAction head "recv-append-entries" + (.receive source destination packet (applied.filterMap id)) emitObserveSends head (← extractSends start) private def ruleRecvAppendEntriesResponse : Reduction Unit := do @@ -361,6 +377,58 @@ private def ruleDrop : Reduction Unit := do -- consume event head "drop_pending_to" +/-- +The log of a snapshot at `seqno`, as far as its node traces it. `termHistory` is the first seqno +of each view, which gives each entry its term; the signature ends the log; and the hooks +which ran before `init` give its configurations and retirements. A hook at `seqno` itself +is of the state which the signature signs, so it goes on the entry before. +Which earlier entries were signatures is not traced. +-/ +private def readSnapshotLog (init : Event) (seqno view : Nat) (termHistory : List Nat) + : Reduction (List Entry) := do + let hooks ← + liftM (m := CCF.Parsec.Parser Event) + ((fun input => .success input (input.events.extract 0 input.position)) + : CCF.Parsec.Parser Event (Array Event)) + let viewAt (index : Nat) := (termHistory.filter (· ≤ index)).length + liftExcept init do + require ((termHistory.zip termHistory.tail).all fun (a, b) => a ≤ b) + "term history out of order" + require (termHistory.all fun start => 1 ≤ start && start ≤ seqno) + "term history outside the snapshot" + require (viewAt seqno == view) "the term history gives the snapshot another view" + let mut updates : Array (Nat × (TransactionMetadata → TransactionMetadata)) := #[] + for hook in hooks do + let (index, update) ← + match hook.body with + | .addConfiguration fields => do + let nodes ← modelMembers hook fields.nodes + pure + ( + fields.idx.getD 0, + fun (m : TransactionMetadata) => { m with configuration := some nodes } + ) + | .retiredCommittedTx fields => do + let retired ← modelMembers hook [fields.retired_node_id] + pure + ( + fields.seqno, + fun (m : TransactionMetadata) => + { m with retirementConfirmations := m.retirementConfirmations ∪ retired } + ) + | _ => continue + liftExcept hook + (require (1 ≤ index && index ≤ seqno && 2 ≤ seqno) + s!"hook outside the snapshot at {seqno}") + updates := updates.push (min index (seqno - 1), update) + if seqno == 0 then return [] + let mut entries := #[] + for index in [1:seqno] do + let metadata := + updates.foldl (fun m (at_, update) => if at_ == index then update m else m) {} + entries := entries.push ⟨viewAt index, .transaction (index - 1) metadata⟩ + return (entries.push ⟨view, .signature⟩).toList + /-- Snapshot installation runs ledger hooks outside the consensus lock, so bare ticks may interleave with their events. @@ -387,10 +455,11 @@ private def ruleInitAsBackup : Reduction Unit := do let init ← peek event head "init_as_backup" event head "become_follower" - let .initAsBackup { seqno, view, .. } := init.body | mismatch init + let .initAsBackup { seqno, view, term_history, .. } := init.body | mismatch init + let entries ← readSnapshotLog init seqno view term_history -- emit emitObserve init "init-as-backup" - emitAction init "init-as-backup" (.initAsBackup head.node seqno view) + emitAction init "init-as-backup" (.local head.node (.initAsBackup entries)) def ruleStep : Reduction Unit := do -- Recv rules diff --git a/lean/consensus/Consensus/Replay/Trace.lean b/lean/consensus/Consensus/Replay/Trace.lean index f3e54fbd353..3008ffc42fe 100644 --- a/lean/consensus/Consensus/Replay/Trace.lean +++ b/lean/consensus/Consensus/Replay/Trace.lean @@ -138,6 +138,15 @@ msgpack_struct seqno : Option Nat := ("sn", readNat) globally_committable : Bool := ("gc", readBool) +msgpack_struct + /-- An entry of a received AppendEntries, which the node has applied. -/ + structure ExecuteAppendEntries where + state : StateSnapshot := ("st", StateSnapshot.read) + from_node_id : String := ("frm", readStr) + view : Nat := ("vw", readNat) + seqno : Nat := ("sn", readNat) + globally_committable : Bool := ("gc", readBool) + msgpack_struct structure AddConfiguration where state : StateSnapshot := ("st", StateSnapshot.read) @@ -152,10 +161,12 @@ msgpack_struct retired_node_id : String := ("ret", readStr) msgpack_struct + /-- `term_history` is the first seqno of each view, from view 1. -/ structure InitAsBackup where state : StateSnapshot := ("st", StateSnapshot.read) seqno : Nat := ("sn", readNat) view : Nat := ("vw", readNat) + term_history : List Nat := ("th", readList readNat) deriving instance Inhabited for StateOnly @@ -165,6 +176,7 @@ inductive Body where | send (event : Send) | recv (event : Recv) | replicateEntry (event : ReplicateEntry) + | executeAppendEntries (event : ExecuteAppendEntries) | addConfiguration (event : AddConfiguration) | retiredCommittedTx (event : RetiredCommittedTx) | initAsBackup (event : InitAsBackup) @@ -179,6 +191,8 @@ def Body.read (function : String) (n : Nat) : Reader Body := else match function with | "replicate_entry" => .replicateEntry <$> ReplicateEntry.readFields n + | "execute_append_entries_sync" => + .executeAppendEntries <$> ExecuteAppendEntries.readFields n | "add_configuration" => .addConfiguration <$> AddConfiguration.readFields n | "retired_committed_tx" => .retiredCommittedTx <$> RetiredCommittedTx.readFields n | "init_as_backup" => .initAsBackup <$> InitAsBackup.readFields n @@ -190,6 +204,7 @@ def Body.state : Body → StateSnapshot | .send event => event.state | .recv event => event.state | .replicateEntry event => event.state + | .executeAppendEntries event => event.state | .addConfiguration event => event.state | .initAsBackup event => event.state | .retiredCommittedTx event => diff --git a/lean/consensus/Consensus/Tests/ReplayDelivery.lean b/lean/consensus/Consensus/Tests/ReplayDelivery.lean index b0742a32652..a04d4ae58d1 100644 --- a/lean/consensus/Consensus/Tests/ReplayDelivery.lean +++ b/lean/consensus/Consensus/Tests/ReplayDelivery.lean @@ -31,11 +31,17 @@ private def appendEntries (request : ReqID) : Envelope := } } -private def receive (network : List Envelope) : Except String ReplayState := +/-- Node 1 receives the packet of `appendEntries`, tracing that it applied `applied`. -/ +private def receive (network : List Envelope) (applied : List ReqID := [1]) + : Except String ReplayState := runInstruction header { state := { header.initial with network } } - (.action (.receive "0" "1" (Packet.ofMessage (appendEntries 1).payload)) default) + (.action + (.receive "0" "1" (Packet.ofMessage (appendEntries 1).payload) + (applied.map + fun request => (1, { term := 2, content := .transaction request {} }))) + default) -/-- Checks delivery selection among queued envelopes whose rendered packets are equal. -/ +/-- Checks delivery selection by rendered packet and by the entries the receiver applied. -/ def run : IO Unit := do match receive [appendEntries 1, appendEntries 1] with | .ok replay => @@ -44,10 +50,20 @@ def run : IO Unit := do (IO.userError "identical candidates: exactly one occurrence must be delivered") | .error error => throw (IO.userError s!"identical candidates: {error}") match receive [appendEntries 1, appendEntries 2] with + | .ok replay => + unless !replay.state.network.contains (appendEntries 1) do + throw (IO.userError "different entries: the applied entry must select the packet") + | .error error => throw (IO.userError s!"different entries: {error}") + match receive [appendEntries 2] with + | .error error => + unless error.startsWith "no matching packet" do + throw (IO.userError s!"entry not sent: unexpected error {error}") + | .ok _ => throw (IO.userError "entry not sent: delivery must fail") + match receive [appendEntries 1] (applied := []) with | .error error => - unless error.startsWith "ambiguous delivery" do - throw (IO.userError s!"different entries: unexpected error {error}") - | .ok _ => throw (IO.userError "different entries: delivery must be ambiguous") + unless error.startsWith "the model applied" do + throw (IO.userError s!"entry not traced: unexpected error {error}") + | .ok _ => throw (IO.userError "entry not traced: delivery must fail") IO.println "Replay delivery checks passed." #eval run diff --git a/lean/consensus/replay/README.md b/lean/consensus/replay/README.md index 2c8d2c5fc87..3d5ddb73138 100644 --- a/lean/consensus/replay/README.md +++ b/lean/consensus/replay/README.md @@ -59,7 +59,7 @@ Snapshot installation runs its `add_configuration` and `retired_committed_tx` ho Replay repeatedly runs the next group of some node, with no other group's actions between its actions. It runs the enabled group with the earliest `ts`, the wall-clock emission time in nanoseconds that a record may carry; without it `m_ts` stands in, which is the order of execution within a process and otherwise only makes diagnostics reproducible, as counters of different processes are not comparable. -A group whose first action is a receive waits until a matching packet is queued, and one whose first action is `init_as_backup` waits until some node has committed its prefix; other actions must be enabled when their group runs. +A group whose first action is a receive waits until a matching packet is queued, and one whose first action is `init_as_backup` waits until some node has committed a signature at the snapshot's seqno, in its view; other actions must be enabled when their group runs. Clocks of different hosts therefore only choose among enabled groups, and cannot fail a trace. If groups remain but none may run, replay fails, listing first the groups that can never run, such as a receive whose packet is never sent. `--schedule` prints the groups in the order they ran, ending with any that failed. @@ -70,7 +70,13 @@ A tick with no action emits no group, so its snapshot is not compared: the node' A trace may so have no group at all. A receive delivers any queued model envelope from its sender whose rendered packet has exactly the native packet's fields, with equal values. -It delivers the queued **model payload**, not reconstructing unrecorded native bytes; if matching envelopes differ in payload, for example in AppendEntries entries, which packets omit, replay fails with an ambiguous delivery. +A packet omits the entries of an AppendEntries, so the receiver's `execute_append_entries_sync` events constrain them: each traces the view, seqno and signature flag of an entry the node applied, and the ledger hooks which follow it trace the entry's retirements and configuration. +The delivered envelope must carry those entries, and the model must apply exactly those, so a trace fails if a node applies an entry which differs from the one sent, or one more or fewer than the model. +A transaction's request is named by its seqno, as neither node traces it. +Replay delivers the queued **model payload**, not reconstructing unrecorded native bytes; if matching envelopes still differ in payload, replay fails with an ambiguous delivery. +An `init_as_backup` copies the committed prefix of a node, which must agree with what the joiner traces of its snapshot: the term of every entry, from the term history (`th`, the first seqno of each view), and, from the hooks which ran before it, the configuration in force and the retirements. +A snapshot traces neither a configuration which a later one replaced, nor which of its earlier entries are signatures. +A term history which is out of order or starts a view after the snapshot fails the trace, as does a hook after the snapshot. An envelope that is never delivered stays queued, which models loss, so `drop_pending_to` emits no observation or action. After each rule's actions, the envelopes they queued must equal the rule's native sends, as a multiset of target and rendered packet. @@ -82,7 +88,7 @@ After each rule's actions, the envelopes they queued must equal the rule's nativ - [`Groups.lean`](../Consensus/Replay/Groups.lean): runs the rules over each node's stream, taking each rule's instructions as a group. - [`Interpreter.lean`](../Consensus/Replay/Interpreter.lean): boundary-state field comparisons, packet selection, send checks, group scheduling and model execution. - [`ReplayMain.lean`](ReplayMain.lean): single-trace validation CLI. -- [`ReplayDelivery.lean`](../Consensus/Tests/ReplayDelivery.lean): delivery selection among equal rendered packets. +- [`ReplayDelivery.lean`](../Consensus/Tests/ReplayDelivery.lean): delivery selection by rendered packet and by the entries the receiver applied. - [`cft_scenarios_runner.py`](../../../tests/cft_scenarios_runner.py): existing native scenario runner and capture generation. See [failure fixtures](fixtures/README.md) for examples and expected diagnostics. diff --git a/lean/consensus/replay/fixtures/README.md b/lean/consensus/replay/fixtures/README.md index 3ff8b20a82e..9868848b7e5 100644 --- a/lean/consensus/replay/fixtures/README.md +++ b/lean/consensus/replay/fixtures/README.md @@ -10,23 +10,28 @@ The [rejected replicate](valid/rejected-replicate.ndjson) control is a `replicat The [bootstrap](valid/bootstrap.ndjson) control starts like a real node: a bare tick and a nomination before genesis, then a flush of the genesis entry. The [interleaved](valid/interleaved.ndjson) control records the replication history with each node in a process of its own, `ts` in the order of the lines and the joiner's events among the leader's, as clock skew would place them: its initialization inside the leader's signature batch, before the leader commits, its receives before their sends, and a whole receive group, including its own `add_configuration`, between the leader's `add_configuration` and its send. -| Fixture | Expected failure | -| ----------------------------------------------------------------------- | ------------------------------------------------------- | -| [Snapshot mismatch](invalid/snapshot-mismatch.ndjson) | Observed view differs from the model | -| [Unsupported snapshot field](invalid/unsupported-snapshot-field.ndjson) | Unknown key in a `st` (state) | -| [Malformed append](invalid/malformed-append.ndjson) | Boolean append argument expected | -| [Ungrouped event](invalid/ungrouped-event.ndjson) | No reduction rule consumes the event | -| [Disabled append](invalid/disabled-append.ndjson) | Append attempted by a non-leader | -| [Missing packet](invalid/missing-packet.ndjson) | No queued model packet to receive | -| [Packet mismatch](invalid/packet-mismatch.ndjson) | Received index differs from the queued model payload | -| [Retirement on signature](invalid/retirement-signature.ndjson) | Retirement follows a signature `replicate_entry` | -| [Retirement seqno mismatch](invalid/retirement-seqno-mismatch.ndjson) | Retirement seqno differs from its `replicate_entry` | -| [Retirement node mismatch](invalid/retirement-node-mismatch.ndjson) | Retirement follows another node's `replicate_entry` | -| [Retirement non-adjacent](invalid/retirement-nonadjacent.ndjson) | An event separates `replicate_entry` and its retirement | -| [Orphan retirement](invalid/retirement-orphan.ndjson) | Retirement without a `replicate_entry` | -| [Uncommitted snapshot](invalid/uncommitted-snapshot.ndjson) | Joiner initializes at an uncommitted signature | -| [Bootstrap event](invalid/bootstrap-event.ndjson) | Event other than a tick or nomination before genesis | -| [Bootstrap flush send](invalid/bootstrap-flush-send.ndjson) | Send from the genesis flush, which must send nothing | +| Fixture | Expected failure | +| --------------------------------------------------------------------------------- | --------------------------------------------------------- | +| [Snapshot mismatch](invalid/snapshot-mismatch.ndjson) | Observed view differs from the model | +| [Unsupported snapshot field](invalid/unsupported-snapshot-field.ndjson) | Unknown key in a `st` (state) | +| [Malformed append](invalid/malformed-append.ndjson) | Boolean append argument expected | +| [Ungrouped event](invalid/ungrouped-event.ndjson) | No reduction rule consumes the event | +| [Disabled append](invalid/disabled-append.ndjson) | Append attempted by a non-leader | +| [Missing packet](invalid/missing-packet.ndjson) | No queued model packet to receive | +| [Packet mismatch](invalid/packet-mismatch.ndjson) | Received index differs from the queued model payload | +| [Retirement on signature](invalid/retirement-signature.ndjson) | Retirement follows a signature `replicate_entry` | +| [Retirement seqno mismatch](invalid/retirement-seqno-mismatch.ndjson) | Retirement seqno differs from its `replicate_entry` | +| [Retirement node mismatch](invalid/retirement-node-mismatch.ndjson) | Retirement follows another node's `replicate_entry` | +| [Retirement non-adjacent](invalid/retirement-nonadjacent.ndjson) | An event separates `replicate_entry` and its retirement | +| [Orphan retirement](invalid/retirement-orphan.ndjson) | Retirement without a `replicate_entry` | +| [Uncommitted snapshot](invalid/uncommitted-snapshot.ndjson) | Joiner initializes at an uncommitted signature | +| [Snapshot term history mismatch](invalid/snapshot-term-history-mismatch.ndjson) | Joiner's term history differs from the committed prefix | +| [Snapshot term history outside](invalid/snapshot-term-history-outside.ndjson) | Joiner's term history starts a view after the snapshot | +| [Snapshot configuration mismatch](invalid/snapshot-configuration-mismatch.ndjson) | Joiner's snapshot hook traces another configuration | +| [Applied signature mismatch](invalid/applied-signature-mismatch.ndjson) | Follower applies a transaction where a signature was sent | +| [Applied configuration mismatch](invalid/applied-configuration-mismatch.ndjson) | Follower applies another configuration than was sent | +| [Bootstrap event](invalid/bootstrap-event.ndjson) | Event other than a tick or nomination before genesis | +| [Bootstrap flush send](invalid/bootstrap-flush-send.ndjson) | Send from the genesis flush, which must send nothing | From `lean/consensus`, inspect a failure directly (exit status 1 is expected). Packing needs Python `msgpack`: diff --git a/lean/consensus/replay/fixtures/invalid/applied-configuration-mismatch.ndjson b/lean/consensus/replay/fixtures/invalid/applied-configuration-mismatch.ndjson new file mode 100644 index 00000000000..0e7e80f8087 --- /dev/null +++ b/lean/consensus/replay/fixtures/invalid/applied-configuration-mismatch.ndjson @@ -0,0 +1,30 @@ +{"pid":"driver","m_ts":0,"msg":{"fn":"become_leader","st":{"id":"0"}}} +{"pid":"driver","m_ts":1,"msg":{"fn":"replicate","st":{"id":"0"}}} +{"pid":"driver","m_ts":2,"msg":{"fn":"replicate_entry","st":{"id":"0"},"gc":false}} +{"pid":"driver","m_ts":3,"msg":{"fn":"add_configuration","st":{"id":"0"},"nds":{"0":{}}}} +{"pid":"driver","m_ts":4,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"}}} +{"pid":"driver","m_ts":5,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"},"sn":2,"gc":true}} +{"pid":"driver","m_ts":6,"msg":{"fn":"commit","st":{"id":"0"},"idx":2}} +{"pid":"driver","m_ts":7,"msg":{"cmd":"trust_nodes,2,1"}} +{"pid":"driver","m_ts":8,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":9,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"},"sn":3,"gc":false}} +{"pid":"driver","m_ts":10,"msg":{"fn":"add_configuration","st":{"id":"0"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":11,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":12,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} +{"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} +{"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} +{"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} +{"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":20,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/invalid/applied-signature-mismatch.ndjson b/lean/consensus/replay/fixtures/invalid/applied-signature-mismatch.ndjson new file mode 100644 index 00000000000..7d3d43b0da3 --- /dev/null +++ b/lean/consensus/replay/fixtures/invalid/applied-signature-mismatch.ndjson @@ -0,0 +1,30 @@ +{"pid":"driver","m_ts":0,"msg":{"fn":"become_leader","st":{"id":"0"}}} +{"pid":"driver","m_ts":1,"msg":{"fn":"replicate","st":{"id":"0"}}} +{"pid":"driver","m_ts":2,"msg":{"fn":"replicate_entry","st":{"id":"0"},"gc":false}} +{"pid":"driver","m_ts":3,"msg":{"fn":"add_configuration","st":{"id":"0"},"nds":{"0":{}}}} +{"pid":"driver","m_ts":4,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"}}} +{"pid":"driver","m_ts":5,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"},"sn":2,"gc":true}} +{"pid":"driver","m_ts":6,"msg":{"fn":"commit","st":{"id":"0"},"idx":2}} +{"pid":"driver","m_ts":7,"msg":{"cmd":"trust_nodes,2,1"}} +{"pid":"driver","m_ts":8,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":9,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"},"sn":3,"gc":false}} +{"pid":"driver","m_ts":10,"msg":{"fn":"add_configuration","st":{"id":"0"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":11,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":12,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} +{"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} +{"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} +{"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} +{"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":20,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":false}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/invalid/bootstrap-flush-send.ndjson b/lean/consensus/replay/fixtures/invalid/bootstrap-flush-send.ndjson index 07c751b75f3..97e2827ba20 100644 --- a/lean/consensus/replay/fixtures/invalid/bootstrap-flush-send.ndjson +++ b/lean/consensus/replay/fixtures/invalid/bootstrap-flush-send.ndjson @@ -16,7 +16,7 @@ {"pid":"driver","m_ts":15,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":16,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":17,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":18,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":18,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":19,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":20,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":21,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} @@ -24,7 +24,9 @@ {"pid":"driver","m_ts":23,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} {"pid":"driver","m_ts":24,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":25,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} -{"pid":"driver","m_ts":26,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} -{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} -{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} -{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":27,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":29,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":30,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":31,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/invalid/disabled-append.ndjson b/lean/consensus/replay/fixtures/invalid/disabled-append.ndjson index c6fddc81325..e4a3d582447 100644 --- a/lean/consensus/replay/fixtures/invalid/disabled-append.ndjson +++ b/lean/consensus/replay/fixtures/invalid/disabled-append.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/invalid/malformed-append.ndjson b/lean/consensus/replay/fixtures/invalid/malformed-append.ndjson index 5abbd38a3ac..b93580a4dd2 100644 --- a/lean/consensus/replay/fixtures/invalid/malformed-append.ndjson +++ b/lean/consensus/replay/fixtures/invalid/malformed-append.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/invalid/missing-packet.ndjson b/lean/consensus/replay/fixtures/invalid/missing-packet.ndjson index b68080959c7..74fa9397943 100644 --- a/lean/consensus/replay/fixtures/invalid/missing-packet.ndjson +++ b/lean/consensus/replay/fixtures/invalid/missing-packet.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/invalid/packet-mismatch.ndjson b/lean/consensus/replay/fixtures/invalid/packet-mismatch.ndjson index 7c66904abc7..828ef1b176c 100644 --- a/lean/consensus/replay/fixtures/invalid/packet-mismatch.ndjson +++ b/lean/consensus/replay/fixtures/invalid/packet-mismatch.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/invalid/snapshot-configuration-mismatch.ndjson b/lean/consensus/replay/fixtures/invalid/snapshot-configuration-mismatch.ndjson new file mode 100644 index 00000000000..d4f67c69cbb --- /dev/null +++ b/lean/consensus/replay/fixtures/invalid/snapshot-configuration-mismatch.ndjson @@ -0,0 +1,30 @@ +{"pid":"driver","m_ts":0,"msg":{"fn":"become_leader","st":{"id":"0"}}} +{"pid":"driver","m_ts":1,"msg":{"fn":"replicate","st":{"id":"0"}}} +{"pid":"driver","m_ts":2,"msg":{"fn":"replicate_entry","st":{"id":"0"},"gc":false}} +{"pid":"driver","m_ts":3,"msg":{"fn":"add_configuration","st":{"id":"0"},"nds":{"0":{}}}} +{"pid":"driver","m_ts":4,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"}}} +{"pid":"driver","m_ts":5,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"},"sn":2,"gc":true}} +{"pid":"driver","m_ts":6,"msg":{"fn":"commit","st":{"id":"0"},"idx":2}} +{"pid":"driver","m_ts":7,"msg":{"cmd":"trust_nodes,2,1"}} +{"pid":"driver","m_ts":8,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":9,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"},"sn":3,"gc":false}} +{"pid":"driver","m_ts":10,"msg":{"fn":"add_configuration","st":{"id":"0"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":11,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":12,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} +{"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} +{"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} +{"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":20,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/invalid/snapshot-mismatch.ndjson b/lean/consensus/replay/fixtures/invalid/snapshot-mismatch.ndjson index fafc8f63e43..0b628fec0f5 100644 --- a/lean/consensus/replay/fixtures/invalid/snapshot-mismatch.ndjson +++ b/lean/consensus/replay/fixtures/invalid/snapshot-mismatch.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/invalid/snapshot-term-history-mismatch.ndjson b/lean/consensus/replay/fixtures/invalid/snapshot-term-history-mismatch.ndjson new file mode 100644 index 00000000000..c9f98a74cde --- /dev/null +++ b/lean/consensus/replay/fixtures/invalid/snapshot-term-history-mismatch.ndjson @@ -0,0 +1,30 @@ +{"pid":"driver","m_ts":0,"msg":{"fn":"become_leader","st":{"id":"0"}}} +{"pid":"driver","m_ts":1,"msg":{"fn":"replicate","st":{"id":"0"}}} +{"pid":"driver","m_ts":2,"msg":{"fn":"replicate_entry","st":{"id":"0"},"gc":false}} +{"pid":"driver","m_ts":3,"msg":{"fn":"add_configuration","st":{"id":"0"},"nds":{"0":{}}}} +{"pid":"driver","m_ts":4,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"}}} +{"pid":"driver","m_ts":5,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"},"sn":2,"gc":true}} +{"pid":"driver","m_ts":6,"msg":{"fn":"commit","st":{"id":"0"},"idx":2}} +{"pid":"driver","m_ts":7,"msg":{"cmd":"trust_nodes,2,1"}} +{"pid":"driver","m_ts":8,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":9,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"},"sn":3,"gc":false}} +{"pid":"driver","m_ts":10,"msg":{"fn":"add_configuration","st":{"id":"0"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":11,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":12,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} +{"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} +{"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,2]}} +{"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} +{"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":20,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/invalid/snapshot-term-history-outside.ndjson b/lean/consensus/replay/fixtures/invalid/snapshot-term-history-outside.ndjson new file mode 100644 index 00000000000..b91498015f9 --- /dev/null +++ b/lean/consensus/replay/fixtures/invalid/snapshot-term-history-outside.ndjson @@ -0,0 +1,30 @@ +{"pid":"driver","m_ts":0,"msg":{"fn":"become_leader","st":{"id":"0"}}} +{"pid":"driver","m_ts":1,"msg":{"fn":"replicate","st":{"id":"0"}}} +{"pid":"driver","m_ts":2,"msg":{"fn":"replicate_entry","st":{"id":"0"},"gc":false}} +{"pid":"driver","m_ts":3,"msg":{"fn":"add_configuration","st":{"id":"0"},"nds":{"0":{}}}} +{"pid":"driver","m_ts":4,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"}}} +{"pid":"driver","m_ts":5,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"},"sn":2,"gc":true}} +{"pid":"driver","m_ts":6,"msg":{"fn":"commit","st":{"id":"0"},"idx":2}} +{"pid":"driver","m_ts":7,"msg":{"cmd":"trust_nodes,2,1"}} +{"pid":"driver","m_ts":8,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":9,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"},"sn":3,"gc":false}} +{"pid":"driver","m_ts":10,"msg":{"fn":"add_configuration","st":{"id":"0"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":11,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":12,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} +{"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} +{"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,3]}} +{"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} +{"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":20,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} +{"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} +{"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/invalid/uncommitted-snapshot.ndjson b/lean/consensus/replay/fixtures/invalid/uncommitted-snapshot.ndjson index a7d2506dae1..3302fa157bc 100644 --- a/lean/consensus/replay/fixtures/invalid/uncommitted-snapshot.ndjson +++ b/lean/consensus/replay/fixtures/invalid/uncommitted-snapshot.ndjson @@ -14,5 +14,5 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":4,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":4,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} diff --git a/lean/consensus/replay/fixtures/invalid/ungrouped-event.ndjson b/lean/consensus/replay/fixtures/invalid/ungrouped-event.ndjson index 97a31ddb6e6..cce21be8b71 100644 --- a/lean/consensus/replay/fixtures/invalid/ungrouped-event.ndjson +++ b/lean/consensus/replay/fixtures/invalid/ungrouped-event.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/invalid/unsupported-snapshot-field.ndjson b/lean/consensus/replay/fixtures/invalid/unsupported-snapshot-field.ndjson index 615734c767a..73caf9cdb5a 100644 --- a/lean/consensus/replay/fixtures/invalid/unsupported-snapshot-field.ndjson +++ b/lean/consensus/replay/fixtures/invalid/unsupported-snapshot-field.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} diff --git a/lean/consensus/replay/fixtures/valid/hook-order.ndjson b/lean/consensus/replay/fixtures/valid/hook-order.ndjson index 62b00609098..251762da2fe 100644 --- a/lean/consensus/replay/fixtures/valid/hook-order.ndjson +++ b/lean/consensus/replay/fixtures/valid/hook-order.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} @@ -22,7 +22,9 @@ {"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} {"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} -{"pid":"driver","m_ts":24,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} -{"pid":"driver","m_ts":25,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} -{"pid":"driver","m_ts":26,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} -{"pid":"driver","m_ts":27,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/lean/consensus/replay/fixtures/valid/interleaved.ndjson b/lean/consensus/replay/fixtures/valid/interleaved.ndjson index 532319b9cac..270e6593701 100644 --- a/lean/consensus/replay/fixtures/valid/interleaved.ndjson +++ b/lean/consensus/replay/fixtures/valid/interleaved.ndjson @@ -5,7 +5,7 @@ {"pid":"node-1","m_ts":4,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}},"ts":1700000000000004000} {"pid":"node-1","m_ts":5,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}},"ts":1700000000000005000} {"pid":"node-0","m_ts":6,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"}},"ts":1700000000000006000} -{"pid":"node-1","m_ts":7,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2},"ts":1700000000000007000} +{"pid":"node-1","m_ts":7,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]},"ts":1700000000000007000} {"pid":"node-0","m_ts":8,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":1,"ci":0,"ls":"Leader"},"sn":2,"gc":true},"ts":1700000000000008000} {"pid":"node-1","m_ts":9,"msg":{"fn":"become_follower","st":{"id":"1"}},"ts":1700000000000009000} {"pid":"node-0","m_ts":10,"msg":{"fn":"commit","st":{"id":"0"},"idx":2},"ts":1700000000000010000} @@ -16,8 +16,10 @@ {"pid":"node-0","m_ts":15,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":2,"ci":2,"ls":"Leader"},"sn":3,"gc":false},"ts":1700000000000015000} {"pid":"node-0","m_ts":16,"msg":{"fn":"add_configuration","st":{"id":"0"},"idx":3,"nds":{"0":{},"1":{}}},"ts":1700000000000016000} {"pid":"node-1","m_ts":17,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}},"ts":1700000000000017000} -{"pid":"node-1","m_ts":18,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}},"ts":1700000000000018000} -{"pid":"node-1","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}},"ts":1700000000000019000} +{"pid":"node-1","m_ts":18,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false},"ts":1700000000000017300} +{"pid":"node-1","m_ts":19,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}},"ts":1700000000000018000} +{"pid":"node-1","m_ts":20,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true},"ts":1700000000000018300} +{"pid":"node-1","m_ts":21,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}},"ts":1700000000000019000} {"pid":"node-0","m_ts":20,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}},"ts":1700000000000020000} {"pid":"node-0","m_ts":21,"msg":{"fn":"replicate","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"}},"ts":1700000000000021000} {"pid":"node-0","m_ts":22,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true},"ts":1700000000000022000} diff --git a/lean/consensus/replay/fixtures/valid/replication.ndjson b/lean/consensus/replay/fixtures/valid/replication.ndjson index 18d09760a9d..4e9b55c40f8 100644 --- a/lean/consensus/replay/fixtures/valid/replication.ndjson +++ b/lean/consensus/replay/fixtures/valid/replication.ndjson @@ -14,7 +14,7 @@ {"pid":"driver","m_ts":13,"msg":{"fn":"replicate_entry","st":{"id":"0","vw":2,"li":3,"ci":2,"ls":"Leader"},"sn":4,"gc":true}} {"pid":"driver","m_ts":14,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":2,"nds":{"0":{}}}} {"pid":"driver","m_ts":15,"msg":{"fn":"tick","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"}}} -{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2}} +{"pid":"driver","m_ts":16,"msg":{"fn":"init_as_backup","st":{"id":"1","vw":0,"li":0,"ci":0,"ls":"None"},"sn":2,"vw":2,"th":[1,1]}} {"pid":"driver","m_ts":17,"msg":{"fn":"become_follower","st":{"id":"1"}}} {"pid":"driver","m_ts":18,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":2,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":19,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":2}}} @@ -22,7 +22,9 @@ {"pid":"driver","m_ts":21,"msg":{"fn":"tick","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"}}} {"pid":"driver","m_ts":22,"msg":{"fn":"send_append_entries","st":{"id":"0"},"to":"1","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} {"pid":"driver","m_ts":23,"msg":{"fn":"recv_append_entries","st":{"id":"1","vw":2,"li":2,"ci":2,"ls":"Follower"},"frm":"0","pkt":{"msg":"append_entries","tm":2,"pi":2,"pt":2,"idx":4,"lci":2,"toi":2,"cnv":false}}} -{"pid":"driver","m_ts":24,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} -{"pid":"driver","m_ts":25,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} -{"pid":"driver","m_ts":26,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} -{"pid":"driver","m_ts":27,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} +{"pid":"driver","m_ts":24,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":3,"gc":false}} +{"pid":"driver","m_ts":25,"msg":{"fn":"add_configuration","st":{"id":"1"},"idx":3,"nds":{"0":{},"1":{}}}} +{"pid":"driver","m_ts":26,"msg":{"fn":"execute_append_entries_sync","st":{"id":"1"},"frm":"0","vw":2,"sn":4,"gc":true}} +{"pid":"driver","m_ts":27,"msg":{"fn":"send_append_entries_response","st":{"id":"1"},"to":"0","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":28,"msg":{"fn":"recv_append_entries_response","st":{"id":"0","vw":2,"li":4,"ci":2,"ls":"Leader"},"frm":"1","pkt":{"msg":"append_entries_response","tm":2,"ok":"OK","lli":4}}} +{"pid":"driver","m_ts":29,"msg":{"fn":"commit","st":{"id":"0"},"idx":4}} diff --git a/src/consensus/aft/cft.h b/src/consensus/aft/cft.h index 2f141212cc5..70ef4387554 100644 --- a/src/consensus/aft/cft.h +++ b/src/consensus/aft/cft.h @@ -485,7 +485,7 @@ namespace aft // before it has received any append entries. std::lock_guard guard(state->lock); - trace::init_as_backup(*state, index, term); + trace::init_as_backup(*state, index, term, TermHistory{term_history}); state->last_idx = index; state->commit_idx = index; @@ -1406,8 +1406,6 @@ namespace aft auto& [ds, i] = ae; CFT_DEBUG_FMT("Replicating on follower {}: {}", state->node_id, i); - trace::execute_append_entries_sync(*state, from.value()); - bool track_deletes_on_missing_keys = false; ccf::kv::ApplyResult apply_success = ds->apply(track_deletes_on_missing_keys); @@ -1417,6 +1415,10 @@ namespace aft send_append_entries_response_nack(from); return; } + bool globally_committable = + (apply_success == ccf::kv::ApplyResult::PASS_SIGNATURE); + trace::execute_append_entries_sync( + *state, from.value(), ds->get_term(), i, globally_committable); state->last_idx = i; try @@ -1441,8 +1443,6 @@ namespace aft return; } - bool globally_committable = - (apply_success == ccf::kv::ApplyResult::PASS_SIGNATURE); if (globally_committable) { start_ticking_if_necessary(); diff --git a/src/consensus/aft/cft_trace_msgpack.h b/src/consensus/aft/cft_trace_msgpack.h index 528d530135b..64b1c1023db 100644 --- a/src/consensus/aft/cft_trace_msgpack.h +++ b/src/consensus/aft/cft_trace_msgpack.h @@ -24,6 +24,7 @@ // vw = view sn = seqno // gc = globally_committable id = node_id // ret = retired_node_id nds = nodes +// th = term_history namespace aft { @@ -184,6 +185,26 @@ namespace ccf::kv } } +namespace aft +{ + /// The first seqno of each view, as `init_as_backup` takes it. + struct TermHistory + { + const std::vector& term_history; + }; + + inline void write_msgpack( + std::vector& out, const TermHistory& history) + { + ccf::msgpack::write_array_header( + out, ccf::msgpack::container_size(history.term_history.size())); + for (const auto seqno : history.term_history) + { + ccf::msgpack::write_msgpack(out, seqno); + } + } +} + namespace aft::trace { constexpr std::string_view cft_trace_tag = "ccf.cft"; @@ -195,7 +216,7 @@ namespace aft::trace DECLARE_CFT_EVENT(send_append_entries, st, pkt, to, mi, si); DECLARE_CFT_EVENT(recv_append_entries_response, st, pkt, frm, mi, si); DECLARE_CFT_EVENT(recv_append_entries, st, pkt, frm); - DECLARE_CFT_EVENT(execute_append_entries_sync, st, frm); + DECLARE_CFT_EVENT(execute_append_entries_sync, st, frm, vw, sn, gc); DECLARE_CFT_EVENT(send_append_entries_response, st, pkt, to); DECLARE_CFT_EVENT(send_request_vote, st, pkt, to); DECLARE_CFT_EVENT(send_request_vote_response, st, pkt, to); @@ -212,7 +233,7 @@ namespace aft::trace DECLARE_CFT_EVENT(step_down_and_nominate_successor, st, cfg, to); DECLARE_CFT_EVENT(replicate_entry, st, vw, sn, gc); DECLARE_CFT_EVENT(retired_committed_tx, id, sn, ret); - DECLARE_CFT_EVENT(init_as_backup, st, sn, vw); + DECLARE_CFT_EVENT(init_as_backup, st, sn, vw, th); DECLARE_CFT_EVENT(batch_flush, st); DECLARE_CFT_EVENT(replicate, st); DECLARE_CFT_EVENT(add_configuration, st, cfg, idx, nds, rid); diff --git a/tests/cft_model/ModelDriver.lean b/tests/cft_model/ModelDriver.lean index 8c4825534ad..b3a20c5fac3 100644 --- a/tests/cft_model/ModelDriver.lean +++ b/tests/cft_model/ModelDriver.lean @@ -560,9 +560,15 @@ private def received (node source : NodeID) (message : Message) (pre : NodeState committed node state (max state.commitIndex (maxCommittableIndexUpTo state.log limit)) for entry in request.entries.drop (state.log.length - request.prevLogIndex) do - stateEvent "execute_append_entries_sync" node state [("frm", named source)] let before := state let index := state.log.length + 1 + stateEvent "execute_append_entries_sync" node state + [ + ("frm", named source), + ("vw", .number entry.term), + ("sn", .number index), + ("gc", .flag entry.content.isSignature) + ] state := { state with log := state.log ++ [entry] } for retired in entry.content.metadata.retirementConfirmations.sort do event "retired_committed_tx" @@ -1053,7 +1059,8 @@ private def addNode (node : NodeID) : IO Unit := do let (before, after) := d.state.nodes.partition (·.1 < node) driver.set { d with state := { d.state with nodes := before ++ fresh :: after } } let events (pre post : NodeState) : IO NodeState := do - stateEvent "init_as_backup" node pre [("sn", .number 0), ("vw", .number 0)] + stateEvent "init_as_backup" node pre + [("sn", .number 0), ("vw", .number 0), ("th", .list [])] stateEvent "become_follower" node post [configurations post] return post unless ← perform (.local node (.initAsBackup [])) events do