Search in sources :

Example 1 with Reconfiguration

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;
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) BftsmartServiceProxyPool(com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool) BftsmartReplica(com.jd.blockchain.consensus.bftsmart.BftsmartReplica) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Example 2 with Reconfiguration

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);
    }
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) ServiceProxy(bftsmart.tom.ServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Example 3 with Reconfiguration

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;
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) BftsmartServiceProxyPool(com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Aggregations

Reconfiguration (bftsmart.reconfiguration.Reconfiguration)3 ReconfigureReply (bftsmart.reconfiguration.ReconfigureReply)3 AsynchServiceProxy (bftsmart.tom.AsynchServiceProxy)2 BftsmartServiceProxyPool (com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool)2 ConsensusView (com.jd.blockchain.consensus.manage.ConsensusView)2 CompletableAsyncFuture (utils.concurrent.CompletableAsyncFuture)2 ServiceProxy (bftsmart.tom.ServiceProxy)1 BftsmartReplica (com.jd.blockchain.consensus.bftsmart.BftsmartReplica)1