-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement interface SnapshotPvtdataHashesConsumer for pvtdata store (#…
…1908) Signed-off-by: manish <manish.sethi@gmail.com>
- Loading branch information
1 parent
e801c2f
commit 5bcb5e0
Showing
17 changed files
with
1,930 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
core/ledger/confighistory/confighistorytest/confighistory.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package confighistorytest | ||
|
||
import ( | ||
"github.com/hyperledger/fabric-protos-go/peer" | ||
"github.com/hyperledger/fabric/core/ledger" | ||
"github.com/hyperledger/fabric/core/ledger/confighistory" | ||
"github.com/hyperledger/fabric/core/ledger/mock" | ||
) | ||
|
||
type Mgr struct { | ||
*confighistory.Mgr | ||
mockCCInfoProvider *mock.DeployedChaincodeInfoProvider | ||
} | ||
|
||
func NewMgr(dbPath string) (*Mgr, error) { | ||
mockCCInfoProvider := &mock.DeployedChaincodeInfoProvider{} | ||
configHistory, err := confighistory.NewMgr(dbPath, mockCCInfoProvider) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Mgr{ | ||
Mgr: configHistory, | ||
mockCCInfoProvider: mockCCInfoProvider, | ||
}, nil | ||
} | ||
|
||
func (m *Mgr) Setup(ledgerID, namespace string, configHistory map[uint64][]*peer.StaticCollectionConfig) error { | ||
for committingBlk, config := range configHistory { | ||
m.mockCCInfoProvider.UpdatedChaincodesReturns( | ||
[]*ledger.ChaincodeLifecycleInfo{ | ||
{ | ||
Name: namespace, | ||
}, | ||
}, nil, | ||
) | ||
|
||
m.mockCCInfoProvider.ChaincodeInfoReturns( | ||
&ledger.DeployedChaincodeInfo{ | ||
Name: namespace, | ||
ExplicitCollectionConfigPkg: BuildCollConfigPkg(config), | ||
}, | ||
nil, | ||
) | ||
|
||
err := m.HandleStateUpdates( | ||
&ledger.StateUpdateTrigger{ | ||
LedgerID: ledgerID, | ||
CommittingBlockNum: committingBlk, | ||
}, | ||
) | ||
defer m.StateCommitDone(ledgerID) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (m *Mgr) Close() { | ||
m.Mgr.Close() | ||
} | ||
|
||
func BuildCollConfigPkg(staticCollectionConfigs []*peer.StaticCollectionConfig) *peer.CollectionConfigPackage { | ||
if len(staticCollectionConfigs) == 0 { | ||
return nil | ||
} | ||
pkg := &peer.CollectionConfigPackage{ | ||
Config: []*peer.CollectionConfig{}, | ||
} | ||
for _, c := range staticCollectionConfigs { | ||
pkg.Config = append(pkg.Config, | ||
&peer.CollectionConfig{ | ||
Payload: &peer.CollectionConfig_StaticCollectionConfig{ | ||
StaticCollectionConfig: c, | ||
}, | ||
}, | ||
) | ||
} | ||
return pkg | ||
} |
107 changes: 107 additions & 0 deletions
107
core/ledger/confighistory/confighistorytest/confighistory_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package confighistorytest | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"math" | ||
"os" | ||
"testing" | ||
|
||
"github.com/golang/protobuf/proto" | ||
"github.com/hyperledger/fabric-protos-go/peer" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConfigHistory(t *testing.T) { | ||
testDir, err := ioutil.TempDir("", "confighitory-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(testDir) | ||
|
||
mgr, err := NewMgr(testDir) | ||
require.NoError(t, err) | ||
defer mgr.Close() | ||
|
||
sampleConfigHistoryNS1 := map[uint64][]*peer.StaticCollectionConfig{ | ||
300: {{Name: "coll1"}, {Name: "coll2"}, {Name: "coll3"}}, | ||
20: {{Name: "coll1"}, {Name: "coll2"}}, | ||
} | ||
|
||
sampleConfigHistoryNS2 := map[uint64][]*peer.StaticCollectionConfig{ | ||
400: {{Name: "coll4"}}, | ||
} | ||
|
||
require.NoError(t, mgr.Setup("ledger-1", "ns1", sampleConfigHistoryNS1)) | ||
require.NoError(t, mgr.Setup("ledger-1", "ns2", sampleConfigHistoryNS2)) | ||
|
||
r := mgr.GetRetriever("ledger-1") | ||
|
||
testcases := []struct { | ||
inputNS string | ||
inputBlkNum uint64 | ||
|
||
outputConfig *peer.CollectionConfigPackage | ||
outputBlkNum uint64 | ||
}{ | ||
{ | ||
inputNS: "ns1", | ||
inputBlkNum: math.MaxUint64, | ||
outputConfig: BuildCollConfigPkg(sampleConfigHistoryNS1[300]), | ||
outputBlkNum: 300, | ||
}, | ||
|
||
{ | ||
inputNS: "ns1", | ||
inputBlkNum: 300, | ||
outputConfig: BuildCollConfigPkg(sampleConfigHistoryNS1[20]), | ||
outputBlkNum: 20, | ||
}, | ||
|
||
{ | ||
inputNS: "ns1", | ||
inputBlkNum: 20, | ||
outputConfig: nil, | ||
outputBlkNum: 0, | ||
}, | ||
|
||
{ | ||
inputNS: "ns2", | ||
inputBlkNum: math.MaxUint64, | ||
outputConfig: BuildCollConfigPkg(sampleConfigHistoryNS2[400]), | ||
outputBlkNum: 400, | ||
}, | ||
|
||
{ | ||
inputNS: "ns2", | ||
inputBlkNum: 200, | ||
outputConfig: nil, | ||
outputBlkNum: 0, | ||
}, | ||
} | ||
|
||
for i, c := range testcases { | ||
t.Run(fmt.Sprintf("testcase-%d", i), func(t *testing.T) { | ||
collectionConfigInfo, err := r.MostRecentCollectionConfigBelow(c.inputBlkNum, c.inputNS) | ||
require.NoError(t, err) | ||
|
||
if c.outputConfig == nil { | ||
require.Nil(t, c.outputConfig) | ||
require.Equal(t, uint64(0), c.outputBlkNum) | ||
return | ||
} | ||
|
||
require.Equal(t, c.outputBlkNum, collectionConfigInfo.CommittingBlockNum) | ||
require.True(t, | ||
proto.Equal( | ||
collectionConfigInfo.CollectionConfig, | ||
c.outputConfig, | ||
), | ||
) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.