2

I'm going through the commercial paper tutorial in the Hyperledger Fabric docs, and I'm getting a runtime error when I try to use the Issue application (Issue.java). https://hyperledger-fabric.readthedocs.io/en/latest/tutorial/commercial_paper.html

I've used the Java chaincode and Java application code given in the commercial paper folder of fabric-samples. https://github.com/hyperledger/fabric-samples/tree/main/commercial-paper

My OS is Debian GNU/Linux 10 (Buster).

When I run mvn exec:java -Dexec.mainClass="org.magnetocorp.AddToWallet", it successfully adds to the wallet. But when I run mvn exec:java -Dexec.mainClass="org.magnetocorp.Issue" it yields the following:

Read wallet info from: ./wallet
log4j:WARN No appenders could be found for logger (org.hyperledger.fabric.sdk.helper.Config).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Use network channel: mychannel.
Use org.papernet.commercialpaper smart contract.
Submit commercial paper issue transaction.

org.hyperledger.fabric.gateway.ContractException: Transaction commit was rejected by peer peer0.org2.example.com
        at org.hyperledger.fabric.gateway.impl.commit.CommitHandlerImpl.onTxEvent(CommitHandlerImpl.java:104)
        at org.hyperledger.fabric.gateway.impl.commit.CommitHandlerImpl.access$000(CommitHandlerImpl.java:26)
        at org.hyperledger.fabric.gateway.impl.commit.CommitHandlerImpl$1.acceptCommit(CommitHandlerImpl.java:33)
        at org.hyperledger.fabric.gateway.impl.event.Listeners.lambda$transaction$7(Listeners.java:122)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at org.hyperledger.fabric.gateway.impl.event.Listeners.lambda$fromTransaction$0(Listeners.java:32)
        at org.hyperledger.fabric.sdk.Channel.lambda$null$12(Channel.java:5974)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

Why was the transaction commit rejected? (And how do I resolve this error?) Any help would be much appreciated.

Ravi
  • 39
  • 1
  • 6
  • I'm facing the same problem using the same OS. Unfortunately, I still can't find a solution online neither fix it. It was hard to find the same exact question. What was the exact problem if you ever fixed it. I tried @bestbeforetoday solution but it doesn't provide more details about the exception itself. A hand would be deeply appreciated. Thanks. – comocoder Oct 16 '21 at 17:36

1 Answers1

1

Assuming you are using a current v2.2.x version of fabric-gateway-java, you should be able to get at some information about the reason for the failure by inspecting the cause linked to that ContractException. Something like this:

Throwable cause = e.getCause();
if (cause instanceof TransactionEventException) {
    BlockEvent.TransactionEvent txEvent = ((TransactionEventException) cause).getTransactionEvent();
    byte validationCode = txEvent.getValidationCode();
}

The validation code values are in the Fabric protobuf definitions.

You can also inspect the proposal responses received from peers to endorse this transaction if the validation code indicates that the endorsement requirements were not met. The proposal responses can be obtained from the ContractException.

The peer logs may also contain more detail about the reason for the failure.

bestbeforetoday
  • 1,302
  • 1
  • 8
  • 12
  • Hello, I'm facing the exact same issue. I added this block of code but it doesn't provide more deep information about what the error is. Any other option to resolve it would be appreciated. I'm new to hyperledger. – comocoder Oct 16 '21 at 06:29
  • The validation code will give you an indication of why the transaction committed unsuccessfully. From there your course of action depends on that reason. For example an MVCC_READ_CONFLICT indicates that another transaction modified keys accessed by your transaction before it committed, so you can just try executing the transaction again. Logs from the peer that rejected the transaction are often a good place to look for additional information. – bestbeforetoday Oct 21 '21 at 08:32