Section LeaderSublogProof.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {rri : raft_refinement_interface}.
Context {cei : candidate_entries_interface}.
Context {vci : votes_correct_interface}.
Context {cci : cronies_correct_interface}.
Context {olpti : one_leader_per_term_interface}.
Ltac prove_in :=
match goal with
| [ _ : nwPackets ?net = _,
_ : In (?p : packet) _ |- _] =>
assert (In p (nwPackets net)) by (repeat find_rewrite; do_in_app; intuition)
| [ _ : nwPackets ?net = _,
_ : pBody ?p = _ |- _] =>
assert (In p (nwPackets net)) by (repeat find_rewrite; intuition)
end.
Notation is_append_entries m :=
(exists t n prevT prevI entries c,
m = AppendEntries t n prevT prevI entries c).
Proof using.
unfold leader_sublog_host_invariant in *. intros.
specialize (H leader e h).
forward H; [apply H1; auto|].
intuition.
rewrite H0 in *. specialize (H1 leader). intuition.
rewrite H7 in *; auto.
rewrite H0 in *. auto.
Qed.
Proof using.
unfold leader_sublog_invariant in *. intros; intuition.
- eauto using leader_sublog_invariant_same_state.
- unfold leader_sublog_nw_invariant in *. intros.
pose proof H1 leader.
pose proof H2 leader; concludes.
pose proof H3 leader. intuition.
symmetry in H13.
repeat find_rewrite.
eapply H11; simpl in *; repeat find_rewrite; eauto.
assert (is_append_entries (pBody p)) by (repeat eexists; eauto).
eauto.
Qed.
Proof using.
unfold raft_net_invariant_do_leader.
intros.
unfold doLeader in *.
break_match; try solve [
find_inversion; simpl in *;
eapply leader_sublog_invariant_subset;
eauto; intuition; simpl in *;
repeat find_apply_hyp_hyp; intuition;
repeat find_higher_order_rewrite; repeat break_if; subst; intuition].
break_if.
- unfold replicaMessage in *. find_inversion. simpl in *.
unfold leader_sublog_invariant in *; intuition.
+ unfold leader_sublog_host_invariant in *. intros.
simpl in *. repeat find_higher_order_rewrite.
repeat break_if; simpl in *; intuition eauto.
+ unfold leader_sublog_nw_invariant in *. intros.
simpl in *. repeat find_higher_order_rewrite.
find_apply_hyp_hyp.
break_if; intuition idtac; simpl in *; subst; intuition eauto;
simpl in *;
repeat do_in_map; subst; simpl in *;
find_inversion; eauto using findGtIndex_in.
- find_inversion.
unfold leader_sublog_invariant, leader_sublog_nw_invariant,
leader_sublog_host_invariant, advanceCommitIndex in *.
intuition; find_higher_order_rewrite; repeat break_if; simpl in *; subst;
repeat break_if; simpl in *; eauto;
find_apply_hyp_hyp; intuition; eauto.
Qed.
Proof using olpti.
unfold raft_net_invariant_client_request.
intros.
unfold leader_sublog_invariant, leader_sublog_nw_invariant,
leader_sublog_host_invariant, handleClientRequest in *. intuition idtac.
- break_match; find_inversion; simpl in *; repeat find_higher_order_rewrite;
repeat break_if; subst; simpl in *;
intuition eauto;
simpl in *; in_crush_finish; intuition eauto. in_crush; eauto.
exfalso.
match goal with
| H : raft_intermediate_reachable _ |- _ =>
eapply one_leader_per_term_invariant in H
end.
assert (leader = h) by (eapply_prop one_leader_per_term; eauto).
intuition.
- break_match; find_inversion; simpl in *; repeat find_higher_order_rewrite;
repeat break_if; find_apply_hyp_hyp; intuition eauto; subst.
simpl in *.
in_crush; eauto.
Qed.
Proof using.
unfold raft_net_invariant_timeout. intros.
unfold leader_sublog_invariant, leader_sublog_nw_invariant,
leader_sublog_host_invariant, handleTimeout, tryToBecomeLeader in *.
intuition idtac; simpl in *.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto; solve_by_inversion.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto;
find_apply_hyp_hyp; intuition eauto; try solve_by_inversion;
in_crush; repeat find_inversion; discriminate.
Qed.
Proof using.
unfold raft_net_invariant_append_entries. intros.
unfold leader_sublog_invariant, leader_sublog_nw_invariant,
leader_sublog_host_invariant, handleAppendEntries, advanceCurrentTerm in *.
intuition idtac; simpl in *.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto; try solve_by_inversion;
do_in_app; intuition; eauto using removeAfterIndex_in.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto;
find_apply_hyp_hyp; intuition eauto; subst; try discriminate.
Qed.
Proof using.
unfold raft_net_invariant_append_entries_reply. intros.
unfold leader_sublog_invariant, leader_sublog_nw_invariant,
leader_sublog_host_invariant, handleAppendEntriesReply, advanceCurrentTerm in *.
intuition idtac; simpl in *.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto; try solve_by_inversion.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto;
find_apply_hyp_hyp; intuition eauto; try discriminate.
Qed.
Proof using.
unfold raft_net_invariant_request_vote. intros.
unfold leader_sublog_invariant, leader_sublog_nw_invariant,
leader_sublog_host_invariant, handleRequestVote, advanceCurrentTerm in *.
intuition idtac; simpl in *.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto; try solve_by_inversion.
- repeat find_higher_order_rewrite; repeat break_match; repeat find_inversion;
subst; simpl in *;
intuition eauto;
find_apply_hyp_hyp; intuition eauto; subst; try discriminate.
Qed.
Definition CandidateEntriesLowered net e h :=
currentTerm (nwState net h) = eTerm e ->
wonElection (dedup name_eq_dec (votesReceived (nwState net h))) = true ->
type (nwState net h) <> Candidate.

Lemma candidate_entries_lowered' :
forall net,
CandidateEntries net ->
votes_correct net ->
cronies_correct net ->
forall h h' e,
In e (log (snd (nwState net h'))) ->
CandidateEntriesLowered (deghost net) e h.