Proof using.
unfold refined_raft_net_invariant_request_vote, match_index_all_entries_inv.
simpl. intros. split.
- unfold match_index_all_entries in *. simpl. intros. break_and.
repeat find_higher_order_rewrite.
update_destruct_simplify_hyp.
+ find_copy_apply_lem_hyp handleRequestVote_type.
intuition; try congruence.
find_copy_apply_lem_hyp handleRequestVote_matchIndex_preserved.
unfold matchIndex_preserved in *. intuition.
update_destruct_simplify_hyp.
* rewrite update_elections_data_requestVote_allEntries.
repeat find_reverse_rewrite.
match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
apply H with (leader := pDst p)
end; auto;
repeat find_rewrite; auto.
* repeat find_reverse_rewrite.
match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
apply H with (leader := pDst p)
end; auto;
repeat find_rewrite; auto.
+ update_destruct_simplify_hyp.
* rewrite update_elections_data_requestVote_allEntries.
repeat find_reverse_rewrite.
match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
eapply H; eauto
end.
* repeat find_reverse_rewrite.
match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
eapply H; eauto
end.
- break_and.
unfold match_index_all_entries_nw in *.
simpl. intros.
find_apply_hyp_hyp. break_or_hyp.
+ repeat find_higher_order_rewrite.
update_destruct_simplify_hyp.
* { find_copy_apply_lem_hyp handleRequestVote_type.
intuition; try congruence.
find_copy_apply_lem_hyp handleRequestVote_matchIndex_preserved.
unfold matchIndex_preserved in *. intuition.
update_destruct_simplify_hyp.
- rewrite update_elections_data_requestVote_allEntries.
repeat find_rewrite.
match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
apply H with (es := es); auto using in_middle_insert; try congruence
end.
- match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
apply H with (es := es); auto using in_middle_insert; try congruence
end.
}
* { update_destruct_simplify_hyp.
- rewrite update_elections_data_requestVote_allEntries.
repeat find_rewrite.
match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
apply H with (es := es); auto using in_middle_insert; try congruence
end.
- match goal with
| [ H : context [ In _ (allEntries _) ] |- _ ] =>
apply H with (es := es); auto using in_middle_insert; try congruence
end.
}
+ simpl in *.
find_apply_lem_hyp handleRequestVote_sends_RVR.
break_exists.
congruence.
Qed.

(* Specifications: *)
Lemma handleRequestVoteReply_spec :
forall h st h' t r st',
handleRequestVoteReply h st h' t r = st' ->
type st' = Follower \/
st' = st \/
(log st' = log st /\
currentTerm st' = currentTerm st /\
matchIndex st' = assoc_set name_eq_dec nil h (maxIndex (log st))).