Skip to content

Commit 978c48c

Browse files
author
Jason Yellick
committed
[FAB-6088] Add v1.1 application capabilities flag
This CR adds parsing of the V1.1 capabilities flag to the application capabilities group. It additionally fixes the orderer capabilities group to be in line with the same pattern followed by the channel and applications group as well as adds some additional unit tests for the orderer capabilities. Change-Id: Ic39d2fbbece96b74de7bfffec7df2729ab51453d Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 376c2ca commit 978c48c

File tree

5 files changed

+83
-8
lines changed

5 files changed

+83
-8
lines changed

common/capabilities/application.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,43 @@ import (
1212

1313
const (
1414
applicationTypeName = "Application"
15+
16+
// ApplicationV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 application capabilities.
17+
ApplicationV1_1 = "V1.1"
1518
)
1619

1720
// ApplicationProvider provides capabilities information for application level config.
1821
type ApplicationProvider struct {
1922
*registry
23+
v11 bool
2024
}
2125

2226
// NewApplicationProvider creates a application capabilities provider.
2327
func NewApplicationProvider(capabilities map[string]*cb.Capability) *ApplicationProvider {
24-
cp := &ApplicationProvider{}
25-
cp.registry = newRegistry(cp, capabilities)
26-
return cp
28+
ap := &ApplicationProvider{}
29+
ap.registry = newRegistry(ap, capabilities)
30+
_, ap.v11 = capabilities[ApplicationV1_1]
31+
return ap
2732
}
2833

2934
// Type returns a descriptive string for logging purposes.
30-
func (cp *ApplicationProvider) Type() string {
35+
func (ap *ApplicationProvider) Type() string {
3136
return applicationTypeName
3237
}
3338

3439
// HasCapability returns true if the capability is supported by this binary.
35-
func (cp *ApplicationProvider) HasCapability(capability string) bool {
40+
func (ap *ApplicationProvider) HasCapability(capability string) bool {
3641
switch capability {
3742
// Add new capability names here
43+
case ApplicationV1_1:
44+
return true
3845
default:
3946
return false
4047
}
4148
}
49+
50+
// LifecycleViaConfig returns true if chaincode lifecycle should be managed via the resources config
51+
// tree rather than via the deprecated v1.0 endorser tx mechanism.
52+
func (ap *ApplicationProvider) LifecycleViaConfig() bool {
53+
return ap.v11
54+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package capabilities
8+
9+
import (
10+
"testing"
11+
12+
cb "github.com/hyperledger/fabric/protos/common"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func TestApplicationV10(t *testing.T) {
18+
op := NewApplicationProvider(map[string]*cb.Capability{})
19+
assert.NoError(t, op.Supported())
20+
assert.False(t, op.LifecycleViaConfig())
21+
}
22+
23+
func TestApplicationV11(t *testing.T) {
24+
op := NewApplicationProvider(map[string]*cb.Capability{
25+
ApplicationV1_1: &cb.Capability{},
26+
})
27+
assert.NoError(t, op.Supported())
28+
assert.True(t, op.LifecycleViaConfig())
29+
}

common/capabilities/orderer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212

1313
const (
1414
ordererTypeName = "Orderer"
15-
OrdererV11 = "V1.1"
15+
16+
// OrdererV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 orderer capabilities.
17+
OrdererV1_1 = "V1.1"
1618
)
1719

1820
// OrdererProvider provides capabilities information for orderer level config.
@@ -25,7 +27,7 @@ type OrdererProvider struct {
2527
func NewOrdererProvider(capabilities map[string]*cb.Capability) *OrdererProvider {
2628
cp := &OrdererProvider{}
2729
cp.registry = newRegistry(cp, capabilities)
28-
_, cp.v11BugFixes = capabilities[OrdererV11]
30+
_, cp.v11BugFixes = capabilities[OrdererV1_1]
2931
return cp
3032
}
3133

@@ -38,6 +40,8 @@ func (cp *OrdererProvider) Type() string {
3840
func (cp *OrdererProvider) HasCapability(capability string) bool {
3941
switch capability {
4042
// Add new capability names here
43+
case OrdererV1_1:
44+
return true
4145
default:
4246
return false
4347
}

common/capabilities/orderer_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package capabilities
8+
9+
import (
10+
"testing"
11+
12+
cb "github.com/hyperledger/fabric/protos/common"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func TestOrdererV10(t *testing.T) {
18+
op := NewOrdererProvider(map[string]*cb.Capability{})
19+
assert.NoError(t, op.Supported())
20+
assert.False(t, op.SetChannelModPolicyDuringCreate())
21+
}
22+
23+
func TestOrdererV11(t *testing.T) {
24+
op := NewOrdererProvider(map[string]*cb.Capability{
25+
OrdererV1_1: &cb.Capability{},
26+
})
27+
assert.NoError(t, op.Supported())
28+
assert.True(t, op.SetChannelModPolicyDuringCreate())
29+
}

orderer/common/msgprocessor/systemchannel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func TestNewChannelConfig(t *testing.T) {
411411
channelID := "foo"
412412
gConf := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)
413413
gConf.Orderer.Capabilities = map[string]bool{
414-
capabilities.OrdererV11: true,
414+
capabilities.OrdererV1_1: true,
415415
}
416416
singleMSPGenesisBlock := provisional.New(gConf).GenesisBlockForChannel(channelID)
417417
configEnv := configtx.UnmarshalConfigEnvelopeOrPanic(

0 commit comments

Comments
 (0)