(* generic receive-transition *)
End CoordinatorGenericReceiveTransitions.
Section CoordinatorReceiveTransitions.
Definition cn_msg_wf d (C : TPCCoh d) (this from : nid) :=
[pred m : TaggedMessage | c_matches_tag (getStC C).2 (tag m)].
Definition cn_receive_prep_yes_trans := rc_recv_trans prep_yes cn_msg_wf.
Definition cn_receive_prep_no_trans := rc_recv_trans prep_no cn_msg_wf.
Definition cn_receive_commit_ack_trans := rc_recv_trans commit_ack cn_msg_wf.
Definition cn_receive_abort_ack_trans := rc_recv_trans abort_ack cn_msg_wf.
End CoordinatorReceiveTransitions.
(* Participant transitions *)
(* State component *)
Definition pstep_send (cs: PStateT) (l : Log) (commit : bool) : PStateT * Log :=
let: (e, s) := cs in
match s with
| PGotRequest d =>
if commit then (e, PRespondedYes d, l) else (e, PRespondedNo d, l)
| PCommitted d => (e.+1, PInit, l)
| PAborted d => (e.+1, PInit, l)
| _ => (cs, l)
end.
Definition p_matches_tag s mtag : bool :=
match s with
| PInit => mtag == prep_req
(* Just because I responded Yes, doesn't mean everyone else did. So the transaction might have been aborted. *)
| PRespondedYes _ => (mtag == commit_req) || (mtag == abort_req)
| PRespondedNo _ => mtag == abort_req
| _ => false
end.
Definition pstep_recv (ps: PStateT) (from : nid) (mtag : ttag)
(mbody : payload) (l : Log) : PStateT * Log :=
if (negb (p_matches_tag ps.2 mtag)) || (from != cn) || (head 0 mbody != ps.1)
then (ps, l)
else let: (e, s) := ps in
match s with
| PInit => (e, PGotRequest (behead mbody), l)
| PRespondedYes d =>
if mtag == commit_req
then (e, PCommitted d, rcons l (true, d))
else
(* Even though I said Yes, the coordinator decided to abort. *)
(e, PAborted d, rcons l (false, d))
| PRespondedNo d => (e, PAborted d, rcons l (false, d))
| _ => (ps, l)
end.
Section ParticipantGenericSendTransitions.
Notation coh := TPCCoh.
Definition HPn this to := (this \in pts /\ to == cn).
Variable ptag : ttag.
(* Precondition -- this is the way one can define multiple send-transitions *)
Variable prec : PStateT -> payload -> Prop.
(* Making sure that the precondition is legit *)
Hypothesis pn_prec_safe :
forall this to s m,
HPn this to -> prec s m -> cohMsg (Msg (TMsg ptag m) this to true) s.1.

(* Specifications: *)
Lemma pn_this_in this to : HPn this to -> this \in nodes.
Variable commit : bool.