Skip to content

Commit 59d65ae

Browse files
committed
Added extra mutation
1 parent 57e49dc commit 59d65ae

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

simulator/src/main/java/byzzbench/simulator/protocols/hbft/mutator/ViewChangeMessageFactory.java

+36
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
import org.springframework.stereotype.Component;
1010

11+
import byzzbench.simulator.Replica;
1112
import byzzbench.simulator.faults.FaultContext;
1213
import byzzbench.simulator.faults.factories.MessageMutatorFactory;
1314
import byzzbench.simulator.faults.faults.MessageMutationFault;
15+
import byzzbench.simulator.protocols.hbft.HbftJavaReplica;
1416
import byzzbench.simulator.protocols.hbft.message.RequestMessage;
1517
import byzzbench.simulator.protocols.hbft.message.ViewChangeMessage;
1618
import byzzbench.simulator.transport.Event;
@@ -455,6 +457,40 @@ public void accept(FaultContext serializable) {
455457

456458
// }
457459
// }
460+
,
461+
new MessageMutationFault("hbft-view-change-first-req-in-R", "Change first request in R", List.of(ViewChangeMessage.class)) {
462+
@Override
463+
public void accept(FaultContext serializable) {
464+
Optional<Event> event = serializable.getEvent();
465+
if (event.isEmpty()) {
466+
throw invalidMessageTypeException;
467+
}
468+
if (!(event.get() instanceof MessageEvent messageEvent)) {
469+
throw invalidMessageTypeException;
470+
}
471+
if (!(messageEvent.getPayload() instanceof ViewChangeMessage message)) {
472+
throw invalidMessageTypeException;
473+
}
474+
String senderId = messageEvent.getSenderId();
475+
Replica sender = serializable.getScenario().getReplicas().get(senderId);
476+
SortedMap<Long, RequestMessage> requests = message.getRequestsR();
477+
Entry<Long, RequestMessage> firstReq = requests.firstEntry();
478+
if (sender instanceof HbftJavaReplica replica) {
479+
SortedMap<Long, RequestMessage> specRequests = replica.getSpeculativeRequests();
480+
for (Long key : specRequests.keySet()) {
481+
if (!specRequests.get(key).equals(firstReq.getValue())) {
482+
requests.remove(firstReq.getKey());
483+
requests.put(firstReq.getKey(), specRequests.get(key));
484+
ViewChangeMessage mutatedMessage = message.withRequestsR(requests);
485+
mutatedMessage.sign(message.getSignedBy());
486+
messageEvent.setPayload(mutatedMessage);
487+
break;
488+
}
489+
}
490+
}
491+
492+
}
493+
}
458494
// //TODO: be able to change the first or last request
459495

460496

simulator/src/main/java/byzzbench/simulator/transport/Transport.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public synchronized void deliverEvent(long eventId) throws Exception {
314314

315315
// if it is a MessageEvent and there is no connectivity between the nodes, drop it
316316
if (e instanceof MessageEvent m && !router.haveConnectivity(m.getSenderId(), m.getRecipientId())) {
317-
log.info("Dropped: " + m.getSenderId() + "->" + m.getRecipientId() + ": " + m.getPayload());
317+
//log.info("Dropped: " + m.getSenderId() + "->" + m.getRecipientId() + ": " + m.getPayload());
318318
m.setStatus(Event.Status.DROPPED);
319319
return;
320320
}
@@ -341,7 +341,7 @@ public synchronized void deliverEvent(long eventId) throws Exception {
341341
}
342342
}
343343

344-
log.info("Delivered " + e);
344+
//log.info("Delivered " + e);
345345
}
346346

347347
/**
@@ -361,7 +361,7 @@ public synchronized void dropEvent(long eventId) {
361361
}
362362
e.setStatus(Event.Status.DROPPED);
363363
this.observers.forEach(o -> o.onEventDropped(e));
364-
log.info("Dropped: " + e);
364+
//log.info("Dropped: " + e);
365365
}
366366

367367
/**
@@ -432,7 +432,7 @@ public synchronized void applyMutation(long eventId, Fault fault) {
432432
this.scenario.getSchedule().appendEvent(mutateMessageEvent);
433433
this.observers.forEach(o -> o.onMessageMutation(mutateMessageEvent.getPayload()));
434434

435-
log.info("Mutated: " + m);
435+
//log.info("Mutated: " + m);
436436
}
437437

438438
public synchronized void applyFault(String faultId) {
@@ -485,7 +485,7 @@ public synchronized long setTimeout(Node node, Runnable runnable,
485485
.build();
486486
this.appendEvent(timeoutEvent);
487487
this.observers.forEach(o -> o.onTimeout(timeoutEvent));
488-
log.info("Timeout set for " + node.getId() + " in " + timeout + "ms: " + timeoutEvent);
488+
//log.info("Timeout set for " + node.getId() + " in " + timeout + "ms: " + timeoutEvent);
489489
return timeoutEvent.getEventId();
490490
}
491491

@@ -503,8 +503,8 @@ public synchronized long setTimeout(Replica replica, Runnable runnable,
503503
this.observers.forEach(o -> o.onTimeout(timeoutEvent));
504504

505505

506-
log.info(description + " timeout set for " + replica.getId() + " in " +
507-
timeout + "ms: " + timeoutEvent);
506+
//log.info(description + " timeout set for " + replica.getId() + " in " +
507+
//timeout + "ms: " + timeoutEvent);
508508
return timeoutEvent.getEventId();
509509
}
510510

@@ -523,8 +523,8 @@ public synchronized long setClientTimeout(String clientId, Runnable runnable,
523523
this.observers.forEach(o -> o.onTimeout(timeoutEvent));
524524

525525

526-
log.info("Timeout set for " + clientId + " in " +
527-
timeout + "ms: " + timeoutEvent);
526+
//log.info("Timeout set for " + clientId + " in " +
527+
//timeout + "ms: " + timeoutEvent);
528528
return timeoutEvent.getEventId();
529529
}
530530

simulator/src/main/resources/application.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ byzzbench:
2222
outputSchedules: buggy # which schedules to write to file? one of 'all', 'buggy' or 'none'
2323

2424
scheduler:
25-
id: "byzzfuzz" # The ID of the scheduler to use
26-
executionMode: async # async (default, any message delivered) or sync (communication-closure hypothesis, FIFO)
25+
id: "random" # The ID of the scheduler to use
26+
executionMode: sync # async (default, any message delivered) or sync (communication-closure hypothesis, FIFO)
2727
maxDropMessages: 0 # Maximum number of messages to drop per scenario
2828
maxMutateMessages: 0 # Maximum number of messages to mutate per scenario
2929
deliverTimeoutWeight: 1 # The weight for scheduler to trigger a timeout
@@ -34,7 +34,7 @@ byzzbench:
3434
params: # additional parameters for the scheduler
3535
# ByzzFuzz
3636
numRoundsWithProcessFaults: 1
37-
numRoundsWithNetworkFaults: 1
37+
numRoundsWithNetworkFaults: 0
3838
numRoundsWithFaults: 2
3939
# Twins
4040
numReplicas: 1

0 commit comments

Comments
 (0)