Search in sources :

Example 6 with NodeSettings

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

the class RaftConsensusSettingsBuilder method convertToProperties.

@Override
public Properties convertToProperties(ConsensusViewSettings settings) {
    if (!(settings instanceof RaftConsensusSettings)) {
        throw new IllegalStateException("settings should be raft-consensus-settings type");
    }
    Properties properties = new Properties();
    RaftConsensusConfig raftConsensusConfig = new RaftConsensusConfig((RaftConsensusSettings) settings);
    PropertiesUtils.mergeFrom(properties, raftConsensusConfig.convert());
    for (NodeSettings nodeSettings : raftConsensusConfig.getNodes()) {
        PropertiesUtils.mergeFrom(properties, ((RaftNodeConfig) nodeSettings).convert());
    }
    RaftConfig raftConfig = (RaftConfig) raftConsensusConfig.getRaftSettings();
    PropertiesUtils.mergeFrom(properties, raftConfig.convert());
    RaftNetworkConfig raftNetworkConfig = (RaftNetworkConfig) raftConsensusConfig.getNetworkSettings();
    PropertiesUtils.mergeFrom(properties, raftNetworkConfig.convert());
    return properties;
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) RaftConsensusSettings(com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings)

Example 7 with NodeSettings

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

the class MsgQueueNodeServerFactory method buildServerSettings.

@Override
public MsgQueueServerSettings buildServerSettings(String realmName, ConsensusViewSettings viewSettings, String nodeAddress, SSLSecurity sslSecurity, Properties properties) {
    if (!(viewSettings instanceof MsgQueueConsensusSettings)) {
        throw new IllegalArgumentException("ConsensusSettings data isn't supported! Accept MsgQueueConsensusSettings only!");
    }
    int id = -1;
    for (NodeSettings nodeSettings : viewSettings.getNodes()) {
        MsgQueueNodeSettings settings = (MsgQueueNodeSettings) nodeSettings;
        if (settings.getAddress().equals(nodeAddress)) {
            id = settings.getId();
            break;
        }
    }
    MsgQueueNodeSettings nodeSettings = new MsgQueueNodeConfig().setAddress(nodeAddress).setId(id);
    MsgQueueServerSettings serverSettings = new MsgQueueServerConfig().setRealmName(realmName).setNodeSettings(nodeSettings).setConsensusSettings((MsgQueueConsensusSettings) viewSettings);
    return serverSettings;
}
Also used : NodeSettings(com.jd.blockchain.consensus.NodeSettings) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) MsgQueueConsensusSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings) MsgQueueServerConfig(com.jd.blockchain.consensus.mq.config.MsgQueueServerConfig) MsgQueueServerSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueServerSettings) MsgQueueNodeConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings)

Example 8 with NodeSettings

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

the class RaftNodeServer method init.

private void init(RaftServerSettings raftServerSettings) {
    this.selfPeerId = nodeSettingsToPeerId(raftServerSettings.getReplicaSettings());
    this.configuration = new Configuration();
    for (NodeSettings nodeSettings : raftServerSettings.getConsensusSettings().getNodes()) {
        this.configuration.addPeer(nodeSettingsToPeerId(nodeSettings));
    }
    if (!this.configuration.contains(selfPeerId)) {
        this.configuration.addPeer(selfPeerId);
    }
    this.clientAuthencationService = new RaftClientAuthenticationService(this);
    CliOptions cliOptions = new CliOptions();
    cliOptions.setRpcConnectTimeoutMs(this.serverSettings.getRaftNetworkSettings().getRpcConnectTimeoutMs());
    cliOptions.setRpcDefaultTimeout(this.serverSettings.getRaftNetworkSettings().getRpcDefaultTimeoutMs());
    cliOptions.setRpcInstallSnapshotTimeout(this.serverSettings.getRaftNetworkSettings().getRpcSnapshotTimeoutMs());
    this.raftClientService = (CliClientServiceImpl) ((CliServiceImpl) RaftServiceFactory.createAndInitCliService(cliOptions)).getCliClientService();
    this.rpcClient = this.raftClientService.getRpcClient();
    this.nodeOptions = initNodeOptions(raftServerSettings);
    this.nodeOptions.setInitialConf(this.configuration);
    LedgerRepository ledgerRepository = LedgerManageUtils.getLedgerRepository(this.ledgerHashDigest);
    this.messageBus = new MessageBusComponent(raftServerSettings.getRaftSettings().getDisruptorBufferSize());
    this.blockSerializer = new SimpleBlockSerializerService();
    this.blockProposer = new BlockProposerService(ledgerRepository);
    this.blockCommitter = new BlockCommitService(this.realmName, this.messageHandle, ledgerRepository, this.messageBus);
    this.blockCommitter.registerCallBack((BlockCommitCallback) blockProposer);
    this.blockSyncer = new BlockSyncService(ledgerRepository, this.rpcClient, this.serverSettings.getRaftNetworkSettings().getRpcRequestTimeoutMs());
    messageBus.register(BLOCK_CATCH_UP_TOPIC, (Subcriber) this.blockSyncer);
    this.stateMachine = new RaftConsensusStateMachine(this.blockCommitter, this.blockSerializer, this.blockSyncer, ledgerRepository);
    this.nodeOptions.setFsm(stateMachine);
    RaftNodeServerContext.getInstance().init(this);
}
Also used : MessageBusComponent(com.jd.blockchain.consensus.raft.msgbus.MessageBusComponent) NodeSettings(com.jd.blockchain.consensus.NodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) Configuration(com.alipay.sofa.jraft.conf.Configuration) CliServiceImpl(com.alipay.sofa.jraft.core.CliServiceImpl) LedgerRepository(com.jd.blockchain.ledger.core.LedgerRepository) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Example 9 with NodeSettings

use of com.jd.blockchain.consensus.NodeSettings 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 10 with NodeSettings

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

the class MsgQueueConsensusSettingsBuilder method updateSettings.

@Override
public ConsensusViewSettings updateSettings(ConsensusViewSettings oldConsensusSettings, Properties newProps) {
    String op = newProps.getProperty("participant.op");
    int id = Integer.valueOf(newProps.getProperty("participant.id"));
    String pubkeyBase58 = newProps.getProperty("system.server." + id + ".pubkey");
    PubKey pubkey = Crypto.resolveAsPubKey(Base58Utils.decode(pubkeyBase58));
    Bytes address = AddressEncoding.generateAddress(pubkey);
    MsgQueueConsensusSettings consensusSettings = (MsgQueueConsensusSettings) oldConsensusSettings;
    NodeSettings[] nodes = consensusSettings.getNodes();
    List<MsgQueueNodeConfig> mqNodes = new ArrayList<>();
    boolean needAdd = true;
    for (NodeSettings settings : nodes) {
        MsgQueueNodeSettings node = (MsgQueueNodeSettings) settings;
        if (node.getPubKey().equals(pubkey)) {
            if (op.equals("deactive")) {
                needAdd = false;
                continue;
            }
        } else {
            MsgQueueNodeConfig nodeConfig = new MsgQueueNodeConfig();
            nodeConfig.setAddress(node.getAddress());
            nodeConfig.setPubKey(node.getPubKey());
            nodeConfig.setId(node.getId());
            mqNodes.add(nodeConfig);
        }
    }
    if (needAdd) {
        MsgQueueNodeConfig nodeConfig = new MsgQueueNodeConfig();
        nodeConfig.setAddress(address.toString());
        nodeConfig.setId(id);
        nodeConfig.setPubKey(pubkey);
        mqNodes.add(nodeConfig);
    }
    MsgQueueConsensusConfig newSettings = new MsgQueueConsensusConfig();
    newSettings.setBlockSettings(consensusSettings.getBlockSettings());
    newSettings.setNetworkSettings(consensusSettings.getNetworkSettings());
    for (MsgQueueNodeConfig node : mqNodes) {
        newSettings.addNodeSettings(node);
    }
    return newSettings;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) MsgQueueConsensusConfig(com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig) ArrayList(java.util.ArrayList) Bytes(utils.Bytes) NodeSettings(com.jd.blockchain.consensus.NodeSettings) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings) MsgQueueConsensusSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings) MsgQueueNodeConfig(com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig) MsgQueueNodeSettings(com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings)

Aggregations

NodeSettings (com.jd.blockchain.consensus.NodeSettings)17 BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)7 RaftNodeSettings (com.jd.blockchain.consensus.raft.settings.RaftNodeSettings)6 MsgQueueConsensusSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueConsensusSettings)4 MsgQueueNodeSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings)4 MsgQueueNodeConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig)3 RaftConsensusSettings (com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings)3 PubKey (com.jd.blockchain.crypto.PubKey)3 NetworkAddress (utils.net.NetworkAddress)3 BftsmartConsensusConfig (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig)2 BftsmartConsensusViewSettings (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings)2 BftsmartNodeConfig (com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig)2 MsgQueueConsensusConfig (com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig)2 MsgQueueBlockSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueBlockSettings)2 MsgQueueNetworkSettings (com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 HostsConfig (bftsmart.reconfiguration.util.HostsConfig)1 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)1 Configuration (com.alipay.sofa.jraft.conf.Configuration)1