Skip to content

Commit

Permalink
[FAB-6367] create genesis tx/block with other MSPs
Browse files Browse the repository at this point in the history
This change set introduces an 'MSPType' field to configtx.yaml, so that the
type of MSP can be specified. This permits credentials for other MSP types,
most notably the idemix MSP, to be included in genesis tx/blocks so that they
can be used as well. If no MSPType is specified, the standard one is
automatically assumed.

Change-Id: I5a609b57cfe85ae030f7a8fbecf8cfd71d3074ae
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Oct 28, 2017
1 parent d230be7 commit 8139bb4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions common/tools/configtxgen/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func NewOrdererGroup(conf *genesisconfig.Orderer) (*cb.ConfigGroup, error) {
// NewOrdererOrgGroup returns an orderer org component of the channel configuration. It defines the crypto material for the
// organization (its MSP). It sets the mod_policy of all elements to "Admins".
func NewOrdererOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, error) {
mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID)
mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID, conf.MSPType)
if err != nil {
return nil, errors.Wrapf(err, "1 - Error loading MSP configuration for org: %s", conf.Name)
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func NewApplicationGroup(conf *genesisconfig.Application) (*cb.ConfigGroup, erro
// NewApplicationOrgGroup returns an application org component of the channel configuration. It defines the crypto material for the organization
// (its MSP) as well as its anchor peers for use by the gossip network. It sets the mod_policy of all elements to "Admins".
func NewApplicationOrgGroup(conf *genesisconfig.Organization) (*cb.ConfigGroup, error) {
mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID)
mspConfig, err := msp.GetVerifyingMspConfig(conf.MSPDir, conf.ID, conf.MSPType)
if err != nil {
return nil, errors.Wrapf(err, "1 - Error loading MSP configuration for org %s: %s", conf.Name)
}
Expand Down
7 changes: 7 additions & 0 deletions common/tools/configtxgen/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"

cf "github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric/msp"
)

const (
Expand Down Expand Up @@ -113,6 +114,7 @@ type Organization struct {
Name string `yaml:"Name"`
ID string `yaml:"ID"`
MSPDir string `yaml:"MSPDir"`
MSPType string `yaml:"MSPType"`
AdminPrincipal string `yaml:"AdminPrincipal"`

// Note: Viper deserialization does not seem to care for
Expand Down Expand Up @@ -277,6 +279,11 @@ func (p *Profile) completeInitialization(configDir string) {
}

func (org *Organization) completeInitialization(configDir string) {
// set the MSP type; if none is specified we assume BCCSP
if org.MSPType == "" {
org.MSPType = msp.ProviderTypeToString(msp.FABRIC)
}

if org.AdminPrincipal == "" {
org.AdminPrincipal = AdminRoleAdminPrincipal
}
Expand Down
2 changes: 1 addition & 1 deletion common/tools/cryptogen/msp/msp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestGenerateVerifyingMSP(t *testing.T) {
"Expected to find file "+file)
}
// finally check to see if we can load this as a verifying MSP config
testMSPConfig, err := fabricmsp.GetVerifyingMspConfig(mspDir, testName)
testMSPConfig, err := fabricmsp.GetVerifyingMspConfig(mspDir, testName, fabricmsp.ProviderTypeToString(fabricmsp.FABRIC))
assert.NoError(t, err, "Error parsing verifying MSP config")
testMSP, err := fabricmsp.New(&fabricmsp.BCCSPNewOpts{NewBaseOpts: fabricmsp.NewBaseOpts{Version: fabricmsp.MSPv1_0}})
assert.NoError(t, err, "Error creating new BCCSP MSP")
Expand Down
12 changes: 10 additions & 2 deletions msp/configbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,16 @@ func GetLocalMspConfig(dir string, bccspConfig *factory.FactoryOpts, ID string)
return getMspConfig(dir, ID, sigid)
}

func GetVerifyingMspConfig(dir string, ID string) (*msp.MSPConfig, error) {
return getMspConfig(dir, ID, nil)
// GetVerifyingMspConfig returns an MSP config given directory, ID and type
func GetVerifyingMspConfig(dir, ID, mspType string) (*msp.MSPConfig, error) {
switch mspType {
case ProviderTypeToString(FABRIC):
return getMspConfig(dir, ID, nil)
case ProviderTypeToString(IDEMIX):
return GetIdemixMspConfig(dir, ID)
default:
return nil, errors.Errorf("unknown MSP type '%s'", mspType)
}
}

func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.MSPConfig, error) {
Expand Down
14 changes: 14 additions & 0 deletions msp/msp.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,18 @@ const (
FABRIC ProviderType = iota // MSP is of FABRIC type
IDEMIX // MSP is of IDEMIX type
OTHER // MSP is of OTHER TYPE

// NOTE: as new types are added to this set,
// the mspTypes array below must be extended
)

var mspTypeStrings []string = []string{"bccsp", "idemix"}

// ProviderTypeToString returns a string that represents the ProviderType integer
func ProviderTypeToString(id ProviderType) string {
if int(id) < 0 || int(id) > len(mspTypeStrings) {
return ""
}

return mspTypeStrings[id]
}
2 changes: 1 addition & 1 deletion msp/msp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestGetSigningIdentityFromVerifyingMSP(t *testing.T) {
os.Exit(-1)
}

conf, err = GetVerifyingMspConfig(mspDir, "DEFAULT")
conf, err = GetVerifyingMspConfig(mspDir, "DEFAULT", ProviderTypeToString(FABRIC))
if err != nil {
fmt.Printf("Setup should have succeeded, got err %s instead", err)
os.Exit(-1)
Expand Down

0 comments on commit 8139bb4

Please sign in to comment.