Skip to content

Commit 4da7373

Browse files
committed
Revert "Trace validation found another divergence within ~30 seconds
after generating approximately 10k states." and finally implement the EWD998 specification.
1 parent 5665744 commit 4da7373

File tree

2 files changed

+35
-123
lines changed

2 files changed

+35
-123
lines changed

specifications/ewd998/impl/src/EWD998.java

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public EWD998(final Map<Integer, Pair> nodes, final int myId, final boolean isIn
8888
inbox.put(pkt);
8989
}
9090

91-
boolean isConclusiveRound = false;
91+
boolean terminationDetected = false;
9292

9393
// --------------------------------------------------------------------------------- //
9494

@@ -141,30 +141,8 @@ public EWD998(final Map<Integer, Pair> nodes, final int myId, final boolean isIn
141141

142142
final JsonObject msg = pkt.get(MSG).getAsJsonObject();
143143

144-
int tokenQ = 0;
145-
Color tokenColor = null;
146-
147144
// --------------------------------------------------------------------------------- //
148-
149-
// InitiateToken and PassToken
150-
if (msg.get(TYPE).equals(TOK)) {
151-
tokenQ = msg.get("q").getAsInt();
152-
tokenColor = Color.valueOf(msg.get("color").getAsString());
153-
154-
if (isInitiator) {
155-
/*
156-
InitiateProbe ==
157-
/\ token.pos = 0
158-
/\ \* previous round inconclusive:
159-
\/ token.color = "black"
160-
\/ color[0] = "black"
161-
\/ counter[0] + token.q > 0
162-
/\ ...
163-
/\ UNCHANGED <<active, counter, pending>>
164-
*/
165-
isConclusiveRound = tokenQ + counter == 0 && color == Color.white && tokenColor == Color.white;
166-
}
167-
} else if (msg.get(TYPE).equals(PL)) {
145+
if (msg.get(TYPE).equals(PL)) {
168146
/*
169147
RecvMsg(i) ==
170148
/\ pending[i] > 0
@@ -186,7 +164,7 @@ public EWD998(final Map<Integer, Pair> nodes, final int myId, final boolean isIn
186164
assert !active;
187165
assert inbox.isEmpty();
188166
return;
189-
} else {
167+
} else if (!msg.get(TYPE).equals(TOK)) {
190168
logline.add("failure", new JsonPrimitive(String.format("Unknown message type: %s", msg.get(TYPE).getAsString())));
191169
System.out.println(logline);
192170
throw new IllegalArgumentException("Unknown message type");
@@ -244,33 +222,39 @@ public EWD998(final Map<Integer, Pair> nodes, final int myId, final boolean isIn
244222
// InitiateToken and PassToken actions
245223
// /\ ...
246224
// /\ token.pos = i
247-
if (tokenColor != null) {
248-
if (isInitiator && isConclusiveRound && !active) {
249-
// Send the trm message to all nodes (us included).
250-
for (Integer n : nodes.keySet()) {
251-
sendMsg(myId, n, getTrm());
225+
if (msg.get(TYPE).equals(TOK)) {
226+
final int tokenQ = msg.get("q").getAsInt();
227+
final Color tokenColor = Color.valueOf(msg.get("color").getAsString());
228+
if (isInitiator) {
229+
final boolean isConclusive =
230+
tokenColor == Color.white &&
231+
color == Color.white &&
232+
tokenQ + counter == 0;
233+
if (isConclusive && !active) {
234+
// If the previous token round was conclusive and the initiator is inactive,
235+
// send termination message to all nodes including myself.
236+
for (Integer n : nodes.keySet()) {
237+
sendMsg(myId, n, getTrm());
238+
}
239+
} else if (!isConclusive) {
240+
/*
241+
InitiateProbe ==
242+
/\ token.pos = 0
243+
/\ \* previous round inconclusive:
244+
\/ token.color = "black"
245+
\/ color[0] = "black"
246+
\/ counter[0] + token.q > 0
247+
/\ ...
248+
/\ UNCHANGED <<active, counter, pending>>
249+
*/
250+
sendMsg(myId, nodes.size() - 1, getTok(0, Color.white));
251+
color = Color.white;
252+
} else {
253+
// This UNCHANGED token does not expliclty appear in the EWD998Chan spec, but
254+
// can be conceptually mapped to the _vars in [Next]_vars ; the InitiateToken
255+
// action is *not* enabled.
256+
inbox.add(pkt);
252257
}
253-
tokenColor = null;
254-
} else if (isInitiator && !isConclusiveRound) {
255-
/*
256-
terminationDetected ==
257-
/\ token.pos = 0
258-
/\ token.color = "white"
259-
/\ token.q + counter[0] = 0
260-
/\ color[0] = "white"
261-
/\ ~ active[0]
262-
263-
*/
264-
/*
265-
InitiateProbe ==
266-
/\ ...
267-
/\ token' = [ pos |-> N-1, q |-> 0, color |-> "white"]
268-
/\ color' = [ color EXCEPT ![0] = "white" ]
269-
/\ UNCHANGED <<active, counter, pending>>
270-
*/
271-
sendMsg(myId, nodes.size() - 1, getTok(0, Color.white));
272-
color = Color.white;
273-
tokenColor = null;
274258
} else if (!active) {
275259
/*
276260
PassToken(i) ==
@@ -284,8 +268,6 @@ public EWD998(final Map<Integer, Pair> nodes, final int myId, final boolean isIn
284268
*/
285269
sendMsg(myId, myId - 1, getTok(tokenQ + counter, color == Color.black ? Color.black : tokenColor));
286270
color = Color.white;
287-
288-
tokenColor = null;
289271
} else {
290272
// This node owns the token and is active; keep the unchanged token.
291273
/*

specifications/ewd998/trace-unstable.ndjson

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)