Section PrevLogCandidateEntriesTerm.
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 {cti : cronies_term_interface}.
Context {cci : cronies_correct_interface}.
Proof using.
unfold refined_raft_net_invariant_init, prevLog_candidateEntriesTerm.
simpl. intuition.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros. break_exists_exists.
repeat find_higher_order_rewrite. intuition.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros. break_exists_exists.
repeat find_higher_order_rewrite.
intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_client_request, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- eapply candidateEntriesTerm_ext; eauto.
eapply candidateEntriesTerm_same; eauto; intros;
update_destruct_simplify; auto.
+ now erewrite update_elections_data_client_request_cronies by eauto.
+ find_apply_lem_hyp handleClientRequest_type. intuition.
+ find_apply_lem_hyp handleClientRequest_type. intuition.
- find_apply_lem_hyp in_map_iff. break_exists. break_and. subst. simpl in *.
exfalso. eapply handleClientRequest_no_append_entries; eauto.
find_rewrite. eauto 10.
Qed.
Proof using.
unfold update_elections_data_timeout.
intros.
repeat break_match; repeat find_inversion; simpl; auto.
break_match; auto.
Qed.
Proof using cti.
unfold candidateEntriesTerm.
intros.
break_exists_exists. break_and.
match goal with
| [ H : handleTimeout _ _ = _ |- _ ] =>
pose proof H;
eapply update_elections_data_timeout_cronies with (t := t) in H
end. break_or_hyp.
- update_destruct_simplify; auto.
find_copy_apply_lem_hyp handleTimeout_type_strong.
intuition; repeat find_rewrite; auto.
find_apply_lem_hyp wonElection_exists_voter.
break_exists.
find_apply_lem_hyp in_dedup_was_in.
find_copy_apply_lem_hyp cronies_term_invariant; auto.
simpl in *.
lia.
- update_destruct_simplify; auto.
find_copy_apply_lem_hyp handleTimeout_type_strong.
find_apply_lem_hyp wonElection_exists_voter.
break_exists.
find_apply_lem_hyp in_dedup_was_in.
find_copy_apply_lem_hyp cronies_term_invariant; auto.
intuition; subst; repeat find_rewrite; auto;
simpl in *; lia.
Qed.
Proof using cti.
unfold refined_raft_net_invariant_timeout, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- eapply candidateEntriesTerm_ext; eauto.
eapply handleClientRequest_preserves_candidateEntriesTerm; eauto.
- find_apply_lem_hyp in_map_iff. break_exists. break_and.
subst. simpl in *.
exfalso. eapply handleTimeout_not_is_append_entries; eauto.
find_rewrite. eauto 10.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros.
break_exists_exists. break_and.
update_destruct_simplify.
- rewrite update_elections_data_appendEntries_cronies.
find_apply_lem_hyp handleAppendEntries_type.
intuition; subst; repeat find_rewrite; auto.
discriminate.
- intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
eapply candidateEntriesTerm_ext; eauto.
eapply handleAppendEntries_preserves_candidateEntriesTerm; eauto.
- exfalso. eapply handleAppendEntries_not_append_entries; eauto.
simpl in *. subst. eauto 10.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros. break_exists_exists.
find_apply_lem_hyp handleAppendEntriesReply_type.
update_destruct_simplify.
- intuition; repeat find_rewrite; auto. discriminate.
- auto.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries_reply, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
eapply candidateEntriesTerm_ext; eauto.
eauto using handleAppendEntriesReply_preserves_candidateEntriesTerm.
- find_apply_lem_hyp in_map_iff. break_exists. break_and.
find_apply_lem_hyp handleAppendEntriesReply_packets.
subst. simpl in *. intuition.
Qed.
Proof using.
unfold update_elections_data_requestVote.
intros.
repeat break_match; auto.
Qed.
Proof using.
unfold advanceCurrentTerm.
intros. repeat break_match; auto.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros.
break_exists_exists.
update_destruct_simplify; intuition.
- now rewrite update_elections_data_requestVote_cronies_same.
- intros.
match goal with
| [ H : context [advanceCurrentTerm ?st ?t] |- _ ] =>
pose proof advanceCurrentTerm_same_or_type_follower st t
end.
intuition.
+ repeat find_rewrite. auto.
+ congruence.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros.
break_exists_exists.
update_destruct_simplify; intuition.
- now rewrite update_elections_data_requestVote_cronies_same.
- unfold handleRequestVote, advanceCurrentTerm in *.
repeat break_match; do_bool; repeat find_inversion; simpl in *; break_and; try discriminate; auto.
Qed.
Proof using.
unfold refined_raft_net_invariant_request_vote, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
- find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
eapply candidateEntriesTerm_ext; eauto.
eapply handleRequestVote_preserves_candidateEntriesTerm; eauto.
- exfalso. eapply handleRequestVote_no_append_entries; eauto.
simpl in *. subst. eauto 10.
Qed.
Proof using cci.
unfold candidateEntriesTerm.
intros.
break_exists_exists.
update_destruct_simplify; auto.
break_and.
unfold raft_data in *. simpl in *.
unfold update_elections_data_requestVoteReply.
match goal with
| |- context [handleRequestVoteReply ?h ?st ?h' ?t ?r] =>
remember (handleRequestVoteReply h st h' t r) as new_state
end; find_copy_apply_lem_hyp handleRequestVoteReply_spec.
repeat (break_match); intuition; repeat find_rewrite; intuition;
simpl; break_if; auto.
- find_apply_lem_hyp cronies_correct_invariant.
unfold cronies_correct in *. intuition.
unfold votes_received_leaders in *.
match goal with
| H :  Leader = _ |- _ =>
symmetry in H
end. find_apply_hyp_hyp.
eapply wonElection_no_dup_in;
eauto using NoDup_dedup, in_dedup_was_in, dedup_In.
- destruct (serverType_eq_dec (type (snd (nwState net x))) Leader); intuition.
find_apply_lem_hyp cronies_correct_invariant; auto.
eapply wonElection_no_dup_in;
eauto using NoDup_dedup, in_dedup_was_in, dedup_In.
Qed.
Proof using cci.
unfold refined_raft_net_invariant_request_vote_reply, prevLog_candidateEntriesTerm.
simpl. intros.
find_apply_hyp_hyp.
find_eapply_lem_hyp app_cons_in_rest; [|solve[eauto]].
eapply candidateEntriesTerm_ext; eauto.
subst.
eapply handleRequestVoteReply_preserves_candidateEntriesTerm; eauto.
Qed.
Proof using.
unfold candidateEntriesTerm.
intros. break_exists_exists.
break_and.
update_destruct_simplify; auto.
split.
- match goal with
| [ H : nwState ?net ?h = (?x, _) |- _ ] =>
replace (x) with (fst (nwState net h)) in * by (rewrite H; auto)
end.
intuition.
- match goal with
| [ H : nwState ?net ?h = (_, ?x) |- _ ] =>
replace (x) with (snd (nwState net h)) in * by (rewrite H; auto); clear H
end.
find_apply_lem_hyp doLeader_type.
intuition. subst. repeat find_rewrite.
auto.
Qed.
Proof using.
unfold getNextIndex.
intros.
repeat find_rewrite.
auto.
Qed.

Lemma replicaMessage_ext :
forall st st' h h',
nextIndex st' = nextIndex st ->
log st' = log st ->
currentTerm st' = currentTerm st ->
commitIndex st' = commitIndex st ->
replicaMessage st' h h' = replicaMessage st h h'.