Skip to content

Commit 269f3cc

Browse files
author
Jason Yellick
committed
[FAB-4342] Fix dev style channel creation
When the orderer is configured without any consortium members, channels may be created with no members. This is an insecure mode, and supported only for development or test environments. However, sometimes it is desirable to create channels with consortium members while in this insecure mode, but the current code rejects such requests because the consortium member is not present. This CR modifies the orderer channel creation code to allow the second use case while in the insecure mode. Change-Id: Ibf37ab1dbdf79b20e1238ad128fccebf04193dfd Signed-off-by: Jason Yellick <[email protected]>
1 parent 9ca37ee commit 269f3cc

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

orderer/multichain/manager.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,16 @@ func (ml *multiLedger) NewChannelConfig(envConfigUpdate *cb.Envelope) (configtxa
262262
return nil, fmt.Errorf("Proposed configuration has no application group members, but consortium contains members")
263263
}
264264

265-
for orgName := range configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups {
266-
consortiumGroup, ok := systemChannelGroup.Groups[config.ConsortiumsGroupKey].Groups[consortium.Name].Groups[orgName]
267-
if !ok {
268-
return nil, fmt.Errorf("Attempted to include a member which is not in the consortium")
265+
// If the consortium has no members, allow the source request to contain arbitrary members
266+
// Otherwise, require that the supplied members are a subset of the consortium members
267+
if len(systemChannelGroup.Groups[config.ConsortiumsGroupKey].Groups[consortium.Name].Groups) > 0 {
268+
for orgName := range configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups {
269+
consortiumGroup, ok := systemChannelGroup.Groups[config.ConsortiumsGroupKey].Groups[consortium.Name].Groups[orgName]
270+
if !ok {
271+
return nil, fmt.Errorf("Attempted to include a member which is not in the consortium")
272+
}
273+
applicationGroup.Groups[orgName] = consortiumGroup
269274
}
270-
applicationGroup.Groups[orgName] = consortiumGroup
271275
}
272276

273277
channelGroup := cb.NewConfigGroup()

orderer/multichain/manager_test.go

+80-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ import (
3939
"github.com/stretchr/testify/assert"
4040
)
4141

42-
var conf *genesisconfig.Profile
43-
var genesisBlock = cb.NewBlock(0, nil) // *cb.Block
42+
var conf, singleMSPConf *genesisconfig.Profile
43+
var genesisBlock, singleMSPGenesisBlock *cb.Block
4444
var mockSigningIdentity msp.SigningIdentity
4545

4646
func init() {
4747
conf = genesisconfig.Load(genesisconfig.SampleInsecureProfile)
4848
logging.SetLevel(logging.DEBUG, "")
4949
genesisBlock = provisional.New(conf).GenesisBlock()
5050
mockSigningIdentity, _ = mmsp.NewNoopMsp().GetDefaultSigningIdentity()
51+
52+
singleMSPConf = genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)
53+
logging.SetLevel(logging.DEBUG, "")
54+
singleMSPGenesisBlock = provisional.New(singleMSPConf).GenesisBlock()
5155
}
5256

5357
func mockCrypto() *mockCryptoHelper {
@@ -75,6 +79,20 @@ func NewRAMLedgerAndFactory(maxSize int) (ledger.Factory, ledger.ReadWriter) {
7579
return rlf, rl
7680
}
7781

82+
func NewRAMLedgerAndFactoryWithMSP() (ledger.Factory, ledger.ReadWriter) {
83+
rlf := ramledger.New(10)
84+
85+
rl, err := rlf.GetOrCreate(provisional.TestChainID)
86+
if err != nil {
87+
panic(err)
88+
}
89+
err = rl.Append(singleMSPGenesisBlock)
90+
if err != nil {
91+
panic(err)
92+
}
93+
return rlf, rl
94+
}
95+
7896
func NewRAMLedger(maxSize int) ledger.ReadWriter {
7997
_, rl := NewRAMLedgerAndFactory(maxSize)
8098
return rl
@@ -202,7 +220,7 @@ func TestManagerImpl(t *testing.T) {
202220

203221
func TestNewChannelConfig(t *testing.T) {
204222

205-
lf, _ := NewRAMLedgerAndFactory(3)
223+
lf, _ := NewRAMLedgerAndFactoryWithMSP()
206224

207225
consenters := make(map[string]Consenter)
208226
consenters[conf.Orderer.OrdererType] = &mockConsenter{}
@@ -364,6 +382,65 @@ func TestNewChannelConfig(t *testing.T) {
364382
},
365383
"^Unknown consortium name:",
366384
},
385+
{
386+
"Missing consortium members",
387+
&cb.Payload{
388+
Data: utils.MarshalOrPanic(&cb.ConfigUpdateEnvelope{
389+
ConfigUpdate: utils.MarshalOrPanic(
390+
&cb.ConfigUpdate{
391+
WriteSet: &cb.ConfigGroup{
392+
Groups: map[string]*cb.ConfigGroup{
393+
config.ApplicationGroupKey: &cb.ConfigGroup{
394+
Version: 1,
395+
},
396+
},
397+
Values: map[string]*cb.ConfigValue{
398+
config.ConsortiumKey: &cb.ConfigValue{
399+
Value: utils.MarshalOrPanic(
400+
&cb.Consortium{
401+
Name: genesisconfig.SampleConsortiumName,
402+
},
403+
),
404+
},
405+
},
406+
},
407+
},
408+
),
409+
}),
410+
},
411+
"Proposed configuration has no application group members, but consortium contains members",
412+
},
413+
{
414+
"Member not in consortium",
415+
&cb.Payload{
416+
Data: utils.MarshalOrPanic(&cb.ConfigUpdateEnvelope{
417+
ConfigUpdate: utils.MarshalOrPanic(
418+
&cb.ConfigUpdate{
419+
WriteSet: &cb.ConfigGroup{
420+
Groups: map[string]*cb.ConfigGroup{
421+
config.ApplicationGroupKey: &cb.ConfigGroup{
422+
Version: 1,
423+
Groups: map[string]*cb.ConfigGroup{
424+
"BadOrgName": &cb.ConfigGroup{},
425+
},
426+
},
427+
},
428+
Values: map[string]*cb.ConfigValue{
429+
config.ConsortiumKey: &cb.ConfigValue{
430+
Value: utils.MarshalOrPanic(
431+
&cb.Consortium{
432+
Name: genesisconfig.SampleConsortiumName,
433+
},
434+
),
435+
},
436+
},
437+
},
438+
},
439+
),
440+
}),
441+
},
442+
"Attempted to include a member which is not in the consortium",
443+
},
367444
} {
368445
t.Run(tc.name, func(t *testing.T) {
369446
_, err := manager.NewChannelConfig(&cb.Envelope{Payload: utils.MarshalOrPanic(tc.payload)})

0 commit comments

Comments
 (0)