Skip to content

Commit 4e7afa6

Browse files
committedJan 22, 2025·
Fixed a bug. Trying to make partitions heal
1 parent 30d6dcc commit 4e7afa6

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed
 

‎simulator/src/main/java/byzzbench/simulator/Client.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class Client implements Serializable, Node {
4545
/**
4646
* The maximum number of requests that can be sent by the client.
4747
*/
48-
private final long maxRequests = 3;
48+
private final long maxRequests = 10;
4949

5050
/**
5151
* The replies received by the client.

‎simulator/src/main/java/byzzbench/simulator/faults/factories/ByzzFuzzScenarioFaultFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public List<Fault> generateFaults(FaultContext input) {
4040

4141
// Create network faults
4242
for (int i = 1; i <= d; i++) {
43-
int round = rand.nextInt(r) + 1;
43+
int round = rand.nextInt(0, r + 1);
4444
Set<String> partition = SetSubsets.getRandomNonEmptySubset(replicaIds);
4545
Fault networkFault = new ByzzFuzzNetworkFault(partition, round);
4646
faults.add(networkFault);
4747
}
4848

4949
// Create process faults
5050
for (int i = 1; i <= c; i++) {
51-
int round = rand.nextInt(r) + 1;
51+
int round = rand.nextInt(0, r + 1);
5252
String sender = replicaIds.stream().skip(rand.nextInt(replicaIds.size())).findFirst().orElseThrow();
5353
Set<String> recipientIds = SetSubsets.getRandomNonEmptySubset(replicaIds);
5454

‎simulator/src/main/java/byzzbench/simulator/protocols/tendermint/MessageLog.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,22 @@ public class MessageLog {
4242

4343
/**
4444
* Adds a message to the message log, maintaining the appropriate mappings.
45+
*
46+
* @param voteMessage the message to add
47+
* @return true if the message was added successfully (not seen before), false otherwise
4548
*/
4649
public boolean addMessage(GenericMessage voteMessage) {
47-
// Add the message to the author's set
48-
receivedMessages.computeIfAbsent(voteMessage.getAuthor(), k -> new TreeSet<>()).add(voteMessage);
50+
// Get the set of received messages for the author
51+
SortedSet<GenericMessage> authorMessages = receivedMessages
52+
.computeIfAbsent(voteMessage.getAuthor(), k -> new TreeSet<>());
53+
54+
// Check if the message already exists
55+
boolean isNewMessage = authorMessages.add(voteMessage);
56+
57+
if (!isNewMessage) {
58+
// Message already exists, return false
59+
return false;
60+
}
4961

5062
// Process the message based on its type
5163
Block block = voteMessage.getBlock() == null ? NULL_BLOCK : voteMessage.getBlock();
@@ -68,7 +80,7 @@ public boolean addMessage(GenericMessage voteMessage) {
6880
}
6981
}
7082

71-
return true;
83+
return true; // Successfully added a new message
7284
}
7385

7486
/**

‎simulator/src/main/java/byzzbench/simulator/protocols/tendermint/TendermintReplica.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ private void broadcastGossipPrevote(PrevoteMessage prevoteMessage) {
488488
private void broadcastPrevote(long height, long round, Block block) {
489489
// messageLog.sentPrevote();
490490
PrevoteMessage prevoteMessage = new PrevoteMessage(height, round, this.getId(), block);
491-
broadcastMessage(prevoteMessage);
491+
broadcastMessageIncludingSelf(prevoteMessage);
492492
}
493493

494494
private void onTimeoutPrevote(long height, long round) {
@@ -609,7 +609,7 @@ private void broadcastGossipPrecommit(PrecommitMessage precommitMessage) {
609609

610610
protected void broadcastPrecommit(long height, long round, Block block) {
611611
PrecommitMessage precommitMessage = new PrecommitMessage(height, round, this.getId(), block);
612-
broadcastMessage(precommitMessage);
612+
broadcastMessageIncludingSelf(precommitMessage);
613613
}
614614

615615
private void onTimeoutPrecommit(long height, long round) {

‎simulator/src/main/java/byzzbench/simulator/protocols/tendermint/TendermintScenarioExecutor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public Replica cloneReplica(Replica replica) {
6161

6262
@Override
6363
public int maxFaultyReplicas(int n) {
64-
return (n - 1) / 3;
64+
return 1;
6565
}
6666
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package byzzbench.simulator.protocols.tendermint.message;
22

33
import byzzbench.simulator.transport.MessagePayload;
4+
import byzzbench.simulator.transport.messages.MessageWithRound;
45
import lombok.Data;
56
import lombok.EqualsAndHashCode;
67
import lombok.With;
78

89
@Data
910
@EqualsAndHashCode(callSuper = true)
1011
@With
11-
public class GossipMessage extends MessagePayload {
12+
public class GossipMessage extends MessagePayload implements MessageWithRound {
1213
private final String replicaId;
1314
private final GenericMessage gossipMessage;
1415

@@ -17,4 +18,9 @@ public class GossipMessage extends MessagePayload {
1718
public String getType() {
1819
return "GOSSIP " + gossipMessage.getType();
1920
}
21+
22+
@Override
23+
public long getRound() {
24+
return gossipMessage.getRound();
25+
}
2026
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public synchronized void deliverEvent(long eventId) throws Exception {
266266
}
267267
}
268268

269-
log.info("Delivered " + e);
269+
// log.info("Delivered " + e);
270270
}
271271

272272
/**

0 commit comments

Comments
 (0)
Please sign in to comment.