Section LogsLeaderLogs.
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 {llsi : leaderLogs_sorted_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Context {llci : leaderLogs_contiguous_interface}.
Context {lllmi : leaderLogs_entries_match_interface}.
Context {lhllsi : leaders_have_leaderLogs_strong_interface}.
Context {nisi : nextIndex_safety_interface}.
Context {si : sorted_interface}.
Context {lpholli : log_properties_hold_on_leader_logs_interface}.
Definition weak_sanity pli ll ll' :=
pli = 0 ->
(exists e, eIndex e = 0 /\ In e ll) \/
ll = ll'.
Definition logs_leaderLogs_nw_weak net :=
forall p t n pli plt es ci e,
In p (nwPackets net) ->
pBody p = AppendEntries t n pli plt es ci ->
In e es ->
exists leader ll es' ll',
In (eTerm e, ll) (leaderLogs (fst (nwState net leader))) /\
Prefix ll' ll /\
removeAfterIndex es (eIndex e) = es' ++ ll' /\
(forall e', In e' es' -> eTerm e' = eTerm e) /\
weak_sanity pli ll ll'.
Proof using.
intros. unfold logs_leaderLogs_nw, logs_leaderLogs_nw_weak, weak_sanity in *.
intros.
eapply_prop_hyp In In; eauto.
break_exists_exists; intuition; subst; try lia.
break_exists; intuition; eauto.
Qed.
Definition logs_leaderLogs_inductive net :=
logs_leaderLogs net /\
logs_leaderLogs_nw net.
Proof using si rri.
intros.
eapply lift_prop; eauto using logs_sorted_invariant.
Qed.
Proof using si rri.
intros.
find_apply_lem_hyp lift_sorted.
unfold logs_sorted, logs_sorted_host in *.
intuition.
unfold deghost in *. simpl in *. break_match; eauto.
Qed.
Proof using nisi rri.
intros.
eapply lift_prop; eauto using nextIndex_safety_invariant.
Qed.
Proof using si nisi rlmli rri.
intros.
find_copy_apply_lem_hyp entries_contiguous_invariant.
find_copy_apply_lem_hyp lift_nextIndex_safety.
assert (pred (getNextIndex (snd (nwState net h)) h') > 0) by lia.
unfold nextIndex_safety in *.
match goal with
| H : forall _ _, type _ = _ -> _ |- _ => specialize (H h h')
end.
intuition.
unfold entries_contiguous in *. specialize (H2 h).
unfold contiguous_range_exact_lo in *. intuition.
match goal with
| H : forall _, _ < _ <= _ -> _ |- _ =>
specialize (H (pred (getNextIndex (snd (nwState net h)) h')))
end.
unfold raft_refined_base_params in *.
repeat find_rewrite_lem deghost_spec. intuition.
break_exists_exists. intuition.
apply findAtIndex_intro; eauto using lift_logs_sorted, sorted_uniqueIndices.
Qed.
Proof using.
unfold update_elections_data_client_request in *.
intros. repeat break_match; repeat find_inversion; auto.
Qed.
Proof using.
unfold update_elections_data_timeout.
intros.
repeat break_match; simpl in *; auto.
Qed.
Proof using.
intros.
unfold update_elections_data_appendEntries.
repeat break_match; subst; simpl in *; auto.
Qed.
Proof using.
unfold update_elections_data_requestVote.
intros.
repeat break_match; auto.
Qed.
Proof using.
unfold update_elections_data_requestVoteReply.
intros.
repeat break_match; auto.
simpl in *. intuition.
Qed.
Ltac prove_in :=
match goal with
| [ _ : nwPackets ?net = _,
_ : In (?p : packet) _ |- _] =>
assert (In p (nwPackets net)) by (repeat find_rewrite; do_in_app; intuition)
| [ _ : nwPackets ?net = _,
_ : pBody ?p = _ |- _] =>
assert (In p (nwPackets net)) by (repeat find_rewrite; intuition)
end.

Lemma contiguous_log_property :
log_property (fun l => contiguous_range_exact_lo l 0).