Skip to content

Commit a6d99d4

Browse files
author
Jason Yellick
committed
[FAB-4871] Add consortium members to MSP Manager
The consortium members MSP definitions are currently being parsed, but they are not being added to the MSP manager for the ordering system channel. This means that if a policy references an organization in a consortium, then that policy will always evaluate to false. This is a problem particularly for updates of the consortium members MSP definitions. This CR passes in a reference to the channel's MSP Manager, rather than creating a new one for each consortium member. Change-Id: Idab43296cdb8d7692d29dec7c5d268554722593f Signed-off-by: Jason Yellick <[email protected]>
1 parent f20846c commit a6d99d4

6 files changed

+21
-23
lines changed

common/config/channel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (cg *ChannelGroup) NewGroup(group string) (ValueProposer, error) {
122122
case OrdererGroupKey:
123123
return NewOrdererGroup(cg.mspConfigHandler), nil
124124
case ConsortiumsGroupKey:
125-
return NewConsortiumsGroup(), nil
125+
return NewConsortiumsGroup(cg.mspConfigHandler), nil
126126
default:
127127
return nil, fmt.Errorf("Disallowed channel group: %s", group)
128128
}

common/config/channel_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ func TestChannelConfig(t *testing.T) {
6767

6868
ag := NewApplicationGroup(nil)
6969
og := NewOrdererGroup(nil)
70-
csg := NewConsortiumsGroup()
70+
csg := NewConsortiumsGroup(nil)
7171
good := make(map[string]ValueProposer)
7272
good[ApplicationGroupKey] = ag
7373
good[OrdererGroupKey] = og
7474
good[ConsortiumsGroupKey] = csg
7575

7676
err := cc.Validate(nil, good)
7777
assert.NoError(t, err, "Unexpected error validating good config groups")
78-
err = cc.Validate(nil, map[string]ValueProposer{ApplicationGroupKey: NewConsortiumsGroup()})
78+
err = cc.Validate(nil, map[string]ValueProposer{ApplicationGroupKey: NewConsortiumsGroup(nil)})
7979
assert.Error(t, err, "Expected error validating bad config group")
80-
err = cc.Validate(nil, map[string]ValueProposer{OrdererGroupKey: NewConsortiumsGroup()})
80+
err = cc.Validate(nil, map[string]ValueProposer{OrdererGroupKey: NewConsortiumsGroup(nil)})
8181
assert.Error(t, err, "Expected error validating bad config group")
8282
err = cc.Validate(nil, map[string]ValueProposer{ConsortiumsGroupKey: NewOrdererGroup(nil)})
8383
assert.Error(t, err, "Expected error validating bad config group")

common/config/consortium.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ type ConsortiumGroup struct {
3333
*Proposer
3434
*ConsortiumConfig
3535

36-
mspConfig *msp.MSPConfigHandler
37-
consortiumsGroup *ConsortiumsGroup
36+
mspConfig *msp.MSPConfigHandler
3837
}
3938

4039
// NewConsortiumGroup creates a new *ConsortiumGroup
41-
func NewConsortiumGroup(consortiumsGroup *ConsortiumsGroup) *ConsortiumGroup {
40+
func NewConsortiumGroup(mspConfig *msp.MSPConfigHandler) *ConsortiumGroup {
4241
cg := &ConsortiumGroup{
43-
mspConfig: msp.NewMSPConfigHandler(),
44-
consortiumsGroup: consortiumsGroup,
42+
mspConfig: mspConfig,
4543
}
4644
cg.Proposer = NewProposer(cg)
4745
return cg
@@ -59,28 +57,21 @@ func (cg *ConsortiumGroup) Allocate() Values {
5957

6058
// BeginValueProposals calls through to Proposer after calling into the MSP config Handler
6159
func (cg *ConsortiumGroup) BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error) {
62-
cg.mspConfig.BeginConfig(tx)
6360
return cg.Proposer.BeginValueProposals(tx, groups)
6461
}
6562

6663
// PreCommit intercepts the precommit request and commits the MSP config handler before calling the underlying proposer
6764
func (cg *ConsortiumGroup) PreCommit(tx interface{}) error {
68-
err := cg.mspConfig.PreCommit(tx)
69-
if err != nil {
70-
return err
71-
}
7265
return cg.Proposer.PreCommit(tx)
7366
}
7467

7568
// RollbackProposals intercepts the rollback request and commits the MSP config handler before calling the underlying proposer
7669
func (cg *ConsortiumGroup) RollbackProposals(tx interface{}) {
77-
cg.mspConfig.RollbackProposals(tx)
7870
cg.Proposer.RollbackProposals(tx)
7971
}
8072

8173
// CommitProposals intercepts the commit request and commits the MSP config handler before calling the underlying proposer
8274
func (cg *ConsortiumGroup) CommitProposals(tx interface{}) {
83-
cg.mspConfig.CommitProposals(tx)
8475
cg.Proposer.CommitProposals(tx)
8576
}
8677

common/config/consortium_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ package config
1818
import (
1919
"testing"
2020

21+
"github.com/hyperledger/fabric/common/config/msp"
2122
cb "github.com/hyperledger/fabric/protos/common"
2223
"github.com/stretchr/testify/assert"
2324
)
2425

2526
func TestConsortiumGroup(t *testing.T) {
2627

27-
cg := NewConsortiumGroup(nil)
28+
cg := NewConsortiumGroup(msp.NewMSPConfigHandler())
2829
og, err := cg.NewGroup("testGroup")
2930
assert.NoError(t, err, "NewGroup should not have returned error")
3031
assert.Equal(t, "testGroup", og.(*OrganizationGroup).Name(),
@@ -45,7 +46,7 @@ func TestConsortiumGroup(t *testing.T) {
4546
}
4647

4748
func TestConsortiumConfig(t *testing.T) {
48-
cg := NewConsortiumGroup(nil)
49+
cg := NewConsortiumGroup(msp.NewMSPConfigHandler())
4950
cc := NewConsortiumConfig(cg)
5051
orgs := cc.Organizations()
5152
assert.Equal(t, 0, len(orgs))
@@ -61,7 +62,7 @@ func TestConsortiumConfig(t *testing.T) {
6162
"testGroup": og,
6263
})
6364
assert.NoError(t, err, "Validate returned unexpected error")
64-
csg := NewConsortiumsGroup()
65+
csg := NewConsortiumsGroup(nil)
6566
err = cc.Validate(t, map[string]ValueProposer{
6667
"testGroup": csg,
6768
})

common/config/consortiums.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package config
1818

1919
import (
2020
"fmt"
21+
22+
"github.com/hyperledger/fabric/common/config/msp"
2123
)
2224

2325
const (
@@ -29,18 +31,22 @@ const (
2931
type ConsortiumsGroup struct {
3032
*Proposer
3133
*ConsortiumsConfig
34+
35+
mspConfig *msp.MSPConfigHandler
3236
}
3337

3438
// NewConsortiumsGroup creates a new *ConsortiumsGroup
35-
func NewConsortiumsGroup() *ConsortiumsGroup {
36-
cg := &ConsortiumsGroup{}
39+
func NewConsortiumsGroup(mspConfig *msp.MSPConfigHandler) *ConsortiumsGroup {
40+
cg := &ConsortiumsGroup{
41+
mspConfig: mspConfig,
42+
}
3743
cg.Proposer = NewProposer(cg)
3844
return cg
3945
}
4046

4147
// NewGroup returns a Consortium instance
4248
func (cg *ConsortiumsGroup) NewGroup(name string) (ValueProposer, error) {
43-
return NewConsortiumGroup(cg), nil
49+
return NewConsortiumGroup(cg.mspConfig), nil
4450
}
4551

4652
// Allocate returns the resources for a new config proposal

common/config/consortiums_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
func TestConsortiums(t *testing.T) {
2525

26-
csg := NewConsortiumsGroup()
26+
csg := NewConsortiumsGroup(nil)
2727
cg, err := csg.NewGroup("testCG")
2828
assert.NoError(t, err, "NewGroup shuld not have returned error")
2929
_, ok := cg.(*ConsortiumGroup)

0 commit comments

Comments
 (0)