Skip to content

Commit 6118aea

Browse files
committed
[FAB-9949] Non-instanced collection config retrieval
This change set makes the collection store have a non-instanced method for collection config retrieval. This is needed both for pluggable validation, and for service discovery. Change-Id: Ic7455727a4618c907b2112480e160a53bb6f6ebe Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent acf93e7 commit 6118aea

File tree

6 files changed

+16
-26
lines changed

6 files changed

+16
-26
lines changed

core/common/privdata/store.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ type Support interface {
2121
// GetQueryExecutorForLedger returns a query executor for the specified channel
2222
GetQueryExecutorForLedger(cid string) (ledger.QueryExecutor, error)
2323

24-
// GetCollectionKVSKey returns the name of the collection
25-
// given the collection criteria
26-
GetCollectionKVSKey(cc common.CollectionCriteria) string
27-
2824
// GetIdentityDeserializer returns an IdentityDeserializer
2925
// instance for the specified chain
3026
GetIdentityDeserializer(chainID string) msp.IdentityDeserializer
3127
}
3228

29+
// StateGetter retrieves data from the state
30+
type State interface {
31+
// GetState retrieves the value for the given key in the given namespace
32+
GetState(namespace string, key string) ([]byte, error)
33+
}
34+
3335
type NoSuchCollectionError common.CollectionCriteria
3436

3537
func (f NoSuchCollectionError) Error() string {
@@ -54,8 +56,12 @@ func (c *simpleCollectionStore) retrieveCollectionConfigPackage(cc common.Collec
5456
return nil, errors.WithMessage(err, fmt.Sprintf("could not retrieve query executor for collection criteria %#v", cc))
5557
}
5658
defer qe.Done()
59+
return RetrieveCollectionConfigPackageFromState(cc, qe)
60+
}
5761

58-
cb, err := qe.GetState("lscc", c.s.GetCollectionKVSKey(cc))
62+
// RetrieveCollectionConfigPackageFromState retrieves the collection config package from the given key from the given state
63+
func RetrieveCollectionConfigPackageFromState(cc common.CollectionCriteria, state State) (*common.CollectionConfigPackage, error) {
64+
cb, err := state.GetState("lscc", BuildCollectionKVSKey(cc.Namespace))
5965
if err != nil {
6066
return nil, errors.WithMessage(err, fmt.Sprintf("error while retrieving collection for collection criteria %#v", cc))
6167
}

core/common/privdata/store_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ func (c *mockStoreSupport) GetQueryExecutorForLedger(cid string) (ledger.QueryEx
2828
return c.Qe, c.QErr
2929
}
3030

31-
func (c *mockStoreSupport) GetCollectionKVSKey(cc common.CollectionCriteria) string {
32-
return cc.Channel + cc.Namespace
33-
}
34-
3531
func (c *mockStoreSupport) GetIdentityDeserializer(chainID string) msp.IdentityDeserializer {
3632
return &mockDeserializer{}
3733
}
@@ -54,7 +50,7 @@ func TestCollectionStore(t *testing.T) {
5450

5551
ccr := common.CollectionCriteria{Channel: "ch", Namespace: "cc", Collection: "mycollection"}
5652

57-
wState["lscc"][support.GetCollectionKVSKey(ccr)] = []byte("barf")
53+
wState["lscc"][BuildCollectionKVSKey(ccr.Namespace)] = []byte("barf")
5854

5955
_, err = cs.RetrieveCollection(ccr)
6056
assert.Error(t, err)
@@ -65,7 +61,7 @@ func TestCollectionStore(t *testing.T) {
6561
assert.NoError(t, err)
6662
assert.NotNil(t, ccpBytes)
6763

68-
wState["lscc"][support.GetCollectionKVSKey(ccr)] = ccpBytes
64+
wState["lscc"][BuildCollectionKVSKey(ccr.Namespace)] = ccpBytes
6965

7066
_, err = cs.RetrieveCollection(ccr)
7167
assert.Error(t, err)
@@ -80,7 +76,7 @@ func TestCollectionStore(t *testing.T) {
8076
assert.NoError(t, err)
8177
assert.NotNil(t, ccpBytes)
8278

83-
wState["lscc"][support.GetCollectionKVSKey(ccr)] = ccpBytes
79+
wState["lscc"][BuildCollectionKVSKey(ccr.Namespace)] = ccpBytes
8480

8581
c, err := cs.RetrieveCollection(ccr)
8682
assert.NoError(t, err)

core/ledger/pvtdatapolicy/btlpolicy.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ func (cs *collectionSupport) GetQueryExecutorForLedger(cid string) (ledger.Query
9898
return cs.lgr.NewQueryExecutor()
9999
}
100100

101-
func (*collectionSupport) GetCollectionKVSKey(cc common.CollectionCriteria) string {
102-
return privdata.BuildCollectionKVSKey(cc.Namespace)
103-
}
104-
105101
func (*collectionSupport) GetIdentityDeserializer(chainID string) msp.IdentityDeserializer {
106102
return nil
107103
}

core/peer/peer.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,6 @@ func (cs *collectionSupport) GetQueryExecutorForLedger(cid string) (ledger.Query
672672
return cs.NewQueryExecutor()
673673
}
674674

675-
func (*collectionSupport) GetCollectionKVSKey(cc common.CollectionCriteria) string {
676-
return privdata.BuildCollectionKVSKey(cc.Namespace)
677-
}
678-
679675
func (*collectionSupport) GetIdentityDeserializer(chainID string) msp.IdentityDeserializer {
680676
return mspmgmt.GetManagerForChain(chainID)
681677
}

core/scc/vscc/validator_onevalidsignature.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ type collectionStoreSupport struct {
7070
sysccprovider.SystemChaincodeProvider
7171
}
7272

73-
func (c *collectionStoreSupport) GetCollectionKVSKey(cc common.CollectionCriteria) string {
74-
return privdata.BuildCollectionKVSKey(cc.Namespace)
75-
}
76-
7773
func (c *collectionStoreSupport) GetIdentityDeserializer(chainID string) m.IdentityDeserializer {
7874
return mspmgmt.GetIdentityDeserializer(chainID)
7975
}

core/scc/vscc/validator_onevalidsignature_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ func validateUpgradeWithCollection(t *testing.T, V1_2Validation bool) {
16091609
assert.Equal(t, string(resp.Message), "LSCC can only issue a single putState upon deploy/upgrade")
16101610
}
16111611

1612-
State["lscc"][(&collectionStoreSupport{v.sccprovider}).GetCollectionKVSKey(common.CollectionCriteria{Channel: "testchainid", Namespace: ccname})] = ccpBytes
1612+
State["lscc"][privdata.BuildCollectionKVSKey(ccname)] = ccpBytes
16131613

16141614
if V1_2Validation {
16151615
ccver = "3"
@@ -2202,7 +2202,7 @@ func TestValidateRWSetAndCollectionForUpgrade(t *testing.T) {
22022202
err = testValidateCollection(t, v, []*common.CollectionConfig{coll1}, cdRWSet, lsccFunc, ac, chid)
22032203
assert.NoError(t, err)
22042204

2205-
State["lscc"][(&collectionStoreSupport{v.sccprovider}).GetCollectionKVSKey(common.CollectionCriteria{Channel: chid, Namespace: ccid})] = ccpBytes
2205+
State["lscc"][privdata.BuildCollectionKVSKey(ccid)] = ccpBytes
22062206

22072207
// Test 2: exactly same as the existing collection config package -> success
22082208
err = testValidateCollection(t, v, []*common.CollectionConfig{coll1, coll2}, cdRWSet, lsccFunc, ac, chid)

0 commit comments

Comments
 (0)