Skip to content

Commit

Permalink
Some minor changes in requesting decisions
Browse files Browse the repository at this point in the history
  • Loading branch information
bergerch committed Apr 23, 2024
1 parent 5307923 commit 313d10f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
18 changes: 10 additions & 8 deletions src/main/java/bftsmart/consensus/roles/Acceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void forwardDecision(Epoch epoch) {
ConsensusMessage forwardDecision = factory.createForwardDecision(cid, epoch.getTimestamp(), value);
forwardDecision.setProof(epoch.getProof());

logger.debug("Attaching proof for forwarded decision: " + cid + " | " + value + " | " + forwardDecision.getProof());
logger.info("Attaching proof for forwarded decision: " + cid + " | " + value + " | " + forwardDecision.getProof());

// Forward to all targets.
communication.send(targets, forwardDecision);
Expand Down Expand Up @@ -494,7 +494,8 @@ private void broadcastDecision(Epoch epoch) {

logger.debug("Attaching proof for forwarded decision: " + cid + " | " + value + " | " + forwardDecision.getProof());

communication.send(controller.getCurrentViewAcceptors(), forwardDecision);
communication.send(controller.getReplicasWithout(controller.getCurrentViewOtherAcceptors(),
executionManager.getCurrentLeader()), forwardDecision);
}


Expand All @@ -507,6 +508,7 @@ private void broadcastDecision(Epoch epoch) {
* @param value epoch.propValueHash
*/
public void sendRequestDecision(Epoch epoch, int cid, int[] receivers, byte[] value) {
logger.info("Send a REQ_DECISION message in cid " + cid);
communication.send(receivers, factory.createRequestDecision(cid, epoch.getTimestamp(), value));
}

Expand All @@ -519,17 +521,17 @@ public void sendRequestDecision(Epoch epoch, int cid, int[] receivers, byte[] va
private void requestDecisionReceived(Epoch epoch, ConsensusMessage msg) {
int cid = epoch.getConsensus().getId();

logger.debug(">>>>>>> Received REQ_DECISION from " + msg.getSender() + " for consensus " + cid);
logger.info(">>>>>>> Received REQ_DECISION from " + msg.getSender() + " for consensus " + cid);

// Check if consensus cid is already decided
// if it is, we can directly forward the decision to the requester
if (epoch.getConsensus().isDecided()) {
logger.debug(">>> >> >> > Consensus " + cid + " is already decided ");
logger.info(">>> >> >> > Consensus " + cid + " is already decided ");
Decision decision = epoch.getConsensus().getDecision();

// Dont forward a decision twice for the same requester in the same consensus instance
if ( !executionManager.hasBeenForwardedAlready(msg.getEpoch(), msg.getSender())) {
logger.debug(">>> >> >> >> > Send FWD_DECISION for epoch " + epoch.getTimestamp() + " to replica " + msg.getSender());
logger.info(">>> >> >> >> > Send FWD_DECISION for epoch " + epoch.getTimestamp() + " to replica " + msg.getSender());

byte[] value = decision.getValue();
int[] targets = new int[1];
Expand All @@ -549,11 +551,11 @@ private void requestDecisionReceived(Epoch epoch, ConsensusMessage msg) {

logger.warn("decision request is too old to handle (decision has been garbage collected) and will be ignored");
} else {
logger.debug(">>> >> >> > Consensus " + cid +
logger.info(">>> >> >> > Consensus " + cid +
" is still undecided remembering replica " + msg.getSender() + " to be forwarded to after deciding");

// Consensus still undecided, remember to forward decision
logger.debug("Remember cid for addToForward " + msg.getEpoch());
logger.info("Remember cid for addToForward " + msg.getEpoch());
executionManager.addToForward(msg.getNumber(), msg.getSender());
}
}
Expand All @@ -567,7 +569,7 @@ private void requestDecisionReceived(Epoch epoch, ConsensusMessage msg) {
*/
private void forwardDecisionReceived(Epoch epoch, ConsensusMessage msg) {
int cid = epoch.getConsensus().getId();
logger.debug(">>>>>>> Received FWD_DECISION from " + msg.getSender() + " for consensus " + cid);
logger.info(">>>>>>> Received FWD_DECISION from " + msg.getSender() + " for consensus " + cid);

// Use proof to Check if decision is valid
boolean decisionIsValid = verifyDecision(msg);
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/bftsmart/reconfiguration/ServerViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
package bftsmart.reconfiguration;

import java.net.InetSocketAddress;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.*;

import bftsmart.reconfiguration.views.View;
import bftsmart.tom.core.TOMLayer;
import bftsmart.tom.core.messages.TOMMessage;
import bftsmart.tom.util.KeyLoader;
import bftsmart.tom.util.TOMUtil;
import java.security.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -98,6 +94,20 @@ public boolean isInCurrentView() {
public int[] getCurrentViewOtherAcceptors() {
return this.otherProcesses;
}
public int[] getReplicasWithout(int[] replicas, int without) {
int index = -1;
for (int i = 0; i < replicas.length; i++) {
if (replicas[i] == without) {
index = i;
break;
}
}
if (index != -1) {
System.arraycopy(replicas, index + 1, replicas, index, replicas.length - index - 1);
replicas = Arrays.copyOfRange(replicas, 0, replicas.length - 1);
}
return replicas;
}

public int[] getCurrentViewAcceptors() {
return this.currentView.getProcesses();
Expand Down
44 changes: 34 additions & 10 deletions src/main/java/bftsmart/tom/core/ExecutionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@

import bftsmart.consensus.Consensus;
import bftsmart.consensus.Epoch;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.TreeMap;

import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.ArrayList;

import bftsmart.consensus.Decision;
import bftsmart.consensus.messages.MessageFactory;
Expand Down Expand Up @@ -323,7 +316,38 @@ public final boolean checkLimits(ConsensusMessage msg) {
int[] requestDecisionFrom = checkRequestDecision(epoch, msg);

if (requestDecisionFrom != null) {

acceptor.sendRequestDecision(epoch, msg.getNumber(), requestDecisionFrom, epoch.propValueHash);
/*
Thread t1 = new Thread() {
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
System.out.println("RequestDecision Thread Interrupted");
}
int[] requestDecisionFrom = checkRequestDecision(epoch, msg);
if (requestDecisionFrom != null) {
acceptor.sendRequestDecision(epoch, msg.getNumber(), requestDecisionFrom, epoch.propValueHash);
}
}
};
t1.start();
/*
TimerTask requestDecisionTask = new TimerTask() {
public void run() {
int[] requestDecisionFrom = checkRequestDecision(epoch, msg);
if (requestDecisionFrom != null) {
acceptor.sendRequestDecision(epoch, msg.getNumber(), requestDecisionFrom, epoch.propValueHash);
}
}
};
Timer timer = new Timer("RequestDecision");
timer.schedule(requestDecisionTask, 10);
*/

}

}
Expand Down Expand Up @@ -673,7 +697,7 @@ public int[] checkRequestDecision(Epoch epoch, ConsensusMessage message) {
/******* END OUTOFCONTEXT CRITICAL SECTION *******/
outOfContextLock.unlock();

return requestDecision ? controller.getCurrentViewOtherAcceptors() : null;
return requestDecision ? controller.getReplicasWithout(controller.getCurrentViewOtherAcceptors(), getCurrentLeader()) : null;
}


Expand Down

0 comments on commit 313d10f

Please sign in to comment.