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.

Lemma handleAppendEntries_success_allEntries : forall h st t n pli plt es ci st' t', handleAppendEntries h st t n pli plt es ci = (st', AppendEntriesReply t' es true) -> es <> nil -> (forall e e' e'', In e es -> In e' (log st) -> eIndex e = eIndex e' -> eTerm e = eTerm e' -> In e'' es -> eIndex e'' <= eIndex e -> In e'' (log st)) -> sorted (log st) -> exists e, In e (log st') /\ In e es /\ eIndex e = maxIndex es /\ eTerm e = maxTerm es.