Section PrevLogLeaderSublogProof.
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 {vci : votes_correct_interface}.
Context {cci : cronies_correct_interface}.
Context {lsi : leader_sublog_interface}.
Context {plceti : prevLog_candidateEntriesTerm_interface}.
Proof using.
unfold raft_net_invariant_init, prevLog_leader_sublog.
simpl. intuition.
Qed.
Proof using.
intros.
find_apply_lem_hyp handleClientRequest_log.
intuition.
- find_rewrite. auto.
- break_exists. intuition. find_rewrite. intuition.
Qed.
Proof using.
unfold raft_net_invariant_client_request, prevLog_leader_sublog.
intros. simpl in *.
repeat find_higher_order_rewrite.
find_apply_hyp_hyp. break_or_hyp.
- break_if; eauto.
find_copy_apply_lem_hyp handleClientRequest_type. break_and.
repeat find_rewrite.
eapply_prop_hyp In In; eauto.
break_exists_exists. intuition.
eauto using handleClientRequest_log_In.
- find_apply_lem_hyp in_map_iff. break_exists. break_and.
exfalso. eapply handleClientRequest_no_append_entries; eauto.
subst. simpl in *. find_rewrite. eauto 10.
Qed.
Proof using.
unfold raft_net_invariant_timeout, prevLog_leader_sublog.
intros. simpl in *.
repeat find_higher_order_rewrite.
find_apply_hyp_hyp. break_or_hyp.
- break_if; eauto.
find_copy_apply_lem_hyp handleTimeout_type.
intuition; repeat find_rewrite; try discriminate.
eapply_prop_hyp In In; eauto.
break_exists_exists. intuition.
erewrite handleTimeout_log_same by eauto.
eauto.
- find_apply_lem_hyp in_map_iff. break_exists. break_and.
exfalso. subst. simpl in *.
eapply handleTimeout_packets; eauto.
find_rewrite. eauto 10.
Qed.
Proof using.
unfold handleAppendEntries.
intros.
repeat break_match; repeat find_inversion; simpl in *; auto.
Qed.
Proof using.
unfold raft_net_invariant_append_entries, prevLog_leader_sublog.
intros. simpl in *.
repeat find_higher_order_rewrite.
find_apply_hyp_hyp. break_or_hyp.
- find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
find_rewrite. break_if; eauto.
find_copy_apply_lem_hyp handleAppendEntries_type_log.
intuition.
+ congruence.
+ repeat find_rewrite.
eapply_prop_hyp In In; eauto.
- find_apply_lem_hyp handleAppendEntries_not_append_entries.
simpl in *. subst. exfalso. eauto 10.
Qed.
Proof using.
unfold raft_net_invariant_append_entries_reply, prevLog_leader_sublog.
intros. simpl in *.
repeat find_higher_order_rewrite.
find_apply_hyp_hyp. break_or_hyp.
- find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
find_rewrite. break_if; eauto.
find_copy_apply_lem_hyp handleAppendEntriesReply_log.
find_rewrite.
find_copy_apply_lem_hyp handleAppendEntriesReply_type.
intuition; repeat find_rewrite; try discriminate.
eauto.
- find_apply_lem_hyp in_map_iff. break_exists. break_and.
exfalso. subst. simpl in *.
find_apply_lem_hyp handleAppendEntriesReply_packets.
subst. simpl in *. intuition.
Qed.
Proof using.
unfold raft_net_invariant_request_vote, prevLog_leader_sublog.
intros. simpl in *.
repeat find_higher_order_rewrite.
find_apply_hyp_hyp. break_or_hyp.
- find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
find_rewrite. break_if; eauto.
find_copy_apply_lem_hyp handleRequestVote_log.
find_copy_apply_lem_hyp handleRequestVote_type.
intuition; repeat find_rewrite; try discriminate.
eauto.
- find_apply_lem_hyp handleRequestVote_no_append_entries.
simpl in *. subst. exfalso. eauto 10.
Qed.
Definition candidateEntriesTerm_lowered (net : network) t p : Prop :=
In p (nwPackets net) ->
pBody p = RequestVoteReply t true ->
currentTerm (nwState net (pDst p)) = t ->
wonElection (dedup name_eq_dec (pSrc p :: votesReceived (nwState net (pDst p)))) = true ->
type (nwState net (pDst p)) <> Candidate.
Proof using.
unfold deghost.
simpl.
intros.
do_in_map.
eauto.
Qed.

Lemma prevLog_candidateEntriesTerm_lowered' :
forall net,
prevLog_candidateEntriesTerm net ->
votes_correct net ->
cronies_correct net ->
forall p p' t leaderId prevLogIndex prevLogTerm entries leaderCommit,
In p (nwPackets (deghost net)) ->
pBody p = AppendEntries t leaderId prevLogIndex prevLogTerm
entries leaderCommit ->
0 < prevLogTerm ->
candidateEntriesTerm_lowered (deghost net) prevLogTerm p'.