@@ -117,15 +117,15 @@ func NewEndorserServer(privDist privateDataDistributor, s Support, pr *packaging
117
117
}
118
118
119
119
// call specified chaincode (system or user)
120
- func (e * Endorser ) callChaincode (txParams * ccprovider.TransactionParams , idBytes []byte , requiresInit bool , input * pb.ChaincodeInput , cid * pb. ChaincodeID ) (* pb.Response , * pb.ChaincodeEvent , error ) {
121
- endorserLogger .Infof ("[%s][%s] Entry chaincode: %s" , txParams .ChannelID , shorttxid (txParams .TxID ), cid )
120
+ func (e * Endorser ) callChaincode (txParams * ccprovider.TransactionParams , idBytes []byte , requiresInit bool , input * pb.ChaincodeInput , chaincodeName string ) (* pb.Response , * pb.ChaincodeEvent , error ) {
121
+ endorserLogger .Infof ("[%s][%s] Entry chaincode: %s" , txParams .ChannelID , shorttxid (txParams .TxID ), chaincodeName )
122
122
defer func (start time.Time ) {
123
123
logger := endorserLogger .WithOptions (zap .AddCallerSkip (1 ))
124
124
elapsedMilliseconds := time .Since (start ).Round (time .Millisecond ) / time .Millisecond
125
- logger .Infof ("[%s][%s] Exit chaincode: %s (%dms)" , txParams .ChannelID , shorttxid (txParams .TxID ), cid , elapsedMilliseconds )
125
+ logger .Infof ("[%s][%s] Exit chaincode: %s (%dms)" , txParams .ChannelID , shorttxid (txParams .TxID ), chaincodeName , elapsedMilliseconds )
126
126
}(time .Now ())
127
127
128
- res , ccevent , err := e .s .Execute (txParams , txParams .ChannelID , cid . Name , txParams .TxID , idBytes , requiresInit , txParams .SignedProp , txParams .Proposal , input )
128
+ res , ccevent , err := e .s .Execute (txParams , txParams .ChannelID , chaincodeName , txParams .TxID , idBytes , requiresInit , txParams .SignedProp , txParams .Proposal , input )
129
129
if err != nil {
130
130
return nil , nil , err
131
131
}
@@ -145,7 +145,7 @@ func (e *Endorser) callChaincode(txParams *ccprovider.TransactionParams, idBytes
145
145
//
146
146
// NOTE that if there's an error all simulation, including the chaincode
147
147
// table changes in lscc will be thrown away
148
- if cid . Name == "lscc" && len (input .Args ) >= 3 && (string (input .Args [0 ]) == "deploy" || string (input .Args [0 ]) == "upgrade" ) {
148
+ if chaincodeName == "lscc" && len (input .Args ) >= 3 && (string (input .Args [0 ]) == "deploy" || string (input .Args [0 ]) == "upgrade" ) {
149
149
userCDS , err := protoutil .GetChaincodeDeploymentSpec (input .Args [2 ])
150
150
if err != nil {
151
151
return nil , nil , err
@@ -197,8 +197,8 @@ func (e *Endorser) SanitizeUserCDS(userCDS *pb.ChaincodeDeploymentSpec) (*pb.Cha
197
197
}
198
198
199
199
// SimulateProposal simulates the proposal by calling the chaincode
200
- func (e * Endorser ) SimulateProposal (txParams * ccprovider.TransactionParams , cid * pb. ChaincodeID ) (ccprovider.ChaincodeDefinition , * pb.Response , []byte , * pb.ChaincodeEvent , error ) {
201
- endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , txParams .ChannelID , shorttxid (txParams .TxID ), cid )
200
+ func (e * Endorser ) SimulateProposal (txParams * ccprovider.TransactionParams , chaincodeName string ) (ccprovider.ChaincodeDefinition , * pb.Response , []byte , * pb.ChaincodeEvent , error ) {
201
+ endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , txParams .ChannelID , shorttxid (txParams .TxID ), chaincodeName )
202
202
defer endorserLogger .Debugf ("[%s][%s] Exit" , txParams .ChannelID , shorttxid (txParams .TxID ))
203
203
// we do expect the payload to be a ChaincodeInvocationSpec
204
204
// if we are supporting other payloads in future, this be glaringly point
@@ -208,9 +208,9 @@ func (e *Endorser) SimulateProposal(txParams *ccprovider.TransactionParams, cid
208
208
return nil , nil , nil , nil , err
209
209
}
210
210
211
- cdLedger , err := e .s .GetChaincodeDefinition (txParams .ChannelID , cid . Name , txParams .TXSimulator )
211
+ cdLedger , err := e .s .GetChaincodeDefinition (txParams .ChannelID , chaincodeName , txParams .TXSimulator )
212
212
if err != nil {
213
- return nil , nil , nil , nil , errors .WithMessagef (err , "make sure the chaincode %s has been successfully defined on channel %s and try again" , cid . Name , txParams .ChannelID )
213
+ return nil , nil , nil , nil , errors .WithMessagef (err , "make sure the chaincode %s has been successfully defined on channel %s and try again" , chaincodeName , txParams .ChannelID )
214
214
}
215
215
216
216
err = e .s .CheckInstantiationPolicy (cdLedger .CCID (), cdLedger )
@@ -219,9 +219,9 @@ func (e *Endorser) SimulateProposal(txParams *ccprovider.TransactionParams, cid
219
219
}
220
220
221
221
// ---3. execute the proposal and get simulation results
222
- res , ccevent , err := e .callChaincode (txParams , cdLedger .Hash (), cdLedger .RequiresInit (), cis .ChaincodeSpec .Input , cid )
222
+ res , ccevent , err := e .callChaincode (txParams , cdLedger .Hash (), cdLedger .RequiresInit (), cis .ChaincodeSpec .Input , chaincodeName )
223
223
if err != nil {
224
- endorserLogger .Errorf ("[%s][%s] failed to invoke chaincode %s, error: %+v" , txParams .ChannelID , shorttxid (txParams .TxID ), cid , err )
224
+ endorserLogger .Errorf ("[%s][%s] failed to invoke chaincode %s, error: %+v" , txParams .ChannelID , shorttxid (txParams .TxID ), chaincodeName , err )
225
225
return nil , nil , nil , nil , err
226
226
}
227
227
@@ -240,7 +240,7 @@ func (e *Endorser) SimulateProposal(txParams *ccprovider.TransactionParams, cid
240
240
}
241
241
242
242
if simResult .PvtSimulationResults != nil {
243
- if cid . Name == "lscc" {
243
+ if chaincodeName == "lscc" {
244
244
// TODO: remove once we can store collection configuration outside of LSCC
245
245
return nil , nil , nil , nil , errors .New ("Private data is forbidden to be used in instantiate" )
246
246
}
@@ -276,13 +276,13 @@ func (e *Endorser) SimulateProposal(txParams *ccprovider.TransactionParams, cid
276
276
}
277
277
278
278
// endorse the proposal by calling the ESCC
279
- func (e * Endorser ) endorseProposal (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.ChaincodeDefinition ) (* pb.ProposalResponse , error ) {
280
- endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), ccid )
279
+ func (e * Endorser ) endorseProposal (chainID string , txid string , signedProp * pb.SignedProposal , proposal * pb.Proposal , response * pb.Response , simRes []byte , event * pb.ChaincodeEvent , visibility []byte , chaincodeName string , txsim ledger.TxSimulator , cd ccprovider.ChaincodeDefinition ) (* pb.ProposalResponse , error ) {
280
+ endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), chaincodeName )
281
281
defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
282
282
283
283
escc := cd .Endorsement ()
284
284
285
- endorserLogger .Debugf ("[%s][%s] escc for chaincode %s is %s" , chainID , shorttxid (txid ), ccid , escc )
285
+ endorserLogger .Debugf ("[%s][%s] escc for chaincode %s is %s" , chainID , shorttxid (txid ), chaincodeName , escc )
286
286
287
287
// marshalling event bytes
288
288
var err error
@@ -294,19 +294,20 @@ func (e *Endorser) endorseProposal(chainID string, txid string, signedProp *pb.S
294
294
}
295
295
}
296
296
297
- ccid .Version = cd .CCVersion ()
298
-
299
297
ctx := Context {
300
298
PluginName : escc ,
301
299
Channel : chainID ,
302
300
SignedProposal : signedProp ,
303
- ChaincodeID : ccid ,
304
- Event : eventBytes ,
305
- SimRes : simRes ,
306
- Response : response ,
307
- Visibility : visibility ,
308
- Proposal : proposal ,
309
- TxID : txid ,
301
+ ChaincodeID : & pb.ChaincodeID {
302
+ Name : chaincodeName ,
303
+ Version : cd .CCVersion (),
304
+ },
305
+ Event : eventBytes ,
306
+ SimRes : simRes ,
307
+ Response : response ,
308
+ Visibility : visibility ,
309
+ Proposal : proposal ,
310
+ TxID : txid ,
310
311
}
311
312
return e .s .EndorseWithPlugin (ctx )
312
313
}
@@ -421,7 +422,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
421
422
// Also obtain a history query executor for history queries, since tx simulator does not cover history
422
423
var txsim ledger.TxSimulator
423
424
var historyQueryExecutor ledger.HistoryQueryExecutor
424
- if acquireTxSimulator (chainID , vr .hdrExt .ChaincodeId ) {
425
+ if acquireTxSimulator (chainID , vr .hdrExt .ChaincodeId . Name ) {
425
426
if txsim , err = e .s .GetTxSimulator (chainID , txid ); err != nil {
426
427
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, nil
427
428
}
@@ -456,7 +457,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
456
457
// to validate the supplied action before endorsing it
457
458
458
459
// 1 -- simulate
459
- cd , res , simulationResult , ccevent , err := e .SimulateProposal (txParams , hdrExt .ChaincodeId )
460
+ cd , res , simulationResult , ccevent , err := e .SimulateProposal (txParams , hdrExt .ChaincodeId . Name )
460
461
if err != nil {
461
462
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, nil
462
463
}
@@ -488,7 +489,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
488
489
pResp = & pb.ProposalResponse {Response : res }
489
490
} else {
490
491
// Note: To endorseProposal(), we pass the released txsim. Hence, an error would occur if we try to use this txsim
491
- pResp , err = e .endorseProposal (chainID , txid , signedProp , prop , res , simulationResult , ccevent , hdrExt .PayloadVisibility , hdrExt .ChaincodeId , txsim , cd )
492
+ pResp , err = e .endorseProposal (chainID , txid , signedProp , prop , res , simulationResult , ccevent , hdrExt .PayloadVisibility , hdrExt .ChaincodeId . Name , txsim , cd )
492
493
493
494
// if error, capture endorsement failure metric
494
495
meterLabels := []string {
@@ -525,15 +526,15 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
525
526
526
527
// determine whether or not a transaction simulator should be
527
528
// obtained for a proposal.
528
- func acquireTxSimulator (chainID string , ccid * pb. ChaincodeID ) bool {
529
+ func acquireTxSimulator (chainID string , chaincodeName string ) bool {
529
530
if chainID == "" {
530
531
return false
531
532
}
532
533
533
534
// ¯\_(ツ)_/¯ locking.
534
535
// Don't get a simulator for the query and config system chaincode.
535
536
// These don't need the simulator and its read lock results in deadlocks.
536
- switch ccid . Name {
537
+ switch chaincodeName {
537
538
case "qscc" , "cscc" :
538
539
return false
539
540
default :
0 commit comments