@@ -176,15 +176,6 @@ func (lscc *lifeCycleSysCC) putChaincodeCollectionData(stub shim.ChaincodeStubIn
176
176
177
177
key := privdata .BuildCollectionKVSKey (cd .Name )
178
178
179
- existingCollection , err := stub .GetState (key )
180
- if err != nil {
181
- return errors .WithMessage (err , fmt .Sprintf ("unable to check whether collection existed earlier for chaincode %s:%s" , cd .Name , cd .Version ))
182
- }
183
- // currently, collections are immutable. Support for collection upgrade will be added later
184
- if existingCollection != nil {
185
- return errors .Errorf ("collection data should not exist for chaincode %s:%s" , cd .Name , cd .Version )
186
- }
187
-
188
179
err = stub .PutState (key , collectionConfigBytes )
189
180
if err != nil {
190
181
return errors .WithMessage (err , fmt .Sprintf ("error putting collection for chaincode %s:%s" , cd .Name , cd .Version ))
@@ -459,17 +450,21 @@ func (lscc *lifeCycleSysCC) executeDeployOrUpgrade(
459
450
policy , escc , vscc , collectionConfigBytes []byte ,
460
451
function string ,
461
452
) (* ccprovider.ChaincodeData , error ) {
462
- if err := lscc .isValidChaincodeName (cds .ChaincodeSpec .ChaincodeId .Name ); err != nil {
453
+
454
+ chaincodeName := cds .ChaincodeSpec .ChaincodeId .Name
455
+ chaincodeVersion := cds .ChaincodeSpec .ChaincodeId .Version
456
+
457
+ if err := lscc .isValidChaincodeName (chaincodeName ); err != nil {
463
458
return nil , err
464
459
}
465
460
466
- if err := lscc .isValidChaincodeVersion (cds . ChaincodeSpec . ChaincodeId . Name , cds . ChaincodeSpec . ChaincodeId . Version ); err != nil {
461
+ if err := lscc .isValidChaincodeVersion (chaincodeName , chaincodeVersion ); err != nil {
467
462
return nil , err
468
463
}
469
464
470
- ccpack , err := lscc .support .GetChaincodeFromLocalStorage (cds . ChaincodeSpec . ChaincodeId . Name , cds . ChaincodeSpec . ChaincodeId . Version )
465
+ ccpack , err := lscc .support .GetChaincodeFromLocalStorage (chaincodeName , chaincodeVersion )
471
466
if err != nil {
472
- retErrMsg := fmt .Sprintf ("cannot get package for chaincode (%s:%s)" , cds . ChaincodeSpec . ChaincodeId . Name , cds . ChaincodeSpec . ChaincodeId . Version )
467
+ retErrMsg := fmt .Sprintf ("cannot get package for chaincode (%s:%s)" , chaincodeName , chaincodeVersion )
473
468
logger .Errorf ("%s-err:%s" , retErrMsg , err )
474
469
return nil , fmt .Errorf ("%s" , retErrMsg )
475
470
}
@@ -479,7 +474,7 @@ func (lscc *lifeCycleSysCC) executeDeployOrUpgrade(
479
474
case DEPLOY :
480
475
return lscc .executeDeploy (stub , chainname , cds , policy , escc , vscc , cd , ccpack , collectionConfigBytes )
481
476
case UPGRADE :
482
- return lscc .executeUpgrade (stub , chainname , cds , policy , escc , vscc , cd , ccpack )
477
+ return lscc .executeUpgrade (stub , chainname , cds , policy , escc , vscc , cd , ccpack , collectionConfigBytes )
483
478
default :
484
479
logger .Panicf ("Programming error, unexpected function '%s'" , function )
485
480
panic ("" ) // unreachable code
@@ -499,9 +494,10 @@ func (lscc *lifeCycleSysCC) executeDeploy(
499
494
collectionConfigBytes []byte ,
500
495
) (* ccprovider.ChaincodeData , error ) {
501
496
//just test for existence of the chaincode in the LSCC
502
- _ , err := lscc .getCCInstance (stub , cds .ChaincodeSpec .ChaincodeId .Name )
497
+ chaincodeName := cds .ChaincodeSpec .ChaincodeId .Name
498
+ _ , err := lscc .getCCInstance (stub , chaincodeName )
503
499
if err == nil {
504
- return nil , ExistsErr (cds . ChaincodeSpec . ChaincodeId . Name )
500
+ return nil , ExistsErr (chaincodeName )
505
501
}
506
502
507
503
//retain chaincode specific data and fill channel specific ones
@@ -538,7 +534,8 @@ func (lscc *lifeCycleSysCC) executeDeploy(
538
534
}
539
535
540
536
// executeUpgrade implements the "upgrade" Invoke transaction.
541
- func (lscc * lifeCycleSysCC ) executeUpgrade (stub shim.ChaincodeStubInterface , chainName string , cds * pb.ChaincodeDeploymentSpec , policy []byte , escc []byte , vscc []byte , cdfs * ccprovider.ChaincodeData , ccpackfs ccprovider.CCPackage ) (* ccprovider.ChaincodeData , error ) {
537
+ func (lscc * lifeCycleSysCC ) executeUpgrade (stub shim.ChaincodeStubInterface , chainName string , cds * pb.ChaincodeDeploymentSpec , policy []byte , escc []byte , vscc []byte , cdfs * ccprovider.ChaincodeData , ccpackfs ccprovider.CCPackage , collectionConfigBytes []byte ) (* ccprovider.ChaincodeData , error ) {
538
+
542
539
chaincodeName := cds .ChaincodeSpec .ChaincodeId .Name
543
540
544
541
// check for existence of chaincode instance only (it has to exist on the channel)
@@ -557,7 +554,7 @@ func (lscc *lifeCycleSysCC) executeUpgrade(stub shim.ChaincodeStubInterface, cha
557
554
558
555
//do not upgrade if same version
559
556
if cdLedger .Version == cds .ChaincodeSpec .ChaincodeId .Version {
560
- return nil , IdenticalVersionErr (cds . ChaincodeSpec . ChaincodeId . Name )
557
+ return nil , IdenticalVersionErr (chaincodeName )
561
558
}
562
559
563
560
//do not upgrade if instantiation policy is violated
@@ -593,6 +590,22 @@ func (lscc *lifeCycleSysCC) executeUpgrade(stub shim.ChaincodeStubInterface, cha
593
590
if err != nil {
594
591
return nil , err
595
592
}
593
+
594
+ ac , exists := lscc .sccprovider .GetApplicationConfig (chainName )
595
+ if ! exists {
596
+ logger .Panicf ("programming error, non-existent appplication config for channel '%s'" , chainName )
597
+ }
598
+
599
+ // TODO: Instead of V1_2Validation(), we should be using something like CollectionUpdate().
600
+ // For time being, V1_2Validation() is used. Need to submit a separate CR to introduce a
601
+ // new capability named CollectionUpdate.
602
+ if ac .Capabilities ().V1_2Validation () {
603
+ err = lscc .putChaincodeCollectionData (stub , cdfs , collectionConfigBytes )
604
+ if err != nil {
605
+ return nil , err
606
+ }
607
+ }
608
+
596
609
lifecycleEvent := & pb.LifecycleEvent {ChaincodeName : chaincodeName }
597
610
lifecycleEventBytes := utils .MarshalOrPanic (lifecycleEvent )
598
611
stub .SetEvent (UPGRADE , lifecycleEventBytes )
0 commit comments