Search in sources :

Example 1 with BftsmartNodeSettings

use of com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings in project jdchain-core by blockchain-jd-com.

the class GatewayQueryServiceHandler method consensusSettingsDecorator.

private ConsensusViewSettings consensusSettingsDecorator(ConsensusViewSettings consensusSettings) {
    if (consensusSettings instanceof BftsmartConsensusViewSettings) {
        // bft-smart单独处理
        BftsmartConsensusViewSettings bftsmartConsensusSettings = (BftsmartConsensusViewSettings) consensusSettings;
        NodeSettings[] nodes = bftsmartConsensusSettings.getNodes();
        BftsmartNodeSettings[] bftsmartNodes = null;
        if (nodes != null && nodes.length > 0) {
            bftsmartNodes = new BftsmartNodeSettings[nodes.length];
            for (int i = 0; i < nodes.length; i++) {
                NodeSettings node = nodes[i];
                if (node instanceof BftsmartNodeSettings) {
                    BftsmartNodeSettings bftsmartNodeSettings = (BftsmartNodeSettings) node;
                    bftsmartNodes[i] = new BftsmartNodeConfig(bftsmartNodeSettings.getPubKey(), bftsmartNodeSettings.getId(), bftsmartNodeSettings.getNetworkAddress());
                }
            }
        }
        return new BftsmartConsensusConfig(bftsmartNodes, bftsmartConsensusSettings.getSystemConfigs(), 0);
    } else if (consensusSettings instanceof RaftConsensusSettings) {
        RaftConsensusSettings raftConsensusSettings = (RaftConsensusSettings) consensusSettings;
        NodeSettings[] nodes = raftConsensusSettings.getNodes();
        RaftNodeSettings[] raftNodeSettings = new RaftNodeSettings[0];
        if (nodes != null && nodes.length > 0) {
            raftNodeSettings = new RaftNodeSettings[nodes.length];
            for (int i = 0; i < nodes.length; i++) {
                NodeSettings node = nodes[i];
                if (node instanceof RaftNodeSettings) {
                    RaftNodeSettings raftNodeSetting = (RaftNodeSettings) node;
                    raftNodeSettings[i] = new RaftNodeConfig(raftNodeSetting.getId(), raftNodeSetting.getAddress(), raftNodeSetting.getPubKey(), raftNodeSetting.getNetworkAddress());
                }
            }
        }
        RaftConsensusConfig raftConsensusConfig = new RaftConsensusConfig();
        RaftConfig raftConfig = new RaftConfig();
        RaftNetworkConfig raftNetworkConfig = new RaftNetworkConfig();
        BeanUtils.copyProperties(raftConsensusSettings, raftConsensusConfig);
        BeanUtils.copyProperties(raftConsensusSettings.getRaftSettings(), raftConfig);
        BeanUtils.copyProperties(raftConsensusSettings.getNetworkSettings(), raftNetworkConfig);
        raftConsensusConfig.setNodeSettingsList(Arrays.asList(raftNodeSettings));
        raftConsensusConfig.setRaftSettings(raftConfig);
        raftConsensusConfig.setNetworkSettings(raftNetworkConfig);
        return raftConsensusConfig;
    } else if (consensusSettings instanceof MsgQueueConsensusSettings) {
        MsgQueueConsensusSettings mqConsensusSettings = (MsgQueueConsensusSettings) consensusSettings;
        MsgQueueConsensusConfig mqConsensusConfig = new MsgQueueConsensusConfig();
        MsgQueueBlockSettings blockSettings = mqConsensusSettings.getBlockSettings();
        MsgQueueBlockConfig mqQueueBlockConfig = new MsgQueueBlockConfig();
        mqQueueBlockConfig.setMaxDelayMilliSecondsPerBlock(blockSettings.getMaxDelayMilliSecondsPerBlock());
        mqQueueBlockConfig.setTxSizePerBlock(blockSettings.getTxSizePerBlock());
        mqConsensusConfig.setBlockSettings(mqQueueBlockConfig);
        MsgQueueNetworkSettings networkSettings = mqConsensusSettings.getNetworkSettings();
        MsgQueueNetworkConfig mqQueueNetworkConfig = new MsgQueueNetworkConfig();
        mqQueueNetworkConfig.setBlockTopic(networkSettings.getBlockTopic());
        mqQueueNetworkConfig.setMsgResultTopic(networkSettings.getMsgResultTopic());
        mqQueueNetworkConfig.setMsgTopic(networkSettings.getMsgTopic());
        mqQueueNetworkConfig.setServer(networkSettings.getServer());
        mqQueueNetworkConfig.setTxTopic(networkSettings.getTxTopic());
        mqQueueNetworkConfig.setTxResultTopic(networkSettings.getTxResultTopic());
        mqConsensusConfig.setNetworkSettings(mqQueueNetworkConfig);
        for (int i = 0; i < mqConsensusSettings.getNodes().length; i++) {
            MsgQueueNodeSettings nodeSettings = (MsgQueueNodeSettings) mqConsensusSettings.getNodes()[i];
            MsgQueueNodeConfig msgQueueNodeConfig = new MsgQueueNodeConfig();
            msgQueueNodeConfig.setAddress(nodeSettings.getAddress());
            msgQueueNodeConfig.setPubKey(nodeSettings.getPubKey());
            msgQueueNodeConfig.setId(nodeSettings.getId());
            mqConsensusConfig.addNodeSettings(msgQueueNodeConfig);
        }
        return mqConsensusConfig;
    }
    return consensusSettings;
}
Also used : BftsmartConsensusViewSettings(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings) RaftNetworkConfig(com.jd.blockchain.consensus.raft.config.RaftNetworkConfig) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) MsgQueueBlockSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings) MsgQueueConsensusConfig(com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig) MsgQueueBlockConfig(com.jd.blockchain.consensus.mq.config.MsgQueueBlockConfig) RaftConsensusSettings(com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings) RaftConsensusConfig(com.jd.blockchain.consensus.raft.config.RaftConsensusConfig) NodeSettings(com.jd.blockchain.consensus.NodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) MsgQueueConsensusSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings) RaftNodeConfig(com.jd.blockchain.consensus.raft.config.RaftNodeConfig) BftsmartConsensusConfig(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig) MsgQueueNodeConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig) MsgQueueNetworkConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig) RaftConfig(com.jd.blockchain.consensus.raft.config.RaftConfig) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) BftsmartNodeConfig(com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig) MsgQueueNetworkSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)

Example 2 with BftsmartNodeSettings

use of com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Bft method createPeerProxy.

private ServiceProxy createPeerProxy(Properties systemConfig, int viewId, List<NodeSettings> origConsensusNodes, SSLSecurity security) {
    HostsConfig hostsConfig;
    List<HostsConfig.Config> configList = new ArrayList<>();
    List<NodeNetwork> nodeAddresses = new ArrayList<>();
    try {
        int[] origConsensusProcesses = new int[origConsensusNodes.size()];
        for (int i = 0; i < origConsensusNodes.size(); i++) {
            BftsmartNodeSettings node = (BftsmartNodeSettings) origConsensusNodes.get(i);
            origConsensusProcesses[i] = node.getId();
            configList.add(new HostsConfig.Config(node.getId(), node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
            nodeAddresses.add(new NodeNetwork(node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
        }
        // 构建共识的代理客户端需要的主机配置和系统参数配置结构
        hostsConfig = new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()]));
        Properties tempSystemConfig = (Properties) systemConfig.clone();
        // 构建tom 配置
        TOMConfiguration tomConfig = new TOMConfiguration(-(new Random().nextInt(Integer.MAX_VALUE - 2) - 1), tempSystemConfig, hostsConfig);
        View view = new View(viewId, origConsensusProcesses, tomConfig.getF(), nodeAddresses.toArray(new NodeNetwork[nodeAddresses.size()]));
        LOGGER.info("ManagementController start updateView operation!, current view : {}", view.toString());
        // 构建共识的代理客户端,连接目标共识节点,并递交交易进行共识过程
        return new ServiceProxy(tomConfig, new MemoryBasedViewStorage(view), null, null, security);
    } catch (Exception e) {
        throw new CreateProxyClientException("create proxy client exception!");
    }
}
Also used : BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) ArrayList(java.util.ArrayList) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) Properties(java.util.Properties) View(bftsmart.reconfiguration.views.View) Random(java.util.Random) ServiceProxy(bftsmart.tom.ServiceProxy) MemoryBasedViewStorage(bftsmart.reconfiguration.views.MemoryBasedViewStorage) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork) TOMConfiguration(bftsmart.reconfiguration.util.TOMConfiguration)

Example 3 with BftsmartNodeSettings

use of com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings in project jdchain-core by blockchain-jd-com.

the class ProxyClientTest method peerStart.

public void peerStart(BftsmartNodeServer[] nodeServers) {
    BftsmartNodeSettings[] nodesSettings = new BftsmartNodeSettings[nodeNum];
    for (int i = 0; i < nodeNum; i++) {
        BlockchainKeypair keyPair = BlockchainKeyGenerator.getInstance().generate();
        PubKey pubKey = keyPair.getPubKey();
        NetworkAddress peerNodeServ = new NetworkAddress("127.0.0.1", peerStartPort + i * 10);
        NodeSettings node = new BftsmartNodeConfig(pubKey, i, peerNodeServ);
        nodesSettings[i] = (BftsmartNodeSettings) node;
    }
    BftsmartConsensusConfig consensusConfig = new BftsmartConsensusConfig(nodesSettings, PropertiesUtils.getOrderedValues(bftsmartConf), 0);
    for (int j = 0; j < nodeNum; j++) {
        BftsmartServerSettingConfig serverSettings = new BftsmartServerSettingConfig();
        serverSettings.setReplicaSettings(nodesSettings[j]);
        serverSettings.setConsensusSettings(consensusConfig);
        BftsmartNodeServer server = new BftsmartNodeServer(serverSettings, null, null, new MemoryStorage("test"));
        nodeServers[j] = server;
        nodeStartPools.execute(() -> {
            server.start();
            startPeer.countDown();
        });
    }
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) BftsmartServerSettingConfig(com.jd.blockchain.consensus.bftsmart.service.BftsmartServerSettingConfig) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) NetworkAddress(utils.net.NetworkAddress) BftsmartConsensusConfig(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig) BlockchainKeypair(com.jd.blockchain.ledger.BlockchainKeypair) BftsmartNodeConfig(com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig) BftsmartNodeServer(com.jd.blockchain.consensus.bftsmart.service.BftsmartNodeServer) MemoryStorage(utils.io.MemoryStorage)

Example 4 with BftsmartNodeSettings

use of com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings in project jdchain-core by blockchain-jd-com.

the class BftsmartCommunication method getSession.

private synchronized NodeSession getSession(String target, boolean created) {
    BftsmartNodeSession session = targetSessions.get(target);
    if (session != null) {
        return session;
    }
    if (created) {
        BftsmartNodeSettings targetNodeSetting = null;
        BftsmartConsensusViewSettings viewSettings = serverSettings.getConsensusSettings();
        NodeSettings[] nodeSettings = viewSettings.getNodes();
        for (NodeSettings ns : nodeSettings) {
            if (ns.getAddress().equals(target)) {
                targetNodeSetting = (BftsmartNodeSettings) ns;
            }
        }
        if (targetNodeSetting == null) {
            return null;
        }
        session = new BftsmartNodeSession(serverSettings.getReplicaSettings().getAddress(), targetNodeSetting.getId(), target);
        targetSessions.put(target, session);
        return session;
    }
    return null;
}
Also used : BftsmartConsensusViewSettings(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings) NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)

Example 5 with BftsmartNodeSettings

use of com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings in project jdchain-core by blockchain-jd-com.

the class BftsmartNodeServer method createConfig.

protected void createConfig() {
    setting = ((BftsmartServerSettings) serverSettings).getConsensusSettings();
    List<HostsConfig.Config> configList = new ArrayList<>();
    NodeSettings[] nodeSettingsArray = setting.getNodes();
    for (NodeSettings nodeSettings : nodeSettingsArray) {
        BftsmartNodeSettings node = (BftsmartNodeSettings) nodeSettings;
        if (node.getId() > MAX_SERVER_ID) {
            // 节点 ID 不允许超过最大值;
            throw new IllegalArgumentException(String.format("The id of node[%s | %s | %s] is large than MAX_SERVER_ID[%s]!", node.getId(), node.getAddress(), node.getNetworkAddress(), MAX_SERVER_ID));
        }
        LOGGER.info("createConfig node id = {}, port = {}", node.getId(), node.getNetworkAddress().getPort());
        configList.add(new HostsConfig.Config(node.getId(), node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
        consensusAddresses.put(node.getId(), new NodeNetwork(node.getNetworkAddress().getHost(), node.getNetworkAddress().getPort(), -1, node.getNetworkAddress().isSecure(), false));
    }
    // create HostsConfig instance based on consensus realm nodes
    hostsConfig = new HostsConfig(configList.toArray(new HostsConfig.Config[configList.size()]));
    systemConfig = PropertiesUtils.createProperties(setting.getSystemConfigs());
    return;
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) BftsmartNodeSettings(com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) ArrayList(java.util.ArrayList) HostsConfig(bftsmart.reconfiguration.util.HostsConfig) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork)

Aggregations

BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)6 NodeSettings (com.jd.blockchain.consensus.NodeSettings)5 HostsConfig (bftsmart.reconfiguration.util.HostsConfig)2 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)2 BftsmartConsensusConfig (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig)2 BftsmartConsensusViewSettings (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings)2 BftsmartNodeConfig (com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig)2 ArrayList (java.util.ArrayList)2 NetworkAddress (utils.net.NetworkAddress)2 TOMConfiguration (bftsmart.reconfiguration.util.TOMConfiguration)1 MemoryBasedViewStorage (bftsmart.reconfiguration.views.MemoryBasedViewStorage)1 View (bftsmart.reconfiguration.views.View)1 ServiceProxy (bftsmart.tom.ServiceProxy)1 BftsmartNodeServer (com.jd.blockchain.consensus.bftsmart.service.BftsmartNodeServer)1 BftsmartServerSettingConfig (com.jd.blockchain.consensus.bftsmart.service.BftsmartServerSettingConfig)1 MsgQueueBlockConfig (com.jd.blockchain.consensus.mq.config.MsgQueueBlockConfig)1 MsgQueueConsensusConfig (com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig)1 MsgQueueNetworkConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNetworkConfig)1 MsgQueueNodeConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig)1 MsgQueueBlockSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings)1