Skip to content

Commit

Permalink
FAB-18067 Discovery support Implicit Collections (#2784)
Browse files Browse the repository at this point in the history
Implemented the fix as suggested by Yacov in his Jira comment.

Verified the fix works against the asset-transfer-secured-agreement sample which uses implicit collections.

Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
  • Loading branch information
andrew-coleman authored Jul 28, 2021
1 parent 240cf0e commit 5331bbc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions core/chaincode/lifecycle/metadata_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/chaincode"
"github.com/hyperledger/fabric/common/policies"
"github.com/hyperledger/fabric/common/policydsl"
"github.com/hyperledger/fabric/core/chaincode/implicitcollection"
"github.com/hyperledger/fabric/protoutil"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -129,6 +131,36 @@ func (mp *MetadataProvider) Metadata(channel string, ccName string, collections
CollectionsConfig: ccInfo.Definition.Collections,
}

for _, col := range collections {
if isImplicit, mspID := implicitcollection.MspIDIfImplicitCollection(col); isImplicit {
// Implicit collection

// Initialize definition of collections if it's missing
if ccInfo.Definition.Collections == nil {
ccInfo.Definition.Collections = &peer.CollectionConfigPackage{}
}

spe := policydsl.SignedByMspMember(mspID)
ccInfo.Definition.Collections.Config = append(ccInfo.Definition.Collections.Config, &peer.CollectionConfig{
Payload: &peer.CollectionConfig_StaticCollectionConfig{
StaticCollectionConfig: &peer.StaticCollectionConfig{
Name: col,
MemberOrgsPolicy: &peer.CollectionPolicyConfig{
Payload: &peer.CollectionPolicyConfig_SignaturePolicy{
SignaturePolicy: spe,
},
},
EndorsementPolicy: &peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: spe,
},
},
},
},
})
}
}

if ccInfo.Definition.Collections == nil {
return ccMetadata
}
Expand Down
5 changes: 5 additions & 0 deletions core/chaincode/lifecycle/metadata_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ var _ = Describe("MetadataProvider", func() {
))
})

It("returns metadata for implicit collections", func() {
metadata := metadataProvider.Metadata("testchannel", "cc-name", "_implicit_org_msp1")
Expect(metadata.CollectionPolicies).To(HaveKey("_implicit_org_msp1"))
})

Context("when the chaincode is not found by the ChaincodeInfoProvider", func() {
BeforeEach(func() {
fakeChaincodeInfoProvider.ChaincodeInfoReturns(nil, errors.New("scrumtrulescent"))
Expand Down
11 changes: 11 additions & 0 deletions integration/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,17 @@ var _ = Describe("DiscoveryService", func() {
Expect(discovered[0].Layouts).To(HaveLen(1))
Expect(discovered[0].Layouts[0].QuantitiesByGroup).To(ConsistOf(uint32(1), uint32(1)))

By("discovering endorsers for Org1 implicit collection")
endorsers.Collection = "mycc:_implicit_org_Org1MSP"
de = discoverEndorsers(network, endorsers)
Eventually(endorsersByGroups(de), network.EventuallyTimeout).Should(ConsistOf(
ConsistOf(network.DiscoveredPeer(org1Peer0)),
))
discovered = de()
Expect(discovered).To(HaveLen(1))
Expect(discovered[0].Layouts).To(HaveLen(1))
Expect(discovered[0].Layouts[0].QuantitiesByGroup).To(ConsistOf(uint32(1)))

By("trying to discover endorsers as an org3 admin")
endorsers = commands.Endorsers{
UserCert: network.PeerUserCert(org3Peer0, "Admin"),
Expand Down

0 comments on commit 5331bbc

Please sign in to comment.