Section CroniesCorrectProof.
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 {vci : votes_correct_interface}.
Context {cvfsi : candidates_vote_for_selves_interface}.
Proof using cvfsi rri.
intros.
eapply lift_prop; [exact candidates_vote_for_selves_invariant|eauto].
Qed.
Proof using.
intros.
unfold handleClientRequest in *; repeat break_match;
repeat find_inversion; subst; simpl in *; find_apply_hyp_hyp; intuition.
Qed.
Proof using.
intros.
unfold handleTimeout, tryToBecomeLeader in *; repeat break_match;
repeat find_inversion; subst; simpl in *; find_apply_hyp_hyp;
in_crush; congruence.
Qed.
Proof using.
intros.
unfold handleAppendEntries, advanceCurrentTerm in *; repeat break_match;
repeat find_inversion; subst; simpl in *; find_apply_hyp_hyp;
in_crush; congruence.
Qed.
Proof using.
intros.
unfold handleAppendEntriesReply, advanceCurrentTerm in *; repeat break_match;
repeat find_inversion; subst; simpl in *; find_apply_hyp_hyp;
in_crush; congruence.
Qed.
Proof using.
unfold refined_raft_net_invariant_client_request. intros.
unfold cronies_correct in *; intuition.
- unfold votes_received_cronies, handleClientRequest in *. intros.
simpl in *. repeat find_higher_order_rewrite.
unfold update_elections_data_client_request in *.
repeat break_match; find_inversion; subst; simpl in *; eauto; try congruence.
- unfold cronies_votes in *. intros.
simpl in *. repeat find_higher_order_rewrite.
unfold update_elections_data_client_request in *.
repeat break_match; subst; simpl in *; eauto.
- unfold votes_nw in *. intros. simpl in *.
assert (In p (nwPackets net)) by eauto using handleClientRequest_rvr.
repeat find_apply_hyp_hyp.
repeat find_higher_order_rewrite.
unfold update_elections_data_client_request in *.
repeat break_match; subst; repeat find_rewrite; simpl in *; intuition.
- unfold votes_received_leaders in *. intros. simpl in *. repeat find_higher_order_rewrite.
unfold handleClientRequest in *.
unfold update_elections_data_client_request in *.
repeat break_match; find_inversion; subst; simpl in *; eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_timeout. intros.
unfold cronies_correct, update_elections_data_timeout in *; intuition.
- unfold votes_received_cronies, handleTimeout, tryToBecomeLeader in *.
intros. simpl in *.
repeat break_match; repeat find_inversion; subst; simpl in *; eauto;
repeat find_higher_order_rewrite; repeat (break_if; simpl in *); auto; congruence.
- unfold cronies_votes, handleTimeout, tryToBecomeLeader in *. intros.
simpl in *.
repeat break_match; repeat find_inversion; subst; simpl in *; eauto;
repeat find_higher_order_rewrite; repeat (break_if; simpl in *); auto;
repeat find_inversion; subst; intuition;
congruence.
- unfold votes_nw in *. intros. simpl in *.
assert (In p (nwPackets net)) by eauto using handleTimeout_rvr.
repeat find_apply_hyp_hyp.
repeat find_higher_order_rewrite.
repeat break_match; subst; repeat find_rewrite; simpl in *; intuition.
- unfold votes_received_leaders in *. intros. simpl in *. repeat find_higher_order_rewrite.
unfold handleTimeout, tryToBecomeLeader in *. simpl in *.
repeat (break_match; subst; simpl in *; repeat find_inversion; try discriminate);
intuition eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries. intros.
unfold cronies_correct in *; intuition.
- unfold votes_received_cronies, handleAppendEntries in *.
intros. simpl in *.
repeat find_higher_order_rewrite.
unfold update_elections_data_appendEntries.
repeat break_match; repeat find_inversion; subst; simpl in *; eauto;
repeat find_higher_order_rewrite; repeat (break_if; simpl in *); intuition; try congruence.
- unfold cronies_votes in *. intros.
simpl in *. repeat find_higher_order_rewrite.
unfold update_elections_data_appendEntries in *.
repeat break_match; repeat find_inversion; subst; simpl in *; eauto.
- unfold votes_nw in *. intros. simpl in *.
assert (In p0 (xs ++ ys)) by eauto using handleAppendEntries_rvr.
assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
repeat find_apply_hyp_hyp.
repeat find_higher_order_rewrite.
unfold update_elections_data_appendEntries in *.
repeat break_match; subst; repeat find_rewrite; simpl in *; intuition.
- unfold votes_received_leaders in *. intros. simpl in *.
repeat find_higher_order_rewrite. repeat break_if; eauto.
subst. simpl in *. unfold handleAppendEntries in *.
repeat break_match; find_inversion; subst; simpl in *;
try discriminate; eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries_reply. intros.
unfold cronies_correct in *; intuition.
- unfold votes_received_cronies, handleAppendEntriesReply, advanceCurrentTerm in *.
intros. simpl in *.
repeat break_match; repeat find_inversion; subst; simpl in *; eauto;
repeat find_higher_order_rewrite; repeat (break_if; simpl in *); intuition; try congruence.
- unfold cronies_votes in *. intros.
simpl in *. repeat find_higher_order_rewrite.
repeat break_match; subst; simpl in *; eauto.
- unfold votes_nw in *. intros. simpl in *.
assert (In p0 (xs ++ ys)) by eauto using handleAppendEntriesReply_rvr.
assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
repeat find_apply_hyp_hyp.
repeat find_higher_order_rewrite.
repeat break_match; subst; repeat find_rewrite; simpl in *; intuition.
- unfold votes_received_leaders in *. intros. simpl in *.
repeat find_higher_order_rewrite. repeat break_if; eauto.
subst. simpl in *. unfold handleAppendEntriesReply, advanceCurrentTerm in *.
repeat break_match; find_inversion; subst; simpl in *;
try discriminate; eauto.
Qed.
Proof using.
intros. unfold handleRequestVote, advanceCurrentTerm in *.
repeat (break_match; try find_inversion; try discriminate);
simpl in *; subst; intuition.
Qed.
Proof using.
intros.
unfold update_elections_data_requestVote in *.
repeat break_match; simpl in *; auto.
Qed.
Proof using.
intros. unfold handleRequestVote, advanceCurrentTerm in *.
repeat break_match; find_inversion; auto.
Qed.
Proof using.
intros. unfold handleRequestVote, advanceCurrentTerm in *.
repeat break_match; find_inversion; auto.
Qed.
Proof using.
intros.
unfold update_elections_data_requestVote.
repeat break_match; simpl in *; intuition.
Qed.
Proof using.
intros.
unfold update_elections_data_requestVote in *.
repeat break_match; simpl in *;
repeat (repeat find_inversion; repeat find_rewrite);
repeat (do_bool; break_and); try congruence; intuition.
Qed.
Proof using vci.
unfold refined_raft_net_invariant_request_vote. intros.
unfold cronies_correct in *; intuition.
- unfold votes_received_cronies in *.
intros. simpl in *. subst.
repeat find_higher_order_rewrite. break_if; simpl in *; subst; eauto.
rewrite update_elections_data_requestVote_cronies.
find_copy_apply_lem_hyp handleRequestVote_votesReceived. repeat find_rewrite.
find_apply_lem_hyp handleRequestVote_currentTerm_same_or_follower.
match goal with
| H : currentTerm _ = currentTerm _ /\ _ \/ _ |- _ =>
destruct H
end; try break_and; repeat find_rewrite; eauto. intuition; congruence.
- unfold cronies_votes in *. intros.
simpl in *.
repeat find_higher_order_rewrite.
repeat break_if; subst; simpl in *; eauto;
try rewrite update_elections_data_requestVote_cronies in *;
eauto using update_elections_data_requestVote_votes_preserved.
- unfold votes_nw in *. intros.
simpl in *.
subst. repeat find_higher_order_rewrite.
find_apply_hyp_hyp. intuition.
+ assert (In p0 (nwPackets net)) by (repeat find_rewrite; in_crush).
simpl.
break_if; simpl in *; eauto.
eapply update_elections_data_requestVote_votes_preserved.
repeat find_reverse_rewrite. eauto.
+ unfold raft_data in *. repeat find_rewrite. repeat find_inversion.
repeat (subst; simpl in *).
find_copy_apply_lem_hyp handleRequestVote_true_votedFor. intuition.
repeat find_rewrite. simpl in *.
break_if; simpl in *; try congruence.
subst.
find_apply_lem_hyp update_elections_data_requestVote_votedFor; intuition.
repeat find_rewrite.
apply update_elections_data_requestVote_votes_preserved.
eapply votes_correct_invariant; eauto.
- unfold votes_received_leaders in *. intros. simpl in *.
repeat find_higher_order_rewrite. repeat break_if; eauto.
subst. simpl in *.
find_copy_apply_lem_hyp handleRequestVote_votesReceived.
find_apply_lem_hyp handleRequestVote_currentTerm_same_or_follower.
intuition; repeat find_rewrite; try congruence; eauto.
Qed.
Proof using.
intros.
unfold handleRequestVoteReply, advanceCurrentTerm in *.
repeat break_match; subst; simpl in *; auto; congruence.
Qed.
Proof using.
intros.
unfold handleRequestVoteReply, advanceCurrentTerm in *.
repeat break_match; simpl in *; subst; simpl in *; do_bool; intuition.
Qed.
Proof using.
intros.
unfold handleRequestVoteReply in *.
repeat (break_match; subst; simpl in *; try discriminate; intuition).
Qed.
Proof using cvfsi vci rri.
unfold refined_raft_net_invariant_request_vote_reply. intros.
assert (candidates_vote_for_selves (deghost net)) by
eauto using candidates_vote_for_selves_l_invariant.
assert (votes_correct net) by eauto using votes_correct_invariant.
unfold cronies_correct in *; intuition.
- unfold votes_received_cronies,
update_elections_data_requestVoteReply in *.
intros. simpl in *.
repeat break_match; repeat find_inversion; subst; simpl in *; eauto;
repeat find_higher_order_rewrite; repeat (break_if; simpl in *); auto; try congruence;
unfold raft_data in *; repeat find_rewrite; intuition; congruence.
- unfold update_elections_data_requestVoteReply, cronies_votes in *. intros.
simpl in *. repeat find_higher_order_rewrite.
repeat (repeat break_match; simpl in *; subst; intuition eauto); try discriminate.
+ match goal with
| H : type ?x = _ |- _ =>
remember x as cst; symmetry in Heqcst
end;
find_copy_apply_lem_hyp handleRequestVoteReply_candidate; auto;
repeat find_rewrite;
unfold votes_correct, currentTerm_votedFor_votes_correct in *; intuition;
unfold candidates_vote_for_selves in *;
match goal with
| H : _ |- _ => apply H
end; intuition;
match goal with
| H : forall _, type _ = _ -> votedFor _ = _ |- _ = Some ?h =>
specialize (H h)
end;
match goal with
| [ H : _ |- _ ] => rewrite deghost_spec in H
end; intuition eauto.
+ match goal with
| H : type ?x = Leader |- _ =>
remember x as cst; symmetry in Heqcst
end.
find_copy_apply_lem_hyp handleRequestVoteReply_leader; auto.
intuition; [repeat find_rewrite; eauto|].
find_eapply_lem_hyp handleRequestVoteReply_votesReceived; eauto.
intuition.
* unfold votes_nw in *.
match goal with
| H : _ = true |- _ => rewrite H in *; clear H
end.
match goal with
| H : pBody _ = _, Hpbody : forall _ _, pBody _ = _ -> _ |- _ =>
apply Hpbody in H
end; [|solve [repeat find_rewrite; in_crush]].
repeat find_rewrite; eauto.
* repeat find_rewrite.
unfold votes_received_cronies in *.
eauto.
+ match goal with
| H : type ?x = _ |- _ =>
remember x as cst; symmetry in Heqcst
end.
find_copy_apply_lem_hyp handleRequestVoteReply_leader; auto.
intuition.
find_eapply_lem_hyp handleRequestVoteReply_votesReceived; eauto.
intuition.
* unfold votes_nw in *.
match goal with
| H : _ = true |- _ => rewrite H in *; clear H
end.
match goal with
| H : pBody _ = _, Hpbody : forall _ _, pBody _ = _ -> _ |- _ =>
apply Hpbody in H
end; [|solve [repeat find_rewrite; in_crush]].
repeat find_rewrite; eauto.
* repeat find_rewrite.
unfold votes_received_cronies in *.
eauto.
+ match goal with
| H : type ?x = _ |- _ =>
remember x as cst; symmetry in Heqcst
end.
find_copy_apply_lem_hyp handleRequestVoteReply_candidate; auto.
find_eapply_lem_hyp handleRequestVoteReply_votesReceived; eauto.
intuition; repeat find_rewrite; eauto.
+ match goal with
| H : type ?x = Leader |- _ =>
remember x as cst; symmetry in Heqcst
end.
find_copy_apply_lem_hyp handleRequestVoteReply_leader; auto.
intuition; [repeat find_rewrite; eauto|].
find_eapply_lem_hyp handleRequestVoteReply_votesReceived; eauto.
intuition.
* unfold votes_nw in *.
match goal with
| H : _ = true |- _ => rewrite H in *; clear H
end.
match goal with
| H : pBody _ = _, Hpbody : forall _ _, pBody _ = _ -> _ |- _ =>
apply Hpbody in H
end; [|solve [repeat find_rewrite; in_crush]].
repeat find_rewrite; eauto.
* repeat find_rewrite.
unfold votes_received_cronies in *.
eauto.
+ match goal with
| H : type ?x = Leader |- _ =>
remember x as cst; symmetry in Heqcst
end.
find_copy_apply_lem_hyp handleRequestVoteReply_leader; auto.
intuition.
find_eapply_lem_hyp handleRequestVoteReply_votesReceived; eauto.
intuition.
* unfold votes_nw in *.
match goal with
| H : _ = true |- _ => rewrite H in *; clear H
end.
match goal with
| H : pBody _ = _, Hpbody : forall _ _, pBody _ = _ -> _ |- _ =>
apply Hpbody in H
end; [|solve [repeat find_rewrite; in_crush]].
repeat find_rewrite; eauto.
* repeat find_rewrite.
unfold votes_received_cronies in *.
eauto.
- unfold votes_nw in *.
intros.
simpl in *. find_apply_hyp_hyp.
match goal with
| H : nwPackets ?net = _,
H' : In ?p _ |- _ =>
assert (In p (nwPackets net)) by (repeat find_rewrite; in_crush);
clear H H'
end.
find_apply_hyp_hyp.
match goal with
| H : In ?x ?y |- In ?x ?z =>
cut (z = y); [intros; repeat find_rewrite; auto|]
end.
repeat find_higher_order_rewrite.
subst.
unfold update_elections_data_requestVoteReply in *.
repeat break_match; subst; simpl in *; repeat find_rewrite; auto.
- unfold votes_received_leaders in *.
intros. simpl in *.
repeat find_higher_order_rewrite. break_if; [|eauto].
simpl in *.
find_apply_lem_hyp handleRequestVoteReply_leader; auto. intuition; subst.
eauto.
Qed.
Proof using.
intros.
unfold doLeader, advanceCommitIndex in *.
repeat break_match; find_inversion; intuition.
Qed.

Lemma do_leader_rvr :
forall st h os st' ms p t ps ps',
doLeader st h = (os, st', ms) ->
(forall p : packet,
In p ps' -> In p ps \/ In p (send_packets h ms)) ->
pBody p = RequestVoteReply t true ->
In p ps' ->
In p ps.