Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 9bf5095

Browse files
committed
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 <cr22rc@gmail.com>
1 parent 0efa9d3 commit 9bf5095

File tree

4 files changed

+25
-28
lines changed

4 files changed

+25
-28
lines changed

src/main/java/org/hyperledger/fabric/sdk/Peer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,9 @@ public String getPropertyName() {
362362
}
363363
}
364364

365+
@Override
366+
public String toString() {
367+
return "Peer " + name + " url: " + url;
368+
369+
}
365370
} // end Peer

src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() thr
7575

7676
}
7777

78+
ByteString getPayloadBytes() {
79+
return proposalResponse.getPayload();
80+
81+
}
82+
7883
public boolean isVerified() {
7984
return isVerified;
8085
}

src/main/java/org/hyperledger/fabric/sdk/SDKUtils.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
3131
import org.hyperledger.fabric.sdk.security.CryptoSuite;
3232

33+
import static java.lang.String.format;
34+
3335
public class SDKUtils {
3436
private SDKUtils() {
3537

@@ -117,18 +119,22 @@ public static Collection<Set<ProposalResponse>> getProposalConsistencySets(Colle
117119

118120
for (ProposalResponse proposalResponse : proposalResponses) {
119121

120-
if (proposalResponse.isInvalid() || proposalResponse.getProposalResponse() == null) {
122+
if (proposalResponse.isInvalid()) {
121123
invalid.add(proposalResponse);
122124
} else {
123-
124-
ByteString rwsetByteString = proposalResponse.getProposalResponsePayloadDeserializer()
125-
.getExtension().getChaincodeAction().getResults();
126-
127-
Set<ProposalResponse> set = ret.computeIfAbsent(rwsetByteString, k -> new HashSet<>());
128-
125+
// payload bytes is what's being signed over so it must be consistent.
126+
final ByteString payloadBytes = proposalResponse.getPayloadBytes();
127+
128+
if (payloadBytes == null) {
129+
throw new InvalidArgumentException(format("proposalResponse.getPayloadBytes() was null from peer: %s.",
130+
proposalResponse.getPeer()));
131+
} else if (payloadBytes.isEmpty()) {
132+
throw new InvalidArgumentException(format("proposalResponse.getPayloadBytes() was empty from peer: %s.",
133+
proposalResponse.getPeer()));
134+
}
135+
Set<ProposalResponse> set = ret.computeIfAbsent(payloadBytes, k -> new HashSet<>());
129136
set.add(proposalResponse);
130137
}
131-
132138
}
133139

134140
return ret.values();

src/test/java/org/hyperledger/fabric/sdkintegration/NetworkConfigIT.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
* <p>
7777
* It first examines the "foo" channel and checks that CHAIN_CODE_NAME has been instantiated on the channel,
7878
* and if not it deploys the chaincode with that name.
79-
*
8079
*/
8180
public class NetworkConfigIT {
8281

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

9998
private static NetworkConfig networkConfig;
10099

101-
102-
103100
@BeforeClass
104101
public static void doMainSetup() throws Exception {
105102
out("\n\n\nRUNNING: NetworkConfigIT.\n");
@@ -108,13 +105,12 @@ public static void doMainSetup() throws Exception {
108105
configHelper.customizeConfig();
109106

110107
// Use the appropriate TLS/non-TLS network config file
111-
networkConfig = NetworkConfig.fromYamlFile(testConfig.getTestNetworkConfigFileYAML());
108+
networkConfig = NetworkConfig.fromYamlFile(testConfig.getTestNetworkConfigFileYAML());
112109

113110
// Ensure the chaincode required for these tests is deployed
114111
deployChaincodeIfRequired();
115112
}
116113

117-
118114
// Determines whether or not the chaincode has been deployed and deploys it if necessary
119115
private static void deployChaincodeIfRequired() throws Exception {
120116

@@ -146,7 +142,6 @@ private static HFClient getTheClient() throws Exception {
146142
return client;
147143
}
148144

149-
150145
private static User getAdminUser(String orgName) throws Exception {
151146

152147
NetworkConfig.UserInfo userInfo = networkConfig.getPeerAdmin(orgName);
@@ -155,7 +150,6 @@ private static User getAdminUser(String orgName) throws Exception {
155150
String userName = userInfo.getEnrollId();
156151
String mspId = userInfo.getMspId();
157152

158-
159153
PrivateKey privateKey = userInfo.getPrivateKey();
160154
String signedCert = userInfo.getSignedCert();
161155

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

168-
169-
170162
@Test
171163
public void testUpdate1() throws Exception {
172164

@@ -178,7 +170,6 @@ public void testUpdate1() throws Exception {
178170
.setVersion(CHAIN_CODE_VERSION)
179171
.setPath(CHAIN_CODE_PATH).build();
180172

181-
182173
final String channelName = channel.getName();
183174

184175
out("Running testUpdate1 - Channel %s", channelName);
@@ -233,7 +224,6 @@ public void testUpdate1() throws Exception {
233224
out("testUpdate1 - done");
234225
}
235226

236-
237227
private static void queryChaincodeForExpectedValue(HFClient client, Channel channel, final String expect, ChaincodeID chaincodeID) {
238228

239229
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<BlockEvent.TransactionEvent> moveAmount(HFClien
333323
return channel.sendTransaction(successful);
334324
}
335325

336-
337326
private static ChaincodeID deployChaincode(HFClient client, Channel channel, String ccName, String ccPath, String ccVersion) throws Exception {
338327

339328
out("deployChaincode - enter");
@@ -385,8 +374,6 @@ private static ChaincodeID deployChaincode(HFClient client, Channel channel, Str
385374
}
386375
}
387376

388-
SDKUtils.getProposalConsistencySets(responses);
389-
// }
390377
out("Received %d install proposal responses. Successful+verified: %d . Failed: %d", numInstallProposal, successful.size(), failed.size());
391378

392379
if (failed.size() > 0) {
@@ -452,7 +439,6 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
452439
assertTrue(event.isValid()); // must be valid to be here.
453440
out("Finished instantiate transaction with transaction id %s", event.getTransactionID());
454441

455-
456442
} catch (Exception e) {
457443
e.printStackTrace();
458444
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
462448
return chaincodeID;
463449
}
464450

465-
466-
467451
private static Channel constructChannel(HFClient client, String channelName) throws Exception {
468452

469453
//Channel newChannel = client.getChannel(channelName);
@@ -475,7 +459,6 @@ private static Channel constructChannel(HFClient client, String channelName) thr
475459
return newChannel.initialize();
476460
}
477461

478-
479462
// Determines if the specified chaincode has been instantiated on the channel
480463
private static boolean checkInstantiatedChaincode(Channel channel, Peer peer, String ccName, String ccPath, String ccVersion) throws InvalidArgumentException, ProposalException {
481464
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
494477
return found;
495478
}
496479

497-
498480
private static void out(String format, Object... args) {
499481

500482
System.err.flush();
@@ -506,5 +488,4 @@ private static void out(String format, Object... args) {
506488

507489
}
508490

509-
510491
}

0 commit comments

Comments
 (0)