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.

Lemma handleRequestVote_spec :
forall h st t h' pli plt st' m,
handleRequestVote h st t h' pli plt = (st', m) ->
currentTerm st <= currentTerm st'.