Skip to content

Commit

Permalink
V2.5 Capabilities For Purge Private Data
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Castrence <juliancastrence@ibm.com>
  • Loading branch information
jrc-ibm authored and denyeart committed Aug 5, 2022
1 parent eaff6f6 commit 4224f46
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
34 changes: 23 additions & 11 deletions common/capabilities/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
// ApplicationV2_0 is the capabilities string for standard new non-backwards compatible fabric v2.0 application capabilities.
ApplicationV2_0 = "V2_0"

// ApplicationV2_5 is the capabilities string for standard new non-backwards compatible fabric v2.5 application capabilities.
ApplicationV2_5 = "V2_5"

// ApplicationPvtDataExperimental is the capabilities string for private data using the experimental feature of collections/sideDB.
ApplicationPvtDataExperimental = "V1_1_PVTDATA_EXPERIMENTAL"

Expand All @@ -43,6 +46,7 @@ type ApplicationProvider struct {
v13 bool
v142 bool
v20 bool
v25 bool
v11PvtDataExperimental bool
}

Expand All @@ -55,6 +59,7 @@ func NewApplicationProvider(capabilities map[string]*cb.Capability) *Application
_, ap.v13 = capabilities[ApplicationV1_3]
_, ap.v142 = capabilities[ApplicationV1_4_2]
_, ap.v20 = capabilities[ApplicationV2_0]
_, ap.v25 = capabilities[ApplicationV2_5]
_, ap.v11PvtDataExperimental = capabilities[ApplicationPvtDataExperimental]
return ap
}
Expand All @@ -66,60 +71,60 @@ func (ap *ApplicationProvider) Type() string {

// ACLs returns whether ACLs may be specified in the channel application config
func (ap *ApplicationProvider) ACLs() bool {
return ap.v12 || ap.v13 || ap.v142 || ap.v20
return ap.v12 || ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// ForbidDuplicateTXIdInBlock specifies whether two transactions with the same TXId are permitted
// in the same block or whether we mark the second one as TxValidationCode_DUPLICATE_TXID
func (ap *ApplicationProvider) ForbidDuplicateTXIdInBlock() bool {
return ap.v11 || ap.v12 || ap.v13 || ap.v142 || ap.v20
return ap.v11 || ap.v12 || ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
// In v1.1, the private channel data is experimental and has to be enabled explicitly.
// In v1.2, the private channel data is enabled by default.
func (ap *ApplicationProvider) PrivateChannelData() bool {
return ap.v11PvtDataExperimental || ap.v12 || ap.v13 || ap.v142 || ap.v20
return ap.v11PvtDataExperimental || ap.v12 || ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// CollectionUpgrade returns true if this channel is configured to allow updates to
// existing collection or add new collections through chaincode upgrade (as introduced in v1.2)
func (ap ApplicationProvider) CollectionUpgrade() bool {
return ap.v12 || ap.v13 || ap.v142 || ap.v20
return ap.v12 || ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// V1_1Validation returns true is this channel is configured to perform stricter validation
// of transactions (as introduced in v1.1).
func (ap *ApplicationProvider) V1_1Validation() bool {
return ap.v11 || ap.v12 || ap.v13 || ap.v142 || ap.v20
return ap.v11 || ap.v12 || ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// V1_2Validation returns true if this channel is configured to perform stricter validation
// of transactions (as introduced in v1.2).
func (ap *ApplicationProvider) V1_2Validation() bool {
return ap.v12 || ap.v13 || ap.v142 || ap.v20
return ap.v12 || ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// V1_3Validation returns true if this channel is configured to perform stricter validation
// of transactions (as introduced in v1.3).
func (ap *ApplicationProvider) V1_3Validation() bool {
return ap.v13 || ap.v142 || ap.v20
return ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// V2_0Validation returns true if this channel supports transaction validation
// as introduced in v2.0. This includes:
// - new chaincode lifecycle
// - implicit per-org collections
func (ap *ApplicationProvider) V2_0Validation() bool {
return ap.v20
return ap.v20 || ap.v25
}

// LifecycleV20 indicates whether the peer should use the deprecated and problematic
// v1.x lifecycle, or whether it should use the newer per channel approve/commit definitions
// process introduced in v2.0. Note, this should only be used on the endorsing side
// of peer processing, so that we may safely remove all checks against it in v2.1.
func (ap *ApplicationProvider) LifecycleV20() bool {
return ap.v20
return ap.v20 || ap.v25
}

// MetadataLifecycle always returns false
Expand All @@ -130,13 +135,18 @@ func (ap *ApplicationProvider) MetadataLifecycle() bool {
// KeyLevelEndorsement returns true if this channel supports endorsement
// policies expressible at a ledger key granularity, as described in FAB-8812
func (ap *ApplicationProvider) KeyLevelEndorsement() bool {
return ap.v13 || ap.v142 || ap.v20
return ap.v13 || ap.v142 || ap.v20 || ap.v25
}

// StorePvtDataOfInvalidTx returns true if the peer needs to store
// the pvtData of invalid transactions.
func (ap *ApplicationProvider) StorePvtDataOfInvalidTx() bool {
return ap.v142 || ap.v20
return ap.v142 || ap.v20 || ap.v25
}

// PurgePvtData returns true if this channel supports the purging of private data
func (ap *ApplicationProvider) PurgePvtData() bool {
return ap.v25
}

// HasCapability returns true if the capability is supported by this binary.
Expand All @@ -153,6 +163,8 @@ func (ap *ApplicationProvider) HasCapability(capability string) bool {
return true
case ApplicationV2_0:
return true
case ApplicationV2_5:
return true
case ApplicationPvtDataExperimental:
return true
case ApplicationResourcesTreeExperimental:
Expand Down
20 changes: 20 additions & 0 deletions common/capabilities/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ func TestApplicationV20(t *testing.T) {
require.True(t, ap.StorePvtDataOfInvalidTx())
}

func TestApplicationV25(t *testing.T) {
ap := NewApplicationProvider(map[string]*cb.Capability{
ApplicationV2_5: {},
})
require.NoError(t, ap.Supported())
require.True(t, ap.ForbidDuplicateTXIdInBlock())
require.True(t, ap.V1_1Validation())
require.True(t, ap.V1_2Validation())
require.True(t, ap.V1_3Validation())
require.True(t, ap.V2_0Validation())
require.True(t, ap.KeyLevelEndorsement())
require.True(t, ap.ACLs())
require.True(t, ap.CollectionUpgrade())
require.True(t, ap.PrivateChannelData())
require.True(t, ap.LifecycleV20())
require.True(t, ap.StorePvtDataOfInvalidTx())
require.True(t, ap.PurgePvtData())
}

func TestApplicationPvtDataExperimental(t *testing.T) {
ap := NewApplicationProvider(map[string]*cb.Capability{
ApplicationPvtDataExperimental: {},
Expand All @@ -102,6 +121,7 @@ func TestHasCapability(t *testing.T) {
require.True(t, ap.HasCapability(ApplicationV1_2))
require.True(t, ap.HasCapability(ApplicationV1_3))
require.True(t, ap.HasCapability(ApplicationV2_0))
require.True(t, ap.HasCapability(ApplicationV2_5))
require.True(t, ap.HasCapability(ApplicationPvtDataExperimental))
require.True(t, ap.HasCapability(ApplicationResourcesTreeExperimental))
require.False(t, ap.HasCapability("default"))
Expand Down
12 changes: 6 additions & 6 deletions integration/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ var _ = Describe("EndToEnd", func() {

By("setting up the channel")
network.CreateAndJoinChannel(orderer, "testchannel")
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_5", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))

By("listing channels with osnadmin")
tlsdir := network.OrdererLocalTLSDir(orderer)
Expand Down Expand Up @@ -285,7 +285,7 @@ var _ = Describe("EndToEnd", func() {
cl := channelparticipation.List(network, orderer)
channelparticipation.ChannelListMatcher(cl, []string{"testchannel"}, []string{"systemchannel"}...)

nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_5", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))

// package, install, and approve by org1 - module chaincode
packageInstallApproveChaincode(network, "testchannel", orderer, chaincode, network.Peer("Org1", "peer0"))
Expand Down Expand Up @@ -415,7 +415,7 @@ var _ = Describe("EndToEnd", func() {

By("Create first channel and deploy the chaincode")
network.CreateAndJoinChannel(orderer, "testchannel")
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_5", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.DeployChaincode(network, "testchannel", orderer, chaincode)
RunQueryInvokeQuery(network, orderer, peer, "testchannel")

Expand All @@ -425,7 +425,7 @@ var _ = Describe("EndToEnd", func() {
channelparticipation.ChannelListMatcher(cl, []string{"testchannel", "testchannel2"}, []string{"systemchannel"}...)

peers := network.PeersWithChannel("testchannel2")
nwo.EnableCapabilities(network, "testchannel2", "Application", "V2_0", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.EnableCapabilities(network, "testchannel2", "Application", "V2_5", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.ApproveChaincodeForMyOrg(network, "testchannel2", orderer, chaincode, peers...)
nwo.CheckCommitReadinessUntilReady(network, "testchannel2", chaincode, network.PeerOrgs(), peers...)
nwo.CommitChaincode(network, "testchannel2", orderer, chaincode, peers[0], peers...)
Expand Down Expand Up @@ -503,7 +503,7 @@ var _ = Describe("EndToEnd", func() {

// The below call waits for the config update to commit on the peer, so
// it will fail if the orderer addresses are wrong.
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_5", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
})
})

Expand Down Expand Up @@ -540,7 +540,7 @@ var _ = Describe("EndToEnd", func() {
network.CreateAndJoinChannels(orderer)

By("enabling new lifecycle capabilities")
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_0", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
nwo.EnableCapabilities(network, "testchannel", "Application", "V2_5", orderer, network.Peer("Org1", "peer0"), network.Peer("Org2", "peer0"))
By("deploying the chaincode")
nwo.DeployChaincode(network, "testchannel", orderer, chaincode)

Expand Down

0 comments on commit 4224f46

Please sign in to comment.