Section VotedForTermSanity.
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 {rvtsi : requestVote_term_sanity_interface}.
Proof using.
red. unfold votedFor_term_sanity in *. simpl in *.
intros. subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_copy_eapply_lem_hyp handleAppendEntries_term_votedFor; eauto.
intuition; repeat find_rewrite; eauto.
- find_copy_apply_lem_hyp handleAppendEntries_currentTerm_leaderId.
intuition; eauto;
eapply_prop_hyp RaftState.votedFor RaftState.votedFor; eauto;
try rewrite <- plus_n_O in *; lia.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. simpl in *.
intros. subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_copy_eapply_lem_hyp handleAppendEntriesReply_term_votedFor; eauto.
intuition; repeat find_rewrite; eauto.
- find_copy_apply_lem_hyp handleAppendEntriesReply_type_term;
intuition; eauto;
eapply_prop_hyp RaftState.votedFor RaftState.votedFor; eauto;
try rewrite <- plus_n_O in *; lia.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. simpl in *.
intros. subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_copy_eapply_lem_hyp handleRequestVoteReply_term_votedFor; eauto.
intuition; repeat find_rewrite; eauto.
- eauto using handleRequestVoteReply_currentTerm.
Qed.
Proof using rvtsi.
red. unfold votedFor_term_sanity in *. simpl in *.
intros. subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_copy_eapply_lem_hyp update_elections_data_request_vote_votedFor; eauto.
intuition; repeat find_rewrite; eauto.
eapply requestVote_term_sanity_invariant; eauto.
- find_copy_apply_lem_hyp handleRequestVote_currentTerm_leaderId.
intuition; repeat find_rewrite; eauto;
eapply_prop_hyp RaftState.votedFor RaftState.votedFor; eauto;
try rewrite <- plus_n_O in *; lia.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. simpl in *.
intros. subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
- find_copy_eapply_lem_hyp update_elections_data_timeout_votedFor; eauto.
intuition; repeat find_rewrite; eauto.
congruence.
- find_copy_apply_lem_hyp handleTimeout_type_strong.
intuition; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. simpl in *.
intros. subst. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
find_copy_eapply_lem_hyp handleClientRequest_term_votedFor;
intuition; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. intros. simpl in *.
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_copy_eapply_lem_hyp doLeader_term_votedFor;
intuition; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. intros. simpl in *.
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_copy_eapply_lem_hyp doGenericServer_log_type_term_votesReceived;
intuition; repeat find_rewrite; eauto.
Qed.
Proof using.
red. unfold votedFor_term_sanity in *. intros. simpl in *.
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.
Qed.

Lemma votedFor_term_sanity_state_same_packet_subset :
refined_raft_net_invariant_state_same_packet_subset votedFor_term_sanity.