Section CommonTheorems.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {cci : cronies_correct_interface}.
Context {vci : votes_correct_interface}.
Proof using.
intros.
unfold candidateEntries in *. break_exists. break_and.
repeat match goal with
| [ H : _ |- _ ] => rewrite deghost_spec in H
end.
intro.
assert (x = h).
{
match goal with
| H : wonElection _ = _ |- _ =>
eapply wonElection_one_in_common in H; [|clear H; eauto]
end.
break_exists. break_and.
eapply_prop one_vote_per_term;
try solve [eapply_prop cronies_votes; eauto].
eapply_prop cronies_votes.
repeat find_reverse_rewrite.
eapply_prop votes_received_cronies; auto.
}
subst.
concludes.
contradiction.
Qed.
Proof using.
unfold votes_correct, cronies_correct.
intros. break_and.
match goal with
| [ H : context [ votes_nw ], H' : context [ pBody ] |- _ ] =>
eapply H in H'
end.
unfold candidateEntries in *. break_exists. break_and.
match goal with
| H : wonElection _ = _ |- _ =>
eapply wonElection_one_in_common in H; [|clear H; eauto]
end.
break_exists.
break_and.
simpl in *.
intuition.
- subst.
apply_prop_hyp cronies_votes In.
assert (x = pDst p) by (eapply_prop one_vote_per_term; eauto).
subst. concludes. contradiction.
- apply_prop_hyp votes_received_cronies In. concludes.
apply_prop_hyp cronies_votes In.
apply_prop_hyp cronies_votes In.
unfold raft_data in *. unfold raft_refined_base_params, raft_refined_multi_params in *.
simpl in *.
repeat find_reverse_rewrite.
assert (x = pDst p) by (eapply_prop one_vote_per_term; eauto).
subst.
repeat concludes. contradiction.
Qed.
Proof using.
unfold candidateEntries.
intuition.
break_exists_exists.
intuition;
repeat find_higher_order_rewrite; auto.
Qed.
Proof using.
unfold candidateEntries.
intuition. break_exists. break_and.
eexists.
repeat find_higher_order_rewrite.
eauto.
Qed.
Proof using.
intros.
unfold cronies_correct in *; intuition.
eapply wonElection_no_dup_in;
eauto using NoDup_dedup, in_dedup_was_in, dedup_In.
Qed.

Lemma handleRequestVoteReply_preserves_candidate_entries :
forall net h h' t r st' e,
st' = handleRequestVoteReply h (snd (nwState net h)) h' t r ->
refined_raft_intermediate_reachable net ->
candidateEntries e (nwState net) ->
candidateEntries e (update name_eq_dec (nwState net) h
(update_elections_data_requestVoteReply h h' t r (nwState net h),
st')).