Definition lifted_state_machine_safety_nw' net :=
    forall p t leaderId prevLogIndex prevLogTerm entries leaderCommit e t',
      In p (nwPackets net) ->
      snd (pBody p) = AppendEntries t leaderId prevLogIndex prevLogTerm
                              entries leaderCommit ->
      lifted_committed net e t' ->
      t >= t' ->
      (prevLogIndex > eIndex e \/
       (prevLogIndex = eIndex e /\ prevLogTerm = eTerm e) \/
       eIndex e > maxIndex entries \/
       In e entries).

(* Specifications: *)
Lemma lifted_state_machine_safety_nw'_invariant : forall (net : @network _ raft_msg_refined_multi_params), msg_refined_raft_intermediate_reachable net -> lifted_state_machine_safety_nw' net.
Lemma lifted_entries_sorted_nw : forall net p t n pli plt es ci, msg_refined_raft_intermediate_reachable net -> In p (nwPackets net) -> snd (pBody p) = AppendEntries t n pli plt es ci -> sorted es.
Lemma update_elections_data_appendEntries_preserves_allEntries' : forall st h t n pli plt es ci x, In x (allEntries (fst st)) -> In x (allEntries (update_elections_data_appendEntries h st t n pli plt es ci)).
Lemma lifted_transitive_commit_invariant : forall net h e e' t, msg_refined_raft_intermediate_reachable net -> In e (log (snd (nwState net h))) -> In e' (log (snd (nwState net h))) -> eIndex e <= eIndex e' -> lifted_committed net e' t -> lifted_committed net e t.
Lemma handleAppendEntries_preserves_commit : forall net net' h p t n pli plt es ci d m e t', msg_refined_raft_intermediate_reachable net -> In p (nwPackets net) -> snd (pBody p) = AppendEntries t n pli plt es ci -> handleAppendEntries h (snd (nwState net h)) t n pli plt es ci = (d, m) -> (forall h', nwState net' h' = update name_eq_dec (nwState net) h (update_elections_data_appendEntries h (nwState net h) t n pli plt es ci, d) h') -> lifted_committed net e t' -> lifted_committed net' e t'.
Lemma handleAppendEntries_currentTerm_le : forall h st t n pli plt es ci st' m, handleAppendEntries h st t n pli plt es ci = (st', m) -> currentTerm st <= currentTerm st'.
Theorem handleAppendEntries_log_detailed : forall h st t n pli plt es ci st' ps, handleAppendEntries h st t n pli plt es ci = (st', ps) -> (commitIndex st' = commitIndex st /\ log st' = log st) \/ (leaderId st' <> None /\ currentTerm st' = t /\ commitIndex st' = max (commitIndex st) (min ci (maxIndex es)) /\ es <> nil /\ pli = 0 /\ t >= currentTerm st /\ log st' = es /\ haveNewEntries st es = true ) \/ (leaderId st' <> None /\ currentTerm st' = t /\ commitIndex st' = max (commitIndex st) (min ci (maxIndex (es ++ (removeAfterIndex (log st) pli)))) /\ es <> nil /\ exists e, In e (log st) /\ eIndex e = pli /\ eTerm e = plt) /\ t >= currentTerm st /\ log st' = es ++ (removeAfterIndex (log st) pli) /\ haveNewEntries st es = true.