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.
Proof using cci.
unfold candidateEntries.
intros. break_exists. break_and.
exists x.
split;
rewrite update_fun_comm; simpl;
rewrite update_fun_comm; simpl;
update_destruct; subst; rewrite_update; auto;
try (unfold update_elections_data_requestVoteReply in *;
repeat break_match; simpl in *; auto;
break_if; simpl in *; repeat find_rewrite; auto);
match goal with
| |- context [handleRequestVoteReply ?h ?st ?h' ?t ?r] =>
remember (handleRequestVoteReply h st h' t r) as new_state
end; find_apply_lem_hyp handleRequestVoteReply_spec; intuition;
repeat find_rewrite; intuition.
- find_apply_lem_hyp cronies_correct_invariant.
unfold cronies_correct in *. intuition.
unfold votes_received_leaders in *.
match goal with
| H :  Leader = _ |- _ =>
symmetry in H
end. find_apply_hyp_hyp.
eapply wonElection_no_dup_in;
eauto using NoDup_dedup, in_dedup_was_in, dedup_In.
- destruct (serverType_eq_dec (type (snd (nwState net x))) Leader); intuition.
find_apply_lem_hyp cronies_correct_invariant; auto.
eapply wonElection_no_dup_in;
eauto using NoDup_dedup, in_dedup_was_in, dedup_In.
Qed.

Lemma doLeader_st :
forall st h os st' ms,
doLeader st h = (os, st', ms) ->
votesReceived st' = votesReceived st /\
currentTerm st' = currentTerm st /\
type st' = type st.