hyperledger / fabric-admin-sdk

Hyperledger Fabric admin SDK
Apache License 2.0
31 stars 19 forks source link

missing attached details for chaincode.Commit(...) #126

Closed 1gezhanghao closed 1 year ago

1gezhanghao commented 1 year ago
err = chaincode.Commit(...)
if err!=nil{
   logger.Error(err)
   if strings.Contains(err.Error(), "see attached details for more info") {
       er := ParseAttachedInfo(err)
       return er
   }
   return err
}

//"google.golang.org/grpc/status"
func ParseAttachedInfo(err error) error {                                                                                                                                             
        statusErr := status.Convert(err)                                                                                                                                          
        details := statusErr.Details()                                                                                                                                            
        logger.Info(len(details))                                                                                                                                       

        var er error                                                                                                                                                              
        if len(details) > 0 {                                                                                                                                              
                for _, detail := range details {                                                                                                                                  
                        er = errors.Join(er, fmt.Errorf("%s", detail))                                                                                                            
                }                                                                                                                                                                 
        }                                                                                                                                                                         
        return er                                                                                                                                                                 
}

when a chaincode not approved by all orgs, do chaincode.Commit(...),it will give a error failed to commit chaincode: rpc error: code = Aborted desc = failed to collect enough transaction endorsements, see attached details for more info

then i try parse the attached details info by ParseAttachedInfo(.), but details length is 0

the peer0.org1.example.com give logs as follows

2023-05-22 08:11:12.415 UTC 014d INFO [lifecycle] CheckCommitReadiness -> Successfully checked commit readiness of chaincode name 'rmbcc' on channel 'pub' with definition {sequence: 1, endorsement info: (version: '1.0', plugin: 'escc', init required: false), validation info: (plugin: 'vscc', policy: '0a2c120c120a080212020800120208011a0d120b0a074f7267314d535010031a0d120b0a074f7267324d53501003'), collections: (<nil>)}
2023-05-22 08:11:12.415 UTC 014e INFO [endorser] callChaincode -> finished chaincode: _lifecycle duration: 2ms channel=pub txID=7d26d657
2023-05-22 08:11:12.416 UTC 014f WARN [gateway] func1 -> Endorse call to endorser failed channel=pub chaincode=_lifecycle txID=7d26d657fbbefb00a6690c74e3b81a966594885b800a682c11137034c66718b8 endorserAddress=peer0.org1.example.com:7051 endorserMspid=Org1MSP error="chaincode response 500, failed to invoke backing implementation of 'CommitChaincodeDefinition': chaincode definition not agreed to by this org (Org1MSP)"
2023-05-22 08:11:12.419 UTC 0150 WARN [gateway] func1 -> Endorse call to endorser failed channel=pub chaincode=_lifecycle txID=7d26d657fbbefb00a6690c74e3b81a966594885b800a682c11137034c66718b8 endorserAddress=peer1.org1.example.com:7051 endorserMspid=Org1MSP error="chaincode response 500, failed to invoke backing implementation of 'CommitChaincodeDefinition': chaincode definition not agreed to by this org (Org1MSP)"
2023-05-22 08:11:12.423 UTC 0151 WARN [gateway] func1 -> Endorse call to endorser failed channel=pub chaincode=_lifecycle txID=7d26d657fbbefb00a6690c74e3b81a966594885b800a682c11137034c66718b8 endorserAddress=peer2.org1.example.com:7051 endorserMspid=Org1MSP error="chaincode response 500, failed to invoke backing implementation of 'CommitChaincodeDefinition': chaincode definition not agreed to by this org (Org1MSP)"
2023-05-22 08:11:12.423 UTC 0152 INFO [comm.grpc.server] 1 -> unary call completed grpc.service=gateway.Gateway grpc.method=Endorse grpc.request_deadline=2023-05-22T08:11:42.412Z grpc.peer_address=172.16.0.1:46132 error="rpc error: code = Aborted desc = failed to endorse transaction, see attached details for more info" grpc.code=Aborted grpc.call_duration=10.646662ms

it sames chaincode.Commit(...) missing the attached details

1gezhanghao commented 1 year ago

same problem to chaincode.Approve(...)

bestbeforetoday commented 1 year ago

The problem looks to be that status.Convert() just checks if the error itself has the required GRPCStatus() method, whereas the error returned wraps the underlying error and so does not directly implement this method. It might be better if the gRPC status functions dealt with wrapped errors better, but the simplest fix is likely to just not wrap the error in the admin API.

bestbeforetoday commented 1 year ago

It looks like this was recently fixed in grpc-go. Updating the grpc dependency version should resolve it, but it would be good to also have a unit test to confirm.

1gezhanghao commented 1 year ago

@bestbeforetoday grpc-go:v.1.55.0 worked, tks