Roxana
Roxana

Reputation: 392

INVOKE_CHAINCODE failed: transaction ID exists

I have a chaincode with two contracts such that the second contract invoke a transaction of the first one as follows:

class ContractA implements ContractInterface{
     .....
     @Transaction
     public boolean trans1(MyContext ctx, String data) {
         ...
         return result;
     }
}

class ContractB implements ContractInterface{
     .....
     @Transaction
     public boolean trans2(MyContext ctx, String data) {
         ...
         Chaincode.Response response = ctx.getStub().invokeChaincode(chaincodeId,
                    new String[]{ContractA:trans1, "data"});
         ...
     }
}

During the execution of trans2, the invokeChaincode fails with the error: "INVOKE_CHAINCODE failed: transaction ID exists". According to the documentation, no other transaction will be created by calling invokeChaincode, therefore, it is correct that the invocation is created with the same transaction ID.

Is it a bug or am I doing something incorrect in my design?

Many thanks in advance, Roxana

Upvotes: 3

Views: 359

Answers (1)

Jason Yellick
Jason Yellick

Reputation: 1624

Performing ctx.getStub().invokeChaincode(chaincodeId, new String[]{ContractA:trans1, "data"}); is asking the peer to perform a chaincode to chaincode invocation, to itself. Recursively calling chaincode is not supported.

The error message here could probably be improved, but essentially, resources are allocated for a chaincode invocation, associated to a txid, which are then cleaned up when the transaction finishes. Because your transaction is already interacting with your chaincode, these resources already exist, and attempting to create them results in the error you see returned.

If you wish to call another function within your own chaincode, simply invoke it as a normal function, rather than attempting to invoke it via the chaincode stub.

Upvotes: 4

Related Questions