Skip to content

Commit d72990c

Browse files
author
Antoni Nowakowski
committed
Merge branch 'tendermint-main' into tendermint-main-fix-byzzfuzz-partitions
2 parents 645d297 + ff4b5f9 commit d72990c

12 files changed

+148
-158
lines changed

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(0, r + 1);
43+
int round = rand.nextInt(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(0, r + 1);
51+
int round = rand.nextInt(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

+8-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import byzzbench.simulator.protocols.tendermint.message.*;
44

5-
import byzzbench.simulator.transport.DefaultClientRequestPayload;
65
import lombok.Getter;
76
import lombok.RequiredArgsConstructor;
87
import lombok.extern.java.Log;
@@ -112,17 +111,17 @@ public int getPrevoteCount(Block block) {
112111
}
113112

114113
/**
115-
* Checks if there are f+1 messages in a specific round after a given round.
114+
* Checks if there are f+1 messages in a specific sequence after a given sequence.
116115
*/
117-
public boolean fPlus1MessagesInRound(long height, long round) {
118-
// Flatten the received messages map and filter by height and round > round
119-
Map<Long, Long> roundMessageCounts = receivedMessages.values().stream()
116+
public boolean fPlus1MessagesInSequence(long height, long sequence) {
117+
// Flatten the received messages map and filter by height and sequence > sequence
118+
Map<Long, Long> sequenceMessageCounts = receivedMessages.values().stream()
120119
.flatMap(Set::stream) // Flatten all sets of messages into a single stream
121-
.filter(m -> m.getHeight() == height && m.getRound() > round) // Apply filters
122-
.collect(Collectors.groupingBy(GenericMessage::getRound, Collectors.counting())); // Group by round and count
120+
.filter(m -> m.getHeight() == height && m.getSequence() > sequence) // Apply filters
121+
.collect(Collectors.groupingBy(GenericMessage::getSequence, Collectors.counting())); // Group by sequence and count
123122

124-
// Check if any round group has at least f + 1 messages
125-
return roundMessageCounts.values().stream()
123+
// Check if any sequence group has at least f + 1 messages
124+
return sequenceMessageCounts.values().stream()
126125
.anyMatch(count -> count >= node.getTolerance() + 1);
127126
}
128127

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

+90-89
Large diffs are not rendered by default.

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/message/CommitMessage.java

-26
This file was deleted.

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/message/GenericMessage.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public abstract class GenericMessage extends MessagePayload implements Comparabl
1111

1212
public abstract long getRound();
1313

14+
public abstract long getSequence();
15+
1416
public abstract String getAuthor();
1517

1618
public abstract long getHeight();
@@ -24,7 +26,7 @@ public int compareTo(GenericMessage other) {
2426
}
2527

2628
return Comparator.comparing(GenericMessage::getHeight)
27-
.thenComparing(GenericMessage::getRound)
29+
.thenComparing(GenericMessage::getSequence)
2830
.thenComparing(GenericMessage::getBlock, Comparator.nullsFirst(Comparator.naturalOrder()))
2931
.thenComparing(GenericMessage::getAuthor, Comparator.nullsFirst(Comparator.naturalOrder()))
3032
.thenComparing(GenericMessage::getType, Comparator.nullsFirst(Comparator.naturalOrder()))
@@ -37,15 +39,15 @@ public boolean equals(Object o) {
3739
if (o == null || getClass() != o.getClass()) return false;
3840
GenericMessage that = (GenericMessage) o;
3941
return getHeight() == that.getHeight() &&
40-
getRound() == that.getRound() &&
42+
getSequence() == that.getSequence() &&
4143
getType().equals(that.getType()) &&
4244
getBlock().equals(that.getBlock()) &&
4345
getAuthor().equals(that.getAuthor());
4446
}
4547

4648
@Override
4749
public int hashCode() {
48-
return Objects.hash(getHeight(), getRound(), getType(), getBlock(), getAuthor());
50+
return Objects.hash(getHeight(), getSequence(), getType(), getBlock(), getAuthor());
4951
}
5052

5153
}

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/message/PrecommitMessage.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@With
1010
public class PrecommitMessage extends GenericMessage {
1111
private final long height; // Current blockchain height
12-
private final long round; // Current round in the consensus process
12+
private final long sequence; // Current round in the consensus process
1313
private final String replicaId; // ID of the validator sending the precommit
1414
private final Block block;
1515

@@ -22,4 +22,9 @@ public String getType() {
2222
public String getAuthor() {
2323
return replicaId;
2424
}
25+
26+
@Override
27+
public long getRound() {
28+
return sequence * 3 + 3;
29+
}
2530
}

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/message/PrevoteMessage.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@With
1010
public class PrevoteMessage extends GenericMessage {
1111
private final long height; // Current blockchain height
12-
private final long round; // Current round in the consensus process
12+
private final long sequence; // Current round in the consensus process
1313
private final String replicaId; // ID of the validator sending the prevote
1414
private final Block block; // Block being prevoted
1515

@@ -22,4 +22,9 @@ public String getType() {
2222
public String getAuthor() {
2323
return replicaId;
2424
}
25+
26+
@Override
27+
public long getRound(){
28+
return sequence * 3 + 2;
29+
}
2530
}

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/message/ProposalMessage.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
public class ProposalMessage extends GenericMessage {
1111
private final String replicaId; // ID of the proposer
1212
private final long height; // Current blockchain height
13-
private final long round; // Current round in the consensus process
14-
private final long validRound; // Round in which the value is valid
13+
private final long sequence; // Current round in the consensus process
14+
private final long validSequence; // Round in which the value is valid
1515
private final Block block; // Block being proposed\
1616

1717
@Override
@@ -23,4 +23,9 @@ public String getType() {
2323
public String getAuthor() {
2424
return replicaId;
2525
}
26+
27+
@Override
28+
public long getRound() {
29+
return sequence * 3 + 1;
30+
}
2631
}

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/mutator/PrecommitMessageMutatorFactory.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import byzzbench.simulator.protocols.tendermint.message.PrecommitMessage;
77
import byzzbench.simulator.transport.Event;
88
import byzzbench.simulator.transport.MessageEvent;
9-
import byzzbench.simulator.transport.MessagePayload;
109
import lombok.ToString;
1110
import org.springframework.stereotype.Component;
1211

@@ -63,7 +62,7 @@ public List<MessageMutationFault> mutators() {
6362
// messageEvent.setPayload(mutatedMessage);
6463
// }
6564
// },
66-
// new MessageMutationFault("tendermint-precommit-round-inc", "Increment Round Number", List.of(PrecommitMessage.class)) {
65+
// new MessageMutationFault("tendermint-precommit-sequence-inc", "Increment sequence Number", List.of(PrecommitMessage.class)) {
6766
// @Override
6867
// public void accept(FaultContext serializable) {
6968
// Optional<Event> event = serializable.getEvent();
@@ -76,12 +75,12 @@ public List<MessageMutationFault> mutators() {
7675
// if (!(messageEvent.getPayload() instanceof PrecommitMessage message)) {
7776
// throw invalidMessageTypeException;
7877
// }
79-
// PrecommitMessage mutatedMessage = message.withRound(message.getRound() + 1);
78+
// PrecommitMessage mutatedMessage = message.withSequence(message.getSequence() + 1);
8079
// mutatedMessage.sign(message.getSignedBy());
8180
// messageEvent.setPayload(mutatedMessage);
8281
// }
8382
// },
84-
// new MessageMutationFault("tendermint-precommit-round-dec", "Decrement Round Number", List.of(PrecommitMessage.class)) {
83+
// new MessageMutationFault("tendermint-precommit-sequence-dec", "Decrement Sequence Number", List.of(PrecommitMessage.class)) {
8584
// @Override
8685
// public void accept(FaultContext serializable) {
8786
// Optional<Event> event = serializable.getEvent();
@@ -94,7 +93,7 @@ public List<MessageMutationFault> mutators() {
9493
// if (!(messageEvent.getPayload() instanceof PrecommitMessage message)) {
9594
// throw invalidMessageTypeException;
9695
// }
97-
// PrecommitMessage mutatedMessage = message.withRound(message.getRound() - 1);
96+
// PrecommitMessage mutatedMessage = message.withSequence(message.getSequence() - 1);
9897
// mutatedMessage.sign(message.getSignedBy());
9998
// messageEvent.setPayload(mutatedMessage);
10099
// }
@@ -122,8 +121,8 @@ public void accept(FaultContext serializable) {
122121
}
123122
},
124123
new MessageMutationFault(
125-
"tendermint-precommit-round-any",
126-
"Assign Random Round Number",
124+
"tendermint-precommit-sequence-any",
125+
"Assign Random Sequence Number",
127126
List.of(PrecommitMessage.class)) {
128127
@Override
129128
public void accept(FaultContext serializable) {
@@ -137,8 +136,8 @@ public void accept(FaultContext serializable) {
137136
if (!(messageEvent.getPayload() instanceof PrecommitMessage message)) {
138137
throw invalidMessageTypeException;
139138
}
140-
long randomRound = random.nextLong(0, 100000); // Adjust range as needed
141-
PrecommitMessage mutatedMessage = message.withRound(randomRound);
139+
long randomSequence = random.nextLong(0, 100000); // Adjust range as needed
140+
PrecommitMessage mutatedMessage = message.withSequence(randomSequence);
142141
mutatedMessage.sign(message.getSignedBy());
143142
messageEvent.setPayload(mutatedMessage);
144143
}

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/mutator/PrevoteMessageMutatorFactory.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public void accept(FaultContext serializable) {
119119
}
120120
},
121121
new MessageMutationFault(
122-
"tendermint-prevote-round-any",
123-
"Assign Random Round Number",
122+
"tendermint-prevote-sequence-any",
123+
"Assign Random Sequence Number",
124124
List.of(PrevoteMessage.class)) {
125125
@Override
126126
public void accept(FaultContext serializable) {
@@ -134,8 +134,8 @@ public void accept(FaultContext serializable) {
134134
if (!(messageEvent.getPayload() instanceof PrevoteMessage message)) {
135135
throw invalidMessageTypeException;
136136
}
137-
long randomRound = random.nextLong(0, 100000); // Adjust range as needed
138-
PrevoteMessage mutatedMessage = message.withRound(randomRound);
137+
long randomSequence = random.nextLong(0, 100000); // Adjust range as needed
138+
PrevoteMessage mutatedMessage = message.withSequence(randomSequence);
139139
mutatedMessage.sign(message.getSignedBy());
140140
messageEvent.setPayload(mutatedMessage);
141141
}

simulator/src/main/java/byzzbench/simulator/protocols/tendermint/mutator/ProposalMessageMutatorFactory.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public void accept(FaultContext serializable) {
120120
}
121121
},
122122
new MessageMutationFault(
123-
"tendermint-proposal-round-any",
124-
"Assign Random Round Number",
123+
"tendermint-proposal-sequence-any",
124+
"Assign Random Sequence Number",
125125
List.of(ProposalMessage.class)) {
126126
@Override
127127
public void accept(FaultContext serializable) {
@@ -135,8 +135,8 @@ public void accept(FaultContext serializable) {
135135
if (!(messageEvent.getPayload() instanceof ProposalMessage message)) {
136136
throw invalidMessageTypeException;
137137
}
138-
long randomRound = random.nextLong(0, 100000); // Adjust range as needed
139-
ProposalMessage mutatedMessage = message.withRound(randomRound);
138+
long randomSequence = random.nextLong(0, 100000); // Adjust range as needed
139+
ProposalMessage mutatedMessage = message.withSequence(randomSequence);
140140
mutatedMessage.sign(message.getSignedBy());
141141
messageEvent.setPayload(mutatedMessage);
142142
}

simulator/src/test/java/byzzbench/simulator/protocols/tendermint/TendermintReplicaTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ void setup() {
5454

5555
@Test
5656
void testHandleProposal() {
57-
TendermintReplica spyReplica = Mockito.spy(replicaA);
58-
RequestMessage request = new RequestMessage("123", 0, "C0");
59-
Block block = new Block(1, 1, 1, "Block", null);
60-
ProposalMessage proposal = new ProposalMessage("A", 0, 1, spyReplica.getValidRound(), block);
61-
62-
spyReplica.handleProposal(proposal);
63-
64-
verify(spyReplica, times(1)).handleProposal(proposal);
57+
// TendermintReplica spyReplica = Mockito.spy(replicaA);
58+
// RequestMessage request = new RequestMessage("123", 0, "C0");
59+
// Block block = new Block(1, 1, 1, "Block", null);
60+
// ProposalMessage proposal = new ProposalMessage("A", 0, 1, spyReplica.getValidRound(), block);
61+
//
62+
// spyReplica.handleProposal(proposal);
63+
//
64+
// verify(spyReplica, times(1)).handleProposal(proposal);
6565
}
6666
}

0 commit comments

Comments
 (0)