Hyperledger Fabric:未知的服务订购者。channel.sendTransaction()上的AtomicBroadcast

时间:2019-05-08 17:32:27

标签: hyperledger-fabric

我是Fabric世界的新手,并且正在Fabric 1.4中测试Java SDK。
我已经通过Visual Studio Code和Fabric本地环境建立了智能合约。
现在,我想与它进行交互,以通过Java调用智能合约终结点。

private Optional<FileAsset> sendTransaction(HFClient client, String functionToCall, String... args) {
    Channel channel = client.getChannel(channelName);

    TransactionProposalRequest tpr = TransactionProposalRequest.newInstance(client.getUserContext());

    ChaincodeID fileChainCCId = ChaincodeID
            .newBuilder()
            .setName(chaincodeName)
            .setVersion(chaincodeVersion)
            .build();

    tpr.setChaincodeID(fileChainCCId);
    tpr.setChaincodeLanguage(Type.NODE);
    tpr.setFcn(functionToCall).setArgs(args);
    tpr.setProposalWaitTime(6_000);

    log.info("Calling function: {} with args: {}", functionToCall, args);



    Map<String, byte[]> tm2 = new HashMap<>();
    tm2.put("HyperLedgerFabric", "TransactionProposalRequest:JavaSDK".getBytes(UTF_8)); // Just

    tm2.put("method", "TransactionProposalRequest".getBytes(UTF_8)); // ditto
    tm2.put("result", ":)".getBytes(UTF_8)); // This should be returned in
                                                // the payload see chaincode
                                                // why.

    tm2.put(EXPECTED_EVENT_NAME, EXPECTED_EVENT_DATA); // This should
                                                        // trigger an event
                                                        // see chaincode
                                                        // why.

    try {
        tpr.setTransientMap(tm2);
    } catch (InvalidArgumentException e) {
        log.error("Error setting transient map. Err: {}", e.getMessage());
        return Optional.empty();
    }

    Collection<ProposalResponse> responses = null;

    try {
        responses = channel.sendTransactionProposal(tpr, channel.getPeers());

    } catch (ProposalException | InvalidArgumentException e) {
        log.error("Error sending transaction proposal: {}. Err: {}", tpr, e.getMessage());
        return Optional.empty();
    }

    List<ProposalResponse> invalid = responses.stream().filter(r -> r.isInvalid()).collect(Collectors.toList());
    if (!invalid.isEmpty()) {
        invalid.forEach(response -> {
            log.error(response.getMessage());
        });
        return Optional.empty();
    }

    List<ProposalResponse> resps = responses.stream()
            .filter(r -> r.getStatus().equals(ProposalResponse.Status.SUCCESS)).collect(Collectors.toList());

    resps.stream().forEach(resp -> {
        log.info("Successful transaction proposal response Txid: {} from peer {}", resp.getTransactionID(),
                resp.getPeer().getName());
    });

    try {
        Collection<Set<ProposalResponse>> proposalConsistencySets = SDKUtils.getProposalConsistencySets(responses);
        if (proposalConsistencySets.size() != 1) {
            log.error("Expected only one set of consistent proposal responses but got {}",
                    proposalConsistencySets.size());
            return Optional.empty();
        }
    } catch (InvalidArgumentException e) {
        log.error("Error generating proposal consistency sets. Err: {}", e.getMessage());
        return Optional.empty();
    }

    // If all responses are fine, then we can proceed with sending the
    // transaction to an orderer

    CompletableFuture<TransactionEvent> sentTransaction = channel.sendTransaction(resps, channel.getOrderers(), client.getUserContext());

    // For simplicity, we just request result with a timeout and verify that
    // for validity.
    BlockEvent.TransactionEvent event = null;
    try {
        event = sentTransaction.get(60, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Error sending transaction to orders. Err: {}", e.getMessage());
        return Optional.empty();
    }

    if (event.isValid()) {
        log.info("Transacion tx: " + event.getTransactionID() + " is completed.");
    } else {
        log.error("Transaction tx: " + event.getTransactionID() + " is invalid.");
    }
    return Optional.empty();
}

打开

CompletableFuture<TransactionEvent> sentTransaction = channel.sendTransaction(resps, channel.getOrderers(), client.getUserContext());

我收到以下错误: 已实施:服务订购者未知。AtomicBroadcast

2019-05-08 18:49:00.761 ERROR 15748 --- [ault-executor-0] o.hyperledger.fabric.sdk.OrdererClient   : OrdererClient{id: 7, channel: mychannel, name: peer0.org1.example.com, url: grpc://localhost:17051}  managed channel isTerminated: false, isShutdown: false, state: READY
2019-05-08 18:49:00.768 ERROR 15748 --- [ault-executor-0] o.hyperledger.fabric.sdk.OrdererClient   : Received error org.hyperledger.fabric.sdk.OrdererClient$1@326e7643  UNIMPLEMENTED: unknown service orderer.AtomicBroadcast

io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown service orderer.AtomicBroadcast
at io.grpc.Status.asRuntimeException(Status.java:530) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:434) [grpc-stub-1.17.1.jar:1.17.1]
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:694) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:397) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:459) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:546) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:467) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:584) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) [grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) [grpc-core-1.17.1.jar:1.17.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_152]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_152]

2019-05-08 18:49:00.769 ERROR 15748 --- [           main] o.hyperledger.fabric.sdk.OrdererClient   : OrdererClient{id: 7, channel: mychannel, name: peer0.org1.example.com, url: grpc://localhost:17051} grpc status Code:unknown service orderer.AtomicBroadcast, Description UNIMPLEMENTED, 
2019-05-08 18:49:00.770 ERROR 15748 --- [           main] o.hyperledger.fabric.sdk.OrdererClient   : OrdererClient{id: 7, channel: mychannel, name: peer0.org1.example.com, url: grpc://localhost:17051}sendTransaction error Channel mychannel, send transaction failed on orderer OrdererClient{id: 7, channel: mychannel, name: peer0.org1.example.com, url: grpc://localhost:17051}. Reason: UNIMPLEMENTED: unknown service orderer.AtomicBroadcast

org.hyperledger.fabric.sdk.exception.TransactionException: Channel mychannel, send transaction failed on orderer OrdererClient{id: 7, channel: mychannel, name: peer0.org1.example.com, url: grpc://localhost:17051}. Reason: UNIMPLEMENTED: unknown service orderer.AtomicBroadcast
at org.hyperledger.fabric.sdk.OrdererClient.sendTransaction(OrdererClient.java:236) ~[fabric-sdk-java-1.4.1.jar:na]
at org.hyperledger.fabric.sdk.Orderer.sendTransaction(Orderer.java:161) [fabric-sdk-java-1.4.1.jar:na]
at org.hyperledger.fabric.sdk.Channel.sendTransaction(Channel.java:4971) [fabric-sdk-java-1.4.1.jar:na]
at org.hyperledger.fabric.sdk.Channel.sendTransaction(Channel.java:4504) [fabric-sdk-java-1.4.1.jar:na]
at it.blockchain.fabric.service.impl.FileChainSmartContractServiceImpl.sendTransaction(FileChainSmartContractServiceImpl.java:205) [classes/:na]
at it.blockchain.fabric.service.impl.FileChainSmartContractServiceImpl.addFileAsset(FileChainSmartContractServiceImpl.java:65) [classes/:na]
at it.blockchain.fabric.clr.DemoCLR.run(DemoCLR.java:40) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:813) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:797) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at it.blockchain.fabric.FilechainFabricDemoApplication.main(FilechainFabricDemoApplication.java:10) [classes/:na]
Caused by: io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown service orderer.AtomicBroadcast
at io.grpc.Status.asRuntimeException(Status.java:530) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:434) ~[grpc-stub-1.17.1.jar:1.17.1]
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:694) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:397) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:459) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:546) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:467) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:584) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) ~[grpc-core-1.17.1.jar:1.17.1]
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) ~[grpc-core-1.17.1.jar:1.17.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_152]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_152]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_152]

2019-05-08 18:49:00.771 ERROR 15748 --- [           main] org.hyperledger.fabric.sdk.Channel       : Channel mychannel unsuccessful sendTransaction to orderer peer0.org1.example.com (grpc://localhost:17051)

有关如何解决它的任何建议?

1 个答案:

答案 0 :(得分:1)

您正在将AtomicBroadcast的对等对象定位为-peer0.org1.example.com

您需要定位一个订购者。似乎您的网络配置有误。