From 9bf5095521b4e1f668b6ef02ab35c7627b9821e4 Mon Sep 17 00:00:00 2001 From: rickr Date: Fri, 12 Jan 2018 15:54:19 -0500 Subject: [PATCH] FAB-7693 Consistency set based off of payload bytes PS 04 hf.revoker attr. renamed to hf.Revoker Change-Id: I0e69803a99a59ed90fa5c9abe174d82f4621c34d Signed-off-by: rickr --- .../java/org/hyperledger/fabric/sdk/Peer.java | 5 +++++ .../fabric/sdk/ProposalResponse.java | 5 +++++ .../org/hyperledger/fabric/sdk/SDKUtils.java | 22 ++++++++++++------- .../sdkintegration/NetworkConfigIT.java | 21 +----------------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/hyperledger/fabric/sdk/Peer.java b/src/main/java/org/hyperledger/fabric/sdk/Peer.java index 4726be8f..2d3c4dfd 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Peer.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Peer.java @@ -362,4 +362,9 @@ public String getPropertyName() { } } + @Override + public String toString() { + return "Peer " + name + " url: " + url; + + } } // end Peer diff --git a/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java b/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java index 16ba9381..2e92aae2 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java +++ b/src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java @@ -75,6 +75,11 @@ ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() thr } + ByteString getPayloadBytes() { + return proposalResponse.getPayload(); + + } + public boolean isVerified() { return isVerified; } diff --git a/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java b/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java index 4f751268..07d064f1 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java +++ b/src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java @@ -30,6 +30,8 @@ import org.hyperledger.fabric.sdk.exception.InvalidArgumentException; import org.hyperledger.fabric.sdk.security.CryptoSuite; +import static java.lang.String.format; + public class SDKUtils { private SDKUtils() { @@ -117,18 +119,22 @@ public static Collection> getProposalConsistencySets(Colle for (ProposalResponse proposalResponse : proposalResponses) { - if (proposalResponse.isInvalid() || proposalResponse.getProposalResponse() == null) { + if (proposalResponse.isInvalid()) { invalid.add(proposalResponse); } else { - - ByteString rwsetByteString = proposalResponse.getProposalResponsePayloadDeserializer() - .getExtension().getChaincodeAction().getResults(); - - Set set = ret.computeIfAbsent(rwsetByteString, k -> new HashSet<>()); - + // payload bytes is what's being signed over so it must be consistent. + final ByteString payloadBytes = proposalResponse.getPayloadBytes(); + + if (payloadBytes == null) { + throw new InvalidArgumentException(format("proposalResponse.getPayloadBytes() was null from peer: %s.", + proposalResponse.getPeer())); + } else if (payloadBytes.isEmpty()) { + throw new InvalidArgumentException(format("proposalResponse.getPayloadBytes() was empty from peer: %s.", + proposalResponse.getPeer())); + } + Set set = ret.computeIfAbsent(payloadBytes, k -> new HashSet<>()); set.add(proposalResponse); } - } return ret.values(); diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/NetworkConfigIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/NetworkConfigIT.java index 6260d000..cb058e9c 100755 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/NetworkConfigIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/NetworkConfigIT.java @@ -76,7 +76,6 @@ *

* It first examines the "foo" channel and checks that CHAIN_CODE_NAME has been instantiated on the channel, * and if not it deploys the chaincode with that name. - * */ public class NetworkConfigIT { @@ -98,8 +97,6 @@ public class NetworkConfigIT { private static NetworkConfig networkConfig; - - @BeforeClass public static void doMainSetup() throws Exception { out("\n\n\nRUNNING: NetworkConfigIT.\n"); @@ -108,13 +105,12 @@ public static void doMainSetup() throws Exception { configHelper.customizeConfig(); // Use the appropriate TLS/non-TLS network config file - networkConfig = NetworkConfig.fromYamlFile(testConfig.getTestNetworkConfigFileYAML()); + networkConfig = NetworkConfig.fromYamlFile(testConfig.getTestNetworkConfigFileYAML()); // Ensure the chaincode required for these tests is deployed deployChaincodeIfRequired(); } - // Determines whether or not the chaincode has been deployed and deploys it if necessary private static void deployChaincodeIfRequired() throws Exception { @@ -146,7 +142,6 @@ private static HFClient getTheClient() throws Exception { return client; } - private static User getAdminUser(String orgName) throws Exception { NetworkConfig.UserInfo userInfo = networkConfig.getPeerAdmin(orgName); @@ -155,7 +150,6 @@ private static User getAdminUser(String orgName) throws Exception { String userName = userInfo.getEnrollId(); String mspId = userInfo.getMspId(); - PrivateKey privateKey = userInfo.getPrivateKey(); String signedCert = userInfo.getSignedCert(); @@ -165,8 +159,6 @@ private static User getAdminUser(String orgName) throws Exception { return admin; } - - @Test public void testUpdate1() throws Exception { @@ -178,7 +170,6 @@ public void testUpdate1() throws Exception { .setVersion(CHAIN_CODE_VERSION) .setPath(CHAIN_CODE_PATH).build(); - final String channelName = channel.getName(); out("Running testUpdate1 - Channel %s", channelName); @@ -233,7 +224,6 @@ public void testUpdate1() throws Exception { out("testUpdate1 - done"); } - private static void queryChaincodeForExpectedValue(HFClient client, Channel channel, final String expect, ChaincodeID chaincodeID) { out("Now query chaincode on channel %s for the value of b expecting to see: %s", channel.getName(), expect); @@ -333,7 +323,6 @@ private static CompletableFuture moveAmount(HFClien return channel.sendTransaction(successful); } - private static ChaincodeID deployChaincode(HFClient client, Channel channel, String ccName, String ccPath, String ccVersion) throws Exception { out("deployChaincode - enter"); @@ -385,8 +374,6 @@ private static ChaincodeID deployChaincode(HFClient client, Channel channel, Str } } - SDKUtils.getProposalConsistencySets(responses); - // } out("Received %d install proposal responses. Successful+verified: %d . Failed: %d", numInstallProposal, successful.size(), failed.size()); if (failed.size() > 0) { @@ -452,7 +439,6 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei assertTrue(event.isValid()); // must be valid to be here. out("Finished instantiate transaction with transaction id %s", event.getTransactionID()); - } catch (Exception e) { e.printStackTrace(); out("Caught an exception running channel %s", channel.getName()); @@ -462,8 +448,6 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei return chaincodeID; } - - private static Channel constructChannel(HFClient client, String channelName) throws Exception { //Channel newChannel = client.getChannel(channelName); @@ -475,7 +459,6 @@ private static Channel constructChannel(HFClient client, String channelName) thr return newChannel.initialize(); } - // Determines if the specified chaincode has been instantiated on the channel private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, String ccName, String ccPath, String ccVersion) throws InvalidArgumentException, ProposalException { out("Checking instantiated chaincode: %s, at version: %s, on peer: %s", ccName, ccVersion, peer.getName()); @@ -494,7 +477,6 @@ private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, St return found; } - private static void out(String format, Object... args) { System.err.flush(); @@ -506,5 +488,4 @@ private static void out(String format, Object... args) { } - }