Skip to content

Commit 7359eac

Browse files
author
Jason Yellick
committed
[FAB-1970] Remove MSP custom config block parsing
https://jira.hyperledger.org/browse/FAB-1970 The MSP implemented its own custom config block parsing as a stopgap, it is no longer needed. This CR removes the last vestiges of this code. It unfortunately leaves the mspmgmt singleton, this should be removed in a later CR. Change-Id: I3b6fa9463bc28f31b6e0b8807d3a3780e253b8d9 Signed-off-by: Jason Yellick <[email protected]>
1 parent e3ce4f1 commit 7359eac

File tree

6 files changed

+20
-217
lines changed

6 files changed

+20
-217
lines changed

core/peer/peer.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,7 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
182182
}
183183

184184
// TODO remove once all references to mspmgmt are gone from peer code
185-
// MSP is now initialized above in configtx.Manager
186-
_, err = mspmgmt.GetMSPManagerFromBlock(cid, cb)
187-
if err != nil {
188-
return err
189-
}
185+
mspmgmt.XXXSetMSPManager(cid, configtxManager.MSPManager())
190186

191187
cs := &chainSupport{
192188
Manager: configtxManager,

msp/mgmt/config.go

-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/hyperledger/fabric/msp"
2727
"github.com/hyperledger/fabric/protos/common"
2828
mspprotos "github.com/hyperledger/fabric/protos/msp"
29-
"github.com/hyperledger/fabric/protos/msp/utils"
3029
)
3130

3231
func LoadLocalMsp(dir string) error {
@@ -83,25 +82,6 @@ func LoadFakeSetupWithLocalMspAndTestChainMsp(dir string) error {
8382
return nil
8483
}
8584

86-
// GetMSPManagerFromBlock returns a new MSP manager from a ConfigurationEnvelope
87-
// Note that chainID should really be obtained from the block. Passing it for
88-
// two reasons (1) efficiency (2) getting chainID from block using protos/utils
89-
// will cause import cycles
90-
func GetMSPManagerFromBlock(cid string, b *common.Block) (msp.MSPManager, error) {
91-
mgrConfig, err := msputils.GetMSPManagerConfigFromBlock(b)
92-
if err != nil {
93-
return nil, err
94-
}
95-
96-
mgr := GetManagerForChain(cid)
97-
err = mgr.Setup(mgrConfig)
98-
if err != nil {
99-
return nil, err
100-
}
101-
102-
return mgr, nil
103-
}
104-
10585
// MSPConfigHandler
10686
type MSPConfigHandler struct {
10787
config []*mspprotos.MSPConfig

msp/mgmt/mgmt.go

+19-17
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,17 @@ var mspLogger = logging.MustGetLogger("msp")
3535

3636
// GetManagerForChain returns the msp manager for the supplied
3737
// chain; if no such manager exists, one is created
38-
func GetManagerForChain(ChainID string) msp.MSPManager {
39-
var mspMgr msp.MSPManager
40-
var created bool = false
41-
{
42-
m.Lock()
43-
defer m.Unlock()
44-
45-
mspMgr = mspMap[ChainID]
46-
if mspMgr == nil {
47-
created = true
48-
mspMgr = msp.NewMSPManager()
49-
mspMap[ChainID] = mspMgr
50-
}
51-
}
38+
func GetManagerForChain(chainID string) msp.MSPManager {
39+
m.Lock()
40+
defer m.Unlock()
5241

53-
if created {
54-
mspLogger.Debugf("Created new msp manager for chain %s", ChainID)
42+
mspMgr, ok := mspMap[chainID]
43+
if !ok {
44+
mspLogger.Debugf("Created new msp manager for chain %s", chainID)
45+
mspMgr = msp.NewMSPManager()
46+
mspMap[chainID] = mspMgr
5547
} else {
56-
mspLogger.Debugf("Returning existing manager for chain %s", ChainID)
48+
mspLogger.Debugf("Returning existing manager for chain %s", chainID)
5749
}
5850

5951
return mspMgr
@@ -82,6 +74,16 @@ func GetManagerForChainIfExists(ChainID string) msp.MSPManager {
8274
return mspMap[ChainID]
8375
}
8476

77+
// XXXSetMSPManager is a stopgap solution to transition from the custom MSP config block
78+
// parsing to the configtx.Manager interface, while preserving the problematic singleton
79+
// nature of the MSP manager
80+
func XXXSetMSPManager(chainID string, manager msp.MSPManager) {
81+
m.Lock()
82+
defer m.Unlock()
83+
84+
mspMap[chainID] = manager
85+
}
86+
8587
// GetLocalMSP returns the local msp (and creates it if it doesn't exist)
8688
func GetLocalMSP() msp.MSP {
8789
var lclMsp msp.MSP

msp/mgmt/peermsp_test.go

-31
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"testing"
2323

2424
"github.com/hyperledger/fabric/common/util"
25-
"github.com/hyperledger/fabric/msp"
26-
"github.com/hyperledger/fabric/protos/msp/testutils"
2725
)
2826

2927
// getTestMSPConfigPath returns the path to sampleconfig for unit tests
@@ -70,32 +68,3 @@ func TestFakeSetup(t *testing.T) {
7068
t.Fatalf("There are no MSPS in the manager for chain %s", util.GetTestChainID())
7169
}
7270
}
73-
74-
func TestGetMSPManagerFromBlock(t *testing.T) {
75-
testMSPConfigPath := getTestMSPConfigPath()
76-
conf, err := msp.GetLocalMspConfig(testMSPConfigPath)
77-
if err != nil {
78-
t.Fatalf("GetLocalMspConfig failed, err %s", err)
79-
}
80-
81-
block, err := msptestutils.GetTestBlockFromMspConfig(conf)
82-
if err != nil {
83-
t.Fatalf("getTestBlockFromMspConfig failed, err %s", err)
84-
}
85-
86-
mgr, err := GetMSPManagerFromBlock("testchainid", block)
87-
if err != nil {
88-
t.Fatalf("GetMSPManagerFromBlock failed, err %s", err)
89-
} else if mgr == nil {
90-
t.Fatalf("Returned nil manager")
91-
}
92-
93-
msps, err := mgr.GetMSPs()
94-
if err != nil {
95-
t.Fatalf("EnlistedMSPs failed, err %s", err)
96-
}
97-
98-
if msps == nil || len(msps) == 0 {
99-
t.Fatalf("There are no MSPS in the manager for chain %s", util.GetTestChainID())
100-
}
101-
}

protos/msp/testutils/testutils.go

-61
This file was deleted.

protos/msp/utils/utils.go

-83
This file was deleted.

0 commit comments

Comments
 (0)