Skip to content

Commit dfe213b

Browse files
Jason Yellickdenyeart
authored andcommitted
FAB-11320 Add application v1.3 capability
To enable the new validation associated with the new chaincode lifecycle, we need a new application level capability for v1.3. This CR creates one. Change-Id: I6629b97c7ce86f12b55f6567f3f29c2fe2586aa5 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 7134f6e commit dfe213b

File tree

2 files changed

+63
-68
lines changed

2 files changed

+63
-68
lines changed

common/capabilities/application.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,23 @@ const (
1919
// ApplicationV1_2 is the capabilties string for standard new non-backwards compatible fabric v1.2 application capabilities.
2020
ApplicationV1_2 = "V1_2"
2121

22+
// ApplicationV1_3 is the capabilties string for standard new non-backwards compatible fabric v1.3 application capabilities.
23+
ApplicationV1_3 = "V1_3"
24+
2225
// ApplicationPvtDataExperimental is the capabilties string for private data using the experimental feature of collections/sideDB.
2326
ApplicationPvtDataExperimental = "V1_1_PVTDATA_EXPERIMENTAL"
2427

2528
// ApplicationResourcesTreeExperimental is the capabilties string for private data using the experimental feature of collections/sideDB.
2629
ApplicationResourcesTreeExperimental = "V1_1_RESOURCETREE_EXPERIMENTAL"
27-
28-
// ApplicationChaincodeLifecycleExperimental is the capabilties string for improved chaincode lifecycle
29-
// which is targetted to be a real feature for v1.2, but which is being included only as experimental
30-
// during development. This string will hopefully be removed prior to the release of v1.2 and
31-
// Will be enabled along with ApplicationV1_2
32-
ApplicationChaincodeLifecycleExperimental = "V1_2_CHAINCODE_LIFECYCLE_EXPERIMENTAL"
3330
)
3431

3532
// ApplicationProvider provides capabilities information for application level config.
3633
type ApplicationProvider struct {
3734
*registry
38-
v11 bool
39-
v12 bool
40-
v11PvtDataExperimental bool
41-
v12LifecycleExperimental bool
35+
v11 bool
36+
v12 bool
37+
v13 bool
38+
v11PvtDataExperimental bool
4239
}
4340

4441
// NewApplicationProvider creates a application capabilities provider.
@@ -47,8 +44,8 @@ func NewApplicationProvider(capabilities map[string]*cb.Capability) *Application
4744
ap.registry = newRegistry(ap, capabilities)
4845
_, ap.v11 = capabilities[ApplicationV1_1]
4946
_, ap.v12 = capabilities[ApplicationV1_2]
47+
_, ap.v13 = capabilities[ApplicationV1_3]
5048
_, ap.v11PvtDataExperimental = capabilities[ApplicationPvtDataExperimental]
51-
_, ap.v12LifecycleExperimental = capabilities[ApplicationChaincodeLifecycleExperimental]
5249
return ap
5350
}
5451

@@ -59,51 +56,57 @@ func (ap *ApplicationProvider) Type() string {
5956

6057
// ACLs returns whether ACLs may be specified in the channel application config
6158
func (ap *ApplicationProvider) ACLs() bool {
62-
return ap.v12
59+
return ap.v12 || ap.v13
6360
}
6461

6562
// ForbidDuplicateTXIdInBlock specifies whether two transactions with the same TXId are permitted
6663
// in the same block or whether we mark the second one as TxValidationCode_DUPLICATE_TXID
6764
func (ap *ApplicationProvider) ForbidDuplicateTXIdInBlock() bool {
68-
return ap.v11 || ap.v12
65+
return ap.v11 || ap.v12 || ap.v13
6966
}
7067

7168
// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
7269
// In v1.1, the private channel data is experimental and has to be enabled explicitly.
7370
// In v1.2, the private channel data is enabled by default.
7471
func (ap *ApplicationProvider) PrivateChannelData() bool {
75-
return ap.v11PvtDataExperimental || ap.v12
72+
return ap.v11PvtDataExperimental || ap.v12 || ap.v13
7673
}
7774

7875
// CollectionUpgrade returns true if this channel is configured to allow updates to
7976
// existing collection or add new collections through chaincode upgrade (as introduced in v1.2)
8077
func (ap ApplicationProvider) CollectionUpgrade() bool {
81-
return ap.v12
78+
return ap.v12 || ap.v13
8279
}
8380

8481
// V1_1Validation returns true is this channel is configured to perform stricter validation
8582
// of transactions (as introduced in v1.1).
8683
func (ap *ApplicationProvider) V1_1Validation() bool {
87-
return ap.v11 || ap.v12
84+
return ap.v11 || ap.v12 || ap.v13
8885
}
8986

9087
// V1_2Validation returns true if this channel is configured to perform stricter validation
9188
// of transactions (as introduced in v1.2).
9289
func (ap *ApplicationProvider) V1_2Validation() bool {
93-
return ap.v12
90+
return ap.v12 || ap.v13
91+
}
92+
93+
// V1_3Validation returns true if this channel is configured to perform stricter validation
94+
// of transactions (as introduced in v1.3).
95+
func (ap *ApplicationProvider) V1_3Validation() bool {
96+
return ap.v13
9497
}
9598

9699
// MetadataLifecycle indicates whether the peer should use the deprecated and problematic
97-
// v1.0/v1.1 lifecycle, or whether it should use the newer per channel peer local chaincode
98-
// metadata package approach planned for release with Fabric v1.2
100+
// v1.0/v1.1/v1.2 lifecycle, or whether it should use the newer per channel peer local chaincode
101+
// metadata package approach planned for release with Fabric v1.3
99102
func (ap *ApplicationProvider) MetadataLifecycle() bool {
100-
return ap.v12LifecycleExperimental
103+
return ap.v13
101104
}
102105

103106
// KeyLevelEndorsement returns true if this channel supports endorsement
104107
// policies expressible at a ledger key granularity, as described in FAB-8812
105108
func (ap *ApplicationProvider) KeyLevelEndorsement() bool {
106-
return ap.v12
109+
return ap.v12 || ap.v13
107110
}
108111

109112
// HasCapability returns true if the capability is supported by this binary.
@@ -114,12 +117,12 @@ func (ap *ApplicationProvider) HasCapability(capability string) bool {
114117
return true
115118
case ApplicationV1_2:
116119
return true
120+
case ApplicationV1_3:
121+
return true
117122
case ApplicationPvtDataExperimental:
118123
return true
119124
case ApplicationResourcesTreeExperimental:
120125
return true
121-
case ApplicationChaincodeLifecycleExperimental:
122-
return true
123126
default:
124127
return false
125128
}

common/capabilities/application_test.go

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,62 @@ import (
1515
)
1616

1717
func TestApplicationV10(t *testing.T) {
18-
op := NewApplicationProvider(map[string]*cb.Capability{})
19-
assert.NoError(t, op.Supported())
18+
ap := NewApplicationProvider(map[string]*cb.Capability{})
19+
assert.NoError(t, ap.Supported())
2020
}
2121

2222
func TestApplicationV11(t *testing.T) {
23-
op := NewApplicationProvider(map[string]*cb.Capability{
23+
ap := NewApplicationProvider(map[string]*cb.Capability{
2424
ApplicationV1_1: {},
2525
})
26-
assert.NoError(t, op.Supported())
27-
assert.True(t, op.ForbidDuplicateTXIdInBlock())
28-
assert.True(t, op.V1_1Validation())
26+
assert.NoError(t, ap.Supported())
27+
assert.True(t, ap.ForbidDuplicateTXIdInBlock())
28+
assert.True(t, ap.V1_1Validation())
2929
}
3030

3131
func TestApplicationV12(t *testing.T) {
32-
op := NewApplicationProvider(map[string]*cb.Capability{
33-
ApplicationV1_2: {},
34-
})
35-
assert.NoError(t, op.Supported())
36-
assert.True(t, op.ForbidDuplicateTXIdInBlock())
37-
assert.True(t, op.V1_1Validation())
38-
assert.True(t, op.V1_2Validation())
39-
assert.True(t, op.KeyLevelEndorsement())
40-
}
41-
42-
func TestApplicationPvtDataExperimental(t *testing.T) {
43-
op := NewApplicationProvider(map[string]*cb.Capability{
44-
ApplicationPvtDataExperimental: {},
45-
})
46-
assert.True(t, op.PrivateChannelData())
47-
48-
op = NewApplicationProvider(map[string]*cb.Capability{
49-
ApplicationV1_2: {},
50-
})
51-
assert.True(t, op.PrivateChannelData())
52-
53-
}
54-
55-
func TestApplicationACLs(t *testing.T) {
5632
ap := NewApplicationProvider(map[string]*cb.Capability{
5733
ApplicationV1_2: {},
5834
})
35+
assert.NoError(t, ap.Supported())
36+
assert.True(t, ap.ForbidDuplicateTXIdInBlock())
37+
assert.True(t, ap.V1_1Validation())
38+
assert.True(t, ap.V1_2Validation())
39+
assert.True(t, ap.KeyLevelEndorsement())
5940
assert.True(t, ap.ACLs())
41+
assert.True(t, ap.CollectionUpgrade())
42+
assert.True(t, ap.PrivateChannelData())
6043
}
6144

62-
func TestApplicationCollectionUpgrade(t *testing.T) {
63-
op := NewApplicationProvider(map[string]*cb.Capability{
64-
ApplicationV1_2: {},
45+
func TestApplicationV13(t *testing.T) {
46+
ap := NewApplicationProvider(map[string]*cb.Capability{
47+
ApplicationV1_3: {},
6548
})
66-
assert.True(t, op.CollectionUpgrade())
49+
assert.NoError(t, ap.Supported())
50+
assert.True(t, ap.ForbidDuplicateTXIdInBlock())
51+
assert.True(t, ap.V1_1Validation())
52+
assert.True(t, ap.V1_2Validation())
53+
assert.True(t, ap.V1_3Validation())
54+
assert.True(t, ap.KeyLevelEndorsement())
55+
assert.True(t, ap.MetadataLifecycle())
56+
assert.True(t, ap.ACLs())
57+
assert.True(t, ap.CollectionUpgrade())
58+
assert.True(t, ap.PrivateChannelData())
6759
}
6860

69-
func TestChaincodeLifecycleExperimental(t *testing.T) {
70-
op := NewApplicationProvider(map[string]*cb.Capability{
71-
ApplicationChaincodeLifecycleExperimental: {},
61+
func TestApplicationPvtDataExperimental(t *testing.T) {
62+
ap := NewApplicationProvider(map[string]*cb.Capability{
63+
ApplicationPvtDataExperimental: {},
7264
})
73-
assert.True(t, op.MetadataLifecycle())
65+
assert.True(t, ap.PrivateChannelData())
7466
}
7567

7668
func TestHasCapability(t *testing.T) {
77-
op := NewApplicationProvider(map[string]*cb.Capability{})
78-
assert.True(t, op.HasCapability(ApplicationV1_1))
79-
assert.True(t, op.HasCapability(ApplicationV1_2))
80-
assert.True(t, op.HasCapability(ApplicationPvtDataExperimental))
81-
assert.True(t, op.HasCapability(ApplicationResourcesTreeExperimental))
82-
assert.True(t, op.HasCapability(ApplicationChaincodeLifecycleExperimental))
83-
assert.False(t, op.HasCapability("default"))
69+
ap := NewApplicationProvider(map[string]*cb.Capability{})
70+
assert.True(t, ap.HasCapability(ApplicationV1_1))
71+
assert.True(t, ap.HasCapability(ApplicationV1_2))
72+
assert.True(t, ap.HasCapability(ApplicationV1_3))
73+
assert.True(t, ap.HasCapability(ApplicationPvtDataExperimental))
74+
assert.True(t, ap.HasCapability(ApplicationResourcesTreeExperimental))
75+
assert.False(t, ap.HasCapability("default"))
8476
}

0 commit comments

Comments
 (0)