Section RequestVoteMaxIndexMaxTerm.
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 {rvrtsi : requestVote_term_sanity_interface}.
Proof using.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
assert (In p0 (nwPackets net)) by
(find_apply_hyp_hyp; repeat find_rewrite; intuition; [in_crush|];
exfalso; subst; simpl in *; subst;
unfold handleAppendEntries in *;
repeat break_match; find_inversion).
repeat find_rewrite.
destruct_update; simpl in *; eauto;
try rewrite votesWithLog_same_append_entries; eauto;
find_apply_lem_hyp handleAppendEntries_log_term_type.
break_or_hyp; try congruence.
break_and; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
assert (In p0 (nwPackets net)) by
(repeat find_rewrite;
find_apply_lem_hyp handleAppendEntriesReply_packets;
subst; simpl in *; find_apply_hyp_hyp; intuition; in_crush).
repeat find_rewrite.
find_copy_apply_lem_hyp handleAppendEntriesReply_log_term_type.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
break_or_hyp; try congruence; break_and; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
assert (In p0 (nwPackets net)) by
(find_apply_hyp_hyp; repeat find_rewrite; intuition; [in_crush|];
exfalso; subst; simpl in *; subst;
unfold handleRequestVote in *;
repeat break_match; find_inversion).
find_copy_apply_lem_hyp handleRequestVote_log_term_type.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
break_or_hyp; try congruence; break_and; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_eapply_lem_hyp handleRequestVoteReply_log_term_type; eauto.
break_and; repeat find_rewrite; eauto.
Qed.
Proof using rvrtsi.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_apply_hyp_hyp. break_or_hyp.
+ exfalso.
find_eapply_lem_hyp update_elections_data_timeout_votesWithLog_votesReceived; eauto.
intuition; try congruence.
find_apply_lem_hyp requestVote_term_sanity_invariant.
eapply_prop_hyp requestVote_term_sanity pBody; eauto.
unfold raft_data in *; simpl in *; unfold raft_data in *; simpl in *.
lia.
+ do_in_map. remember (pSrc p). subst p.
simpl in *.
intuition; eapply handleTimeout_messages; eauto.
- find_apply_hyp_hyp. break_or_hyp; eauto.
do_in_map. subst. simpl in *. intuition.
Qed.
Proof using.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
find_copy_apply_lem_hyp handleClientRequest_packets.
subst. simpl in *.
find_apply_hyp_hyp. break_or_hyp.
repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
try rewrite votesWithLog_same_client_request; eauto;
find_apply_lem_hyp handleClientRequest_candidate; subst; eauto.
intuition.
Qed.
Proof using.
red. unfold requestVote_maxIndex_maxTerm. intros. simpl in *.
assert (In p (nwPackets net)) by
(find_apply_hyp_hyp; intuition;
do_in_map; subst;
unfold doLeader, replicaMessage in *;
repeat break_match; find_inversion; subst; simpl in *; intuition;
do_in_map; subst; simpl in *; congruence).
match goal with
| H : nwState ?net ?h = (?gd, ?d) |- _ =>
replace gd with (fst (nwState net h)) in * by (rewrite H; reflexivity);
replace d with (snd (nwState net h)) in * by (rewrite H; reflexivity);
clear H
end.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
find_apply_lem_hyp doLeader_candidate; subst; eauto.
Qed.

Lemma requestVote_maxIndex_maxTerm_do_generic_server :
refined_raft_net_invariant_do_generic_server requestVote_maxIndex_maxTerm.