Skip to content

Commit 107ce5b

Browse files
committed
fix build
1 parent f333b33 commit 107ce5b

8 files changed

+163
-153
lines changed

simulator/src/main/java/byzzbench/simulator/HbftClient.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,39 @@ public class HbftClient extends Client {
7171
*/
7272
@Override
7373
public void sendRequest() {
74-
String requestId = String.format("%s/%d", super.id, super.requestSequenceNumber.incrementAndGet());
74+
String requestId = String.format("%s/%d", getId(), getRequestSequenceNumber().incrementAndGet());
7575
long timestamp = this.getCurrentTime().toEpochMilli();
76-
RequestMessage request = new RequestMessage(requestId, timestamp, super.id);
77-
this.sentRequests.put(super.requestSequenceNumber.get(), request);
76+
RequestMessage request = new RequestMessage(requestId, timestamp, getId());
77+
this.sentRequests.put(getRequestSequenceNumber().get(), request);
7878
this.sentRequestsByTimestamp.put(timestamp, requestId);
7979
this.broadcastRequest(timestamp, requestId);
8080

8181
// Set timeout
8282
Long timeoutId = this.setTimeout("REQUEST", this::retransmitOrPanic, this.timeout);
83-
timeouts.put(super.requestSequenceNumber.get(), timeoutId);
83+
timeouts.put(getRequestSequenceNumber().get(), timeoutId);
8484
}
8585

8686
public void retransmitOrPanic() {
87-
long tolerance = (long) Math.floor((super.scenario.getTransport().getNodeIds().size() - 1) / 3);
87+
long tolerance = (long) Math.floor((getScenario().getTransport().getNodeIds().size() - 1) / 3);
8888
if (this.shouldRetransmit(tolerance)) {
89-
String requestId = String.format("%s/%d", super.id, super.requestSequenceNumber.get());
89+
String requestId = String.format("%s/%d", getId(), getRequestSequenceNumber().get());
9090
// Based on hBFT 4.1 it uses the identical request
9191
// TODO: It probably should not be the same timestamp
92-
long timestamp = this.sentRequests.get(super.requestSequenceNumber.get()).getTimestamp();
92+
long timestamp = this.sentRequests.get(getRequestSequenceNumber().get()).getTimestamp();
9393
this.broadcastRequest(timestamp, requestId);
9494
} else if (this.shouldPanic(tolerance)) {
95-
RequestMessage message = this.sentRequests.get(super.requestSequenceNumber.get());
96-
PanicMessage panic = new PanicMessage(this.digest(message), this.getCurrentTime().toEpochMilli(), super.id);
97-
super.scenario.getTransport().multicast(this, super.scenario.getTransport().getNodeIds(), panic);
95+
RequestMessage message = this.sentRequests.get(getRequestSequenceNumber().get());
96+
PanicMessage panic = new PanicMessage(this.digest(message), this.getCurrentTime().toEpochMilli(), getId());
97+
getScenario().getTransport().multicast(this, getScenario().getTransport().getNodeIds(), panic);
9898
}
99-
this.clearTimeout(timeouts.get(super.requestSequenceNumber.get()));
99+
this.clearTimeout(timeouts.get(getRequestSequenceNumber().get()));
100100
Long timeoutId = this.setTimeout("REQUEST", this::retransmitOrPanic, this.timeout);
101-
timeouts.put(super.requestSequenceNumber.get(), timeoutId);
101+
timeouts.put(getRequestSequenceNumber().get(), timeoutId);
102102
}
103103

104104
private void broadcastRequest(long timestamp, String requestId) {
105105
MessagePayload payload = new ClientRequestMessage(timestamp, requestId);
106-
SortedSet<String> replicaIds = super.scenario.getTransport().getNodeIds();
106+
SortedSet<String> replicaIds = getScenario().getTransport().getNodeIds();
107107
getScenario().getTransport().multicast(this, replicaIds, payload);
108108
}
109109

@@ -131,9 +131,9 @@ public void handleMessage(String senderId, MessagePayload payload) {
131131
*/
132132
if (this.completedReplies(clientReplyMessage.getTolerance())
133133
&& !this.completedRequests.contains(key)
134-
&& super.requestSequenceNumber.get() <= this.maxRequests) {
134+
&& getRequestSequenceNumber().get() <= getMaxRequests()) {
135135
this.completedRequests.add(key);
136-
this.clearTimeout(this.timeouts.get(super.requestSequenceNumber.get()));
136+
this.clearTimeout(this.timeouts.get(getRequestSequenceNumber().get()));
137137
this.sendRequest();
138138
}
139139
}
@@ -148,15 +148,15 @@ public void handleMessage(String senderId, MessagePayload payload) {
148148
*/
149149
public long setTimeout(String name, Runnable r, long timeout) {
150150
Duration duration = Duration.ofSeconds(timeout);
151-
return super.scenario.getTransport().setTimeout(this, r, duration, name);
151+
return getScenario().getTransport().setTimeout(this, r, duration, name);
152152
}
153153

154154
/**
155155
* Checks whether client should retransmit the request
156156
* if #replies < f + 1
157157
*/
158158
public boolean shouldRetransmit(long tolerance) {
159-
String currRequest = String.format("%s/%d", super.id, super.requestSequenceNumber.get());
159+
String currRequest = String.format("%s/%d", getId(), getRequestSequenceNumber().get());
160160
if (!hbftreplies.containsKey(currRequest)) {
161161
return true;
162162
}
@@ -171,7 +171,7 @@ public boolean shouldRetransmit(long tolerance) {
171171
* if f + 1 <= #replies < 2f + 1
172172
*/
173173
public boolean shouldPanic(long tolerance) {
174-
String currRequest = String.format("%s/%d", super.id, super.requestSequenceNumber.get());
174+
String currRequest = String.format("%s/%d", getId(), getRequestSequenceNumber().get());
175175
for (ClientReplyKey key : hbftreplies.get(currRequest).keySet()) {
176176
return this.hbftreplies.get(currRequest).get(key).size() >= tolerance + 1
177177
&& this.hbftreplies.get(currRequest).get(key).size() < tolerance * 2 + 1;
@@ -183,7 +183,7 @@ public boolean shouldPanic(long tolerance) {
183183
* Checks whether it has received 2f + 1 replies
184184
*/
185185
public boolean completedReplies(long tolerance) {
186-
String currRequest = String.format("%s/%d", super.id, super.requestSequenceNumber.get());
186+
String currRequest = String.format("%s/%d", getId(), getRequestSequenceNumber().get());
187187
if (!hbftreplies.containsKey(currRequest)) {
188188
return false;
189189
}
@@ -199,7 +199,7 @@ public boolean completedReplies(long tolerance) {
199199
* Clear all timeouts for this client.
200200
*/
201201
// public void clearAllTimeouts() {
202-
// super.scenario.getTransport().clearClientTimeouts(super.id);
202+
// getScenario.getTransport().clearClientTimeouts(getId());
203203
// }
204204

205205
/**

simulator/src/main/java/byzzbench/simulator/protocols/fab/FastByzantineClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void sendRequest(String senderId) {
9696
String command = String.format("%s/%d", this.getId(), sequenceNumber);
9797
// TODO: compute the digest
9898
RequestMessage request = new RequestMessage(this.getId(), sequenceNumber, "-1", command);
99-
this.getScenario().getTransport().sendClientRequest(this.getId(), request, senderId);
99+
this.getScenario().getTransport().sendMessage(this, request, senderId);
100100
}
101101

102102
@Override

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

+51-42
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,41 @@
2323
@Log
2424
@Getter
2525
public class FastByzantineReplica extends LeaderBasedProtocolReplica {
26+
// The number of replicas in the system with each role.
27+
private final int p, a, l, f;
28+
// Timeout until the proposer replica starts suspecting the leader for the lack of progress.
29+
private final long messageTimeoutDuration;
30+
@JsonIgnore
31+
private final Transport transport;
32+
// Current client ID that the system is communicating with.
33+
private final String clientId;
34+
/**
35+
* The log of received messages for the replica.
36+
*/
37+
@JsonIgnore
38+
private final MessageLog messageLog;
2639
// In the "Fast Byzantine Consensus" protocol, a replica can have one or more roles.
2740
// The possible roles are : PROPOSER, ACCEPTOR, LEARNER.
2841
// The required number of replicas with each role is:
2942
// p ( proposers ) = 3 * f + 1, a ( acceptors ) = 5 * f + 1, l ( learners ) = 3 * f + 1.
3043
private List<Role> roles = new ArrayList<>();
31-
32-
// The number of replicas in the system with each role.
33-
private final int p, a, l, f;
3444
// The message round number.
3545
private long viewNumber;
3646
private long proposalNumber;
3747
// The value that the leader replica is proposing - changes each round, depending on the client request.
3848
private byte[] proposedValue;
3949
// The progress certificate for the current view.
4050
private ProgressCertificate pc;
41-
// Timeout until the proposer replica starts suspecting the leader for the lack of progress.
42-
private final long messageTimeoutDuration;
4351
// Current leader.
4452
@Setter
4553
private String leaderId;
4654
@Setter
4755
private boolean isCurrentlyLeader;
48-
4956
// The set of node IDs in the system for each role.
5057
private SortedSet<String> acceptorNodeIds = new TreeSet<>();
5158
private SortedSet<String> learnerNodeIds = new TreeSet<>();
52-
private SortedSet<String> proposerNodeIds = new TreeSet<>();;
53-
private SortedSet<String> nodeIds = new TreeSet<>();;
54-
55-
@JsonIgnore
56-
private final Transport transport;
57-
58-
// Current client ID that the system is communicating with.
59-
private String clientId;
60-
59+
private SortedSet<String> proposerNodeIds = new TreeSet<>();
60+
private SortedSet<String> nodeIds = new TreeSet<>();
6161
private boolean isSatisfied;
6262
// Keep track of the timeouts set by the replica.
6363
private long learnerTimeoutId = -1;
@@ -67,11 +67,6 @@ public class FastByzantineReplica extends LeaderBasedProtocolReplica {
6767
@Setter
6868
private boolean isRecovered;
6969
private int forwards;
70-
/**
71-
* The log of received messages for the replica.
72-
*/
73-
@JsonIgnore
74-
private MessageLog messageLog;
7570
private boolean committed;
7671
private byte[] operation;
7772
private long viewChangeRequests = 0;
@@ -188,15 +183,16 @@ private void leaderOnStart(ProposeMessage proposeMessage) {
188183
private void proposerOnStart() {
189184
int learnedThreshold = (int) Math.ceil((l + f + 1) / 2.0);
190185

191-
this.proposerTimeoutId = this.setTimeout(
192-
"proposer-timeout",
193-
() -> {
194-
if (!messageLog.proposerHasLearned(learnedThreshold)) {
195-
log.warning("Leader suspected by proposer " + getId());
196-
broadcastMessageIncludingSelf(new SuspectMessage(getId(), this.leaderId, this.viewNumber));
197-
}
198-
}, Duration.ofMillis(messageTimeoutDuration));
186+
this.proposerTimeoutId = this.setTimeout(
187+
"proposer-timeout",
188+
() -> {
189+
if (!messageLog.proposerHasLearned(learnedThreshold)) {
190+
log.warning("Leader suspected by proposer " + getId());
191+
broadcastMessageIncludingSelf(new SuspectMessage(getId(), this.leaderId, this.viewNumber));
192+
}
193+
}, Duration.ofMillis(messageTimeoutDuration));
199194
}
195+
200196
/**
201197
* Learner replica starts by awaiting to learn a value.
202198
* If it has not learned any value after waiting, send a PULL message to all other LEARNER replicas.
@@ -218,10 +214,10 @@ private void learnerOnStart() {
218214

219215
/**
220216
* Handle a client request received by the replica.
217+
*
221218
* @param clientId the ID of the client
222219
* @param request the request payload
223220
*/
224-
@Override
225221
public void handleClientRequest(String clientId, Serializable request) throws UnsupportedOperationException {
226222
// If the client request is not send to the leader, forward it to the leader.
227223
if (!isLeader()) {
@@ -302,7 +298,8 @@ private void handleForwardClientRequest(String sender, ForwardClientRequest forw
302298

303299
/**
304300
* Handle a PROPOSE message send by a replica with Proposer role, who is the leader, received by all Acceptor replicas.
305-
* @param sender : the nodeId of the sender (the current leader)
301+
*
302+
* @param sender : the nodeId of the sender (the current leader)
306303
* @param proposeMessage : the PROPOSE message with the proposed value and round number
307304
*/
308305
private void handleProposeMessage(String sender, ProposeMessage proposeMessage) {
@@ -320,7 +317,8 @@ private void handleProposeMessage(String sender, ProposeMessage proposeMessage)
320317

321318
/**
322319
* Handle an ACCEPT message sent by an Acceptor replica, received by a Learner replica.
323-
* @param sender : the nodeId of the sender (an Acceptor replica)
320+
*
321+
* @param sender : the nodeId of the sender (an Acceptor replica)
324322
* @param acceptMessage : the ACCEPT message with the value and proposal number
325323
*/
326324
private void handleAcceptMessage(String sender, AcceptMessage acceptMessage) {
@@ -354,7 +352,8 @@ private void handleAcceptMessage(String sender, AcceptMessage acceptMessage) {
354352

355353
/**
356354
* Handle a LEARN message sent by a Proposer replica, received by a Proposer replica.
357-
* @param sender : the nodeId of the sender (a Learner replica)
355+
*
356+
* @param sender : the nodeId of the sender (a Learner replica)
358357
* @param learnMessage : the LEARN message with the value and proposal number
359358
*/
360359
private void handleLearnMessageProposer(String sender, LearnMessage learnMessage) {
@@ -390,7 +389,8 @@ private void handleLearnMessageProposer(String sender, LearnMessage learnMessage
390389

391390
/**
392391
* Handle a LEARN message sent by a Learner replica, received by a Learner replica.
393-
* @param sender : the nodeId of the sender (a Learner replica)
392+
*
393+
* @param sender : the nodeId of the sender (a Learner replica)
394394
* @param learnMessage : the LEARN message with the value and proposal number
395395
*/
396396
private void handleLearnMessageLearner(String sender, LearnMessage learnMessage) {
@@ -428,7 +428,8 @@ private void handleLearnMessageLearner(String sender, LearnMessage learnMessage)
428428

429429
/**
430430
* Handle a SATISFIED message received by a Proposer replica.
431-
* @param sender : the nodeId of the sender (a Proposer replica)
431+
*
432+
* @param sender : the nodeId of the sender (a Proposer replica)
432433
* @param satisfiedMessage : the SATISFIED message with the value and proposal number
433434
*/
434435
private void handleSatisfiedMessage(String sender, SatisfiedMessage satisfiedMessage) {
@@ -466,7 +467,8 @@ private void handleSatisfiedMessage(String sender, SatisfiedMessage satisfiedMes
466467
/**
467468
* Handle a QUERY message received by an Acceptor replica.
468469
* This message is sent after a new leader has been elected.
469-
* @param sender : the nodeId of the sender (the new leader)
470+
*
471+
* @param sender : the nodeId of the sender (the new leader)
470472
* @param queryMessage : the QUERY message with the view number and progress certificate
471473
*/
472474
private void handleQueryMessage(String sender, QueryMessage queryMessage) {
@@ -494,7 +496,8 @@ private void handleQueryMessage(String sender, QueryMessage queryMessage) {
494496

495497
/**
496498
* Handle a PULL message received by a Learner replica. Should send the learned value, if any.
497-
* @param sender : the nodeId of the sender (a Learner replica)
499+
*
500+
* @param sender : the nodeId of the sender (a Learner replica)
498501
* @param pullMessage : the PULL message
499502
*/
500503
private void handlePullMessage(String sender, PullMessage pullMessage) {
@@ -515,7 +518,8 @@ private void handlePullMessage(String sender, PullMessage pullMessage) {
515518

516519
/**
517520
* Handle a SUSPECT message received by a replica.
518-
* @param sender : the nodeId of the sender (a replica that suspects the leader)
521+
*
522+
* @param sender : the nodeId of the sender (a replica that suspects the leader)
519523
* @param suspectMessage : the SUSPECT message with the nodeId of the suspected leader
520524
*/
521525
private void handleSuspectMessage(String sender, SuspectMessage suspectMessage) {
@@ -535,7 +539,8 @@ private void handleSuspectMessage(String sender, SuspectMessage suspectMessage)
535539

536540
/**
537541
* Handle a REPLY message received by the leader replica.
538-
* @param sender : the nodeId of the sender (an Acceptor replica which was queried)
542+
*
543+
* @param sender : the nodeId of the sender (an Acceptor replica which was queried)
539544
* @param replyMessage : the REPLY message with the value and round number of the previous round
540545
*/
541546
public void handleReplyMessage(String sender, ReplyMessage replyMessage) {
@@ -579,7 +584,8 @@ public void handleReplyMessage(String sender, ReplyMessage replyMessage) {
579584
* Handle a VIEW_CHANGE message received by a replica.
580585
* This is used to update the view number and leader ID sent to all the other replicas
581586
* after a replica elected a new leader.
582-
* @param sender : the nodeId of the sender (the replica that elected a new leader)
587+
*
588+
* @param sender : the nodeId of the sender (the replica that elected a new leader)
583589
* @param viewChangeMessage : the VIEW_CHANGE message with the new view number and leader ID
584590
*/
585591
private void handleViewChangeMessage(String sender, ViewChangeMessage viewChangeMessage) {
@@ -695,9 +701,10 @@ private String getNewLeader() {
695701

696702
/**
697703
* Move replica to the next view number and reset the replica.
704+
*
698705
* @param newViewNumber : the new view number
699-
* @param sender : the nodeId of the sender that triggered the reset
700-
* @param message : the message that caused the reset
706+
* @param sender : the nodeId of the sender that triggered the reset
707+
* @param message : the message that caused the reset
701708
*/
702709
public void reset(long newViewNumber, String sender, MessagePayload message) {
703710
// Since we are resetting the replica, previous timeouts should be cleared
@@ -715,7 +722,9 @@ public void reset(long newViewNumber, String sender, MessagePayload message) {
715722
onStart();
716723
}
717724

718-
/** Methods for checking the roles of the replica. **/
725+
/**
726+
* Methods for checking the roles of the replica.
727+
**/
719728
private boolean isAcceptor() {
720729
return this.roles.contains(Role.ACCEPTOR);
721730
}

0 commit comments

Comments
 (0)