Skip to content

Commit 61b445c

Browse files
committed
FAB-14180 Chan. Cap. V1_4_2 Consensus type migration
Add Channel capability V1_4_2 to gate consensus type migration in the peer and orderer. When this capablity is on, the peer will allow config transactions which change Orderer.ConsensusType.Type to pass through the Bundle.ValidateNew(). (This will be implemented in a following change). Change-Id: If422f0292b0093f589a44e30a1a71dae2872e29a Signed-off-by: Yoav Tock <tock@il.ibm.com>
1 parent aa90765 commit 61b445c

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

common/capabilities/channel.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ import (
1414
const (
1515
channelTypeName = "Channel"
1616

17-
// ChannelV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 channel capabilities.
17+
// ChannelV1_1 is the capabilities string for standard new non-backwards compatible fabric v1.1 channel capabilities.
1818
ChannelV1_1 = "V1_1"
1919

20-
// ChannelV1_3 is the capabilties string for standard new non-backwards compatible fabric v1.3 channel capabilities.
20+
// ChannelV1_3 is the capabilities string for standard new non-backwards compatible fabric v1.3 channel capabilities.
2121
ChannelV1_3 = "V1_3"
22+
23+
// ChannelV1_4_2 is the capabilities string for standard new non-backwards compatible fabric v1.4.2 channel capabilities.
24+
ChannelV1_4_2 = "V1_4_2"
2225
)
2326

2427
// ChannelProvider provides capabilities information for channel level config.
2528
type ChannelProvider struct {
2629
*registry
27-
v11 bool
28-
v13 bool
30+
v11 bool
31+
v13 bool
32+
v142 bool
2933
}
3034

3135
// NewChannelProvider creates a channel capabilities provider.
@@ -34,6 +38,7 @@ func NewChannelProvider(capabilities map[string]*cb.Capability) *ChannelProvider
3438
cp.registry = newRegistry(cp, capabilities)
3539
_, cp.v11 = capabilities[ChannelV1_1]
3640
_, cp.v13 = capabilities[ChannelV1_3]
41+
_, cp.v142 = capabilities[ChannelV1_4_2]
3742
return cp
3843
}
3944

@@ -46,6 +51,8 @@ func (cp *ChannelProvider) Type() string {
4651
func (cp *ChannelProvider) HasCapability(capability string) bool {
4752
switch capability {
4853
// Add new capability names here
54+
case ChannelV1_4_2:
55+
fallthrough
4956
case ChannelV1_3:
5057
return true
5158
case ChannelV1_1:
@@ -58,6 +65,8 @@ func (cp *ChannelProvider) HasCapability(capability string) bool {
5865
// MSPVersion returns the level of MSP support required by this channel.
5966
func (cp *ChannelProvider) MSPVersion() msp.MSPVersion {
6067
switch {
68+
case cp.v142:
69+
return msp.MSPv1_3
6170
case cp.v13:
6271
return msp.MSPv1_3
6372
case cp.v11:
@@ -66,3 +75,8 @@ func (cp *ChannelProvider) MSPVersion() msp.MSPVersion {
6675
return msp.MSPv1_0
6776
}
6877
}
78+
79+
// ConsensusTypeMigration return true if consensus-type migration is supported and permitted in both orderer and peer.
80+
func (cp *ChannelProvider) ConsensusTypeMigration() bool {
81+
return cp.v142
82+
}

common/capabilities/channel_test.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,60 @@ import (
1515
)
1616

1717
func TestChannelV10(t *testing.T) {
18-
op := NewChannelProvider(map[string]*cb.Capability{})
19-
assert.NoError(t, op.Supported())
20-
assert.True(t, op.MSPVersion() == msp.MSPv1_0)
18+
cp := NewChannelProvider(map[string]*cb.Capability{})
19+
assert.NoError(t, cp.Supported())
20+
assert.True(t, cp.MSPVersion() == msp.MSPv1_0)
21+
assert.False(t, cp.ConsensusTypeMigration())
2122
}
2223

2324
func TestChannelV11(t *testing.T) {
24-
op := NewChannelProvider(map[string]*cb.Capability{
25+
cp := NewChannelProvider(map[string]*cb.Capability{
2526
ChannelV1_1: {},
2627
})
27-
assert.NoError(t, op.Supported())
28-
assert.True(t, op.MSPVersion() == msp.MSPv1_1)
28+
assert.NoError(t, cp.Supported())
29+
assert.True(t, cp.MSPVersion() == msp.MSPv1_1)
30+
assert.False(t, cp.ConsensusTypeMigration())
2931
}
3032

3133
func TestChannelV13(t *testing.T) {
32-
op := NewChannelProvider(map[string]*cb.Capability{
34+
cp := NewChannelProvider(map[string]*cb.Capability{
3335
ChannelV1_1: {},
3436
ChannelV1_3: {},
3537
})
36-
assert.NoError(t, op.Supported())
37-
assert.True(t, op.MSPVersion() == msp.MSPv1_3)
38+
assert.NoError(t, cp.Supported())
39+
assert.True(t, cp.MSPVersion() == msp.MSPv1_3)
40+
assert.False(t, cp.ConsensusTypeMigration())
41+
42+
cp = NewChannelProvider(map[string]*cb.Capability{
43+
ChannelV1_3: {},
44+
})
45+
assert.NoError(t, cp.Supported())
46+
assert.True(t, cp.MSPVersion() == msp.MSPv1_3)
47+
assert.False(t, cp.ConsensusTypeMigration())
48+
}
49+
50+
func TestChannelV141(t *testing.T) {
51+
cp := NewChannelProvider(map[string]*cb.Capability{
52+
ChannelV1_3: {},
53+
ChannelV1_4_2: {},
54+
})
55+
assert.NoError(t, cp.Supported())
56+
assert.True(t, cp.MSPVersion() == msp.MSPv1_3)
57+
assert.True(t, cp.ConsensusTypeMigration())
58+
59+
cp = NewChannelProvider(map[string]*cb.Capability{
60+
ChannelV1_4_2: {},
61+
})
62+
assert.NoError(t, cp.Supported())
63+
assert.True(t, cp.MSPVersion() == msp.MSPv1_3)
64+
assert.True(t, cp.ConsensusTypeMigration())
65+
}
66+
67+
func TestChannelNotSuported(t *testing.T) {
68+
cp := NewChannelProvider(map[string]*cb.Capability{
69+
ChannelV1_1: {},
70+
ChannelV1_3: {},
71+
"Bogus_Not_suported": {},
72+
})
73+
assert.EqualError(t, cp.Supported(), "Channel capability Bogus_Not_suported is required but not supported")
3874
}

0 commit comments

Comments
 (0)