use of bftsmart.reconfiguration.Reconfiguration in project jdchain-core by blockchain-jd-com.
the class BftsmartConsensusManageService method addNode.
@Override
public AsyncFuture<ConsensusView> addNode(Replica replica) {
BftsmartServiceProxyPool serviceProxyPool = getServiceProxyPool();
BftsmartReplica bftsmartReplica = (BftsmartReplica) replica;
CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
AsynchServiceProxy serviceProxy = null;
try {
serviceProxy = serviceProxyPool.borrowObject();
Reconfiguration reconfiguration = new Reconfiguration(serviceProxy.getProcessId(), serviceProxy);
reconfiguration.addServer(bftsmartReplica.getId(), bftsmartReplica.getNetworkAddress());
ReconfigureReply reply = reconfiguration.execute();
asyncFuture.complete(new BftsmartView(reply.getView()));
} catch (Exception e) {
asyncFuture.error(e);
} finally {
if (serviceProxy != null) {
serviceProxyPool.returnObject(serviceProxy);
}
}
return asyncFuture;
}
use of bftsmart.reconfiguration.Reconfiguration in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Bft method updateView.
// 通知原有的共识网络更新共识的视图ID
private View updateView(ParticipantNode node, NetworkAddress networkAddress, SSLSecurity security, ManagementController.ParticipantUpdateType participantUpdateType, Properties systemConfig, int viewId, List<NodeSettings> origConsensusNodes) {
LOGGER.info("ManagementController start updateView operation!");
TransactionRequest reconfigRequest = null;
try {
ServiceProxy peerProxy = createPeerProxy(systemConfig, viewId, origConsensusNodes, security);
Reconfiguration reconfiguration = new Reconfiguration(peerProxy.getProcessId(), peerProxy);
if (participantUpdateType == ManagementController.ParticipantUpdateType.ACTIVE) {
// addServer的第一个参数指待加入共识的新参与方的编号
reconfiguration.addServer(node.getId(), networkAddress);
reconfigRequest = prepareReconfigTx("active");
} else if (participantUpdateType == ManagementController.ParticipantUpdateType.DEACTIVE) {
// 参数为待移除共识节点的id
reconfiguration.removeServer(node.getId());
reconfigRequest = prepareReconfigTx("deactive");
} else if (participantUpdateType == ManagementController.ParticipantUpdateType.UPDATE) {
// 共识参数修改,先移除后添加
reconfiguration.removeServer(node.getId());
reconfiguration.addServer(node.getId(), networkAddress);
reconfigRequest = prepareReconfigTx("update");
} else {
throw new IllegalArgumentException("op type error!");
}
// 把交易作为reconfig操作的扩展信息携带,目的是为了让该操作上链,便于后续跟踪;
reconfiguration.addExtendInfo(BinaryProtocol.encode(reconfigRequest, TransactionRequest.class));
// 执行更新目标共识网络的视图ID
ReconfigureReply reconfigureReply = reconfiguration.execute();
peerProxy.close();
// 返回新视图
return reconfigureReply.getView();
} catch (Exception e) {
throw new ViewUpdateException("view update fail exception!", e);
}
}
use of bftsmart.reconfiguration.Reconfiguration in project jdchain-core by blockchain-jd-com.
the class BftsmartConsensusManageService method removeNode.
@Override
public AsyncFuture<ConsensusView> removeNode(Replica replica) {
BftsmartServiceProxyPool serviceProxyPool = getServiceProxyPool();
CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
AsynchServiceProxy serviceProxy = null;
try {
serviceProxy = serviceProxyPool.borrowObject();
Reconfiguration reconfiguration = new Reconfiguration(serviceProxy.getProcessId(), serviceProxy);
reconfiguration.removeServer(replica.getId());
ReconfigureReply reply = reconfiguration.execute();
asyncFuture.complete(new BftsmartView(reply.getView()));
} catch (Exception e) {
asyncFuture.error(e);
} finally {
if (serviceProxy != null) {
serviceProxyPool.returnObject(serviceProxy);
}
}
return asyncFuture;
}
Aggregations