Section RequestVoteReplyMoreUpToDate.
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 {rvmimti : requestVote_maxIndex_maxTerm_interface}.
Context {rvrtsi : requestVoteReply_term_sanity_interface}.
Context {vfmutdi : votedFor_moreUpToDate_interface}.
Proof using.
red. unfold requestVoteReply_moreUpToDate. 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;
intuition; repeat find_rewrite; try congruence;
eauto.
Qed.
Proof using.
red. unfold requestVoteReply_moreUpToDate. 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_votesReceived.
find_copy_apply_lem_hyp handleAppendEntriesReply_log_term_type.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
intuition; try congruence; repeat find_rewrite; eauto.
Qed.
Proof using vfmutdi rvmimti.
red. unfold requestVoteReply_moreUpToDate. intros. simpl in *.
find_copy_apply_lem_hyp handleRequestVote_votesReceived.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_copy_apply_lem_hyp handleRequestVote_log_term_type; intuition; try congruence.
repeat find_rewrite.
find_apply_hyp_hyp. intuition.
+ assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
repeat find_rewrite.
eapply_prop_hyp pBody pBody; eauto.
break_exists_exists. intuition.
eauto using update_elections_data_request_vote_votesWithLog_old.
+ remember (pSrc p0) as h.
subst_max. simpl in *. subst_max.
find_copy_apply_lem_hyp handleRequestVote_reply_true.
find_eapply_lem_hyp update_elections_data_request_vote_votedFor; eauto;
intuition; eauto; repeat find_rewrite.
* find_eapply_lem_hyp votedFor_moreUpToDate_invariant; eauto.
repeat conclude_using eauto.
break_exists_exists; intuition; eauto using update_elections_data_request_vote_votesWithLog_old.
* find_apply_lem_hyp requestVote_maxIndex_maxTerm_invariant.
eapply_prop_hyp requestVote_maxIndex_maxTerm pBody; eauto.
concludes. intuition; subst.
eexists; intuition; eauto.
- find_copy_apply_lem_hyp handleRequestVote_log_term_type; intuition; try congruence.
repeat find_rewrite.
find_apply_hyp_hyp. intuition.
+ assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
repeat find_rewrite.
eapply_prop_hyp pBody pBody; eauto.
+ remember (pDst p0) as h.
subst_max. simpl in *. subst_max.
find_copy_apply_lem_hyp handleRequestVote_reply_true. intuition.
- find_apply_hyp_hyp; intuition.
+ assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
repeat find_rewrite.
eapply_prop_hyp pBody pBody; eauto.
break_exists_exists. intuition.
eauto using update_elections_data_request_vote_votesWithLog_old.
+ remember (pSrc p0) as h.
subst. simpl in *. subst.
find_copy_apply_lem_hyp handleRequestVote_reply_true. intuition.
find_eapply_lem_hyp update_elections_data_request_vote_votedFor; eauto.
intuition; repeat find_rewrite; eauto.
* find_copy_apply_lem_hyp votedFor_moreUpToDate_invariant.
eapply_prop_hyp votedFor_moreUpToDate RaftState.votedFor; eauto.
concludes.
break_exists_exists; intuition; eauto using update_elections_data_request_vote_votesWithLog_old.
* find_apply_lem_hyp requestVote_maxIndex_maxTerm_invariant.
eapply_prop_hyp requestVote_maxIndex_maxTerm pBody; eauto.
concludes. intuition; subst.
eexists; intuition; eauto.
- find_apply_hyp_hyp. intuition.
+ assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
repeat find_rewrite.
eapply_prop_hyp pBody pBody; eauto.
+ subst. simpl in *. subst. simpl in *.
find_copy_apply_lem_hyp handleRequestVote_reply_true. intuition.
Qed.
Proof using.
red. unfold requestVoteReply_moreUpToDate. intros. simpl in *.
subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- erewrite handleRequestVoteReply_log; eauto.
find_copy_eapply_lem_hyp handleRequestVoteReply_log_term_type; eauto.
intuition.
repeat find_rewrite.
rewrite update_elections_data_request_vote_reply_votesWithLog.
eauto.
- erewrite handleRequestVoteReply_log; eauto.
find_copy_eapply_lem_hyp handleRequestVoteReply_log_term_type; eauto.
intuition.
repeat find_rewrite. eauto.
- rewrite update_elections_data_request_vote_reply_votesWithLog.
eauto.
Qed.

Lemma requestVoteReply_moreUpToDate_timeout :
refined_raft_net_invariant_timeout requestVoteReply_moreUpToDate.