Section MatchIndexAllEntries.
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 {naetli : no_append_entries_to_leader_interface}.
Context {naetsi : no_append_entries_to_self_interface}.
Context {taifoli : terms_and_indices_from_one_log_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Context {laei : log_all_entries_interface}.
Context {aelli : append_entries_leaderLogs_interface}.
Context {lsi : leader_sublog_interface}.
Context {lhllsi : leaders_have_leaderLogs_strong_interface}.
Context {ollpti : one_leaderLog_per_term_interface}.
Context {mili : match_index_leader_interface}.
Context {matchisi : match_index_sanity_interface}.
Context {aersi : append_entries_reply_sublog_interface}.
Context {cei : candidate_entries_interface}.
Context {vci : votes_correct_interface}.
Context {cci : cronies_correct_interface}.
Definition match_index_all_entries_nw (net : network) : Prop :=
forall p t es e,
In p (nwPackets net) ->
pBody p = AppendEntriesReply t es true ->
currentTerm (snd (nwState net (pDst p))) = t ->
In e (log (snd (nwState net (pDst p)))) ->
eTerm e = t ->
eIndex e <= maxIndex es ->
type (snd (nwState net (pDst p))) = Leader ->
In (t, e) (allEntries (fst (nwState net (pSrc p)))).
Definition match_index_all_entries_inv (net : network) : Prop :=
match_index_all_entries net /\ match_index_all_entries_nw net.
Proof using.
unfold refined_raft_net_invariant_init,
match_index_all_entries_inv,
match_index_all_entries_nw,
match_index_all_entries.
simpl. intros.
intuition.
Qed.
Proof using.
intros. unfold handleClientRequest in *.
break_match; find_inversion; subst; intuition.
simpl in *. eauto 10.
Qed.
Proof using mili rri.
intros.
pose proof lift_prop _ match_index_leader_invariant _ ltac:(eauto) leader.
find_rewrite_lem deghost_spec. concludes. auto.
Qed.
Proof using matchisi rri.
intros.
pose proof lift_prop _ match_index_sanity_invariant _ ltac:(eauto) leader h.
find_rewrite_lem deghost_spec. concludes. auto.
Qed.

Lemma lifted_append_entries_reply_sublog :
forall net p t es h e,
refined_raft_intermediate_reachable net ->
In p (nwPackets net) ->
pBody p = AppendEntriesReply t es true ->
currentTerm (snd (nwState net h)) = t ->
type (snd (nwState net h)) = Leader ->
In e es ->
In e (log (snd (nwState net h))).