0

我正在尝试动态创建通道并实例化链码。我有以下两种方法:

public Channel createChannel(String name, ChannelConfiguration cc) throws InvalidArgumentException, TransactionException, ProposalException {
    byte[] channelConfigurationSignatures = client.getChannelConfigurationSignature(cc, client.getUserContext());
    // gets the first orderer
    Orderer orderer = getFirstOrderer();
    Channel channel = client.newChannel(name, orderer, cc, channelConfigurationSignatures);
    for (Peer peer : getAllPeers()) {
        channel.joinPeer(peer);
    }
    return channel;
}

public void instantiateChaincode(Channel channel, String name, String version, String path) throws InvalidArgumentException, ProposalException {
    InstantiateProposalRequest instantiateProposalRequest = client.newInstantiationProposalRequest();
    instantiateProposalRequest.setProposalWaitTime(180000);
    instantiateProposalRequest.setChaincodeID(buildChaincodeID(name, version, path));
    instantiateProposalRequest.setChaincodeLanguage(Type.JAVA);
    instantiateProposalRequest.setFcn("init");
    instantiateProposalRequest.setArgs(new String[] {""});
    Collection<ProposalResponse> responses = channel.sendInstantiationProposal(instantiateProposalRequest);
    channel.sendTransaction(responses);
}

以上client来自GatewayImplFabric Gateway(https://github.com/hyperledger/fabric-gateway-java/blob/main/src/main/java/org/hyperledger/fabric/gateway/impl/GatewayImpl.java)。

我正在测试的两个用例是:

  1. 创建一个通道并在该通道上实例化链码
  2. 在网络中的现有通道上实例化链码

我的第一个用例没有问题。这是一个示例调试输出,作为我的问题的上下文:

Reading connection profile and creating orderers/peers...
orderers = 3
Orderer{id: 1, channelName: , name:orderer1.myorg.com, url: grpcs://192.168.50.87:7050}
Orderer{id: 2, channelName: , name:orderer2.myorg.com, url: grpcs://192.168.50.65:7050}
Orderer{id: 3, channelName: , name:orderer3.myorg.com, url: grpcs://192.168.50.65:8050}
peers = 3
Peer{ id: 4, name: peer1.myorg.com, channelName: null, url: grpcs://192.168.50.87:7051}
Peer{ id: 5, name: peer2.myorg.com, channelName: null, url: grpcs://192.168.50.65:7051}
Peer{ id: 6, name: peer3.myorg.com, channelName: null, url: grpcs://192.168.50.65:8051}

Creating channel decninee-channel...
Orderers/peers in channel "decninee-channel" are as follows:
Orderer{id: 1, channelName: decninee-channel, name:orderer1.myorg.com, url: grpcs://192.168.50.87:7050}
Peer{ id: 5, name: peer2.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.65:7051}
Peer{ id: 6, name: peer3.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.65:8051}
Peer{ id: 4, name: peer1.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.87:7051}

Instantiating productOwnership:1.0 for channel decninee-channel...
Getting network from gateway...
Orderers/peers in channel "decninee-channel" are as follows:
Orderer{id: 1, channelName: decninee-channel, name:orderer1.myorg.com, url: grpcs://192.168.50.87:7050}
Peer{ id: 5, name: peer2.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.65:7051}
Peer{ id: 6, name: peer3.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.65:8051}
Peer{ id: 4, name: peer1.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.87:7051}

相比之下,当我独立测试我的第二个用例时,我看到以下内容:

Reading connection profile and creating orderers/peers...
orderers = 3
Orderer{id: 1, channelName: , name:orderer1.myorg.com, url: grpcs://192.168.50.87:7050}
Orderer{id: 2, channelName: , name:orderer2.myorg.com, url: grpcs://192.168.50.65:7050}
Orderer{id: 3, channelName: , name:orderer3.myorg.com, url: grpcs://192.168.50.65:8050}
peers = 3
Peer{ id: 4, name: peer1.myorg.com, channelName: null, url: grpcs://192.168.50.87:7051}
Peer{ id: 5, name: peer2.myorg.com, channelName: null, url: grpcs://192.168.50.65:7051}
Peer{ id: 6, name: peer3.myorg.com, channelName: null, url: grpcs://192.168.50.65:8051}

Instantiating productProvenance:1.0 for channel decninee-channel...
Getting network from gateway...
Orderers/peers in channel "decninee-channel" are as follows:
Orderer{id: 14, channelName: decninee-channel, name:orderer3.myorg.com:7050, url: grpcs://orderer3.myorg.com:7050, mspid: OrdererMSP}
Orderer{id: 15, channelName: decninee-channel, name:orderer1.myorg.com:7050, url: grpcs://orderer1.myorg.com:7050, mspid: OrdererMSP}
Orderer{id: 16, channelName: decninee-channel, name:orderer2.myorg.com:7050, url: grpcs://orderer2.myorg.com:7050, mspid: OrdererMSP}
Peer{ id: 21, name: peer3.myorg.com:7051, channelName: decninee-channel, url: grpcs://peer3.myorg.com:7051, mspid: myorgMSP}
Peer{ id: 19, name: peer1.myorg.com:7051, channelName: decninee-channel, url: grpcs://peer1.myorg.com:7051, mspid: myorgMSP}
Peer{ id: 9, name: peer2.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.65:7051, mspid: myorgMSP}
Peer{ id: 10, name: peer3.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.65:8051, mspid: myorgMSP}
Peer{ id: 17, name: peer2.myorg.com:7051, channelName: decninee-channel, url: grpcs://peer2.myorg.com:7051, mspid: myorgMSP}
Peer{ id: 8, name: peer1.myorg.com, channelName: decninee-channel, url: grpcs://192.168.50.87:7051, mspid: myorgMSP}

这个测试用例失败了,因为:

  1. 订购者有不同的 URL,导致UnknownHostException我尝试发送交易时。
  2. 对于每个对等点,我看到两个条目:对等点 1 有两个PeerID 为 8 和 19,依此类推。这成为一个问题,因为实例化提案被发送到所有对等体,所以我得到了六个响应而不是三个响应,其中三个由于UnknownHostException.

示例 UnknownHostException 堆栈跟踪:

Peer{ id: 21, name: peer3.myorg.com:7051, channelName: decninee-channel, url: grpcs://peer3.myorg.com:7051, mspid: myorgMSP} ... FAILURE ... Channel Channel{id: 7, name: decninee-channel} Sending proposal with transaction: bbdd4791f825059673eda3c7038e6a95b770184cfb196f56f364644b7e57fde1 to Peer{ id: 21, name: peer3.myorg.com:7051, channelName: decninee-channel, url: grpcs://peer3.myorg.com:7051, mspid: myorgMSP} failed because of: gRPC failure=Status{code=UNAVAILABLE, description=Unable to resolve host peer3.myorg.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: peer3.myorg.com
    at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:223)
    at io.grpc.internal.DnsNameResolver.doResolve(DnsNameResolver.java:282)
    at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.UnknownHostException: peer3.myorg.com
    at java.net.InetAddress.getAllByName0(InetAddress.java:1281)
    at java.net.InetAddress.getAllByName(InetAddress.java:1193)
    at java.net.InetAddress.getAllByName(InetAddress.java:1127)
    at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:631)
    at io.grpc.internal.DnsNameResolver.resolveAddresses(DnsNameResolver.java:219)
    ... 5 more
}

我应该如何解决这个问题,以便两个用例都成功?

4

0 回答 0