Skip to content

Commit ff31dd1

Browse files
committed
[FAB-10026] Store to filter collection configs
While the transient store returns results of the private data simulations it uses filter to return the relevant namespaces and collections, however the provided filter is not applied for for the collections configs. This comments adds filtering of the configs based on filter used for private data itself. Change-Id: I8788717ae93a1f522feaf2aa2feb935a780f6594 Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent 7437da1 commit ff31dd1

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

core/transientstore/store.go

+6
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,13 @@ func (scanner *RwsetScanner) NextWithConfig() (*EndorserPvtSimulationResultsWith
403403
if err := proto.Unmarshal(dbVal[1:], txPvtRWSetWithConfig); err != nil {
404404
return nil, err
405405
}
406+
406407
filteredTxPvtRWSet = trimPvtWSet(txPvtRWSetWithConfig.GetPvtRwset(), scanner.filter)
408+
configs, err := trimPvtCollectionConfigs(txPvtRWSetWithConfig.CollectionConfigs, scanner.filter)
409+
if err != nil {
410+
return nil, err
411+
}
412+
txPvtRWSetWithConfig.CollectionConfigs = configs
407413
} else {
408414
// old proto, i.e., TxPvtReadWriteSet
409415
if err := proto.Unmarshal(dbVal, txPvtRWSet); err != nil {

core/transientstore/store_helper.go

+25
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ package transientstore
88

99
import (
1010
"bytes"
11+
"errors"
1112
"path/filepath"
1213

1314
"github.com/hyperledger/fabric/common/ledger/util"
1415
"github.com/hyperledger/fabric/core/config"
1516
"github.com/hyperledger/fabric/core/ledger"
17+
"github.com/hyperledger/fabric/protos/common"
1618
"github.com/hyperledger/fabric/protos/ledger/rwset"
1719
)
1820

@@ -215,3 +217,26 @@ func trimPvtWSet(pvtWSet *rwset.TxPvtReadWriteSet, filter ledger.PvtNsCollFilter
215217
}
216218
return filteredTxPvtRwSet
217219
}
220+
221+
func trimPvtCollectionConfigs(configs map[string]*common.CollectionConfigPackage,
222+
filter ledger.PvtNsCollFilter) (map[string]*common.CollectionConfigPackage, error) {
223+
if filter == nil {
224+
return configs, nil
225+
}
226+
result := make(map[string]*common.CollectionConfigPackage)
227+
228+
for ns, pkg := range configs {
229+
result[ns] = &common.CollectionConfigPackage{}
230+
for _, colConf := range pkg.GetConfig() {
231+
switch cconf := colConf.Payload.(type) {
232+
case *common.CollectionConfig_StaticCollectionConfig:
233+
if filter.Has(ns, cconf.StaticCollectionConfig.Name) {
234+
result[ns].Config = append(result[ns].Config, colConf)
235+
}
236+
default:
237+
return nil, errors.New("unexpected collection type")
238+
}
239+
}
240+
}
241+
return result, nil
242+
}

core/transientstore/store_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"sort"
1313
"testing"
1414

15-
"github.com/davecgh/go-spew/spew"
1615
"github.com/golang/protobuf/proto"
1716

1817
"github.com/hyperledger/fabric/common/cauthdsl"
@@ -479,6 +478,16 @@ func TestTransientStoreRetrievalWithFilter(t *testing.T) {
479478
expectedSimulationRes := samplePvtSimResWithConfig
480479
expectedSimulationRes.GetPvtRwset().NsPvtRwset[0].CollectionPvtRwset = expectedSimulationRes.GetPvtRwset().NsPvtRwset[0].CollectionPvtRwset[0:1]
481480
expectedSimulationRes.GetPvtRwset().NsPvtRwset[1].CollectionPvtRwset = expectedSimulationRes.GetPvtRwset().NsPvtRwset[1].CollectionPvtRwset[1:]
481+
expectedSimulationRes.CollectionConfigs, err = trimPvtCollectionConfigs(expectedSimulationRes.CollectionConfigs, filter)
482+
assert.NoError(t, err)
483+
for ns, colName := range map[string]string{"ns-1": "coll-1", "ns-2": "coll-2"} {
484+
config := expectedSimulationRes.CollectionConfigs[ns]
485+
assert.NotNil(t, config)
486+
ns1Config := config.Config
487+
assert.Equal(t, len(ns1Config), 1)
488+
ns1ColConfig := ns1Config[0].GetStaticCollectionConfig()
489+
assert.NotNil(t, ns1ColConfig.Name, colName)
490+
}
482491

483492
var expectedRes []*EndorserPvtSimulationResultsWithConfig
484493
for i := 0; i < numEntries; i++ {
@@ -490,7 +499,6 @@ func TestTransientStoreRetrievalWithFilter(t *testing.T) {
490499
sortResults(expectedRes)
491500
sortResults(actualRes)
492501
assert.Equal(t, expectedRes, actualRes)
493-
t.Logf("Actual Res = %s", spew.Sdump(actualRes))
494502
}
495503

496504
func sortResults(res []*EndorserPvtSimulationResultsWithConfig) {

integration/runner/cryptogen.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package runner
88

99
import (
1010
"os/exec"
11+
1112
"github.com/tedsuo/ifrit/ginkgomon"
1213
)
1314

0 commit comments

Comments
 (0)