Skip to content

Commit 33aeb75

Browse files
committed
[FAB-10392] err if ccUpgrade has ccConfig & !v12
Currently, when v12 capability is not enabled, if the chaincode upgrade tx contains collectionConfigPackage, we just ignore the passed collection. Instead, this CR throw an error so that user can set necessary capability tag to perform collection upgrades. Change-Id: If91b54bb5f05f78e294b2bc611c6c37f85896c13 Signed-off-by: senthil <cendhu@gmail.com>
1 parent 04a7a60 commit 33aeb75

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

core/scc/lscc/errors.go

+7
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,10 @@ type InstantiationPolicyMissing string
126126
func (f InstantiationPolicyMissing) Error() string {
127127
return "instantiation policy missing"
128128
}
129+
130+
// CollectionsConfigUpgradesNotAllowed when V1_2 capability is not enabled
131+
type CollectionsConfigUpgradesNotAllowed string
132+
133+
func (f CollectionsConfigUpgradesNotAllowed) Error() string {
134+
return "as V1_2 capability is not enabled, collection upgrades are not allowed"
135+
}

core/scc/lscc/lscc.go

+4
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ func (lscc *lifeCycleSysCC) executeUpgrade(stub shim.ChaincodeStubInterface, cha
590590
if err != nil {
591591
return nil, err
592592
}
593+
} else {
594+
if collectionConfigBytes != nil {
595+
return nil, errors.New(CollectionsConfigUpgradesNotAllowed("").Error())
596+
}
593597
}
594598

595599
lifecycleEvent := &pb.LifecycleEvent{ChaincodeName: chaincodeName}

core/scc/lscc/lscc_test.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,9 @@ func TestUpgrade(t *testing.T) {
486486
assert.NoError(t, err)
487487
assert.NotNil(t, ccpBytes)
488488

489-
// As the PrivateChannelData is enabled and collectionConfigBytes is valid, no error is expected
490-
testUpgrade(t, "example02", "0", "example02", "1", path, "", scc, stub, ccpBytes)
491-
// Should contain an entry for the chaincodeData only as the V1_2Validation is disabled.
492-
// Only in V1_2Validation, collection upgrades are allowed. Note that V1_2Validation
493-
// would be replaced with CollectionUpgrade capability.
494-
assert.Equal(t, 1, len(stub.State))
495-
_, ok := stub.State["example02"]
496-
assert.Equal(t, true, ok)
489+
// As v12 capability is not enabled (which is required for the collection upgrade), an error is expected
490+
expectedErrorMsg := "as V1_2 capability is not enabled, collection upgrades are not allowed"
491+
testUpgrade(t, "example02", "0", "example02", "1", path, expectedErrorMsg, scc, stub, ccpBytes)
497492

498493
// Enable PrivateChannelData and V1_2Validation
499494
mocksccProvider = (&mscc.MocksccProviderFactory{
@@ -517,7 +512,7 @@ func TestUpgrade(t *testing.T) {
517512
testUpgrade(t, "example02", "0", "example02", "1", path, "", scc, stub, []byte("nil"))
518513
// Should contain an entry for the chaincodeData only as the collectionConfigBytes is nil
519514
assert.Equal(t, 1, len(stub.State))
520-
_, ok = stub.State["example02"]
515+
_, ok := stub.State["example02"]
521516
assert.Equal(t, true, ok)
522517

523518
scc = New(mocksccProvider, mockAclProvider)

0 commit comments

Comments
 (0)