Skip to content

Commit

Permalink
[FAB-10392] err if ccUpgrade has ccConfig & !v12
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cendhu committed May 25, 2018
1 parent 04a7a60 commit 33aeb75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
7 changes: 7 additions & 0 deletions core/scc/lscc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,10 @@ type InstantiationPolicyMissing string
func (f InstantiationPolicyMissing) Error() string {
return "instantiation policy missing"
}

// CollectionsConfigUpgradesNotAllowed when V1_2 capability is not enabled
type CollectionsConfigUpgradesNotAllowed string

func (f CollectionsConfigUpgradesNotAllowed) Error() string {
return "as V1_2 capability is not enabled, collection upgrades are not allowed"
}
4 changes: 4 additions & 0 deletions core/scc/lscc/lscc.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ func (lscc *lifeCycleSysCC) executeUpgrade(stub shim.ChaincodeStubInterface, cha
if err != nil {
return nil, err
}
} else {
if collectionConfigBytes != nil {
return nil, errors.New(CollectionsConfigUpgradesNotAllowed("").Error())
}
}

lifecycleEvent := &pb.LifecycleEvent{ChaincodeName: chaincodeName}
Expand Down
13 changes: 4 additions & 9 deletions core/scc/lscc/lscc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,9 @@ func TestUpgrade(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, ccpBytes)

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

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

scc = New(mocksccProvider, mockAclProvider)
Expand Down

0 comments on commit 33aeb75

Please sign in to comment.