Skip to content

Commit 58ddd21

Browse files
author
Jason Yellick
committed
[FAB-5647] Extract common comp from config/channel
In the last CR in these series, the entirety of the config structures were moved to fabric/common/channel/config. This includes code like the Proposer and StandardValues which is applicable outside of the context of the channel config. This CR moves this subset back to the fabric/common/config directory. Change-Id: I5ff5378a1362ee5da28deec2d46f5dd07ba889e0 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 8dc7883 commit 58ddd21

23 files changed

+132
-124
lines changed

common/config/api.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package config
8+
9+
type ValueProposer interface {
10+
// BeginValueProposals called when a config proposal is begun
11+
BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error)
12+
13+
// RollbackProposals called when a config proposal is abandoned
14+
RollbackProposals(tx interface{})
15+
16+
// PreCommit is invoked before committing the config to catch
17+
// any errors which cannot be caught on a per proposal basis
18+
// TODO, rename other methods to remove Value/Proposal references
19+
PreCommit(tx interface{}) error
20+
21+
// CommitProposals called when a config proposal is committed
22+
CommitProposals(tx interface{})
23+
}

common/config/channel/api.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,3 @@ type Orderer interface {
9797
// Organizations returns the organizations for the ordering service
9898
Organizations() map[string]Org
9999
}
100-
101-
type ValueProposer interface {
102-
// BeginValueProposals called when a config proposal is begun
103-
BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error)
104-
105-
// RollbackProposals called when a config proposal is abandoned
106-
RollbackProposals(tx interface{})
107-
108-
// PreCommit is invoked before committing the config to catch
109-
// any errors which cannot be caught on a per proposal basis
110-
// TODO, rename other methods to remove Value/Proposal references
111-
PreCommit(tx interface{}) error
112-
113-
// CommitProposals called when a config proposal is committed
114-
CommitProposals(tx interface{})
115-
}

common/config/channel/application.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package config
1919
import (
2020
"fmt"
2121

22+
"github.com/hyperledger/fabric/common/config"
2223
"github.com/hyperledger/fabric/common/config/channel/msp"
2324
)
2425

@@ -29,13 +30,13 @@ const (
2930

3031
// ApplicationGroup represents the application config group
3132
type ApplicationGroup struct {
32-
*Proposer
33+
*config.Proposer
3334
*ApplicationConfig
3435
mspConfig *msp.MSPConfigHandler
3536
}
3637

3738
type ApplicationConfig struct {
38-
*standardValues
39+
*config.StandardValues
3940

4041
applicationGroup *ApplicationGroup
4142
applicationOrgs map[string]ApplicationOrg
@@ -46,22 +47,22 @@ func NewApplicationGroup(mspConfig *msp.MSPConfigHandler) *ApplicationGroup {
4647
ag := &ApplicationGroup{
4748
mspConfig: mspConfig,
4849
}
49-
ag.Proposer = NewProposer(ag)
50+
ag.Proposer = config.NewProposer(ag)
5051

5152
return ag
5253
}
5354

54-
func (ag *ApplicationGroup) NewGroup(name string) (ValueProposer, error) {
55+
func (ag *ApplicationGroup) NewGroup(name string) (config.ValueProposer, error) {
5556
return NewApplicationOrgGroup(name, ag.mspConfig), nil
5657
}
5758

5859
// Allocate returns a new instance of the ApplicationConfig
59-
func (ag *ApplicationGroup) Allocate() Values {
60+
func (ag *ApplicationGroup) Allocate() config.Values {
6061
return NewApplicationConfig(ag)
6162
}
6263

6364
func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig {
64-
sv, err := NewStandardValues(&(struct{}{}))
65+
sv, err := config.NewStandardValues(&(struct{}{}))
6566
if err != nil {
6667
logger.Panicf("Programming error: %s", err)
6768
}
@@ -70,11 +71,11 @@ func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig {
7071
applicationGroup: ag,
7172

7273
// Currently there are no config values
73-
standardValues: sv,
74+
StandardValues: sv,
7475
}
7576
}
7677

77-
func (ac *ApplicationConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
78+
func (ac *ApplicationConfig) Validate(tx interface{}, groups map[string]config.ValueProposer) error {
7879
ac.applicationOrgs = make(map[string]ApplicationOrg)
7980
var ok bool
8081
for key, value := range groups {

common/config/channel/applicationorg.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package config
1818

1919
import (
20+
"github.com/hyperledger/fabric/common/config"
2021
mspconfig "github.com/hyperledger/fabric/common/config/channel/msp"
2122
pb "github.com/hyperledger/fabric/protos/peer"
2223

@@ -42,7 +43,7 @@ type ApplicationOrgConfig struct {
4243

4344
// ApplicationOrgGroup defines the configuration for an application org
4445
type ApplicationOrgGroup struct {
45-
*Proposer
46+
*config.Proposer
4647
*OrganizationGroup
4748
*ApplicationOrgConfig
4849
}
@@ -52,7 +53,7 @@ func NewApplicationOrgGroup(id string, mspConfig *mspconfig.MSPConfigHandler) *A
5253
aog := &ApplicationOrgGroup{
5354
OrganizationGroup: NewOrganizationGroup(id, mspConfig),
5455
}
55-
aog.Proposer = NewProposer(aog)
56+
aog.Proposer = config.NewProposer(aog)
5657
return aog
5758
}
5859

@@ -61,7 +62,7 @@ func (aog *ApplicationOrgConfig) AnchorPeers() []*pb.AnchorPeer {
6162
return aog.protos.AnchorPeers.AnchorPeers
6263
}
6364

64-
func (aog *ApplicationOrgGroup) Allocate() Values {
65+
func (aog *ApplicationOrgGroup) Allocate() config.Values {
6566
return NewApplicationOrgConfig(aog)
6667
}
6768

@@ -78,15 +79,15 @@ func NewApplicationOrgConfig(aog *ApplicationOrgGroup) *ApplicationOrgConfig {
7879
applicationOrgGroup: aog,
7980
}
8081
var err error
81-
aoc.standardValues, err = NewStandardValues(aoc.protos, aoc.OrganizationConfig.protos)
82+
aoc.StandardValues, err = config.NewStandardValues(aoc.protos, aoc.OrganizationConfig.protos)
8283
if err != nil {
8384
logger.Panicf("Programming error: %s", err)
8485
}
8586

8687
return aoc
8788
}
8889

89-
func (aoc *ApplicationOrgConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
90+
func (aoc *ApplicationOrgConfig) Validate(tx interface{}, groups map[string]config.ValueProposer) error {
9091
if logger.IsEnabledFor(logging.DEBUG) {
9192
logger.Debugf("Anchor peers for org %s are %v", aoc.applicationOrgGroup.name, aoc.protos.AnchorPeers)
9293
}

common/config/channel/applicationorg_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package config
1818

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

2325
func TestApplicationOrgInterface(t *testing.T) {
24-
_ = ValueProposer(NewApplicationOrgGroup("id", nil))
26+
_ = config.ValueProposer(NewApplicationOrgGroup("id", nil))
2527
}

common/config/channel/channel.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"math"
2222

2323
"github.com/hyperledger/fabric/bccsp"
24+
"github.com/hyperledger/fabric/common/config"
2425
"github.com/hyperledger/fabric/common/config/channel/msp"
2526
"github.com/hyperledger/fabric/common/util"
2627
cb "github.com/hyperledger/fabric/protos/common"
@@ -78,7 +79,7 @@ func (ccs *channelConfigSetter) Commit() {
7879
// ChannelGroup
7980
type ChannelGroup struct {
8081
*ChannelConfig
81-
*Proposer
82+
*config.Proposer
8283
mspConfigHandler *msp.MSPConfigHandler
8384
}
8485

@@ -87,12 +88,12 @@ func NewChannelGroup(mspConfigHandler *msp.MSPConfigHandler) *ChannelGroup {
8788
ChannelConfig: NewChannelConfig(),
8889
mspConfigHandler: mspConfigHandler,
8990
}
90-
cg.Proposer = NewProposer(cg)
91+
cg.Proposer = config.NewProposer(cg)
9192
return cg
9293
}
9394

9495
// Allocate creates new config resources for a pending config update
95-
func (cg *ChannelGroup) Allocate() Values {
96+
func (cg *ChannelGroup) Allocate() config.Values {
9697
return &channelConfigSetter{
9798
ChannelConfig: NewChannelConfig(),
9899
target: &cg.ChannelConfig,
@@ -115,7 +116,7 @@ func (cg *ChannelGroup) ConsortiumsConfig() *ConsortiumsGroup {
115116
}
116117

117118
// NewGroup instantiates either a new application or orderer config
118-
func (cg *ChannelGroup) NewGroup(group string) (ValueProposer, error) {
119+
func (cg *ChannelGroup) NewGroup(group string) (config.ValueProposer, error) {
119120
switch group {
120121
case ApplicationGroupKey:
121122
return NewApplicationGroup(cg.mspConfigHandler), nil
@@ -130,7 +131,7 @@ func (cg *ChannelGroup) NewGroup(group string) (ValueProposer, error) {
130131

131132
// ChannelConfig stores the channel configuration
132133
type ChannelConfig struct {
133-
*standardValues
134+
*config.StandardValues
134135
protos *ChannelProtos
135136

136137
hashingAlgorithm func(input []byte) []byte
@@ -147,7 +148,7 @@ func NewChannelConfig() *ChannelConfig {
147148
}
148149

149150
var err error
150-
cc.standardValues, err = NewStandardValues(cc.protos)
151+
cc.StandardValues, err = config.NewStandardValues(cc.protos)
151152
if err != nil {
152153
logger.Panicf("Programming error: %s", err)
153154
}
@@ -176,7 +177,7 @@ func (cc *ChannelConfig) ConsortiumName() string {
176177

177178
// Validate inspects the generated configuration protos, ensures that the values are correct, and
178179
// sets the ChannelConfig fields that may be referenced after Commit
179-
func (cc *ChannelConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
180+
func (cc *ChannelConfig) Validate(tx interface{}, groups map[string]config.ValueProposer) error {
180181
for _, validator := range []func() error{
181182
cc.validateHashingAlgorithm,
182183
cc.validateBlockDataHashingStructure,

common/config/channel/channel_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/hyperledger/fabric/bccsp"
25+
"github.com/hyperledger/fabric/common/config"
2526
"github.com/hyperledger/fabric/common/util"
2627
cb "github.com/hyperledger/fabric/protos/common"
2728

@@ -68,20 +69,20 @@ func TestChannelConfig(t *testing.T) {
6869
ag := NewApplicationGroup(nil)
6970
og := NewOrdererGroup(nil)
7071
csg := NewConsortiumsGroup(nil)
71-
good := make(map[string]ValueProposer)
72+
good := make(map[string]config.ValueProposer)
7273
good[ApplicationGroupKey] = ag
7374
good[OrdererGroupKey] = og
7475
good[ConsortiumsGroupKey] = csg
7576

7677
err := cc.Validate(nil, good)
7778
assert.NoError(t, err, "Unexpected error validating good config groups")
78-
err = cc.Validate(nil, map[string]ValueProposer{ApplicationGroupKey: NewConsortiumsGroup(nil)})
79+
err = cc.Validate(nil, map[string]config.ValueProposer{ApplicationGroupKey: NewConsortiumsGroup(nil)})
7980
assert.Error(t, err, "Expected error validating bad config group")
80-
err = cc.Validate(nil, map[string]ValueProposer{OrdererGroupKey: NewConsortiumsGroup(nil)})
81+
err = cc.Validate(nil, map[string]config.ValueProposer{OrdererGroupKey: NewConsortiumsGroup(nil)})
8182
assert.Error(t, err, "Expected error validating bad config group")
82-
err = cc.Validate(nil, map[string]ValueProposer{ConsortiumsGroupKey: NewOrdererGroup(nil)})
83+
err = cc.Validate(nil, map[string]config.ValueProposer{ConsortiumsGroupKey: NewOrdererGroup(nil)})
8384
assert.Error(t, err, "Expected error validating bad config group")
84-
err = cc.Validate(nil, map[string]ValueProposer{ConsortiumKey: NewConsortiumGroup(nil)})
85+
err = cc.Validate(nil, map[string]config.ValueProposer{ConsortiumKey: NewConsortiumGroup(nil)})
8586
assert.Error(t, err, "Expected error validating bad config group")
8687

8788
}

common/config/channel/consortium.go

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package config
1919
import (
2020
"fmt"
2121

22+
"github.com/hyperledger/fabric/common/config"
2223
"github.com/hyperledger/fabric/common/config/channel/msp"
2324
cb "github.com/hyperledger/fabric/protos/common"
2425
)
@@ -30,7 +31,7 @@ type ConsortiumProtos struct {
3031

3132
// ConsortiumGroup stores the set of Consortium
3233
type ConsortiumGroup struct {
33-
*Proposer
34+
*config.Proposer
3435
*ConsortiumConfig
3536

3637
mspConfig *msp.MSPConfigHandler
@@ -41,43 +42,23 @@ func NewConsortiumGroup(mspConfig *msp.MSPConfigHandler) *ConsortiumGroup {
4142
cg := &ConsortiumGroup{
4243
mspConfig: mspConfig,
4344
}
44-
cg.Proposer = NewProposer(cg)
45+
cg.Proposer = config.NewProposer(cg)
4546
return cg
4647
}
4748

4849
// NewGroup returns a Consortium instance
49-
func (cg *ConsortiumGroup) NewGroup(name string) (ValueProposer, error) {
50+
func (cg *ConsortiumGroup) NewGroup(name string) (config.ValueProposer, error) {
5051
return NewOrganizationGroup(name, cg.mspConfig), nil
5152
}
5253

5354
// Allocate returns the resources for a new config proposal
54-
func (cg *ConsortiumGroup) Allocate() Values {
55+
func (cg *ConsortiumGroup) Allocate() config.Values {
5556
return NewConsortiumConfig(cg)
5657
}
5758

58-
// BeginValueProposals calls through to Proposer after calling into the MSP config Handler
59-
func (cg *ConsortiumGroup) BeginValueProposals(tx interface{}, groups []string) (ValueDeserializer, []ValueProposer, error) {
60-
return cg.Proposer.BeginValueProposals(tx, groups)
61-
}
62-
63-
// PreCommit intercepts the precommit request and commits the MSP config handler before calling the underlying proposer
64-
func (cg *ConsortiumGroup) PreCommit(tx interface{}) error {
65-
return cg.Proposer.PreCommit(tx)
66-
}
67-
68-
// RollbackProposals intercepts the rollback request and commits the MSP config handler before calling the underlying proposer
69-
func (cg *ConsortiumGroup) RollbackProposals(tx interface{}) {
70-
cg.Proposer.RollbackProposals(tx)
71-
}
72-
73-
// CommitProposals intercepts the commit request and commits the MSP config handler before calling the underlying proposer
74-
func (cg *ConsortiumGroup) CommitProposals(tx interface{}) {
75-
cg.Proposer.CommitProposals(tx)
76-
}
77-
7859
// ConsortiumConfig holds the consoritums configuration information
7960
type ConsortiumConfig struct {
80-
*standardValues
61+
*config.StandardValues
8162
protos *ConsortiumProtos
8263
orgs map[string]*OrganizationGroup
8364

@@ -92,7 +73,7 @@ func NewConsortiumConfig(cg *ConsortiumGroup) *ConsortiumConfig {
9273
consortiumGroup: cg,
9374
}
9475
var err error
95-
cc.standardValues, err = NewStandardValues(cc.protos)
76+
cc.StandardValues, err = config.NewStandardValues(cc.protos)
9677
if err != nil {
9778
logger.Panicf("Programming error: %s", err)
9879
}
@@ -116,7 +97,7 @@ func (cc *ConsortiumConfig) Commit() {
11697
}
11798

11899
// Validate builds the Consortium map
119-
func (cc *ConsortiumConfig) Validate(tx interface{}, groups map[string]ValueProposer) error {
100+
func (cc *ConsortiumConfig) Validate(tx interface{}, groups map[string]config.ValueProposer) error {
120101
var ok bool
121102
for key, group := range groups {
122103
cc.orgs[key], ok = group.(*OrganizationGroup)

common/config/channel/consortium_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package config
1818
import (
1919
"testing"
2020

21+
"github.com/hyperledger/fabric/common/config"
2122
"github.com/hyperledger/fabric/common/config/channel/msp"
2223
cb "github.com/hyperledger/fabric/protos/common"
2324
"github.com/stretchr/testify/assert"
@@ -58,12 +59,12 @@ func TestConsortiumConfig(t *testing.T) {
5859
assert.Equal(t, cg.ConsortiumConfig, cc, "Error committing ConsortiumConfig")
5960

6061
og, _ := cg.NewGroup("testGroup")
61-
err := cc.Validate(t, map[string]ValueProposer{
62+
err := cc.Validate(t, map[string]config.ValueProposer{
6263
"testGroup": og,
6364
})
6465
assert.NoError(t, err, "Validate returned unexpected error")
6566
csg := NewConsortiumsGroup(nil)
66-
err = cc.Validate(t, map[string]ValueProposer{
67+
err = cc.Validate(t, map[string]config.ValueProposer{
6768
"testGroup": csg,
6869
})
6970
assert.Error(t, err, "Validate should have failed")

0 commit comments

Comments
 (0)