Definition log_leaderLogs_prefix_within_term net :=
    forall h t ll leader,
      In (t, ll) (leaderLogs (fst (nwState net leader))) ->
      prefix_within_term (log (snd (nwState net h))) ll.Definition allEntries_log_prefix_within_term net :=
    forall h h',
      prefix_within_term (map snd (allEntries (fst (nwState net h)))) (log (snd (nwState net h'))).Definition allEntries_append_entries_prefix_within_term_nw net :=
    forall p t n pli plt es ci h e e',
      In p (nwPackets net) ->
      pBody p = AppendEntries t n pli plt es ci ->
      eTerm e = eTerm e' ->
      eIndex e <= eIndex e' ->
      In e (map snd (allEntries (fst (nwState net h)))) ->
      In e' es ->
      (In e es \/ (eIndex e = pli /\ eTerm e = plt) \/ (eIndex e < pli /\ eTerm e <= plt)).Definition append_entries_leaderLogs_prefix_within_term net :=
    forall p t n pli plt es ci h t' ll,
      In p (nwPackets net) ->
      pBody p = AppendEntries t n pli plt es ci ->
      In (t', ll) (leaderLogs (fst (nwState net h))) ->
      prefix_within_term es ll.Definition append_entries_log_prefix_within_term net :=
    forall p t n pli plt es ci h,
      In p (nwPackets net) ->
      pBody p = AppendEntries t n pli plt es ci ->
      prefix_within_term es (log (snd (nwState net h))).Definition prefix_within_term_inductive net :=
    allEntries_leaderLogs_prefix_within_term net /\
    log_leaderLogs_prefix_within_term net /\
    allEntries_log_prefix_within_term net /\
    allEntries_append_entries_prefix_within_term_nw net /\
    append_entries_leaderLogs_prefix_within_term net /\
    append_entries_log_prefix_within_term net.

Lemma doLeader_spec : forall st h os st' ms m t n pli plt es ci, doLeader st h = (os, st', ms) -> In m ms -> snd m = AppendEntries t n pli plt es ci -> t = currentTerm st /\ log st' = log st /\ type st = Leader /\ ((pli = 0 /\ plt = 0 /\ es = findGtIndex (log st) 0) \/ ((exists e, findAtIndex (log st) pli = Some e /\ eTerm e = plt) /\ es = findGtIndex (log st) pli) \/ exists h', pred (getNextIndex st h') <> 0 /\ findAtIndex (log st) (pred (getNextIndex st h')) = None).