Search in sources :

Example 1 with TxResponseMessage

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;
}
Also used : TxResponseMessage(com.jd.blockchain.transaction.TxResponseMessage)

Example 2 with TxResponseMessage

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;
}
Also used : TransactionResponse(com.jd.blockchain.ledger.TransactionResponse) ArrayList(java.util.ArrayList) TxResponseMessage(com.jd.blockchain.transaction.TxResponseMessage)

Example 3 with TxResponseMessage

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);
}
Also used : TxResponseMessage(com.jd.blockchain.transaction.TxResponseMessage) TransactionRequest(com.jd.blockchain.ledger.TransactionRequest)

Example 4 with TxResponseMessage

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;
}
Also used : DefaultMessageTransmitter(com.jd.blockchain.consensus.mq.client.DefaultMessageTransmitter) TxResponseMessage(com.jd.blockchain.transaction.TxResponseMessage) ExtendMessage(com.jd.blockchain.consensus.mq.event.ExtendMessage) ExtendMessageResult(com.jd.blockchain.consensus.mq.event.ExtendMessageResult)

Example 5 with TxResponseMessage

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));
}
Also used : BftsmartConsensusViewSettings(com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings) ServiceProxy(bftsmart.tom.ServiceProxy) TxResponseMessage(com.jd.blockchain.transaction.TxResponseMessage) Properties(java.util.Properties)

Aggregations

TxResponseMessage (com.jd.blockchain.transaction.TxResponseMessage)6 ServiceProxy (bftsmart.tom.ServiceProxy)1 BftsmartConsensusViewSettings (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusViewSettings)1 DefaultMessageTransmitter (com.jd.blockchain.consensus.mq.client.DefaultMessageTransmitter)1 ExtendMessage (com.jd.blockchain.consensus.mq.event.ExtendMessage)1 ExtendMessageResult (com.jd.blockchain.consensus.mq.event.ExtendMessageResult)1 TransactionRequest (com.jd.blockchain.ledger.TransactionRequest)1 TransactionResponse (com.jd.blockchain.ledger.TransactionResponse)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1