Skip to content

Commit 70a8b01

Browse files
author
Srinivasan Muralidharan
committed
FAB-2194 unmarshal Response only when resp. is from CC
https://jira.hyperledger.org/browse/FAB-2194 Look for pb.Response only on pb.ChaincodeMessage_COMPLETED. Others are non-CC errors and will not carry response from chaincode. Change-Id: I24160a643dd09089f0e2f5cf694e620cde29b0fc Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent d58349a commit 70a8b01

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

core/chaincode/exectransaction.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,28 @@ func Execute(ctxt context.Context, cccid *ccprovider.CCContext, spec interface{}
7878
// Rollback transaction
7979
return nil, nil, fmt.Errorf("Failed to receive a response for (%s)", cccid.TxID)
8080
}
81-
res := &pb.Response{}
82-
unmarshalErr := proto.Unmarshal(resp.Payload, res)
83-
if unmarshalErr != nil {
84-
return nil, nil, fmt.Errorf("Failed to unmarshal response for (%s): %s", cccid.TxID, unmarshalErr)
85-
}
8681

8782
if resp.ChaincodeEvent != nil {
8883
resp.ChaincodeEvent.ChaincodeId = cccid.Name
8984
resp.ChaincodeEvent.TxId = cccid.TxID
9085
}
9186

9287
if resp.Type == pb.ChaincodeMessage_COMPLETED {
88+
res := &pb.Response{}
89+
unmarshalErr := proto.Unmarshal(resp.Payload, res)
90+
if unmarshalErr != nil {
91+
return nil, nil, fmt.Errorf("Failed to unmarshal response for (%s): %s", cccid.TxID, unmarshalErr)
92+
}
93+
9394
// Success
9495
return res, resp.ChaincodeEvent, nil
9596
} else if resp.Type == pb.ChaincodeMessage_ERROR {
9697
// Rollback transaction
9798
return nil, resp.ChaincodeEvent, fmt.Errorf("Transaction returned with failure: %s", string(resp.Payload))
9899
}
99100

100-
return res, nil, fmt.Errorf("receive a response for (%s) but in invalid state(%d)", cccid.TxID, resp.Type)
101+
//TODO - this should never happen ... a panic is more appropriate but will save that for future
102+
return nil, nil, fmt.Errorf("receive a response for (%s) but in invalid state(%d)", cccid.TxID, resp.Type)
101103
}
102104

103105
// ExecuteWithErrorFilter is similar to Execute, but filters error contained in chaincode response and returns Payload of response only.

0 commit comments

Comments
 (0)