Section QueryPlusTPC.
(* Querying on behalf of the coordinator (it's easier this way, thanks *)
(* to cn_agreement lemma). In order to query on behald of the *)
(* participan, a different invariant-based fact should be proven. *)
(****************************************************************)
(*************         Basic definitions       ******************)
(****************************************************************)
Variables (lc lq : Label).
Variables (cn : nid) (pts : seq nid).
Hypothesis Lab_neq: lq != lc.
Hypothesis Hnin : cn \notin pts.
Hypothesis Puniq : uniq pts.
Hypothesis PtsNonEmpty : pts != [::].
(* Core protocol *)
Definition pc : protocol := TwoPhaseInductiveProof.tpc_with_inv lc [::] Hnin.
Definition Data : Type := (nat * Log).
Definition qnodes := cn :: pts.
(* Serialization of logs *)
Variable serialize : Data -> seq nat.
Variable deserialize : seq nat -> Data.
Hypothesis ds_inverse : left_inverse serialize deserialize.
(* This one is in the init state *)
Definition local_indicator (d : Data) :=
[Pred h | h = st :-> (d.1, CInit) \+ log :-> d.2].
(* Data is just a log *)
Definition core_state_to_data n h (d : Data)  :=
if n == cn
then h = st :-> (d.1, CInit) \+ log :-> d.2
else h = st :-> (d.1, PInit) \+ log :-> d.2.
(***************  Intermediate definitions **********************)
(* Composite world *)
Definition W := QueryHooked.W lq pc Data qnodes serialize core_state_to_data.
Notation loc_qry s := (getLocal cn (getStatelet s lq)).
Notation loc_tpc' s n := (getLocal n (getStatelet s lc)).
Notation loc_tpc s := (loc_tpc' s cn).
Notation qry_init := (query_init_state lq Data qnodes serialize cn).

Lemma find_empty l i : l \notin dom i -> getStatelet i l = empty_dstatelet.