Skip to content

Commit 9cf6a27

Browse files
committed
[FAB-6640] Bridge app capabilities flag and MSP
This change-set does the following: - When a channel is configured, the MSP application capabilities flag is used to instantiate the proper MSP version. Change-Id: I69884fcca644ac75ffa4e5164c30baacf85a09c3 Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 448d384 commit 9cf6a27

File tree

14 files changed

+63
-43
lines changed

14 files changed

+63
-43
lines changed

common/capabilities/channel.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package capabilities
88

99
import (
10+
"github.com/hyperledger/fabric/msp"
1011
cb "github.com/hyperledger/fabric/protos/common"
1112
)
1213

@@ -17,17 +18,6 @@ const (
1718
ChannelV1_1 = "V1.1"
1819
)
1920

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
29-
)
30-
3121
// ChannelProvider provides capabilities information for channel level config.
3222
type ChannelProvider struct {
3323
*registry
@@ -59,11 +49,11 @@ func (cp *ChannelProvider) HasCapability(capability string) bool {
5949
}
6050

6151
// MSPVersion returns the level of MSP support required by this channel.
62-
func (cp *ChannelProvider) MSPVersion() MSPVersion {
52+
func (cp *ChannelProvider) MSPVersion() msp.MSPVersion {
6353
switch {
6454
case cp.v11:
65-
return MSPv1_1
55+
return msp.MSPv1_1
6656
default:
67-
return MSPv1_0
57+
return msp.MSPv1_0
6858
}
6959
}

common/capabilities/channel_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ import (
1111

1212
cb "github.com/hyperledger/fabric/protos/common"
1313

14+
"github.com/hyperledger/fabric/msp"
1415
"github.com/stretchr/testify/assert"
1516
)
1617

1718
func TestChannelV10(t *testing.T) {
1819
op := NewChannelProvider(map[string]*cb.Capability{})
1920
assert.NoError(t, op.Supported())
20-
assert.True(t, op.MSPVersion() == MSPv1_0)
21+
assert.True(t, op.MSPVersion() == msp.MSPv1_0)
2122
}
2223

2324
func TestChannelV11(t *testing.T) {
2425
op := NewChannelProvider(map[string]*cb.Capability{
2526
ChannelV1_1: &cb.Capability{},
2627
})
2728
assert.NoError(t, op.Supported())
28-
assert.True(t, op.MSPVersion() == MSPv1_1)
29+
assert.True(t, op.MSPVersion() == msp.MSPv1_1)
2930
}

common/channelconfig/api.go

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

12-
"github.com/hyperledger/fabric/common/capabilities"
1312
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
1413
"github.com/hyperledger/fabric/common/policies"
1514
"github.com/hyperledger/fabric/msp"
@@ -109,7 +108,7 @@ type ChannelCapabilities interface {
109108

110109
// MSPVersion specifies the version of the MSP this channel must understand, including the MSP types
111110
// and MSP principal types.
112-
MSPVersion() capabilities.MSPVersion
111+
MSPVersion() msp.MSPVersion
113112
}
114113

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

common/channelconfig/consortium_test.go

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

11-
"github.com/hyperledger/fabric/common/capabilities"
11+
"github.com/hyperledger/fabric/msp"
1212
cb "github.com/hyperledger/fabric/protos/common"
13-
1413
"github.com/stretchr/testify/assert"
1514
)
1615

1716
func TestConsortiumConfig(t *testing.T) {
18-
cc, err := NewConsortiumConfig(&cb.ConfigGroup{}, NewMSPConfigHandler(capabilities.MSPv1_0))
17+
cc, err := NewConsortiumConfig(&cb.ConfigGroup{}, NewMSPConfigHandler(msp.MSPv1_0))
1918
assert.NoError(t, err)
2019
orgs := cc.Organizations()
2120
assert.Equal(t, 0, len(orgs))

common/channelconfig/msp.go

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

12-
"github.com/hyperledger/fabric/common/capabilities"
1312
"github.com/hyperledger/fabric/msp"
1413
"github.com/hyperledger/fabric/msp/cache"
1514
mspprotos "github.com/hyperledger/fabric/protos/msp"
@@ -24,11 +23,11 @@ type pendingMSPConfig struct {
2423

2524
// MSPConfigHandler
2625
type MSPConfigHandler struct {
27-
version capabilities.MSPVersion
26+
version msp.MSPVersion
2827
idMap map[string]*pendingMSPConfig
2928
}
3029

31-
func NewMSPConfigHandler(mspVersion capabilities.MSPVersion) *MSPConfigHandler {
30+
func NewMSPConfigHandler(mspVersion msp.MSPVersion) *MSPConfigHandler {
3231
return &MSPConfigHandler{
3332
version: mspVersion,
3433
idMap: make(map[string]*pendingMSPConfig),
@@ -37,15 +36,13 @@ func NewMSPConfigHandler(mspVersion capabilities.MSPVersion) *MSPConfigHandler {
3736

3837
// ProposeValue called when an org defines an MSP
3938
func (bh *MSPConfigHandler) ProposeMSP(mspConfig *mspprotos.MSPConfig) (msp.MSP, error) {
40-
// TODO utilize bh.version to initialize the MSP
41-
4239
// check that the type for that MSP is supported
4340
if mspConfig.Type != int32(msp.FABRIC) {
4441
return nil, fmt.Errorf("Setup error: unsupported msp type %d", mspConfig.Type)
4542
}
4643

4744
// create the msp instance
48-
mspInst, err := msp.New(&msp.BCCSPNewOpts{NewBaseOpts: msp.NewBaseOpts{Version: msp.MSPv1_0}})
45+
mspInst, err := msp.New(&msp.BCCSPNewOpts{NewBaseOpts: msp.NewBaseOpts{Version: bh.version}})
4946
if err != nil {
5047
return nil, fmt.Errorf("Creating the MSP manager failed, err %s", err)
5148
}

common/channelconfig/msp_test.go

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

12-
"github.com/hyperledger/fabric/common/capabilities"
1312
"github.com/hyperledger/fabric/core/config"
1413
"github.com/hyperledger/fabric/msp"
1514
mspprotos "github.com/hyperledger/fabric/protos/msp"
@@ -24,25 +23,33 @@ func TestMSPConfigManager(t *testing.T) {
2423

2524
// test success:
2625

27-
mspCH := NewMSPConfigHandler(capabilities.MSPv1_0)
26+
mspVers := []msp.MSPVersion{msp.MSPv1_0, msp.MSPv1_1}
2827

29-
_, err = mspCH.ProposeMSP(conf)
30-
assert.NoError(t, err)
28+
for _, ver := range mspVers {
29+
mspCH := NewMSPConfigHandler(ver)
3130

32-
mgr, err := mspCH.CreateMSPManager()
33-
assert.NoError(t, err)
34-
assert.NotNil(t, mgr)
31+
_, err = mspCH.ProposeMSP(conf)
32+
assert.NoError(t, err)
3533

36-
msps, err := mgr.GetMSPs()
37-
assert.NoError(t, err)
34+
mgr, err := mspCH.CreateMSPManager()
35+
assert.NoError(t, err)
36+
assert.NotNil(t, mgr)
37+
38+
msps, err := mgr.GetMSPs()
39+
assert.NoError(t, err)
40+
41+
if msps == nil || len(msps) == 0 {
42+
t.Fatalf("There are no MSPS in the manager")
43+
}
3844

39-
if msps == nil || len(msps) == 0 {
40-
t.Fatalf("There are no MSPS in the manager")
45+
for _, mspInst := range msps {
46+
assert.Equal(t, mspInst.GetVersion(), msp.MSPVersion(ver))
47+
}
4148
}
4249
}
4350

4451
func TestMSPConfigFailure(t *testing.T) {
45-
mspCH := NewMSPConfigHandler(capabilities.MSPv1_0)
52+
mspCH := NewMSPConfigHandler(msp.MSPv1_0)
4653

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

common/mocks/config/channel.go

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

1919
import (
20-
"github.com/hyperledger/fabric/common/capabilities"
2120
"github.com/hyperledger/fabric/common/channelconfig"
2221
"github.com/hyperledger/fabric/common/util"
22+
"github.com/hyperledger/fabric/msp"
2323
)
2424

2525
func nearIdentityHash(input []byte) []byte {
@@ -67,7 +67,7 @@ type ChannelCapabilities struct {
6767
SupportedErr error
6868

6969
// MSPVersionVal is returned by MSPVersion()
70-
MSPVersionVal capabilities.MSPVersion
70+
MSPVersionVal msp.MSPVersion
7171
}
7272

7373
// Supported returns SupportedErr
@@ -76,6 +76,6 @@ func (cc *ChannelCapabilities) Supported() error {
7676
}
7777

7878
// MSPVersion returns MSPVersionVal
79-
func (cc *ChannelCapabilities) MSPVersion() capabilities.MSPVersion {
79+
func (cc *ChannelCapabilities) MSPVersion() msp.MSPVersion {
8080
return cc.MSPVersionVal
8181
}

common/mocks/msp/noopmsp.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func (msp *noopmsp) Setup(*msp.MSPConfig) error {
3535
return nil
3636
}
3737

38+
func (msp *noopmsp) GetVersion() m.MSPVersion {
39+
return m.MSPv1_0
40+
}
41+
3842
func (msp *noopmsp) GetType() m.ProviderType {
3943
return 0
4044
}

msp/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func New(opts NewOpts) (MSP, error) {
5656
}
5757
case *IdemixNewOpts:
5858
switch opts.GetVersion() {
59-
case MSPv1_0:
59+
case MSPv1_1:
6060
return newIdemixMsp()
6161
default:
6262
return nil, errors.Errorf("Invalid *IdemixNewOpts. Version not recognized [%v]", opts.GetVersion())

msp/factory_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func TestNew(t *testing.T) {
4848
assert.Equal(t, runtime.FuncForPC(reflect.ValueOf(i.(*bccspmsp).internalValidateIdentityOusFunc).Pointer()).Name(), "github.com/hyperledger/fabric/msp.(*bccspmsp).(github.com/hyperledger/fabric/msp.validateIdentityOUsV11)-fm")
4949

5050
i, err = New(&IdemixNewOpts{NewBaseOpts{Version: MSPv1_0}})
51+
assert.Error(t, err)
52+
assert.Nil(t, i)
53+
assert.Contains(t, err.Error(), "Invalid *IdemixNewOpts. Version not recognized [0]")
54+
55+
i, err = New(&IdemixNewOpts{NewBaseOpts{Version: MSPv1_1}})
5156
assert.NoError(t, err)
5257
assert.NotNil(t, i)
5358
}

0 commit comments

Comments
 (0)