Definition leaderLogs_entries_match_nw (net : network) : Prop :=
    forall h llt ll p t src pli plt es ci,
      In (llt, ll) (leaderLogs (fst (nwState net h))) ->
      In p (nwPackets net) ->
      pBody p = AppendEntries t src pli plt es ci ->
      (forall e1 e2,
         eIndex e1 = eIndex e2 ->
         eTerm e1 = eTerm e2 ->
         In e1 es ->
         In e2 ll ->
         (forall e3,
            eIndex e3 <= eIndex e1 ->
            In e3 es ->
            In e3 ll) /\
         (pli <> 0 ->
          exists e4,
            eIndex e4 = pli /\
            eTerm e4 = plt /\
            In e4 ll)).Definition leaderLogs_entries_match (net : network) : Prop :=
    leaderLogs_entries_match_host net /\
    leaderLogs_entries_match_nw net.

(* Specifications: *)
Lemma leaderLogs_entries_match_init : refined_raft_net_invariant_init leaderLogs_entries_match.
Lemma entries_match_cons_gt_maxTerm : forall x xs ys, sorted xs -> sorted ys -> eIndex x > maxIndex xs -> eTerm x > maxTerm ys -> entries_match xs ys -> entries_match (x :: xs) ys.
Lemma entries_match_cons_sublog : forall x xs ys, sorted xs -> sorted ys -> eIndex x > maxIndex xs -> entries_match xs ys -> (forall y, In y ys -> eTerm x = eTerm y -> In y xs) -> entries_match (x :: xs) ys.
Lemma lifted_logs_sorted_nw : forall net p t n plt plti es ci, refined_raft_intermediate_reachable net -> In p (nwPackets net) -> pBody p = AppendEntries t n plt plti es ci -> sorted es.
Lemma lifted_logs_sorted_host : forall net h , refined_raft_intermediate_reachable net -> sorted (log (snd (nwState net h))).
Lemma leaderLogs_entries_match_nw_packet_set : forall net net', leaderLogs_entries_match_nw net -> (forall p, In p (nwPackets net') -> is_append_entries (pBody p) -> In p (nwPackets net)) -> (forall h, leaderLogs (fst (nwState net' h)) = leaderLogs (fst (nwState net h))) -> leaderLogs_entries_match_nw net'.
Lemma leaderLogs_entries_match_host_state_same : forall net net', leaderLogs_entries_match_host net -> (forall h, leaderLogs (fst (nwState net' h)) = leaderLogs (fst (nwState net h))) -> (forall h, log (snd (nwState net' h)) = log (snd (nwState net h))) -> leaderLogs_entries_match_host net'.
Lemma leaderLogs_entries_match_client_request : refined_raft_net_invariant_client_request leaderLogs_entries_match.
Lemma leaderLogs_entries_match_timeout : refined_raft_net_invariant_timeout leaderLogs_entries_match.
Lemma lifted_log_matching : forall net, refined_raft_intermediate_reachable net -> log_matching (deghost net).
Lemma lifted_log_matching_host : forall net, refined_raft_intermediate_reachable net -> (forall h h', entries_match (log (snd (nwState net h))) (log (snd (nwState net h')))) /\ (forall h i, 1 <= i <= maxIndex (log (snd (nwState net h))) -> exists e, eIndex e = i /\ In e (log (snd (nwState net h)))) /\ (forall h e, In e (log (snd (nwState net h))) -> eIndex e > 0).
Lemma lifted_log_matching_nw : forall net, refined_raft_intermediate_reachable net -> forall p t leaderId prevLogIndex prevLogTerm entries leaderCommit, In p (nwPackets net) -> pBody p = AppendEntries t leaderId prevLogIndex prevLogTerm entries leaderCommit -> (forall h e1 e2, In e1 entries -> In e2 (log (snd (nwState net h))) -> eIndex e1 = eIndex e2 -> eTerm e1 = eTerm e2 -> (forall e3, eIndex e3 <= eIndex e1 -> In e3 entries -> In e3 (log (snd (nwState net h)))) /\ (prevLogIndex <> 0 -> exists e4, eIndex e4 = prevLogIndex /\ eTerm e4 = prevLogTerm /\ In e4 (log (snd (nwState net h))))) /\ (forall i, prevLogIndex < i <= maxIndex entries -> exists e, eIndex e = i /\ In e entries) /\ (forall e, In e entries -> prevLogIndex < eIndex e).