Skip to content

Commit 21539ef

Browse files
committed
[FAB-6627] MSPConfigHandler to support idemix MSPs
This change set introduces support for the generation of idemix MSPs from config transactions. Change-Id: Ib1f82826a916eb9be9bc1a4337899a5a58281f2a Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
1 parent a47bf65 commit 21539ef

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

common/channelconfig/msp.go

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

12+
"github.com/golang/protobuf/proto"
1213
"github.com/hyperledger/fabric/msp"
1314
"github.com/hyperledger/fabric/msp/cache"
1415
mspprotos "github.com/hyperledger/fabric/protos/msp"
15-
16-
"github.com/golang/protobuf/proto"
16+
"github.com/pkg/errors"
1717
)
1818

1919
type pendingMSPConfig struct {
@@ -36,44 +36,54 @@ func NewMSPConfigHandler(mspVersion msp.MSPVersion) *MSPConfigHandler {
3636

3737
// ProposeValue called when an org defines an MSP
3838
func (bh *MSPConfigHandler) ProposeMSP(mspConfig *mspprotos.MSPConfig) (msp.MSP, error) {
39-
// check that the type for that MSP is supported
40-
if mspConfig.Type != int32(msp.FABRIC) {
41-
return nil, fmt.Errorf("Setup error: unsupported msp type %d", mspConfig.Type)
42-
}
43-
44-
// create the msp instance
45-
mspInst, err := msp.New(&msp.BCCSPNewOpts{NewBaseOpts: msp.NewBaseOpts{Version: bh.version}})
46-
if err != nil {
47-
return nil, fmt.Errorf("Creating the MSP manager failed, err %s", err)
48-
}
39+
var theMsp msp.MSP
40+
var err error
41+
42+
switch mspConfig.Type {
43+
case int32(msp.FABRIC):
44+
// create the bccsp msp instance
45+
mspInst, err := msp.New(&msp.BCCSPNewOpts{NewBaseOpts: msp.NewBaseOpts{Version: bh.version}})
46+
if err != nil {
47+
return nil, errors.WithMessage(err, "creating the MSP manager failed")
48+
}
4949

50-
casheMSP, err := cache.New(mspInst)
51-
if err != nil {
52-
return nil, fmt.Errorf("Creating the MSP manager failed, err %s", err)
50+
// add a cache layer on top
51+
theMsp, err = cache.New(mspInst)
52+
if err != nil {
53+
return nil, errors.WithMessage(err, "creating the MSP cache failed")
54+
}
55+
case int32(msp.IDEMIX):
56+
// create the idemix msp instance
57+
theMsp, err = msp.New(&msp.IdemixNewOpts{msp.NewBaseOpts{Version: bh.version}})
58+
if err != nil {
59+
return nil, errors.WithMessage(err, "creating the MSP manager failed")
60+
}
61+
default:
62+
return nil, errors.New(fmt.Sprintf("Setup error: unsupported msp type %d", mspConfig.Type))
5363
}
5464

5565
// set it up
56-
err = casheMSP.Setup(mspConfig)
66+
err = theMsp.Setup(mspConfig)
5767
if err != nil {
58-
return nil, fmt.Errorf("Setting up the MSP manager failed, err %s", err)
68+
return nil, errors.WithMessage(err, "setting up the MSP manager failed")
5969
}
6070

6171
// add the MSP to the map of pending MSPs
62-
mspID, _ := casheMSP.GetIdentifier()
72+
mspID, _ := theMsp.GetIdentifier()
6373

6474
existingPendingMSPConfig, ok := bh.idMap[mspID]
6575
if ok && !proto.Equal(existingPendingMSPConfig.mspConfig, mspConfig) {
66-
return nil, fmt.Errorf("Attempted to define two different versions of MSP: %s", mspID)
76+
return nil, errors.New(fmt.Sprintf("Attempted to define two different versions of MSP: %s", mspID))
6777
}
6878

6979
if !ok {
7080
bh.idMap[mspID] = &pendingMSPConfig{
7181
mspConfig: mspConfig,
72-
msp: casheMSP,
82+
msp: theMsp,
7383
}
7484
}
7585

76-
return casheMSP, nil
86+
return theMsp, nil
7787
}
7888

7989
func (bh *MSPConfigHandler) CreateMSPManager() (msp.MSPManager, error) {

0 commit comments

Comments
 (0)