Section LeaderLogsTermSanity.
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 {ctgli : candidate_term_gt_log_interface}.
Proof using ctgli rri.
intros. eapply lift_prop; eauto using candidate_term_gt_log_invariant.
Qed.
Ltac term_sanity_start :=
red; unfold leaderLogs_term_sanity; simpl; intros.
Ltac term_sanity_start_update :=
term_sanity_start;
repeat find_higher_order_rewrite; update_destruct; rewrite_update; [|eauto].
Proof using.
unfold leaderLogs_term_sanity. intros. find_higher_order_rewrite.
update_destruct; subst; rewrite_update; simpl in *; [find_rewrite|]; eauto.
Qed.
Ltac term_sanity_unchanged' lem :=
red; intros; eapply leaderLogs_term_sanity_unchanged; subst;
pose lem; eauto.
Tactic Notation "term_sanity_unchanged" constr(lem) := term_sanity_unchanged' lem.
Tactic Notation "term_sanity_unchanged" := term_sanity_unchanged' eq_refl (* bogus *).
Proof using ctgli rri.
term_sanity_start_update.
find_copy_apply_lem_hyp handleRequestVoteReply_type.
find_copy_apply_lem_hyp handleRequestVoteReply_log.
find_eapply_lem_hyp leaderLogs_update_elections_data_RVR; auto.
unfold ghost_data, raft_data in *. simpl in *. subst.
intuition; eauto; repeat find_rewrite; try discriminate.
find_apply_lem_hyp candidate_term_gt_log_lifted.
unfold candidate_term_gt_log in *. simpl in *; repeat break_match; simpl in *.
unfold gt in *. subst. repeat find_rewrite. eapply H3; auto.
Qed.
Ltac term_sanity_break_update :=
term_sanity_start_update;
match goal with
h : _ |- _ => eapply h
end; [| eauto];
match goal with
h : _ |- _ => solve [rewrite h; auto]
end.
Proof using ctgli rri.
intros.
apply refined_raft_net_invariant; auto.
- term_sanity_start; contradiction.
- term_sanity_unchanged update_elections_data_client_request_leaderLogs.
- term_sanity_unchanged update_elections_data_timeout_leaderLogs.
- term_sanity_unchanged update_elections_data_appendEntries_leaderLogs.
- term_sanity_unchanged.
- term_sanity_unchanged leaderLogs_update_elections_data_requestVote.
- apply leaderLogs_term_sanity_request_vote_reply.
- term_sanity_break_update.
- term_sanity_break_update.
- term_sanity_start; find_reverse_higher_order_rewrite; eauto.
- term_sanity_break_update.
Qed.
Ltac currentTerm_sanity_start :=
red; unfold leaderLogs_currentTerm_sanity; simpl; intros.
Ltac currentTerm_sanity_start_update :=
currentTerm_sanity_start;
repeat find_higher_order_rewrite; update_destruct; rewrite_update; [|eauto].
Proof using.
unfold leaderLogs_currentTerm_sanity. intros. find_higher_order_rewrite.
update_destruct; subst; rewrite_update.
- simpl in *. find_rewrite. find_apply_hyp_hyp. lia.
- eauto.
Qed.
Ltac currentTerm_sanity_unchanged :=
red; intros; eapply leaderLogs_currentTerm_sanity_unchanged; subst; eauto.
Ltac currentTerm_sanity_break_update :=
currentTerm_sanity_start_update;
match goal with
h : _ |- _ => eapply h
end; [| eauto];
match goal with
h : _ |- _ => solve [rewrite h; auto]
end.
Proof using.
currentTerm_sanity_start. contradiction.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- apply update_elections_data_client_request_leaderLogs.
- find_apply_lem_hyp handleClientRequest_type. intuition.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- apply update_elections_data_timeout_leaderLogs.
- find_apply_lem_hyp handleTimeout_type_strong. intuition.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- apply update_elections_data_appendEntries_leaderLogs.
- find_apply_lem_hyp handleAppendEntries_type_term. intuition.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- find_apply_lem_hyp handleAppendEntriesReply_type_term. intuition.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- apply leaderLogs_update_elections_data_requestVote.
- find_apply_lem_hyp handleRequestVote_type_term. intuition.
Qed.
Proof using.
currentTerm_sanity_start_update. simpl in *.
find_eapply_lem_hyp leaderLogs_update_elections_data_RVR; [|auto].
find_copy_apply_lem_hyp handleRequestVoteReply_type.
intuition.
- find_apply_hyp_hyp. repeat find_rewrite. auto.
- find_apply_hyp_hyp. lia.
- find_apply_hyp_hyp. repeat find_rewrite. auto.
- subst. auto.
- subst. auto.
- subst. auto.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- find_rewrite. auto.
- find_rewrite. simpl. find_apply_lem_hyp doLeader_type. intuition.
Qed.
Proof using.
currentTerm_sanity_unchanged.
- find_rewrite. auto.
- find_rewrite. simpl. find_apply_lem_hyp doGenericServer_type. intuition.
Qed.
Proof using.
currentTerm_sanity_start. find_reverse_higher_order_rewrite. eauto.
Qed.
Proof using.
currentTerm_sanity_start_update. specialize (H0 h). repeat find_rewrite.
find_apply_hyp_hyp. subst. unfold reboot. auto.
Qed.
Proof using rri.
intros.
apply refined_raft_net_invariant; auto.
- apply leaderLogs_currentTerm_sanity_init.
- apply leaderLogs_currentTerm_sanity_client_request.
- apply leaderLogs_currentTerm_sanity_timeout.
- apply leaderLogs_currentTerm_sanity_append_entries.
- apply leaderLogs_currentTerm_sanity_append_entries_reply.
- apply leaderLogs_currentTerm_sanity_request_vote.
- apply leaderLogs_currentTerm_sanity_request_vote_reply.
- apply leaderLogs_currentTerm_sanity_do_leader.
- apply leaderLogs_currentTerm_sanity_do_generic_server.
- apply leaderLogs_currentTerm_sanity_state_same_packet_subset.
- apply leaderLogs_currentTerm_sanity_reboot.
Qed.
Ltac ctsc_start :=
red; unfold leaderLogs_currentTerm_sanity_candidate; simpl; intros.
Ltac ctsc_start_update :=
ctsc_start;
repeat find_higher_order_rewrite; update_destruct; rewrite_update; [|eauto].
Proof using.
unfold leaderLogs_currentTerm_sanity_candidate. intros. find_higher_order_rewrite.
update_destruct; subst; rewrite_update; [|eauto].
simpl in *. repeat find_rewrite. intuition; find_apply_hyp_hyp; lia.
Qed.
Ltac ctsc_unchanged :=
red; intros; eapply leaderLogs_currentTerm_sanity_candidate_unchanged; subst; eauto.
Proof using.
ctsc_start. contradiction.
Qed.

Lemma leaderLogs_currentTerm_sanity_candidate_client_request :
refined_raft_net_invariant_client_request leaderLogs_currentTerm_sanity_candidate.