Skip to content

Commit

Permalink
FAB-7693 Consistency set based off of payload bytes
Browse files Browse the repository at this point in the history
PS
04 hf.revoker attr. renamed to hf.Revoker

Change-Id: I0e69803a99a59ed90fa5c9abe174d82f4621c34d
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Jan 22, 2018
1 parent 0efa9d3 commit 9bf5095
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,9 @@ public String getPropertyName() {
}
}

@Override
public String toString() {
return "Peer " + name + " url: " + url;

}
} // end Peer
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() thr

}

ByteString getPayloadBytes() {
return proposalResponse.getPayload();

}

public boolean isVerified() {
return isVerified;
}
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -117,18 +119,22 @@ public static Collection<Set<ProposalResponse>> 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<ProposalResponse> 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<ProposalResponse> set = ret.computeIfAbsent(payloadBytes, k -> new HashSet<>());
set.add(proposalResponse);
}

}

return ret.values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
* <p>
* 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 {

Expand All @@ -98,8 +97,6 @@ public class NetworkConfigIT {

private static NetworkConfig networkConfig;



@BeforeClass
public static void doMainSetup() throws Exception {
out("\n\n\nRUNNING: NetworkConfigIT.\n");
Expand All @@ -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 {

Expand Down Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -165,8 +159,6 @@ private static User getAdminUser(String orgName) throws Exception {
return admin;
}



@Test
public void testUpdate1() throws Exception {

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -333,7 +323,6 @@ private static CompletableFuture<BlockEvent.TransactionEvent> 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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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();
Expand All @@ -506,5 +488,4 @@ private static void out(String format, Object... args) {

}


}

0 comments on commit 9bf5095

Please sign in to comment.