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

Commit d119aad

Browse files
bestbeforetodaycr22rc
authored andcommitted
FABJ-451: Allow proposals to be sent more than once
Change-Id: I3c389223adce3f77ecfa3899ec35ecaaaba48b1b Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
1 parent 5e25c68 commit d119aad

File tree

4 files changed

+30
-55
lines changed

4 files changed

+30
-55
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,8 +2776,6 @@ public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposa
27762776
throw new InvalidArgumentException("InstantiateProposalRequest is null");
27772777
}
27782778

2779-
instantiateProposalRequest.setSubmitted();
2780-
27812779
checkPeers(peers);
27822780

27832781
try {
@@ -4725,8 +4723,6 @@ private ProposalResponse sendProposalSerially(TransactionRequest proposalRequest
47254723

47264724
for (Peer peer : peers) {
47274725

4728-
proposalRequest.submitted = false;
4729-
47304726
try {
47314727

47324728
Collection<ProposalResponse> proposalResponses = sendProposal(proposalRequest, Collections.singletonList(peer));
@@ -4791,8 +4787,6 @@ private Collection<ProposalResponse> sendProposal(TransactionRequest proposalReq
47914787
// throw new InvalidArgumentException("The proposalRequest's chaincode ID is null");
47924788
// }
47934789

4794-
proposalRequest.setSubmitted();
4795-
47964790
try {
47974791
TransactionContext transactionContext = getTransactionContext(proposalRequest.getUserContext());
47984792
transactionContext.verify(proposalRequest.doVerify());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,6 @@ public Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest i
868868

869869
clientCheck();
870870

871-
installProposalRequest.setSubmitted();
872871
Channel systemChannel = Channel.newSystemChannel(this);
873872

874873
return systemChannel.sendInstallProposal(installProposalRequest, peers);

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public class TransactionRequest {
3030
protected boolean init = false;
3131
private User userContext;
3232

33-
boolean submitted = false;
34-
3533
private final Config config = Config.getConfig();
3634

3735
// The local path containing the chaincode to deploy in network mode.
@@ -355,26 +353,6 @@ public void setProposalWaitTime(long proposalWaitTime) {
355353
this.proposalWaitTime = proposalWaitTime;
356354
}
357355

358-
/**
359-
* If this request has been submitted already.
360-
*
361-
* @return true if the already submitted.
362-
*/
363-
364-
public boolean isSubmitted() {
365-
return submitted;
366-
}
367-
368-
void setSubmitted() throws InvalidArgumentException {
369-
370-
if (submitted) {
371-
// Has already been submitted.
372-
throw new InvalidArgumentException("Request has been already submitted and can not be reused.");
373-
}
374-
User.userContextCheck(userContext);
375-
this.submitted = true;
376-
}
377-
378356
protected TransactionRequest(User userContext) {
379357
this.userContext = userContext;
380358
}

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import java.io.IOException;
1919
import java.net.MalformedURLException;
2020
import java.nio.file.Paths;
21-
import java.util.Arrays;
2221
import java.util.Collection;
22+
import java.util.Collections;
2323
import java.util.EnumSet;
2424
import java.util.HashMap;
2525
import java.util.LinkedList;
@@ -78,6 +78,7 @@
7878
import static org.hyperledger.fabric.sdk.testutils.TestUtils.getPEMStringFromPrivateKey;
7979
import static org.hyperledger.fabric.sdk.testutils.TestUtils.resetConfig;
8080
import static org.hyperledger.fabric.sdk.testutils.TestUtils.testRemovingAddingPeersOrderers;
81+
import static org.junit.Assert.assertArrayEquals;
8182
import static org.junit.Assert.assertEquals;
8283
import static org.junit.Assert.assertFalse;
8384
import static org.junit.Assert.assertNotNull;
@@ -217,7 +218,7 @@ public void runFabricTest(final SampleStore sampleStore) throws Exception {
217218
sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg2");
218219
Channel barChannel = constructChannel(BAR_CHANNEL_NAME, client, sampleOrg);
219220
assertTrue(barChannel.isInitialized());
220-
/**
221+
/*
221222
* sampleStore.saveChannel uses {@link Channel#serializeChannel()}
222223
*/
223224
sampleStore.saveChannel(barChannel);
@@ -345,7 +346,7 @@ class ChaincodeEventCapture { //A test class to capture chaincode events
345346
boolean isFooChain = FOO_CHANNEL_NAME.equals(channelName);
346347
out("Running channel %s", channelName);
347348

348-
Collection<Orderer> orderers = channel.getOrderers();
349+
channel.getOrderers();
349350
final ChaincodeID chaincodeID;
350351
Collection<ProposalResponse> responses;
351352
Collection<ProposalResponse> successful = new LinkedList<>();
@@ -381,15 +382,15 @@ class ChaincodeEventCapture { //A test class to capture chaincode events
381382
/////////////////////////////////////////////////////////////////////////////////////////////////
382383
/////////////////////////////////////////////////////////////////////////////////////////////////
383384
/////////////////////////////////////////////////////////////////////////////////////////////////
384-
/**
385+
/*
385386
* PLEASE READ !!
386387
*
387388
* The following is using Fabric v1.0 APIs for testing and demoing backward compatibility.
388389
* After v2.0 Fabric release unless there is a need for this in your application it is highly
389390
* encouraged to move to Fabric v2.0 capabilities and use the new v2.0 Lifecycle APIs for managing chaincode.
390391
* @see <a href="https://github.com/hyperledger/fabric-sdk-java/blob/master/docs/release_v2.0.0_notes.md#fabj-288-lifecycle-chaincode-management"</a>
391392
*
392-
**/
393+
*/
393394
/////////////////////////////////////////////////////////////////////////////////////////////////
394395
/////////////////////////////////////////////////////////////////////////////////////////////////
395396
/////////////////////////////////////////////////////////////////////////////////////////////////
@@ -496,7 +497,7 @@ class ChaincodeEventCapture { //A test class to capture chaincode events
496497
instantiateProposalRequest.setChaincodeID(chaincodeID);
497498
instantiateProposalRequest.setChaincodeLanguage(CHAIN_CODE_LANG);
498499
instantiateProposalRequest.setFcn("init");
499-
instantiateProposalRequest.setArgs(new String[] {"a", "500", "b", "" + (200 + delta)});
500+
instantiateProposalRequest.setArgs("a", "500", "b", String.valueOf(200 + delta));
500501
Map<String, byte[]> tm = new HashMap<>();
501502
tm.put("HyperLedgerFabric", "InstantiateProposalRequest:JavaSDK".getBytes(UTF_8));
502503
tm.put("method", "InstantiateProposalRequest".getBytes(UTF_8));
@@ -510,7 +511,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
510511
chaincodeEndorsementPolicy.fromYamlFile(new File(TEST_FIXTURES_PATH + "/sdkintegration/chaincodeendorsementpolicy.yaml"));
511512
instantiateProposalRequest.setChaincodeEndorsementPolicy(chaincodeEndorsementPolicy);
512513

513-
out("Sending instantiateProposalRequest to all peers with arguments: a and b set to 100 and %s respectively", "" + (200 + delta));
514+
out("Sending instantiateProposalRequest to all peers with arguments: a and b set to 100 and %s respectively", String.valueOf(200 + delta));
514515
successful.clear();
515516
failed.clear();
516517

@@ -541,7 +542,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
541542
}
542543
///////////////
543544
/// Send instantiate transaction to orderer
544-
out("Sending instantiateTransaction to orderer with a and b set to 100 and %s respectively", "" + (200 + delta));
545+
out("Sending instantiateTransaction to orderer with a and b set to 100 and %s respectively", String.valueOf(200 + delta));
545546

546547
//Specify what events should complete the interest in this transaction. This is the default
547548
// for all to complete. It's possible to specify many different combinations like
@@ -692,10 +693,10 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
692693
////////////////////////////
693694
// Send Query Proposal to all peers
694695
//
695-
String expect = "" + (300 + delta);
696+
String expect = String.valueOf(300 + delta);
696697
out("Now query chaincode for the value of b.");
697698
QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest();
698-
queryByChaincodeRequest.setArgs(new String[] {"b"});
699+
queryByChaincodeRequest.setArgs("b");
699700
queryByChaincodeRequest.setFcn("query");
700701
queryByChaincodeRequest.setChaincodeID(chaincodeID);
701702

@@ -704,16 +705,19 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
704705
tm2.put("method", "QueryByChaincodeRequest".getBytes(UTF_8));
705706
queryByChaincodeRequest.setTransientMap(tm2);
706707

707-
Collection<ProposalResponse> queryProposals = channel.queryByChaincode(queryByChaincodeRequest, channel.getPeers());
708-
for (ProposalResponse proposalResponse : queryProposals) {
709-
if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ProposalResponse.Status.SUCCESS) {
710-
fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() +
711-
". Messages: " + proposalResponse.getMessage()
712-
+ ". Was verified : " + proposalResponse.isVerified());
713-
} else {
714-
String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8();
715-
out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload);
716-
assertEquals(payload, expect);
708+
// Try each peer in turn just to confirm the request object can be reused
709+
for (Peer peer : channel.getPeers()) {
710+
Collection<ProposalResponse> queryProposals = channel.queryByChaincode(queryByChaincodeRequest, Collections.singletonList(peer));
711+
for (ProposalResponse proposalResponse : queryProposals) {
712+
if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ProposalResponse.Status.SUCCESS) {
713+
fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() +
714+
". Messages: " + proposalResponse.getMessage()
715+
+ ". Was verified : " + proposalResponse.isVerified());
716+
} else {
717+
String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8();
718+
out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload);
719+
assertEquals(payload, expect);
720+
}
717721
}
718722
}
719723

@@ -798,7 +802,7 @@ policy OR(Org1MSP.member, Org2MSP.member) meaning 1 signature from someone in ei
798802
assertEquals(chaincodeEventListenerHandle, chaincodeEventCapture.handle);
799803
assertEquals(testTxID, chaincodeEventCapture.chaincodeEvent.getTxId());
800804
assertEquals(EXPECTED_EVENT_NAME, chaincodeEventCapture.chaincodeEvent.getEventName());
801-
assertTrue(Arrays.equals(EXPECTED_EVENT_DATA, chaincodeEventCapture.chaincodeEvent.getPayload()));
805+
assertArrayEquals(EXPECTED_EVENT_DATA, chaincodeEventCapture.chaincodeEvent.getPayload());
802806
assertEquals(CHAIN_CODE_NAME, chaincodeEventCapture.chaincodeEvent.getChaincodeId());
803807

804808
BlockEvent blockEvent = chaincodeEventCapture.blockEvent;
@@ -945,8 +949,8 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
945949
out(" Transaction number %d has channel id: %s", i, channelId);
946950
out(" Transaction number %d has epoch: %d", i, envelopeInfo.getEpoch());
947951
out(" Transaction number %d has transaction timestamp: %tB %<te, %<tY %<tT %<Tp", i, envelopeInfo.getTimestamp());
948-
out(" Transaction number %d has type id: %s", i, "" + envelopeInfo.getType());
949-
out(" Transaction number %d has nonce : %s", i, "" + Hex.encodeHexString(envelopeInfo.getNonce()));
952+
out(" Transaction number %d has type id: %s", i, envelopeInfo.getType());
953+
out(" Transaction number %d has nonce : %s", i, Hex.encodeHexString(envelopeInfo.getNonce()));
950954
out(" Transaction number %d has submitter mspid: %s, certificate: %s", i, envelopeInfo.getCreator().getMspid(), envelopeInfo.getCreator().getId());
951955

952956
if (envelopeInfo.getType() == TRANSACTION_ENVELOPE) {
@@ -956,7 +960,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
956960
out(" Transaction number %d has %d actions", i, transactionEnvelopeInfo.getTransactionActionInfoCount());
957961
assertEquals(1, transactionEnvelopeInfo.getTransactionActionInfoCount()); // for now there is only 1 action per transaction.
958962
out(" Transaction number %d isValid %b", i, transactionEnvelopeInfo.isValid());
959-
assertEquals(transactionEnvelopeInfo.isValid(), true);
963+
assertTrue(transactionEnvelopeInfo.isValid());
960964
out(" Transaction number %d validation code %d", i, transactionEnvelopeInfo.getValidationCode());
961965
assertEquals(0, transactionEnvelopeInfo.getValidationCode());
962966

@@ -999,7 +1003,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
9991003
ChaincodeEvent chaincodeEvent = transactionActionInfo.getEvent();
10001004
assertNotNull(chaincodeEvent);
10011005

1002-
assertTrue(Arrays.equals(EXPECTED_EVENT_DATA, chaincodeEvent.getPayload()));
1006+
assertArrayEquals(EXPECTED_EVENT_DATA, chaincodeEvent.getPayload());
10031007
assertEquals(testTxID, chaincodeEvent.getTxId());
10041008
assertEquals(CHAIN_CODE_NAME, chaincodeEvent.getChaincodeId());
10051009
assertEquals(EXPECTED_EVENT_NAME, chaincodeEvent.getEventName());
@@ -1076,7 +1080,7 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
10761080
}
10771081
}
10781082
if (!TX_EXPECTED.isEmpty()) {
1079-
fail(TX_EXPECTED.get(0));
1083+
fail(TX_EXPECTED.values().toString());
10801084
}
10811085
} catch (InvalidProtocolBufferRuntimeException e) {
10821086
throw e.getCause();

0 commit comments

Comments
 (0)