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 handleAppendEntriesReply_spec : forall n st src t es b st' l, handleAppendEntriesReply n st src t es b = (st', l) -> (type st' = type st /\ matchIndex st' = matchIndex st /\ currentTerm st' = currentTerm st) \/ (currentTerm st' = t /\ type st' = Follower) \/ (b = true /\ t = currentTerm st' /\ type st' = type st /\ matchIndex st' = assoc_set name_eq_dec (matchIndex st) src (PeanoNat.Nat.max (assoc_default name_eq_dec (matchIndex st) src 0) (maxIndex es)) /\ currentTerm st' = currentTerm st).