Require Export Verdi.Verdi.
Require Export StructTact.Fin.
Open Scope bool.
Set Implicit Arguments.
Class RaftParams (orig_base_params : BaseParams)
:= {
N : nat ;
input_eq_dec : forall x y : input, {x = y} + {x <> y} ;
output_eq_dec : forall x y : output, {x = y} + {x <> y} ;
clientId : Type ;
clientId_eq_dec : forall x y : clientId, {x = y} + {x <> y}
}.
Section Raft.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Definition term := nat.
Definition logIndex := nat.
Definition name := fin N.
Definition nodes : list name := all_fin _.
Definition name_eq_dec : forall x y : name, {x = y} + {x <> y} := fin_eq_dec _.
Notation "a >? b" := (b <? a) (at level 70).
Notation "a >=? b" := (b <=? a) (at level 70).
Notation "a == b" := (beq_nat a b) (at level 70).
Notation "a != b" := (negb (beq_nat a b)) (at level 70).
Notation "a === b" := (if fin_eq_dec _ a b then true else false) (at level 42).
Record entry := mkEntry {
eAt : name;
eClient : clientId;
eId : nat;
eIndex : logIndex;
eTerm : term;
eInput : input
}.
Inductive msg : Type :=
| RequestVote : term -> name -> logIndex -> term -> msg
| RequestVoteReply : term -> bool -> msg
| AppendEntries : term -> (name) -> logIndex -> term -> (list entry) -> logIndex -> msg
| AppendEntriesReply : term -> (list entry) -> bool -> msg.
Inductive raft_input : Type :=
| Timeout : raft_input
| ClientRequest : clientId -> nat -> input -> raft_input.
Inductive raft_output : Type :=
| NotLeader : clientId -> nat -> raft_output
| ClientResponse : clientId -> nat -> output -> raft_output.
Inductive serverType : Set :=
| Follower
| Candidate
| Leader.
Definition serverType_eq_dec : forall x y : serverType, {x = y} + {x <> y}.

Lemma step_failure_star_raft_intermediate_reachable :
forall failed net tr,
step_failure_star step_failure_init (failed, net) tr ->
raft_intermediate_reachable net.