Skip to content

Commit 7998d07

Browse files
Jason Yellickkchristidis
Jason Yellick
authored andcommitted
[FAB-2646] (PA) Create consortium configuration
In order to support returning the list of channels via the ordering system channel configuration, there needs to be additional configuration structures representing the groups which may create channels. We call these groups Consortiums by convention, where each consortium represents a group of organizations which may form channels together. Note, this also include FAB-2647 as combined with FAB-2700 it provides testing coverage for the new code. Change-Id: Iaa7dada39daa153c95613b47def8169b57f27be4 Signed-off-by: Jason Yellick <[email protected]> Signed-off-by: Kostas Christidis <[email protected]>
1 parent 7f114bb commit 7998d07

File tree

14 files changed

+483
-83
lines changed

14 files changed

+483
-83
lines changed

common/config/api.go

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package config
2121
import (
2222
"time"
2323

24+
cb "github.com/hyperledger/fabric/protos/common"
2425
ab "github.com/hyperledger/fabric/protos/orderer"
2526
pb "github.com/hyperledger/fabric/protos/peer"
2627
)
@@ -62,6 +63,18 @@ type Channel interface {
6263
OrdererAddresses() []string
6364
}
6465

66+
// Consortiums represents the set of consortiums serviced by an ordering service
67+
type Consortiums interface {
68+
// Consortiums returns the set of consortiums
69+
Consortiums() map[string]Consortium
70+
}
71+
72+
// Consortium represents a group of orgs which may create channels together
73+
type Consortium interface {
74+
// ChannelCreationPolicy returns the policy to check when instantiating a channel for this consortium
75+
ChannelCreationPolicy() *cb.Policy
76+
}
77+
6578
// Orderer stores the common shared orderer config
6679
type Orderer interface {
6780
// ConsensusType returns the configured consensus type

common/config/channel.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,20 @@ func (cg *ChannelGroup) ApplicationConfig() *ApplicationGroup {
105105
return cg.ChannelConfig.appConfig
106106
}
107107

108+
// ConsortiumsConfig returns the consortium config associated with this channel if it exists
109+
func (cg *ChannelGroup) ConsortiumsConfig() *ConsortiumsGroup {
110+
return cg.ChannelConfig.consortiumsConfig
111+
}
112+
108113
// NewGroup instantiates either a new application or orderer config
109114
func (cg *ChannelGroup) NewGroup(group string) (ValueProposer, error) {
110115
switch group {
111116
case ApplicationGroupKey:
112117
return NewApplicationGroup(cg.mspConfigHandler), nil
113118
case OrdererGroupKey:
114119
return NewOrdererGroup(cg.mspConfigHandler), nil
120+
case ConsortiumsGroupKey:
121+
return NewConsortiumsGroup(), nil
115122
default:
116123
return nil, fmt.Errorf("Disallowed channel group: %s", group)
117124
}
@@ -124,8 +131,9 @@ type ChannelConfig struct {
124131

125132
hashingAlgorithm func(input []byte) []byte
126133

127-
appConfig *ApplicationGroup
128-
ordererConfig *OrdererGroup
134+
appConfig *ApplicationGroup
135+
ordererConfig *OrdererGroup
136+
consortiumsConfig *ConsortiumsGroup
129137
}
130138

131139
// NewChannelConfig creates a new ChannelConfig
@@ -183,6 +191,11 @@ func (cc *ChannelConfig) Validate(tx interface{}, groups map[string]ValuePropose
183191
if !ok {
184192
return fmt.Errorf("Orderer group was not Orderer config")
185193
}
194+
case ConsortiumsGroupKey:
195+
cc.consortiumsConfig, ok = value.(*ConsortiumsGroup)
196+
if !ok {
197+
return fmt.Errorf("Consortiums group was no Consortium config")
198+
}
186199
default:
187200
return fmt.Errorf("Disallowed channel group: %s", key)
188201
}

common/config/consortium.go

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/hyperledger/fabric/common/config/msp"
23+
cb "github.com/hyperledger/fabric/protos/common"
24+
)
25+
26+
// ConsortiumProtos holds the config protos for the consortium config
27+
type ConsortiumProtos struct {
28+
ChannelCreationPolicy *cb.Policy
29+
}
30+
31+
// ConsortiumGroup stores the set of Consortium
32+
type ConsortiumGroup struct {
33+
*Proposer
34+
*ConsortiumConfig
35+
36+
mspConfig *msp.MSPConfigHandler
37+
consortiumsGroup *ConsortiumsGroup
38+
}
39+
40+
// NewConsortiumGroup creates a new *ConsortiumGroup
41+
func NewConsortiumGroup(consortiumsGroup *ConsortiumsGroup) *ConsortiumGroup {
42+
cg := &ConsortiumGroup{
43+
mspConfig: msp.NewMSPConfigHandler(),
44+
consortiumsGroup: consortiumsGroup,
45+
}
46+
cg.Proposer = NewProposer(cg)
47+
return cg
48+
}
49+
50+
// NewGroup returns a Consortium instance
51+
func (cg *ConsortiumGroup) NewGroup(name string) (ValueProposer, error) {
52+
return NewOrganizationGroup(name, cg.mspConfig), nil
53+
}
54+
55+
// Allocate returns the resources for a new config proposal
56+
func (cg *ConsortiumGroup) Allocate() Values {
57+
return NewConsortiumConfig(cg)
58+
}
59+
60+
// BeginValueProposals calls through to Proposer after calling into the MSP config Handler
61+
func (cg *ConsortiumGroup) BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error) {
62+
cg.mspConfig.BeginConfig(tx)
63+
return cg.Proposer.BeginValueProposals(tx, groups)
64+
}
65+
66+
// PreCommit intercepts the precommit request and commits the MSP config handler before calling the underlying proposer
67+
func (cg *ConsortiumGroup) PreCommit(tx interface{}) error {
68+
err := cg.mspConfig.PreCommit(tx)
69+
if err != nil {
70+
return err
71+
}
72+
return cg.Proposer.PreCommit(tx)
73+
}
74+
75+
// RollbackProposals intercepts the rollback request and commits the MSP config handler before calling the underlying proposer
76+
func (cg *ConsortiumGroup) RollbackProposals(tx interface{}) {
77+
cg.mspConfig.RollbackProposals(tx)
78+
cg.Proposer.RollbackProposals(tx)
79+
}
80+
81+
// CommitProposals intercepts the commit request and commits the MSP config handler before calling the underlying proposer
82+
func (cg *ConsortiumGroup) CommitProposals(tx interface{}) {
83+
cg.mspConfig.CommitProposals(tx)
84+
cg.Proposer.CommitProposals(tx)
85+
}
86+
87+
// ConsortiumConfig holds the consoritums configuration information
88+
type ConsortiumConfig struct {
89+
*standardValues
90+
protos *ConsortiumProtos
91+
orgs map[string]*OrganizationGroup
92+
93+
consortiumGroup *ConsortiumGroup
94+
}
95+
96+
// NewConsortiumConfig creates a new instance of the consoritums config
97+
func NewConsortiumConfig(cg *ConsortiumGroup) *ConsortiumConfig {
98+
cc := &ConsortiumConfig{
99+
protos: &ConsortiumProtos{},
100+
orgs: make(map[string]*OrganizationGroup),
101+
consortiumGroup: cg,
102+
}
103+
var err error
104+
cc.standardValues, err = NewStandardValues(cc.protos)
105+
if err != nil {
106+
logger.Panicf("Programming error: %s", err)
107+
}
108+
return cc
109+
}
110+
111+
// Organizations returns the set of organizations in the consortium
112+
func (cc *ConsortiumConfig) Organizations() map[string]*OrganizationGroup {
113+
return cc.orgs
114+
}
115+
116+
// CreationPolicy returns the policy structure used to validate
117+
// the channel creation
118+
func (cc *ConsortiumConfig) ChannelCreationPolicy() *cb.Policy {
119+
return cc.protos.ChannelCreationPolicy
120+
}
121+
122+
// Commit commits the ConsortiumConfig
123+
func (cc *ConsortiumConfig) Commit() {
124+
cc.consortiumGroup.ConsortiumConfig = cc
125+
}
126+
127+
// Validate builds the Consortium map
128+
func (cc *ConsortiumConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
129+
var ok bool
130+
for key, group := range groups {
131+
cc.orgs[key], ok = group.(*OrganizationGroup)
132+
if !ok {
133+
return fmt.Errorf("Unexpected group type: %T", group)
134+
}
135+
}
136+
return nil
137+
}

common/config/consortiums.go

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import (
20+
"fmt"
21+
)
22+
23+
const (
24+
// ConsortiumsGroupKey is the group name for the consortiums config
25+
ConsortiumsGroupKey = "Consortiums"
26+
)
27+
28+
// ConsortiumsGroup stores the set of Consortiums
29+
type ConsortiumsGroup struct {
30+
*Proposer
31+
*ConsortiumsConfig
32+
}
33+
34+
// NewConsortiumsGroup creates a new *ConsortiumsGroup
35+
func NewConsortiumsGroup() *ConsortiumsGroup {
36+
cg := &ConsortiumsGroup{}
37+
cg.Proposer = NewProposer(cg)
38+
return cg
39+
}
40+
41+
// NewGroup returns a Consortium instance
42+
func (cg *ConsortiumsGroup) NewGroup(name string) (ValueProposer, error) {
43+
return NewConsortiumGroup(cg), nil
44+
}
45+
46+
// Allocate returns the resources for a new config proposal
47+
func (cg *ConsortiumsGroup) Allocate() Values {
48+
return NewConsortiumsConfig(cg)
49+
}
50+
51+
// ConsortiumsConfig holds the consoritums configuration information
52+
type ConsortiumsConfig struct {
53+
*standardValues
54+
consortiums map[string]Consortium
55+
56+
consortiumsGroup *ConsortiumsGroup
57+
}
58+
59+
// NewConsortiumsConfig creates a new instance of the consoritums config
60+
func NewConsortiumsConfig(cg *ConsortiumsGroup) *ConsortiumsConfig {
61+
cc := &ConsortiumsConfig{
62+
consortiums: make(map[string]Consortium),
63+
consortiumsGroup: cg,
64+
}
65+
var err error
66+
cc.standardValues, err = NewStandardValues()
67+
if err != nil {
68+
logger.Panicf("Programming error: %s", err)
69+
}
70+
return cc
71+
}
72+
73+
// Consortiums returns a map of the current consortiums
74+
func (cc *ConsortiumsConfig) Consortiums() map[string]Consortium {
75+
return cc.consortiums
76+
}
77+
78+
// Commit commits the ConsortiumsConfig
79+
func (cc *ConsortiumsConfig) Commit() {
80+
cc.consortiumsGroup.ConsortiumsConfig = cc
81+
}
82+
83+
// Validate builds the Consortiums map
84+
func (cc *ConsortiumsConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
85+
var ok bool
86+
for key, group := range groups {
87+
cc.consortiums[key], ok = group.(*ConsortiumGroup)
88+
if !ok {
89+
return fmt.Errorf("Unexpected group type: %T", group)
90+
}
91+
}
92+
return nil
93+
}

common/config/consortiums_util.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import (
20+
cb "github.com/hyperledger/fabric/protos/common"
21+
"github.com/hyperledger/fabric/protos/utils"
22+
)
23+
24+
const (
25+
// ChannelCreationPolicyKey is the key for the ChannelCreationPolicy value
26+
ChannelCreationPolicyKey = "ChannelCreationPolicy"
27+
)
28+
29+
// TemplateConsortiumsGroup creates an empty consortiums group
30+
func TemplateConsortiumsGroup() *cb.ConfigGroup {
31+
result := cb.NewConfigGroup()
32+
result.Groups[ConsortiumsGroupKey] = cb.NewConfigGroup()
33+
return result
34+
}
35+
36+
// TemplateConsortiumChannelCreationPolicy sets the ChannelCreationPolicy for a given consortium
37+
func TemplateConsortiumChannelCreationPolicy(name string, policy *cb.Policy) *cb.ConfigGroup {
38+
result := TemplateConsortiumsGroup()
39+
result.Groups[ConsortiumsGroupKey].Groups[name] = cb.NewConfigGroup()
40+
result.Groups[ConsortiumsGroupKey].Groups[name].Values[ChannelCreationPolicyKey] = &cb.ConfigValue{
41+
Value: utils.MarshalOrPanic(policy),
42+
}
43+
return result
44+
}

common/config/root.go

+4
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ func (r *Root) Orderer() *OrdererGroup {
8787
func (r *Root) Application() *ApplicationGroup {
8888
return r.channel.ApplicationConfig()
8989
}
90+
91+
func (r *Root) Consortiums() *ConsortiumsGroup {
92+
return r.channel.ConsortiumsConfig()
93+
}

common/configtx/api/api.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ type Resources interface {
5252
// PolicyManager returns the policies.Manager for the channel
5353
PolicyManager() policies.Manager
5454

55-
// ChannelConfig returns the ChannelConfig for the chain
55+
// ChannelConfig returns the config.Channel for the chain
5656
ChannelConfig() config.Channel
5757

58-
// OrdererConfig returns the configtxorderer.SharedConfig for the channel
58+
// OrdererConfig returns the config.Orderer for the channel
5959
OrdererConfig() config.Orderer
6060

61+
// ConsortiumsConfig() returns the config.Consortiums for the channel
62+
ConsortiumsConfig() config.Consortiums
63+
6164
// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
6265
ApplicationConfig() config.Application
6366

common/configtx/initializer.go

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func (r *resources) ApplicationConfig() config.Application {
5656
return r.configRoot.Application()
5757
}
5858

59+
// ConsortiumsConfig returns the api.ConsortiumsConfig for the chain
60+
func (r *resources) ConsortiumsConfig() config.Consortiums {
61+
return r.configRoot.Consortiums()
62+
}
63+
5964
// MSPManager returns the msp.MSPManager for the chain
6065
func (r *resources) MSPManager() msp.MSPManager {
6166
return r.mspConfigHandler

0 commit comments

Comments
 (0)