Definition minimal_contradicting_leader_log net t e :=
    argmin (fun l => fst (fst l)) (contradicting_leader_logs net nodes t e).

(* Specifications: *)
Lemma minimal_contradicting_leader_log_None : forall net t e, minimal_contradicting_leader_log net t e = None -> forall t' log h, In (t', log) (leaderLogs (fst (nwState net h))) -> t' > t -> In e log.
Lemma In_contradicting_logs_on_leader_elim : forall l t e t' l', In (t', l') (contradicting_leader_logs_on_leader l t e) -> In (t', l') l /\ t < t' /\ ~ In e l'.
Lemma in_contradicting_leader_logs : forall net nodes t e t' h l, In (t', h, l) (contradicting_leader_logs net nodes t e) -> In (t', l) (contradicting_leader_logs_on_leader (leaderLogs (fst (nwState net h))) t e).
Lemma in_contradicting_leader_logs_on_leader_in_leaderLog : forall ll t e t' l, In (t', l) (contradicting_leader_logs_on_leader ll t e) -> In (t', l) ll.
Lemma in_contradicting_leader_logs_on_leader_not_in_log : forall t' l ll t e, In (t', l) (contradicting_leader_logs_on_leader ll t e) -> In e l -> False.
Lemma in_contradicting_leader_logs_on_leader_term_lt : forall t' l ll t e, In (t', l) (contradicting_leader_logs_on_leader ll t e) -> t < t'.
Lemma contradicting_leader_logs_on_leader_complete : forall t e t' l ll, In (t', l) ll -> t < t' -> ~ In e l -> In (t', l) (contradicting_leader_logs_on_leader ll t e).
Lemma contradicting_leader_logs_complete : forall net nodes h t e l t', In h nodes -> In (t', l) (contradicting_leader_logs_on_leader (leaderLogs (fst (nwState net h))) t e) -> In (t', h, l) (contradicting_leader_logs net nodes t e).
Lemma minimal_contradicting_leader_log_elim : forall net t e t' h l, minimal_contradicting_leader_log net t e = Some (t', h, l) -> (t < t' /\ In (t', l) (leaderLogs (fst (nwState net h))) /\ ~ In e l /\ (forall h' t'' l', In (t'', l') (leaderLogs (fst (nwState net h'))) -> (t'' <= t \/ t'' >= t' \/ In e l'))).
Lemma maxTerm_zero_or_entry : forall l, maxTerm l = 0 \/ exists e, In e l /\ eTerm e = maxTerm l.
Lemma maxIndex_zero_or_entry : forall l, maxIndex l = 0 \/ exists e, In e l /\ eIndex e = maxIndex l.
Theorem leader_completeness_directly_committed_invariant : forall net, refined_raft_intermediate_reachable net -> leader_completeness_directly_committed net.
Theorem leader_completeness_committed_invariant : forall net, refined_raft_intermediate_reachable net -> leader_completeness_committed net.
Theorem leader_completeness_invariant : forall net, refined_raft_intermediate_reachable net -> leader_completeness net.