Skip to content

Commit 376c2ca

Browse files
author
Jason Yellick
committed
[FAB-6485] Add capabilities hook for MSP version
The MSP framework needs to know which version of MSP semantics to use for principal evaluation etc. This needs to be determined based on the capabilities defined by the channel. This CR adds a new method to the capabilities interface for the channel which returns an MSP version. It also modifies the MSPConfigHandler to accept this version, but for the time being, does nothing with it. There is a TODO left in the code for where this flag should be used by the new MSP code which consumes it. Change-Id: Ic23be11b6814ae830ebd113442c365f7dd58de9b Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 40c423f commit 376c2ca

File tree

9 files changed

+91
-11
lines changed

9 files changed

+91
-11
lines changed

common/capabilities/channel.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,33 @@ import (
1212

1313
const (
1414
channelTypeName = "Channel"
15+
16+
// ChannelV1_1 is the capabilties string for standard new non-backwards compatible fabric v1.1 channel capabilities.
17+
ChannelV1_1 = "V1.1"
18+
)
19+
20+
// MSPVersion is used to communicate the level of the Channel MSP to the MSP implementations.
21+
type MSPVersion int
22+
23+
const (
24+
// MSPv1_0 is the version of the MSP framework shipped with v1.0.x of fabric.
25+
MSPv1_0 = iota
26+
27+
// MSPv1_1 is the version of the MSP framework enabled in v1.1.0 of fabric.
28+
MSPv1_1
1529
)
1630

1731
// ChannelProvider provides capabilities information for channel level config.
1832
type ChannelProvider struct {
1933
*registry
34+
v11 bool
2035
}
2136

2237
// NewChannelProvider creates a channel capabilities provider.
2338
func NewChannelProvider(capabilities map[string]*cb.Capability) *ChannelProvider {
2439
cp := &ChannelProvider{}
2540
cp.registry = newRegistry(cp, capabilities)
41+
_, cp.v11 = capabilities[ChannelV1_1]
2642
return cp
2743
}
2844

@@ -35,7 +51,19 @@ func (cp *ChannelProvider) Type() string {
3551
func (cp *ChannelProvider) HasCapability(capability string) bool {
3652
switch capability {
3753
// Add new capability names here
54+
case ChannelV1_1:
55+
return true
3856
default:
3957
return false
4058
}
4159
}
60+
61+
// MSPVersion returns the level of MSP support required by this channel.
62+
func (cp *ChannelProvider) MSPVersion() MSPVersion {
63+
switch {
64+
case cp.v11:
65+
return MSPv1_1
66+
default:
67+
return MSPv1_0
68+
}
69+
}

common/capabilities/channel_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 TestChannelV10(t *testing.T) {
18+
op := NewChannelProvider(map[string]*cb.Capability{})
19+
assert.NoError(t, op.Supported())
20+
assert.True(t, op.MSPVersion() == MSPv1_0)
21+
}
22+
23+
func TestChannelV11(t *testing.T) {
24+
op := NewChannelProvider(map[string]*cb.Capability{
25+
ChannelV1_1: &cb.Capability{},
26+
})
27+
assert.NoError(t, op.Supported())
28+
assert.True(t, op.MSPVersion() == MSPv1_1)
29+
}

common/channelconfig/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package channelconfig
99
import (
1010
"time"
1111

12+
"github.com/hyperledger/fabric/common/capabilities"
1213
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
1314
"github.com/hyperledger/fabric/common/policies"
1415
"github.com/hyperledger/fabric/msp"
@@ -105,6 +106,10 @@ type Orderer interface {
105106
type ChannelCapabilities interface {
106107
// Supported returns an error if there are unknown capabilities in this channel which are required
107108
Supported() error
109+
110+
// MSPVersion specifies the version of the MSP this channel must understand, including the MSP types
111+
// and MSP principal types.
112+
MSPVersion() capabilities.MSPVersion
108113
}
109114

110115
// ApplicationCapabilities defines the capabilities for the application portion of a channel

common/channelconfig/channel.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ func NewChannelConfig(channelGroup *cb.ConfigGroup) (*ChannelConfig, error) {
8383
protos: &ChannelProtos{},
8484
}
8585

86-
mspConfigHandler := NewMSPConfigHandler()
87-
8886
if err := DeserializeProtoValuesFromGroup(channelGroup, cc.protos); err != nil {
8987
return nil, errors.Wrap(err, "failed to deserialize values")
9088
}
@@ -93,6 +91,9 @@ func NewChannelConfig(channelGroup *cb.ConfigGroup) (*ChannelConfig, error) {
9391
return nil, err
9492
}
9593

94+
capabilities := cc.Capabilities()
95+
mspConfigHandler := NewMSPConfigHandler(capabilities.MSPVersion())
96+
9697
var err error
9798
for groupName, group := range channelGroup.Groups {
9899
switch groupName {

common/channelconfig/consortium_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ package channelconfig
88
import (
99
"testing"
1010

11+
"github.com/hyperledger/fabric/common/capabilities"
1112
cb "github.com/hyperledger/fabric/protos/common"
13+
1214
"github.com/stretchr/testify/assert"
1315
)
1416

1517
func TestConsortiumConfig(t *testing.T) {
16-
cc, err := NewConsortiumConfig(&cb.ConfigGroup{}, NewMSPConfigHandler())
18+
cc, err := NewConsortiumConfig(&cb.ConfigGroup{}, NewMSPConfigHandler(capabilities.MSPv1_0))
1719
assert.NoError(t, err)
1820
orgs := cc.Organizations()
1921
assert.Equal(t, 0, len(orgs))

common/channelconfig/msp.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package channelconfig
99
import (
1010
"fmt"
1111

12+
"github.com/hyperledger/fabric/common/capabilities"
1213
"github.com/hyperledger/fabric/msp"
1314
"github.com/hyperledger/fabric/msp/cache"
1415
mspprotos "github.com/hyperledger/fabric/protos/msp"
@@ -23,17 +24,21 @@ type pendingMSPConfig struct {
2324

2425
// MSPConfigHandler
2526
type MSPConfigHandler struct {
26-
idMap map[string]*pendingMSPConfig
27+
version capabilities.MSPVersion
28+
idMap map[string]*pendingMSPConfig
2729
}
2830

29-
func NewMSPConfigHandler() *MSPConfigHandler {
31+
func NewMSPConfigHandler(mspVersion capabilities.MSPVersion) *MSPConfigHandler {
3032
return &MSPConfigHandler{
31-
idMap: make(map[string]*pendingMSPConfig),
33+
version: mspVersion,
34+
idMap: make(map[string]*pendingMSPConfig),
3235
}
3336
}
3437

3538
// ProposeValue called when an org defines an MSP
3639
func (bh *MSPConfigHandler) ProposeMSP(mspConfig *mspprotos.MSPConfig) (msp.MSP, error) {
40+
// TODO utilize bh.version to initialize the MSP
41+
3742
// check that the type for that MSP is supported
3843
if mspConfig.Type != int32(msp.FABRIC) {
3944
return nil, fmt.Errorf("Setup error: unsupported msp type %d", mspConfig.Type)

common/channelconfig/msp_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package channelconfig
99
import (
1010
"testing"
1111

12+
"github.com/hyperledger/fabric/common/capabilities"
1213
"github.com/hyperledger/fabric/common/cauthdsl"
1314
"github.com/hyperledger/fabric/core/config"
1415
"github.com/hyperledger/fabric/msp"
@@ -26,7 +27,7 @@ func TestMSPConfigManager(t *testing.T) {
2627

2728
// test success:
2829

29-
mspCH := NewMSPConfigHandler()
30+
mspCH := NewMSPConfigHandler(capabilities.MSPv1_0)
3031

3132
_, err = mspCH.ProposeMSP(conf)
3233
assert.NoError(t, err)
@@ -44,7 +45,7 @@ func TestMSPConfigManager(t *testing.T) {
4445
}
4546

4647
func TestMSPConfigFailure(t *testing.T) {
47-
mspCH := NewMSPConfigHandler()
48+
mspCH := NewMSPConfigHandler(capabilities.MSPv1_0)
4849

4950
// begin/propose/commit
5051
t.Run("Bad proto", func(t *testing.T) {

common/mocks/config/channel.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package config
1818

1919
import (
20+
"github.com/hyperledger/fabric/common/capabilities"
2021
"github.com/hyperledger/fabric/common/channelconfig"
2122
"github.com/hyperledger/fabric/common/util"
2223
)
@@ -64,9 +65,17 @@ func (scm *Channel) Capabilities() channelconfig.ChannelCapabilities {
6465
type ChannelCapabilities struct {
6566
// SupportedErr is returned by Supported()
6667
SupportedErr error
68+
69+
// MSPVersionVal is returned by MSPVersion()
70+
MSPVersionVal capabilities.MSPVersion
6771
}
6872

6973
// Supported returns SupportedErr
70-
func (oc *ChannelCapabilities) Supported() error {
71-
return oc.SupportedErr
74+
func (cc *ChannelCapabilities) Supported() error {
75+
return cc.SupportedErr
76+
}
77+
78+
// MSPVersion returns MSPVersionVal
79+
func (cc *ChannelCapabilities) MSPVersion() capabilities.MSPVersion {
80+
return cc.MSPVersionVal
7281
}

orderer/common/multichannel/registrar_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func TestResourcesCheck(t *testing.T) {
292292
CapabilitiesVal: &mockchannelconfig.OrdererCapabilities{},
293293
},
294294
ChannelConfigVal: &mockchannelconfig.Channel{
295-
CapabilitiesVal: &mockchannelconfig.OrdererCapabilities{},
295+
CapabilitiesVal: &mockchannelconfig.ChannelCapabilities{},
296296
},
297297
})
298298

0 commit comments

Comments
 (0)