use of com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings 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;
}
use of com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Bft method submitNodeStateChangeTx.
@Override
public TransactionResponse submitNodeStateChangeTx(ParticipantContext context, int activeID, TransactionRequest txRequest, List<NodeSettings> origConsensusNodes) {
Properties systemConfig = getCustomProperties(context);
int viewId = ((BftsmartConsensusViewSettings) getConsensusSetting(context)).getViewId();
TransactionResponse transactionResponse = new TxResponseMessage();
ServiceProxy peerProxy = createPeerProxy(systemConfig, viewId, origConsensusNodes, context.sslSecurity());
byte[] result = peerProxy.invokeOrdered(BinaryProtocol.encode(txRequest, TransactionRequest.class));
if (result == null) {
((TxResponseMessage) transactionResponse).setExecutionState(TransactionState.CONSENSUS_NO_REPLY_ERROR);
return transactionResponse;
}
peerProxy.close();
return txResponseWrapper(BinaryProtocol.decode(result));
}
use of com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings 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;
}
use of com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Bft method applyConsensusGroupNodeChange.
@Override
public WebResponse applyConsensusGroupNodeChange(ParticipantContext context, ParticipantNode node, @Nullable NetworkAddress changeConsensusNodeAddress, List<NodeSettings> origConsensusNodes, ManagementController.ParticipantUpdateType type) {
Properties systemConfig = getCustomProperties(context);
int viewId = ((BftsmartConsensusViewSettings) getConsensusSetting(context)).getViewId();
SSLSecurity security = context.sslSecurity();
try {
View newView = updateView(node, changeConsensusNodeAddress, security, type, systemConfig, viewId, origConsensusNodes);
if (newView == null) {
throw new IllegalStateException("client recv response timeout, consensus may be stalemate, please restart all nodes!");
}
boolean isSuccess = false;
if (type == ManagementController.ParticipantUpdateType.DEACTIVE) {
if (!newView.isMember(node.getId())) {
isSuccess = true;
}
} else {
if (newView.isMember(node.getId())) {
isSuccess = true;
}
}
if (isSuccess) {
LOGGER.info("update view success!");
}
} catch (Exception e) {
LOGGER.error("updateView exception!", e);
return WebResponse.createFailureResult(-1, "commit tx to orig consensus, tx execute succ but view update failed, please restart all nodes and copy database for new participant node!");
}
return WebResponse.createSuccessResult(null);
}
Aggregations