Skip to content

Commit

Permalink
Update purge private data integration tests
Browse files Browse the repository at this point in the history
Confirm data is purged on previously eligible peer when it is no longer
eligible

Signed-off-by: James Taylor <[email protected]>
(cherry picked from commit 09e70f9)
  • Loading branch information
jt-nti authored and denyeart committed Jan 24, 2023
1 parent c68efd3 commit 8857efa
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 11 deletions.
1 change: 1 addition & 0 deletions integration/nwo/template/core_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ ledger:
enableHistoryDatabase: true
pvtdataStore:
deprioritizedDataReconcilerInterval: 60m
purgeInterval: 1
operations:
listenAddress: 127.0.0.1:{{ .PeerPort Peer "Operations" }}
Expand Down
64 changes: 53 additions & 11 deletions integration/pvtdata/data_purge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"github.com/hyperledger/fabric/protoutil"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/tedsuo/ifrit"
ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2"
)

var _ = Describe("Pvtdata purge", func() {
Expand All @@ -37,8 +39,9 @@ var _ = Describe("Pvtdata purge", func() {
testDir string
network *nwo.Network
orderer *nwo.Orderer
org2Peer0 *nwo.Peer
process ifrit.Process
org2Peer0, org3Peer0 *nwo.Peer
processes map[string]ifrit.Process
peerRunners map[string]*ginkgomon.Runner
cancel context.CancelFunc
chaincode *nwo.Chaincode
)
Expand All @@ -53,9 +56,17 @@ var _ = Describe("Pvtdata purge", func() {
network.GenerateConfigTree()
network.Bootstrap()

networkRunner := network.NetworkGroupRunner()
process = ifrit.Invoke(networkRunner)
processes = map[string]ifrit.Process{}
peerRunners = map[string]*ginkgomon.Runner{}

ordererRunner := network.OrdererGroupRunner()
process := ifrit.Invoke(ordererRunner)
Eventually(process.Ready(), network.EventuallyTimeout).Should(BeClosed())
processes["OrdererGroupRunner"] = process

for _, peer := range network.Peers {
startPeer(network, processes, peerRunners, peer)
}

orderer = network.Orderer("orderer")

Expand Down Expand Up @@ -90,6 +101,7 @@ var _ = Describe("Pvtdata purge", func() {
nwo.DeployChaincode(network, channelID, orderer, *chaincode)

org2Peer0 = network.Peer("Org2", "peer0")
org3Peer0 = network.Peer("Org3", "peer0")

_, cancel = context.WithTimeout(context.Background(), network.EventuallyTimeout)

Expand All @@ -99,7 +111,7 @@ var _ = Describe("Pvtdata purge", func() {
AfterEach(func() {
cancel()

if process != nil {
for _, process := range processes {
process.Signal(syscall.SIGTERM)
Eventually(process.Wait(), network.EventuallyTimeout).Should(Receive())
}
Expand Down Expand Up @@ -272,12 +284,35 @@ var _ = Describe("Pvtdata purge", func() {
})
PIt("should correctly enforce other endorsement policies (TBC)")

// 4. Data is purged on previously eligible but now ineligible peer
// - Add a few keys into a collection
// - Submit a collection config update to remove an org
// - Issue a purge transaction to delete few keys
// - The removed orgs peer should have purged the historical versions of intended key
PIt("should remove all purged data from a previously eligible peer")
It("should remove all purged data from a previously eligible peer", func() {
marblechaincodeutil.AddMarble(network, orderer, channelID, chaincode.Name, `{"name":"test-marble-80", "color":"white", "size":4, "owner":"liz", "price":4}`, org2Peer0)
marblechaincodeutil.AddMarble(network, orderer, channelID, chaincode.Name, `{"name":"test-marble-8080", "color":"orange", "size":80, "owner":"clive", "price":88}`, org2Peer0)

marblechaincodeutil.AssertPresentInCollectionM(network, channelID, chaincode.Name, "test-marble-0", org2Peer0)
marblechaincodeutil.AssertPresentInCollectionMPD(network, channelID, chaincode.Name, "test-marble-0", org2Peer0)
marblechaincodeutil.AssertPresentInCollectionM(network, channelID, chaincode.Name, "test-marble-80", org2Peer0)
marblechaincodeutil.AssertPresentInCollectionMPD(network, channelID, chaincode.Name, "test-marble-80", org2Peer0)
marblechaincodeutil.AssertPresentInCollectionM(network, channelID, chaincode.Name, "test-marble-8080", org2Peer0)
marblechaincodeutil.AssertPresentInCollectionMPD(network, channelID, chaincode.Name, "test-marble-8080", org2Peer0)

chaincode.Version = "1.1"
chaincode.CollectionsConfig = CollectionConfig("remove_org3_config.json")
chaincode.Sequence = "2"
nwo.DeployChaincode(network, channelID, orderer, *chaincode)

marblechaincodeutil.PurgeMarble(network, orderer, channelID, chaincode.Name, `{"name":"test-marble-0"}`, org2Peer0)
marblechaincodeutil.PurgeMarble(network, orderer, channelID, chaincode.Name, `{"name":"test-marble-80"}`, org2Peer0)

marblechaincodeutil.AssertDoesNotExistInCollectionM(network, channelID, chaincode.Name, "test-marble-0", org3Peer0)
marblechaincodeutil.AssertDoesNotExistInCollectionMPD(network, channelID, chaincode.Name, "test-marble-0", org3Peer0)
marblechaincodeutil.AssertDoesNotExistInCollectionM(network, channelID, chaincode.Name, "test-marble-80", org3Peer0)
marblechaincodeutil.AssertDoesNotExistInCollectionMPD(network, channelID, chaincode.Name, "test-marble-80", org3Peer0)

runner := peerRunners[org3Peer0.ID()]
Eventually(runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Purging private data from private data storage channel=testchannel chaincode=marblesp collection=collectionMarblePrivateDetails key=test-marble-0 blockNum=\\d+ tranNum=\\d+"))
Eventually(runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Purging private data from private data storage channel=testchannel chaincode=marblesp collection=collectionMarblePrivateDetails key=test-marble-80 blockNum=\\d+ tranNum=\\d+"))
Eventually(runner.Err(), network.EventuallyTimeout).Should(gbytes.Say("Purged private data from private data storage channel=testchannel numKeysPurged=3 numPrivateDataStoreRecordsPurged=1"))
})

// 5. A new peer able to reconcile from a purged peer
// - Stop one of the peers of an eligible org
Expand Down Expand Up @@ -411,3 +446,10 @@ func getPrivateDataKeys(client pb.Deliver_DeliverWithPrivateDataClient, ledgerHe
}
}
}

func startPeer(network *nwo.Network, processes map[string]ifrit.Process, runners map[string]*ginkgomon.Runner, peer *nwo.Peer) {
runners[peer.ID()] = network.PeerRunner(peer)
p := ifrit.Invoke(runners[peer.ID()])
processes[peer.ID()] = p
Eventually(p.Ready(), network.EventuallyTimeout).Should(BeClosed())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "collectionMarbles",
"policy": "OR('Org1MSP.member', 'Org2MSP.member')",
"requiredPeerCount": 1,
"maxPeerCount": 2,
"blockToLive":1000000,
"memberOnlyRead": false
},
{
"name": "collectionMarblePrivateDetails",
"policy": "OR('Org1MSP.member', 'Org2MSP.member')",
"requiredPeerCount": 1,
"maxPeerCount": 2,
"blockToLive":1000000,
"memberOnlyRead": false
}
]

0 comments on commit 8857efa

Please sign in to comment.