@@ -80,21 +80,23 @@ func (*Endorser) checkEsccAndVscc(prop *pb.Proposal) error {
80
80
func (* Endorser ) getTxSimulator (ledgername string ) (ledger.TxSimulator , error ) {
81
81
lgr := peer .GetLedger (ledgername )
82
82
if lgr == nil {
83
- return nil , fmt .Errorf ("chain does not exist(%s) " , ledgername )
83
+ return nil , fmt .Errorf ("channel does not exist: %s " , ledgername )
84
84
}
85
85
return lgr .NewTxSimulator ()
86
86
}
87
87
88
88
func (* Endorser ) getHistoryQueryExecutor (ledgername string ) (ledger.HistoryQueryExecutor , error ) {
89
89
lgr := peer .GetLedger (ledgername )
90
90
if lgr == nil {
91
- return nil , fmt .Errorf ("chain does not exist(%s) " , ledgername )
91
+ return nil , fmt .Errorf ("channel does not exist: %s " , ledgername )
92
92
}
93
93
return lgr .NewHistoryQueryExecutor ()
94
94
}
95
95
96
96
//call specified chaincode (system or user)
97
97
func (e * Endorser ) callChaincode (ctxt context.Context , chainID string , version string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cis * pb.ChaincodeInvocationSpec , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (* pb.Response , * pb.ChaincodeEvent , error ) {
98
+ endorserLogger .Debugf ("Entry - txid: %s channel id: %s version: %s" , txid , chainID , version )
99
+ defer endorserLogger .Debugf ("Exit" )
98
100
var err error
99
101
var res * pb.Response
100
102
var ccevent * pb.ChaincodeEvent
@@ -117,9 +119,8 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
117
119
//per doc anything < 500 can be sent as TX.
118
120
//fabric errors will always be >= 500 (ie, unambiguous errors )
119
121
//"lscc" will respond with status 200 or >=500 (ie, unambiguous OK or ERROR)
120
- //This leaves all < 500 errors to user chaincodes
121
122
if res .Status >= shim .ERROR {
122
- return nil , nil , fmt . Errorf ( string ( res . Message ))
123
+ return res , nil , nil
123
124
}
124
125
125
126
//----- BEGIN - SECTION THAT MAY NEED TO BE DONE IN LSCC ------
@@ -200,6 +201,8 @@ func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
200
201
201
202
//simulate the proposal by calling the chaincode
202
203
func (e * Endorser ) simulateProposal (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (* ccprovider.ChaincodeData , * pb.Response , []byte , * pb.ChaincodeEvent , error ) {
204
+ endorserLogger .Debugf ("Entry - txid: %s channel id: %s" , txid , chainID )
205
+ defer endorserLogger .Debugf ("Exit" )
203
206
//we do expect the payload to be a ChaincodeInvocationSpec
204
207
//if we are supporting other payloads in future, this be glaringly point
205
208
//as something that should change
@@ -263,6 +266,7 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
263
266
var ccevent * pb.ChaincodeEvent
264
267
res , ccevent , err = e .callChaincode (ctx , chainID , version , txid , signedProp , prop , cis , cid , txsim )
265
268
if err != nil {
269
+ endorserLogger .Errorf ("callChaincode() failed for txid: %s error: %s" , txid , err )
266
270
return nil , nil , nil , nil , err
267
271
}
268
272
@@ -286,7 +290,8 @@ func (e *Endorser) getCDSFromLSCC(ctx context.Context, chainID string, txid stri
286
290
287
291
//endorse the proposal by calling the ESCC
288
292
func (e * Endorser ) endorseProposal (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , proposal * pb.Proposal , response * pb.Response , simRes []byte , event * pb.ChaincodeEvent , visibility []byte , ccid * pb.ChaincodeID , txsim ledger.TxSimulator , cd * ccprovider.ChaincodeData ) (* pb.ProposalResponse , error ) {
289
- endorserLogger .Debugf ("endorseProposal starts for chainID %s, ccid %s" , chainID , ccid )
293
+ endorserLogger .Debugf ("Entry - txid: %s channel id: %s chaincode id: %s" , txid , chainID , ccid )
294
+ defer endorserLogger .Debugf ("Exit" )
290
295
291
296
isSysCC := cd == nil
292
297
// 1) extract the name of the escc that is requested to endorse this chaincode
@@ -303,7 +308,7 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
303
308
}
304
309
}
305
310
306
- endorserLogger .Debugf ("endorseProposal info: escc for cid %s is %s" , ccid , escc )
311
+ endorserLogger .Debugf ("info: escc for chaincode id %s is %s" , ccid , escc )
307
312
308
313
// marshalling event bytes
309
314
var err error
@@ -353,7 +358,7 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
353
358
}
354
359
355
360
if res .Status >= shim .ERROR {
356
- return nil , fmt . Errorf ( string ( res . Message ))
361
+ return & pb. ProposalResponse { Response : res }, nil
357
362
}
358
363
359
364
prBytes := res .Payload
@@ -377,6 +382,8 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
377
382
378
383
// ProcessProposal process the Proposal
379
384
func (e * Endorser ) ProcessProposal (ctx context.Context , signedProp * pb.SignedProposal ) (* pb.ProposalResponse , error ) {
385
+ endorserLogger .Debugf ("Entry" )
386
+ defer endorserLogger .Debugf ("Exit" )
380
387
// at first, we check whether the message is valid
381
388
prop , hdr , hdrExt , err := validation .ValidateProposalMessage (signedProp )
382
389
if err != nil {
@@ -395,7 +402,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
395
402
396
403
// block invocations to security-sensitive system chaincodes
397
404
if syscc .IsSysCCAndNotInvokableExternal (hdrExt .ChaincodeId .Name ) {
398
- endorserLogger .Errorf ("ProcessProposal error : an attempt was made by %#v to invoke system chaincode %s" ,
405
+ endorserLogger .Errorf ("Error : an attempt was made by %#v to invoke system chaincode %s" ,
399
406
shdr .Creator , hdrExt .ChaincodeId .Name )
400
407
err = fmt .Errorf ("Chaincode %s cannot be invoked through a proposal" , hdrExt .ChaincodeId .Name )
401
408
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, err
@@ -468,6 +475,23 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
468
475
if err != nil {
469
476
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, err
470
477
}
478
+ if res != nil {
479
+ if res .Status >= shim .ERROR {
480
+ endorserLogger .Debugf ("simulateProposal() resulted in chaincode error for txid: %s" , txid )
481
+ var cceventBytes []byte
482
+ if ccevent != nil {
483
+ cceventBytes , err = putils .GetBytesChaincodeEvent (ccevent )
484
+ if err != nil {
485
+ return nil , fmt .Errorf ("failed to marshal event bytes - %s" , err )
486
+ }
487
+ }
488
+ pResp , err := putils .CreateProposalResponseFailure (prop .Header , prop .Payload , res , simulationResult , cceventBytes , hdrExt .ChaincodeId , hdrExt .PayloadVisibility )
489
+ if err != nil {
490
+ return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, err
491
+ }
492
+ return pResp , nil
493
+ }
494
+ }
471
495
472
496
//2 -- endorse and get a marshalled ProposalResponse message
473
497
var pResp * pb.ProposalResponse
@@ -481,6 +505,12 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
481
505
if err != nil {
482
506
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, err
483
507
}
508
+ if pResp != nil {
509
+ if res .Status >= shim .ERROR {
510
+ endorserLogger .Debugf ("endorseProposal() resulted in chaincode error for txid: %s" , txid )
511
+ return pResp , nil
512
+ }
513
+ }
484
514
}
485
515
486
516
// Set the proposal response payload - it
0 commit comments