use of com.jd.blockchain.transaction.TxResponseMessage in project jdchain-core by blockchain-jd-com.
the class TransactionBatchProcessor method discard.
/**
* 直接丢弃交易;
*
* @param request
* @param txState
* @return 丢弃交易的回复;只包含原始请求中的交易内容哈希和交易被丢弃的原因,而不包含区块信息;
*/
private TransactionResponse discard(TransactionRequest request, TransactionState txState) {
// 丢弃交易的回复;只返回请求的交易内容哈希和交易被丢弃的原因,
TxResponseMessage resp = new TxResponseMessage(request.getTransactionHash());
resp.setExecutionState(txState);
LOGGER.error("Discard transaction request! --[BlockHeight={}][RequestHash={}][ResponseState={}]", newBlockEditor.getBlockHeight(), request.getTransactionHash(), resp.getExecutionState());
return resp;
}
use of com.jd.blockchain.transaction.TxResponseMessage in project jdchain-core by blockchain-jd-com.
the class BftsmartNodeServer method updateAppResponses.
@Override
public List<byte[]> updateAppResponses(List<byte[]> asyncResponseLinkedList, byte[] commonHash, boolean isConsistent) {
List<byte[]> updatedResponses = new ArrayList<>();
TxResponseMessage resp = null;
for (int i = 0; i < asyncResponseLinkedList.size(); i++) {
TransactionResponse txResponse = BinaryProtocol.decode(asyncResponseLinkedList.get(i));
if (isConsistent) {
resp = new TxResponseMessage(txResponse.getContentHash());
} else {
resp = new TxResponseMessage(Crypto.resolveAsHashDigest(commonHash));
}
resp.setExecutionState(TransactionState.IGNORED_BY_BLOCK_FULL_ROLLBACK);
updatedResponses.add(BinaryProtocol.encode(resp, TransactionResponse.class));
}
return updatedResponses;
}
use of com.jd.blockchain.transaction.TxResponseMessage in project jdchain-core by blockchain-jd-com.
the class BftsmartNodeServer method createAppResponse.
// Block full rollback responses, generated in pre compute phase, due to tx
// exception
private byte[] createAppResponse(byte[] command, TransactionState transactionState) {
TransactionRequest txRequest = BinaryProtocol.decode(command);
TxResponseMessage resp = new TxResponseMessage(txRequest.getTransactionHash());
resp.setExecutionState(transactionState);
return BinaryProtocol.encode(resp, TransactionResponse.class);
}
use of com.jd.blockchain.transaction.TxResponseMessage in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4MQ method submitNodeStateChangeTx.
@Override
public TransactionResponse submitNodeStateChangeTx(ParticipantContext context, int activeID, TransactionRequest txRequest, List<NodeSettings> origConsensusNodes) {
TxResponseMessage responseMessage = new TxResponseMessage();
DefaultMessageTransmitter mqClient = null;
try {
// 初始化区块队列
initBlockQueue(context, activeID);
// 发送拓扑变更消息,通知领导者推送落块消息
mqClient = createMQClient(context);
ExtendMessage extendMessage = new ExtendMessage(MessageType.RECONFIGURE, null);
AsyncFuture<byte[]> msgFuture = mqClient.sendUnordered(MessageConvertor.serializeExtendMessage(extendMessage));
byte[] result = msgFuture.get(MQ_INVOKE_TIMEOUT, TimeUnit.MILLISECONDS);
if (result == null) {
responseMessage.setExecutionState(TransactionState.TIMEOUT);
} else {
ExtendMessageResult messageResult = MessageConvertor.convertBytesExtendMessageResult(result);
if (!messageResult.isSuccess()) {
LOGGER.error("extend message execute error: {}", messageResult.getError());
responseMessage.setExecutionState(TransactionState.CONSENSUS_ERROR);
} else {
// 发送激活交易
AsyncFuture<byte[]> txFuture = mqClient.sendOrdered(BinaryProtocol.encode(txRequest, TransactionRequest.class));
result = txFuture.get(MQ_INVOKE_TIMEOUT, TimeUnit.MILLISECONDS);
if (result == null) {
responseMessage.setExecutionState(TransactionState.TIMEOUT);
return responseMessage;
}
return BinaryProtocol.decode(result);
}
}
} catch (Exception e) {
LOGGER.error("message or tx execute error", e);
responseMessage.setExecutionState(TransactionState.CONSENSUS_ERROR);
} finally {
if (null != mqClient) {
mqClient.close();
}
}
return responseMessage;
}
use of com.jd.blockchain.transaction.TxResponseMessage 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));
}
Aggregations