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

Commit 465d871

Browse files
committed
FAB-4088 Determine which proposals are consistent
Decided this should be checked all the time by default. Allow users to turn off and then check explicitly if they so desire. Change-Id: Ied8c02db63fe6af0033e25f061031e5a75b553b2 Signed-off-by: rickr <cr22rc@gmail.com>
1 parent 457ac61 commit 465d871

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -995,16 +995,16 @@ private Block getConfigurationBlock() throws TransactionException {
995995
Payload payload = Payload.parseFrom(envelopeRet.getPayload());
996996
ChannelHeader channelHeader = ChannelHeader.parseFrom(payload.getHeader().getChannelHeader());
997997
if (channelHeader.getType() != HeaderType.CONFIG.getNumber()) {
998-
throw new TransactionException(format("Bad last configuation block type %d, expected %d",
998+
throw new TransactionException(format("Bad last configuration block type %d, expected %d",
999999
channelHeader.getType(), HeaderType.CONFIG.getNumber()));
10001000
}
10011001

10021002
if (!name.equals(channelHeader.getChannelId())) {
1003-
throw new TransactionException(format("Bad last configuation block channel id %s, expected %s",
1003+
throw new TransactionException(format("Bad last configuration block channel id %s, expected %s",
10041004
channelHeader.getChannelId(), name));
10051005
}
10061006

1007-
logger.trace(format("Channel %s getConfigurationBlock retraceturned %s", name, "" + configBlock));
1007+
logger.trace(format("Channel %s getConfigurationBlock returned %s", name, "" + configBlock));
10081008
if (!logger.isTraceEnabled()) {
10091009
logger.debug(format("Channel %s getConfigurationBlock returned", name));
10101010
}
@@ -1246,9 +1246,9 @@ public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposa
12461246
*
12471247
* @param instantiateProposalRequest
12481248
* @param peers
1249+
* @return
12491250
* @throws IllegalArgumentException
12501251
* @throws ProposalException
1251-
* @return
12521252
*/
12531253

12541254
public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposalRequest instantiateProposalRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
@@ -1502,7 +1502,7 @@ public BlockInfo queryBlockByHash(Peer peer, byte[] blockHash) throws InvalidArg
15021502
}
15031503
responseBlock = new BlockInfo(Block.parseFrom(proposalResponse.getProposalResponse().getResponse().getPayload()));
15041504
} catch (Exception e) {
1505-
String emsg = format("queryBlockByHash hash: %s %npeer %s channel %s %nerror: %s",
1505+
String emsg = format("queryBlockByHash hash: %s peer %s channel %s error: %s",
15061506
Hex.encodeHexString(blockHash), peer.getName(), name, e.getMessage());
15071507
logger.error(emsg, e);
15081508
throw new ProposalException(emsg, e);
@@ -2057,7 +2057,6 @@ public Collection<ProposalResponse> queryByChaincode(QueryByChaincodeRequest que
20572057
* @return
20582058
* @throws InvalidArgumentException
20592059
* @throws ProposalException
2060-
*
20612060
*/
20622061

20632062
public Collection<ProposalResponse> queryByChaincode(QueryByChaincodeRequest queryByChaincodeRequest, Collection<Peer> peers) throws InvalidArgumentException, ProposalException {
@@ -2229,6 +2228,15 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
22292228
throw new TransactionException("sendTransaction on channel not initialized.");
22302229
}
22312230

2231+
if (config.getProposalConsistencyValidation()) {
2232+
2233+
if (1 != SDKUtils.getProposalConsistencySets(proposalResponses).size()) {
2234+
throw new IllegalArgumentException("The proposal responses do not have consistent read write sets");
2235+
2236+
}
2237+
2238+
}
2239+
22322240
List<FabricProposalResponse.Endorsement> ed = new LinkedList<>();
22332241
FabricProposal.Proposal proposal = null;
22342242
ByteString proposalResponsePayload = null;
@@ -2275,8 +2283,6 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe
22752283

22762284
}
22772285

2278-
//TransactionResponse tresp = new TransactionResponse(transactionContext.getTxID(), transactionContext.getChannelID(), resp.getStatusValue(), resp.getStatus().name());
2279-
22802286
}
22812287

22822288
if (success) {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class ProposalResponse extends ChaincodeResponse {
2525

2626
private static final Log logger = LogFactory.getLog(ProposalResponse.class);
27-
Config config = Config.getConfig();
27+
final static Config config = Config.getConfig();
2828
private FabricProposal.SignedProposal signedProposal;
2929

3030
private boolean isVerified = false;
@@ -40,7 +40,7 @@ public class ProposalResponse extends ChaincodeResponse {
4040

4141
}
4242

43-
public ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() throws InvalidArgumentException {
43+
ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() throws InvalidArgumentException {
4444
ProposalResponsePayloadDeserializer ret = null;
4545

4646
if (proposalResponsePayload != null) {
@@ -158,6 +158,7 @@ void setPeer(Peer peer) {
158158

159159
/**
160160
* Chaincode ID that was executed.
161+
*
161162
* @return See {@link ChaincodeID}
162163
* @throws InvalidArgumentException
163164
*/
@@ -185,10 +186,10 @@ public ChaincodeID getChaincodeID() throws InvalidArgumentException {
185186
* ChaincodeActionResponsePayload is the result of the executing chaincode.
186187
*
187188
* @return the result of the executing chaincode.
188-
* @throws InvalidProtocolBufferException
189+
* @throws InvalidArgumentException
189190
*/
190191

191-
public byte[] getChaincodeActionResponsePayload() throws InvalidProtocolBufferException, InvalidArgumentException {
192+
public byte[] getChaincodeActionResponsePayload() throws InvalidArgumentException {
192193

193194
try {
194195

@@ -229,6 +230,7 @@ public int getChaincodeActionResponseStatus() throws InvalidArgumentException {
229230

230231
/**
231232
* getChaincodeActionResponseReadWriteSetInfo get this proposals read write set.
233+
*
232234
* @return The read write set. See {@link TxReadWriteSetInfo}
233235
* @throws InvalidArgumentException
234236
*/

src/main/java/org/hyperledger/fabric/sdk/helper/Config.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class Config {
4141
public static final String HASH_ALGORITHM = "org.hyperledger.fabric.sdk.hash_algorithm";
4242
public static final String CACERTS = "org.hyperledger.fabric.sdk.cacerts";
4343
public static final String PROPOSAL_WAIT_TIME = "org.hyperledger.fabric.sdk.proposal.wait.time";
44+
public static final String PROPOSAL_CONSISTENCY_VALIDATION = "org.hyperledger.fabric.sdk.proposal.consistency_validation";
4445
public static final String GENESISBLOCK_WAIT_TIME = "org.hyperledger.fabric.sdk.channel.genesisblock_wait_time";
4546
public static final String ASYMMETRIC_KEY_TYPE = "org.hyperledger.fabric.sdk.crypto.asymmetric_key_type";
4647
public static final String KEY_AGREEMENT_ALGORITHM = "org.hyperledger.fabric.sdk.crypto.key_agreement_algorithm";
@@ -85,6 +86,7 @@ private Config() {
8586
defaultProperty(SIGNATURE_ALGORITHM, "SHA256withECDSA");
8687
defaultProperty(SECURITY_LEVEL, "256");
8788
defaultProperty(HASH_ALGORITHM, "SHA2");
89+
defaultProperty(PROPOSAL_CONSISTENCY_VALIDATION, "true");
8890
// TODO remove this once we have implemented MSP and get the peer certs from the channel
8991
defaultProperty(CACERTS, "/genesisblock/peercacert.pem");
9092

@@ -275,6 +277,18 @@ public int maxLogStringLength() {
275277
return Integer.parseInt(getProperty(MAX_LOG_STRING_LENGTH));
276278
}
277279

280+
/**
281+
* getProposalConsistencyValidation determine if validation of the proposals should
282+
* be done before sending to the orderer.
283+
*
284+
* @return if true proposals will be checked they are consistent with each other before sending to the Orderer
285+
*/
286+
287+
public boolean getProposalConsistencyValidation() {
288+
return Boolean.parseBoolean(getProperty(PROPOSAL_CONSISTENCY_VALIDATION));
289+
290+
}
291+
278292
public int extraLogLevel = -1;
279293

280294
public boolean extraLogLevel(int val) {

0 commit comments

Comments
 (0)