Section LogAllEntries.
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 {tsi : term_sanity_interface}.
Ltac rewrite_goal :=
match goal with
| H: _ = _ |- _ => rewrite H
end.
Definition no_entries_past_current_term_host_lifted net :=
forall (h : name) e,
In e (log (snd (nwState net h))) ->
eTerm e <= currentTerm (snd (nwState net h)).
Proof using tsi rri.
unfold no_entries_past_current_term_host_lifted.
pose proof deghost_spec.
do 4 intro.
repeat find_reverse_higher_order_rewrite.
eapply lift_prop; eauto.
intros.
find_apply_lem_hyp no_entries_past_current_term_invariant; eauto.
Qed.
Proof using.
intros.
unfold handleAppendEntries in *.
repeat break_match; simpl in *; do_bool; repeat find_inversion; auto; try lia;
simpl in *;
unfold advanceCurrentTerm in *; repeat break_match; do_bool; auto.
Qed.
Proof using tsi rri.
red. unfold log_all_entries. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|copy_eapply_prop_hyp In In; repeat find_rewrite; auto].
find_copy_apply_lem_hyp handleAppendEntries_currentTerm_monotonic.
find_eapply_lem_hyp update_elections_data_appendEntries_log_allEntries;
intuition; eauto; repeat find_rewrite; repeat rewrite_goal; eauto.
- copy_eapply_prop_hyp In In; repeat find_rewrite; auto.
find_apply_lem_hyp no_entries_past_current_term_host_lifted_invariant; auto.
repeat find_rewrite. eauto using le_antisym.
- subst.
apply in_app_iff. right.
find_apply_hyp_hyp.
find_apply_lem_hyp no_entries_past_current_term_host_lifted_invariant; auto.
eauto using le_antisym.
- subst.
apply in_app_iff.
left.
apply in_map_iff. eauto.
- do_in_app. intuition.
+ subst.
apply in_app_iff.
left.
apply in_map_iff. eauto.
+ subst.
apply in_app_iff. right.
find_apply_lem_hyp removeAfterIndex_in.
find_apply_hyp_hyp.
find_apply_lem_hyp no_entries_past_current_term_host_lifted_invariant; auto.
eauto using le_antisym.
Qed.
Proof using tsi rri.
red. unfold log_all_entries. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|copy_eapply_prop_hyp In In; repeat find_rewrite; auto].
find_copy_apply_lem_hyp handleAppendEntriesReply_log. find_rewrite.
find_copy_apply_lem_hyp handleAppendEntriesReply_type_term.
intuition; repeat find_rewrite; copy_eapply_prop_hyp In In; repeat find_rewrite; auto.
find_apply_lem_hyp no_entries_past_current_term_host_lifted_invariant; auto.
repeat find_rewrite. eauto using le_antisym.
Qed.
Proof using tsi rri.
red. unfold log_all_entries. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|copy_eapply_prop_hyp In In; repeat find_rewrite; auto].
find_copy_apply_lem_hyp handleRequestVote_log. find_rewrite.
find_copy_apply_lem_hyp handleRequestVote_type_term.
rewrite update_elections_data_requestVote_allEntries.
intuition; repeat find_rewrite; copy_eapply_prop_hyp In In; repeat find_rewrite; auto.
find_apply_lem_hyp no_entries_past_current_term_host_lifted_invariant; auto.
repeat find_rewrite. eauto using le_antisym.
Qed.
Proof using tsi rri.
red. unfold log_all_entries. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto;
[|copy_eapply_prop_hyp In In; repeat find_rewrite; auto].
find_erewrite_lem handleRequestVoteReply_log.
rewrite update_elections_data_requestVoteReply_allEntries.
match goal with
| |- context [handleRequestVoteReply ?h ?st ?h' ?t ?v] =>
pose proof handleRequestVoteReply_type h st h' t v
(handleRequestVoteReply h st h' t v)
end.
intuition; repeat find_rewrite;
copy_eapply_prop_hyp In In; repeat find_rewrite; auto.
find_apply_lem_hyp no_entries_past_current_term_host_lifted_invariant; auto.
repeat find_rewrite.
unfold raft_data in *. simpl in *.
unfold raft_data in *. simpl in *.
lia.
Qed.

Lemma log_all_entries_do_leader :
refined_raft_net_invariant_do_leader log_all_entries.