@@ -127,7 +127,7 @@ type Handler struct {
127
127
// ready.
128
128
state State
129
129
// chaincodeID holds the ID of the chaincode that registered with the peer.
130
- chaincodeID * pb. ChaincodeID
130
+ chaincodeID string
131
131
132
132
// serialLock is used to serialize sends across the grpc chat stream.
133
133
serialLock sync.Mutex
@@ -229,11 +229,10 @@ func (h *Handler) HandleTransaction(msg *pb.ChaincodeMessage, delegate handleFun
229
229
txContext , err = h .isValidTxSim (msg .ChannelId , msg .Txid , "no ledger context" )
230
230
}
231
231
232
- chaincodeName := h .chaincodeID .Name + ":" + h .chaincodeID .Version
233
232
meterLabels := []string {
234
233
"type" , msg .Type .String (),
235
234
"channel" , msg .ChannelId ,
236
- "chaincode" , chaincodeName ,
235
+ "chaincode" , h . chaincodeID ,
237
236
}
238
237
h .Metrics .ShimRequestsReceived .With (meterLabels ... ).Add (1 )
239
238
@@ -341,11 +340,8 @@ func (h *Handler) checkACL(signedProp *pb.SignedProposal, proposal *pb.Proposal,
341
340
}
342
341
343
342
func (h * Handler ) deregister () {
344
- if h .chaincodeID != nil {
345
- // FIXME: this works once again because h.chaincodeID.Name
346
- // is not the chaincode name but the concatenation of name
347
- // and version (FAB-14630)
348
- h .Registry .Deregister (h .chaincodeID .Name )
343
+ if h .chaincodeID != "" {
344
+ h .Registry .Deregister (h .chaincodeID )
349
345
}
350
346
}
351
347
@@ -417,18 +413,18 @@ func (h *Handler) ProcessStream(stream ccintf.ChaincodeStream) error {
417
413
418
414
// sendReady sends READY to chaincode serially (just like REGISTER)
419
415
func (h * Handler ) sendReady () error {
420
- chaincodeLogger .Debugf ("sending READY for chaincode %+v " , h .chaincodeID )
416
+ chaincodeLogger .Debugf ("sending READY for chaincode %s " , h .chaincodeID )
421
417
ccMsg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_READY }
422
418
423
419
// if error in sending tear down the h
424
420
if err := h .serialSend (ccMsg ); err != nil {
425
- chaincodeLogger .Errorf ("error sending READY (%s) for chaincode %+v " , err , h .chaincodeID )
421
+ chaincodeLogger .Errorf ("error sending READY (%s) for chaincode %s " , err , h .chaincodeID )
426
422
return err
427
423
}
428
424
429
425
h .state = Ready
430
426
431
- chaincodeLogger .Debugf ("Changed to state ready for chaincode %+v " , h .chaincodeID )
427
+ chaincodeLogger .Debugf ("Changed to state ready for chaincode %s " , h .chaincodeID )
432
428
433
429
return nil
434
430
}
@@ -441,12 +437,12 @@ func (h *Handler) notifyRegistry(err error) {
441
437
}
442
438
443
439
if err != nil {
444
- h .Registry .Failed (h .chaincodeID . Name , err )
440
+ h .Registry .Failed (h .chaincodeID , err )
445
441
chaincodeLogger .Errorf ("failed to start %s -- %s" , h .chaincodeID , err )
446
442
return
447
443
}
448
444
449
- h .Registry .Ready (h .chaincodeID . Name )
445
+ h .Registry .Ready (h .chaincodeID )
450
446
}
451
447
452
448
// handleRegister is invoked when chaincode tries to register.
@@ -460,14 +456,17 @@ func (h *Handler) HandleRegister(msg *pb.ChaincodeMessage) {
460
456
}
461
457
462
458
// Now register with the chaincodeSupport
463
- h .chaincodeID = chaincodeID
459
+ // Note: chaincodeID.Name is actually of the form name:version for older chaincodes, and
460
+ // of the form label:hash for newer chaincodes. Either way, it is the handle by which
461
+ // we track the chaincode's registration.
462
+ h .chaincodeID = chaincodeID .Name
464
463
err = h .Registry .Register (h )
465
464
if err != nil {
466
465
h .notifyRegistry (err )
467
466
return
468
467
}
469
468
470
- chaincodeLogger .Debugf ("Got %s for chaincodeID = %s, sending back %s" , pb .ChaincodeMessage_REGISTER , chaincodeID , pb .ChaincodeMessage_REGISTERED )
469
+ chaincodeLogger .Debugf ("Got %s for chaincodeID = %s, sending back %s" , pb .ChaincodeMessage_REGISTER , h . chaincodeID , pb .ChaincodeMessage_REGISTERED )
471
470
if err := h .serialSend (& pb.ChaincodeMessage {Type : pb .ChaincodeMessage_REGISTERED }); err != nil {
472
471
chaincodeLogger .Errorf ("error sending %s: %s" , pb .ChaincodeMessage_REGISTERED , err )
473
472
h .notifyRegistry (err )
@@ -476,7 +475,7 @@ func (h *Handler) HandleRegister(msg *pb.ChaincodeMessage) {
476
475
477
476
h .state = Established
478
477
479
- chaincodeLogger .Debugf ("Changed state to established for %+v " , h .chaincodeID )
478
+ chaincodeLogger .Debugf ("Changed state to established for %s " , h .chaincodeID )
480
479
481
480
// for dev mode this will also move to ready automatically
482
481
h .notifyRegistry (nil )
@@ -513,11 +512,11 @@ func (h *Handler) registerTxid(msg *pb.ChaincodeMessage) bool {
513
512
}
514
513
515
514
// Log the issue and drop the request
516
- chaincodeName := "unknown"
517
- if h .chaincodeID != nil {
518
- chaincodeName = h .chaincodeID . Name
515
+ chaincodeID := "unknown"
516
+ if h .chaincodeID != "" {
517
+ chaincodeID = h .chaincodeID
519
518
}
520
- chaincodeLogger .Errorf ("[%s] Another request pending for this CC: %s, Txid: %s, ChannelID: %s. Cannot process." , shorttxid (msg .Txid ), chaincodeName , msg .Txid , msg .ChannelId )
519
+ chaincodeLogger .Errorf ("[%s] Another request pending for this CC: %s, Txid: %s, ChannelID: %s. Cannot process." , shorttxid (msg .Txid ), chaincodeID , msg .Txid , msg .ChannelId )
521
520
return false
522
521
}
523
522
0 commit comments