Skip to content

Commit 296b81f

Browse files
committed
Add new mutator for PROPOSE message and other logs
1 parent 30f071b commit 296b81f

File tree

4 files changed

+210
-161
lines changed

4 files changed

+210
-161
lines changed

simulator/src/main/java/byzzbench/simulator/protocols/fab2/FastByzantineReplica.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class FastByzantineReplica extends LeaderBasedProtocolReplica {
3131

3232
// The number of replicas in the system with each role.
3333
private final int p, a, l, f;
34-
// The message round number.
3534
private long viewNumber;
3635
private long proposalNumber;
3736
// The value that the leader replica is proposing - changes each round, depending on the client request.
@@ -386,7 +385,11 @@ private void handleAcceptMessage(String sender, AcceptMessage acceptMessage) {
386385
moveToNextProposal();
387386
}
388387

389-
log.info("Learner " + getId() + " received ACCEPT from " + sender + " and proposal number " + proposalNumber);
388+
log.info("Learner " + getId() +
389+
" received ACCEPT from " + sender +
390+
" and proposal number " + sequenceNumber
391+
+ " with value " + new String(acceptMessage.getValueAndProposalNumber().getValue()));
392+
390393
int acceptedThreshold = (int) Math.ceil((a + (3 * f) + 1) / 2.0);
391394
boolean isAccepted = messageLog.onAccept(sender, acceptMessage, acceptedThreshold);
392395
operation = acceptMessage.getValueAndProposalNumber().getValue();
@@ -443,9 +446,10 @@ private void handleLearnMessageProposer(String sender, LearnMessage learnMessage
443446
isSatisfied = true;
444447
}
445448

449+
// Leader is ready to move to the next request.
446450
// Leader is ready to move to the next request.
447451
if (isLeader() && !requests.isEmpty()
448-
&& messageLog.getProposersWithLearnedValue().size() >= p) {
452+
&& messageLog.getProposersWithLearnedValue().size() >= l) {
449453
Serializable request = requests.poll();
450454
this.proposalNumber++;
451455
log.info("Increasing proposal number: " + this.proposalNumber);
@@ -499,9 +503,9 @@ private void handleLearnMessageLearner(String sender, LearnMessage learnMessage)
499503

500504
log.info("Learner " + getId() + " sending reply to client...");
501505
this.sendReplyToClient(clientId, learnMessage.getValueAndProposalNumber().getValue());
502-
503506
}
504507

508+
multicastMessage(new LearnMessage(learnMessage.getValueAndProposalNumber()), this.proposerNodeIds);
505509
if (this.learnerTimeoutId != -1) this.clearTimeout(this.learnerTimeoutId);
506510
} else {
507511
log.info("Learner " + getId() + " has not learned the value yet");

simulator/src/main/java/byzzbench/simulator/protocols/fab2/MessageLog.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ public boolean onAccept(String senderId, AcceptMessage acceptMessage, int thresh
179179
}
180180
});
181181

182+
// Log the values in the acceptorsWithAcceptedProposals
183+
acceptorsWithAcceptedProposal.forEach((k, v) -> {
184+
log.info("Acceptor " + k + " accepted value " + Arrays.toString(v.getValue()) + " with proposal number " + v.getProposalNumber());
185+
});
186+
182187
log.info("The number of accepted values for the same proposal value is " + currentAccepted.get());
183188
if (currentAccepted.get() >= threshold) {
184189
log.info("The learner has learned the value");
@@ -188,7 +193,7 @@ public boolean onAccept(String senderId, AcceptMessage acceptMessage, int thresh
188193
}
189194

190195
// Remove message from the acceptMessages map
191-
// if (acceptMessages.containsKey(proposalNumber)) acceptMessages.get(proposalNumber).remove(acceptMessage);
196+
if (acceptMessages.containsKey(proposalNumber)) acceptMessages.get(proposalNumber).remove(acceptMessage);
192197

193198
return false;
194199
}
@@ -224,6 +229,7 @@ public boolean learnerHasLearnedValue(Pair learnValue, int quorum) {
224229
}
225230
});
226231

232+
log.info("The number of learned values for the same proposal value is " + currentLearnedWithSamePair.get());
227233
if (currentLearnedWithSamePair.get() >= quorum && learnedValue == null) {
228234
this.learnedValue = learnValue;
229235
return true;

simulator/src/main/java/byzzbench/simulator/protocols/fab2/mutator/ProposeMessageMutatorFactory2.java

+35
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,41 @@ public void accept(FaultContext serializable) {
118118
))
119119
);
120120

121+
messageEvent.setPayload(mutatedMessage);
122+
}
123+
},
124+
125+
new MessageMutationFault(
126+
"fab-propose-value",
127+
"Any Propose Number",
128+
List.of(ProposeMessage.class)
129+
) {
130+
@Override
131+
public void accept(FaultContext serializable) {
132+
Optional<Event> event = serializable.getEvent();
133+
Random random = new Random();
134+
int mutation = random.nextInt(2, 100);
135+
136+
if (event.isEmpty()) {
137+
throw new IllegalArgumentException("Invalid message type");
138+
}
139+
140+
if (!(event.get() instanceof MessageEvent messageEvent)) {
141+
throw new IllegalArgumentException("Invalid message type");
142+
}
143+
144+
if (!(messageEvent.getPayload() instanceof ProposeMessage message)) {
145+
throw new IllegalArgumentException("Invalid message type");
146+
}
147+
148+
ProposeMessage mutatedMessage = message.withValueAndProposalNumber(
149+
new Pair("value".getBytes(),
150+
new ProposalNumber(
151+
message.getValueAndProposalNumber().getProposalNumber().getViewNumber(),
152+
message.getValueAndProposalNumber().getProposalNumber().getSequenceNumber()
153+
))
154+
);
155+
121156
messageEvent.setPayload(mutatedMessage);
122157
}
123158
}

0 commit comments

Comments
 (0)