Section CroniesTermProof.
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}.
Proof using.
intros. unfold handleClientRequest in *.
break_match; find_inversion; intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_client_request, cronies_term,
update_elections_data_client_request in *.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *. find_apply_lem_hyp handleClientRequest_spec.
repeat find_rewrite.
repeat break_match; simpl in *; eauto.
Qed.
(*   H : handleTimeout h' (snd (nwState net h')) = (out, d, l) In h0 (cronies (update_elections_data_timeout h' (nwState net h')) t) *)
Proof using.
intros.
unfold handleTimeout, tryToBecomeLeader, update_elections_data_timeout in *.
repeat (break_match; repeat find_inversion; simpl in *; auto);
intuition;
unfold handleTimeout, tryToBecomeLeader in *;
repeat (break_match; repeat find_inversion; simpl in *; auto); congruence.
Qed.
Proof using.
unfold refined_raft_net_invariant_timeout, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
find_eapply_lem_hyp handleTimeout_spec; eauto. intuition.
eapply le_trans; [|eauto]; eauto.
Qed.
Proof using.
intros. unfold doLeader in *.
repeat break_match; repeat find_inversion; auto.
Qed.
Proof using.
unfold refined_raft_net_invariant_do_leader, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
find_apply_lem_hyp doLeader_spec.
repeat find_rewrite.
match goal with
| H : nwState ?net ?h = (?g, ?st) |- _ =>
replace g with (fst (nwState net h)) in *; [|rewrite H; auto];
replace st with (snd (nwState net h)) in *; [|rewrite H; auto]
end; eauto.
Qed.
Proof using.
intros. unfold doGenericServer in *.
repeat break_match; repeat find_inversion;
use_applyEntries_spec; subst; simpl in *;
auto.
Qed.
Proof using.
unfold refined_raft_net_invariant_do_generic_server, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
find_apply_lem_hyp doGenericServer_spec.
repeat find_rewrite.
match goal with
| H : nwState ?net ?h = (?g, ?st) |- _ =>
replace g with (fst (nwState net h)) in *; [|rewrite H; auto];
replace st with (snd (nwState net h)) in *; [|rewrite H; auto]
end; eauto.
Qed.
Proof using.
intros.
unfold handleAppendEntries, advanceCurrentTerm in *.
repeat break_match; find_inversion; simpl in *;
do_bool; auto.
Qed.
Proof using.
intros.
unfold update_elections_data_appendEntries in *.
repeat break_match; repeat find_rewrite; subst; simpl in *; auto.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
find_apply_lem_hyp handleAppendEntries_spec.
find_eapply_lem_hyp update_elections_data_appendEntries_spec; eauto.
eapply le_trans; [|eauto]; eauto.
Qed.
Proof using.
intros.
unfold handleAppendEntriesReply, advanceCurrentTerm in *.
repeat break_match; try find_inversion; subst; simpl in *;
do_bool; intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_append_entries_reply, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
find_apply_lem_hyp handleAppendEntriesReply_spec.
eapply le_trans; [|eauto]; eauto.
Qed.
Proof using.
intros.
unfold handleRequestVote, advanceCurrentTerm in *.
repeat break_match; try find_inversion; subst; simpl in *;
do_bool; intuition.
Qed.
Proof using.
intros.
unfold update_elections_data_requestVote in *.
repeat break_match; repeat find_rewrite; subst; simpl in *; auto.
Qed.
Proof using.
unfold refined_raft_net_invariant_request_vote, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
find_apply_lem_hyp handleRequestVote_spec.
find_eapply_lem_hyp update_elections_data_requestVote_spec; eauto.
eapply le_trans; [|eauto]; eauto.
Qed.
Proof using.
intros.
unfold handleRequestVoteReply, advanceCurrentTerm in *.
repeat break_match; try find_inversion; subst; simpl in *; intuition;
do_bool; intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_request_vote_reply, cronies_term.
intros. subst. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
match goal with
| H : forall _, st' _ = _ |- _ => clear H
end.
unfold update_elections_data_requestVoteReply in *.
match goal with
| |- context [handleRequestVoteReply ?h ?st ?h' ?t ?v] =>
remember (handleRequestVoteReply h st h' t v) as new_state
end.
find_copy_apply_lem_hyp handleRequestVoteReply_spec.
intuition.
- unfold update_elections_data_requestVoteReply in *.
break_match; simpl in *; repeat find_rewrite; eauto;
break_match; eauto;
subst; repeat find_reverse_rewrite; intuition.
- unfold update_elections_data_requestVoteReply in *.
break_match; simpl in *;
try solve [subst; unfold raft_data in *; congruence].
eapply le_trans; [|eauto]; eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_init, cronies_term.
intros. simpl in *. intuition.
Qed.
Proof using.
unfold refined_raft_net_invariant_reboot, cronies_term, reboot.
intros. simpl in *. repeat find_higher_order_rewrite.
update_destruct; subst; rewrite_update; eauto.
simpl in *.
match goal with
| H : nwState ?net ?h = (?g, ?st) |- _ =>
replace g with (fst (nwState net h)) in *; [|rewrite H; auto];
replace st with (snd (nwState net h)) in *; [|rewrite H; auto]
end; eauto.
Qed.
Proof using.
unfold refined_raft_net_invariant_state_same_packet_subset, cronies_term.
intros.
repeat find_reverse_higher_order_rewrite. eauto.
Qed.

Theorem cronies_term_invariant :
forall net,
refined_raft_intermediate_reachable net ->
cronies_term net.