Skip to content

Commit 795a690

Browse files
author
Jason Yellick
committed
[FAB-1825] Initialize MSP via configtx.Handler
https://jira.hyperledger.org/browse/FAB-1825 This changeset populates the MSP manager via the config transaction via the configtx.Handler interface. It also moves the peer msp dir to msp/mgmt as the peer needs to stop accessing this package directly and use the MSP manager provided by the config resources. Change-Id: I9ee08a46fa033ad0101dd80e770c7ee327a951d9 Signed-off-by: Jason Yellick <[email protected]>
1 parent 9dbaeca commit 795a690

25 files changed

+66
-47
lines changed

common/configtx/resources.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/hyperledger/fabric/common/cauthdsl"
2121
"github.com/hyperledger/fabric/common/chainconfig"
2222
"github.com/hyperledger/fabric/common/policies"
23+
"github.com/hyperledger/fabric/msp"
24+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2325
cb "github.com/hyperledger/fabric/protos/common"
2426
)
2527

@@ -32,6 +34,9 @@ type Resources interface {
3234

3335
// ChainConfig returns the chainconfig.Descriptor for the chain
3436
ChainConfig() chainconfig.Descriptor
37+
38+
// MSPManager returns the msp.MSPManager for the chain
39+
MSPManager() msp.MSPManager
3540
}
3641

3742
// Initializer is a structure which is only useful before a configtx.Manager
@@ -44,9 +49,10 @@ type Initializer interface {
4449
}
4550

4651
type resources struct {
47-
handlers map[cb.ConfigurationItem_ConfigurationType]Handler
48-
policyManager policies.Manager
49-
chainConfig chainconfig.Descriptor
52+
handlers map[cb.ConfigurationItem_ConfigurationType]Handler
53+
policyManager policies.Manager
54+
chainConfig chainconfig.Descriptor
55+
mspConfigHandler *mspmgmt.MSPConfigHandler
5056
}
5157

5258
// PolicyManager returns the policies.Manager for the chain
@@ -59,22 +65,27 @@ func (r *resources) ChainConfig() chainconfig.Descriptor {
5965
return r.chainConfig
6066
}
6167

68+
// MSPManager returns the msp.MSPManager for the chain
69+
func (r *resources) MSPManager() msp.MSPManager {
70+
return r.mspConfigHandler.GetMSPManager()
71+
}
72+
6273
// Handlers returns the handlers to be used when initializing the configtx.Manager
6374
func (r *resources) Handlers() map[cb.ConfigurationItem_ConfigurationType]Handler {
6475
return r.handlers
6576
}
6677

6778
// NewInitializer creates a chain initializer for the basic set of common chain resources
6879
func NewInitializer() Initializer {
80+
mspConfigHandler := &mspmgmt.MSPConfigHandler{}
6981
policyProviderMap := make(map[int32]policies.Provider)
7082
for pType := range cb.Policy_PolicyType_name {
7183
rtype := cb.Policy_PolicyType(pType)
7284
switch rtype {
7385
case cb.Policy_UNKNOWN:
7486
// Do not register a handler
7587
case cb.Policy_SIGNATURE:
76-
policyProviderMap[pType] = cauthdsl.NewPolicyProvider(
77-
cauthdsl.NewMockDeserializer()) // FIXME: here we should pass in the orderer MSP as soon as it's ready
88+
policyProviderMap[pType] = cauthdsl.NewPolicyProvider(mspConfigHandler)
7889
case cb.Policy_MSP:
7990
// Add hook for MSP Handler here
8091
}
@@ -91,14 +102,17 @@ func NewInitializer() Initializer {
91102
handlers[rtype] = chainConfig
92103
case cb.ConfigurationItem_Policy:
93104
handlers[rtype] = policyManager
105+
case cb.ConfigurationItem_MSP:
106+
handlers[rtype] = mspConfigHandler
94107
default:
95108
handlers[rtype] = NewBytesHandler()
96109
}
97110
}
98111

99112
return &resources{
100-
handlers: handlers,
101-
policyManager: policyManager,
102-
chainConfig: chainConfig,
113+
handlers: handlers,
114+
policyManager: policyManager,
115+
chainConfig: chainConfig,
116+
mspConfigHandler: mspConfigHandler,
103117
}
104118
}

common/localmsp/signer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package localmsp
1919
import (
2020
"fmt"
2121

22-
"github.com/hyperledger/fabric/core/crypto/primitives"
2322
"github.com/hyperledger/fabric/common/crypto"
23+
"github.com/hyperledger/fabric/core/crypto/primitives"
24+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2425
cb "github.com/hyperledger/fabric/protos/common"
25-
"github.com/hyperledger/fabric/core/peer/msp"
2626
)
2727

2828
type mspSigner struct {

common/localmsp/signer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/hyperledger/fabric/core/crypto/primitives"
2424
"github.com/stretchr/testify/assert"
25-
"github.com/hyperledger/fabric/core/peer/msp"
25+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2626
)
2727

2828
func TestMain(m *testing.M) {

core/chaincode/exectransaction_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import (
3838

3939
"github.com/golang/protobuf/proto"
4040
"github.com/hyperledger/fabric/core/ledger/ledgermgmt"
41-
"github.com/hyperledger/fabric/core/peer/msp"
4241
"github.com/hyperledger/fabric/msp"
42+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
4343
"github.com/hyperledger/fabric/protos/common"
4444
"github.com/spf13/viper"
4545
"golang.org/x/net/context"

core/common/validation/fullflow_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
"os"
2626

2727
"github.com/hyperledger/fabric/common/util"
28-
"github.com/hyperledger/fabric/core/peer/msp"
2928
"github.com/hyperledger/fabric/msp"
29+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3030
"github.com/hyperledger/fabric/protos/common"
3131
"github.com/hyperledger/fabric/protos/peer"
3232
"github.com/hyperledger/fabric/protos/utils"

core/common/validation/msgvalidation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"bytes"
2323

24-
mspmgmt "github.com/hyperledger/fabric/core/peer/msp"
24+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2525
"github.com/hyperledger/fabric/protos/common"
2626
pb "github.com/hyperledger/fabric/protos/peer"
2727
"github.com/hyperledger/fabric/protos/utils"

core/endorser/endorser_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"github.com/hyperledger/fabric/core/chaincode"
3131
"github.com/hyperledger/fabric/core/container"
3232
"github.com/hyperledger/fabric/core/peer"
33-
"github.com/hyperledger/fabric/core/peer/msp"
3433
"github.com/hyperledger/fabric/msp"
34+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3535
"github.com/hyperledger/fabric/protos/common"
3636
pb "github.com/hyperledger/fabric/protos/peer"
3737
pbutils "github.com/hyperledger/fabric/protos/utils"

core/peer/peer.go

+5-15
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ import (
3333
"github.com/hyperledger/fabric/core/committer/txvalidator"
3434
"github.com/hyperledger/fabric/core/ledger"
3535
"github.com/hyperledger/fabric/core/ledger/ledgermgmt"
36-
"github.com/hyperledger/fabric/core/peer/msp"
3736
"github.com/hyperledger/fabric/gossip/service"
38-
"github.com/hyperledger/fabric/msp"
37+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3938
"github.com/hyperledger/fabric/protos/common"
4039
"github.com/hyperledger/fabric/protos/utils"
4140
)
@@ -45,17 +44,12 @@ var peerLogger = logging.MustGetLogger("peer")
4544
type chainSupport struct {
4645
configtx.Manager
4746
ledger ledger.PeerLedger
48-
mspmgr msp.MSPManager
4947
}
5048

5149
func (cs *chainSupport) Ledger() ledger.PeerLedger {
5250
return cs.ledger
5351
}
5452

55-
func (cs *chainSupport) MSPManager() msp.MSPManager {
56-
return cs.mspmgr
57-
}
58-
5953
// chain is a local struct to manage objects in a chain
6054
type chain struct {
6155
cs *chainSupport
@@ -173,16 +167,16 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
173167
return err
174168
}
175169

176-
// TODO Move to the configtx.Handler interface (which MSP already implements)
177-
mgr, err := mspmgmt.GetMSPManagerFromBlock(cid, cb)
170+
// TODO remove once all references to mspmgmt are gone from peer code
171+
// MSP is now initialized above in configtx.Manager
172+
_, err = mspmgmt.GetMSPManagerFromBlock(cid, cb)
178173
if err != nil {
179174
return err
180175
}
181176

182177
cs := &chainSupport{
183178
Manager: configtxManager,
184179
ledger: ledger,
185-
mspmgr: mgr,
186180
}
187181

188182
c := committer.NewLedgerCommitter(ledger, txvalidator.NewTxValidator(cs))
@@ -197,11 +191,7 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
197191
chains.Lock()
198192
defer chains.Unlock()
199193
chains.list[cid] = &chain{
200-
cs: &chainSupport{
201-
Manager: configtxManager,
202-
ledger: ledger,
203-
mspmgr: mgr,
204-
},
194+
cs: cs,
205195
cb: cb,
206196
committer: c,
207197
}

core/system_chaincode/escc/endorser_onevalidsignature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/hyperledger/fabric/protos/utils"
2626
"github.com/op/go-logging"
2727

28-
"github.com/hyperledger/fabric/core/peer/msp"
28+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2929
)
3030

3131
var logger = logging.MustGetLogger("escc")

core/system_chaincode/escc/endorser_onevalidsignature_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"github.com/hyperledger/fabric/common/util"
2727
"github.com/hyperledger/fabric/core/chaincode/shim"
2828
"github.com/hyperledger/fabric/core/common/validation"
29-
"github.com/hyperledger/fabric/core/peer/msp"
29+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3030
"github.com/hyperledger/fabric/protos/common"
3131
pb "github.com/hyperledger/fabric/protos/peer"
3232
putils "github.com/hyperledger/fabric/protos/utils"

core/system_chaincode/vscc/validator_onevalidsignature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/hyperledger/fabric/common/cauthdsl"
2424
"github.com/hyperledger/fabric/core/chaincode/shim"
25-
"github.com/hyperledger/fabric/core/peer/msp"
25+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2626
"github.com/hyperledger/fabric/protos/common"
2727
"github.com/hyperledger/fabric/protos/utils"
2828
"github.com/op/go-logging"

core/system_chaincode/vscc/validator_onevalidsignature_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/hyperledger/fabric/common/cauthdsl"
2525
"github.com/hyperledger/fabric/common/util"
2626
"github.com/hyperledger/fabric/core/chaincode/shim"
27-
"github.com/hyperledger/fabric/core/peer/msp"
2827
"github.com/hyperledger/fabric/msp"
28+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2929
"github.com/hyperledger/fabric/protos/common"
3030
"github.com/hyperledger/fabric/protos/peer"
3131
"github.com/hyperledger/fabric/protos/utils"

core/peer/msp/config.go msp/mgmt/config.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package mspmgmt
17+
package mgmt
1818

1919
import (
2020
"fmt"
@@ -138,3 +138,8 @@ func (bh *MSPConfigHandler) ProposeConfig(configItem *common.ConfigurationItem)
138138
func (bh *MSPConfigHandler) GetMSPManager() msp.MSPManager {
139139
return bh.committedMgr
140140
}
141+
142+
// DesierializeIdentity allows *MSPConfigHandler to implement the msp.Common interface
143+
func (bh *MSPConfigHandler) DeserializeIdentity(serializedIdentity []byte) (msp.Identity, error) {
144+
return bh.committedMgr.DeserializeIdentity(serializedIdentity)
145+
}

core/peer/msp/mgmt.go msp/mgmt/mgmt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package mspmgmt
17+
package mgmt
1818

1919
import (
2020
"sync"

core/peer/msp/mspconfigmgr_test.go msp/mgmt/mspconfigmgr_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package mspmgmt
17+
package mgmt_test
1818

1919
import (
2020
"testing"
2121

2222
"github.com/golang/protobuf/proto"
2323
"github.com/hyperledger/fabric/common/configtx"
2424
"github.com/hyperledger/fabric/msp"
25+
. "github.com/hyperledger/fabric/msp/mgmt"
2526
"github.com/hyperledger/fabric/protos/common"
2627
"github.com/hyperledger/fabric/protos/msp/utils"
2728
"github.com/stretchr/testify/assert"
2829
)
2930

3031
func TestMSPConfigManager(t *testing.T) {
31-
conf, err := msp.GetLocalMspConfig("../../../msp/sampleconfig/")
32+
conf, err := msp.GetLocalMspConfig("../sampleconfig/")
3233
assert.NoError(t, err)
3334

3435
confBytes, err := proto.Marshal(conf)

core/peer/msp/peermsp_test.go msp/mgmt/peermsp_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package mspmgmt
17+
package mgmt
1818

1919
import (
2020
"testing"

orderer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646

4747
"github.com/Shopify/sarama"
4848
"github.com/hyperledger/fabric/common/localmsp"
49-
"github.com/hyperledger/fabric/core/peer/msp"
49+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
5050
logging "github.com/op/go-logging"
5151
)
5252

orderer/mocks/configtx/configtx.go

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/hyperledger/fabric/common/chainconfig"
2121
"github.com/hyperledger/fabric/common/configtx"
2222
"github.com/hyperledger/fabric/common/policies"
23+
"github.com/hyperledger/fabric/msp"
2324
cb "github.com/hyperledger/fabric/protos/common"
2425
)
2526

@@ -32,6 +33,9 @@ type Initializer struct {
3233

3334
// ChainConfigVal is returned as the result of ChainConfig()
3435
ChainConfigVal chainconfig.Descriptor
36+
37+
// MSPManagerVal is returned as the result of MSPManager()
38+
MSPManagerVal msp.MSPManager
3539
}
3640

3741
// Returns the HandlersVal
@@ -49,6 +53,11 @@ func (i *Initializer) ChainConfig() chainconfig.Descriptor {
4953
return i.ChainConfigVal
5054
}
5155

56+
// Returns the MSPManagerVal
57+
func (i *Initializer) MSPManager() msp.MSPManager {
58+
return i.MSPManagerVal
59+
}
60+
5261
// Manager is a mock implementation of configtx.Manager
5362
type Manager struct {
5463
Initializer

orderer/sbft_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
"github.com/golang/protobuf/proto"
3131
"github.com/hyperledger/fabric/common/localmsp"
32-
"github.com/hyperledger/fabric/core/peer/msp"
32+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3333
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
3434
"github.com/hyperledger/fabric/orderer/ledger"
3535
"github.com/hyperledger/fabric/orderer/ledger/ram"

peer/chaincode/upgrade_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/hyperledger/fabric/peer/common"
2626
pb "github.com/hyperledger/fabric/protos/peer"
2727
// "github.com/hyperledger/fabric/protos/utils"
28-
"github.com/hyperledger/fabric/core/peer/msp"
28+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2929
)
3030

3131
var once sync.Once

peer/channel/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/hyperledger/fabric/protos/utils"
2828

2929
"github.com/golang/protobuf/proto"
30-
"github.com/hyperledger/fabric/core/peer/msp"
30+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
3131
"github.com/spf13/cobra"
3232
)
3333

peer/channel/create_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"sync"
2323
"testing"
2424

25-
"github.com/hyperledger/fabric/core/peer/msp"
25+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2626
"github.com/hyperledger/fabric/peer/common"
2727
cb "github.com/hyperledger/fabric/protos/common"
2828
)

peer/common/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/hyperledger/fabric/common/flogging"
2525
"github.com/hyperledger/fabric/core/errors"
2626
"github.com/hyperledger/fabric/core/peer"
27-
"github.com/hyperledger/fabric/core/peer/msp"
2827
"github.com/hyperledger/fabric/msp"
28+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2929
pb "github.com/hyperledger/fabric/protos/peer"
3030
"github.com/spf13/viper"
3131
)

protos/testutils/txtestutils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222

2323
"path/filepath"
2424

25-
"github.com/hyperledger/fabric/core/peer/msp"
2625
"github.com/hyperledger/fabric/msp"
26+
mspmgmt "github.com/hyperledger/fabric/msp/mgmt"
2727
"github.com/hyperledger/fabric/protos/common"
2828
pb "github.com/hyperledger/fabric/protos/peer"
2929
putils "github.com/hyperledger/fabric/protos/utils"

0 commit comments

Comments
 (0)