Skip to content

Commit

Permalink
FAB-4088 Determine which proposals are consistent
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cr22rc committed May 24, 2017
1 parent 457ac61 commit 465d871
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/main/java/org/hyperledger/fabric/sdk/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -995,16 +995,16 @@ private Block getConfigurationBlock() throws TransactionException {
Payload payload = Payload.parseFrom(envelopeRet.getPayload());
ChannelHeader channelHeader = ChannelHeader.parseFrom(payload.getHeader().getChannelHeader());
if (channelHeader.getType() != HeaderType.CONFIG.getNumber()) {
throw new TransactionException(format("Bad last configuation block type %d, expected %d",
throw new TransactionException(format("Bad last configuration block type %d, expected %d",
channelHeader.getType(), HeaderType.CONFIG.getNumber()));
}

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

logger.trace(format("Channel %s getConfigurationBlock retraceturned %s", name, "" + configBlock));
logger.trace(format("Channel %s getConfigurationBlock returned %s", name, "" + configBlock));
if (!logger.isTraceEnabled()) {
logger.debug(format("Channel %s getConfigurationBlock returned", name));
}
Expand Down Expand Up @@ -1246,9 +1246,9 @@ public Collection<ProposalResponse> sendInstantiationProposal(InstantiateProposa
*
* @param instantiateProposalRequest
* @param peers
* @return
* @throws IllegalArgumentException
* @throws ProposalException
* @return
*/

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

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

if (config.getProposalConsistencyValidation()) {

if (1 != SDKUtils.getProposalConsistencySets(proposalResponses).size()) {
throw new IllegalArgumentException("The proposal responses do not have consistent read write sets");

}

}

List<FabricProposalResponse.Endorsement> ed = new LinkedList<>();
FabricProposal.Proposal proposal = null;
ByteString proposalResponsePayload = null;
Expand Down Expand Up @@ -2275,8 +2283,6 @@ public CompletableFuture<TransactionEvent> sendTransaction(Collection<ProposalRe

}

//TransactionResponse tresp = new TransactionResponse(transactionContext.getTxID(), transactionContext.getChannelID(), resp.getStatusValue(), resp.getStatus().name());

}

if (success) {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/hyperledger/fabric/sdk/ProposalResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class ProposalResponse extends ChaincodeResponse {

private static final Log logger = LogFactory.getLog(ProposalResponse.class);
Config config = Config.getConfig();
final static Config config = Config.getConfig();
private FabricProposal.SignedProposal signedProposal;

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

}

public ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() throws InvalidArgumentException {
ProposalResponsePayloadDeserializer getProposalResponsePayloadDeserializer() throws InvalidArgumentException {
ProposalResponsePayloadDeserializer ret = null;

if (proposalResponsePayload != null) {
Expand Down Expand Up @@ -158,6 +158,7 @@ void setPeer(Peer peer) {

/**
* Chaincode ID that was executed.
*
* @return See {@link ChaincodeID}
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -185,10 +186,10 @@ public ChaincodeID getChaincodeID() throws InvalidArgumentException {
* ChaincodeActionResponsePayload is the result of the executing chaincode.
*
* @return the result of the executing chaincode.
* @throws InvalidProtocolBufferException
* @throws InvalidArgumentException
*/

public byte[] getChaincodeActionResponsePayload() throws InvalidProtocolBufferException, InvalidArgumentException {
public byte[] getChaincodeActionResponsePayload() throws InvalidArgumentException {

try {

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

/**
* getChaincodeActionResponseReadWriteSetInfo get this proposals read write set.
*
* @return The read write set. See {@link TxReadWriteSetInfo}
* @throws InvalidArgumentException
*/
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/helper/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Config {
public static final String HASH_ALGORITHM = "org.hyperledger.fabric.sdk.hash_algorithm";
public static final String CACERTS = "org.hyperledger.fabric.sdk.cacerts";
public static final String PROPOSAL_WAIT_TIME = "org.hyperledger.fabric.sdk.proposal.wait.time";
public static final String PROPOSAL_CONSISTENCY_VALIDATION = "org.hyperledger.fabric.sdk.proposal.consistency_validation";
public static final String GENESISBLOCK_WAIT_TIME = "org.hyperledger.fabric.sdk.channel.genesisblock_wait_time";
public static final String ASYMMETRIC_KEY_TYPE = "org.hyperledger.fabric.sdk.crypto.asymmetric_key_type";
public static final String KEY_AGREEMENT_ALGORITHM = "org.hyperledger.fabric.sdk.crypto.key_agreement_algorithm";
Expand Down Expand Up @@ -85,6 +86,7 @@ private Config() {
defaultProperty(SIGNATURE_ALGORITHM, "SHA256withECDSA");
defaultProperty(SECURITY_LEVEL, "256");
defaultProperty(HASH_ALGORITHM, "SHA2");
defaultProperty(PROPOSAL_CONSISTENCY_VALIDATION, "true");
// TODO remove this once we have implemented MSP and get the peer certs from the channel
defaultProperty(CACERTS, "/genesisblock/peercacert.pem");

Expand Down Expand Up @@ -275,6 +277,18 @@ public int maxLogStringLength() {
return Integer.parseInt(getProperty(MAX_LOG_STRING_LENGTH));
}

/**
* getProposalConsistencyValidation determine if validation of the proposals should
* be done before sending to the orderer.
*
* @return if true proposals will be checked they are consistent with each other before sending to the Orderer
*/

public boolean getProposalConsistencyValidation() {
return Boolean.parseBoolean(getProperty(PROPOSAL_CONSISTENCY_VALIDATION));

}

public int extraLogLevel = -1;

public boolean extraLogLevel(int val) {
Expand Down

0 comments on commit 465d871

Please sign in to comment.