Skip to content

Commit bcb9259

Browse files
author
Jason Yellick
committed
[FAB-2526] Move consolidate config to one package
https://jira.hyperledger.org/browse/FAB-2526 This CR consolidates config from fabric/common/configvalues/root and fabric/common/configvalues to be in fabric/common/config. This completes the refactoring of the config needed to support config inspection which will follow in subsequent changesets. Change-Id: I081547be49abc3d0839f0b3accd01d378f36bf81 Signed-off-by: Jason Yellick <[email protected]>
1 parent efa8237 commit bcb9259

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+116
-118
lines changed

common/configvalues/api.go common/config/api.go

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ type Application interface {
4949
Organizations() map[string]ApplicationOrg
5050
}
5151

52+
// Channel gives read only access to the channel configuration
53+
type Channel interface {
54+
// HashingAlgorithm returns the default algorithm to be used when hashing
55+
// such as computing block hashes, and CreationPolicy digests
56+
HashingAlgorithm() func(input []byte) []byte
57+
58+
// BlockDataHashingStructureWidth returns the width to use when constructing the
59+
// Merkle tree to compute the BlockData hash
60+
BlockDataHashingStructureWidth() uint32
61+
62+
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
63+
OrdererAddresses() []string
64+
}
65+
5266
// Orderer stores the common shared orderer config
5367
type Orderer interface {
5468
// ConsensusType returns the configured consensus type

common/configvalues/root/application.go common/config/application.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ package config
1919
import (
2020
"fmt"
2121

22-
api "github.com/hyperledger/fabric/common/configvalues"
23-
"github.com/hyperledger/fabric/common/configvalues/msp"
22+
"github.com/hyperledger/fabric/common/config/msp"
2423
)
2524

2625
const (
@@ -39,7 +38,7 @@ type ApplicationConfig struct {
3938
*standardValues
4039

4140
applicationGroup *ApplicationGroup
42-
applicationOrgs map[string]api.ApplicationOrg
41+
applicationOrgs map[string]ApplicationOrg
4342
}
4443

4544
// NewSharedConfigImpl creates a new SharedConfigImpl with the given CryptoHelper
@@ -52,7 +51,7 @@ func NewApplicationGroup(mspConfig *msp.MSPConfigHandler) *ApplicationGroup {
5251
return ag
5352
}
5453

55-
func (ag *ApplicationGroup) NewGroup(name string) (api.ValueProposer, error) {
54+
func (ag *ApplicationGroup) NewGroup(name string) (ValueProposer, error) {
5655
return NewApplicationOrgGroup(name, ag.mspConfig), nil
5756
}
5857

@@ -75,8 +74,8 @@ func NewApplicationConfig(ag *ApplicationGroup) *ApplicationConfig {
7574
}
7675
}
7776

78-
func (ac *ApplicationConfig) Validate(groups map[string]api.ValueProposer) error {
79-
ac.applicationOrgs = make(map[string]api.ApplicationOrg)
77+
func (ac *ApplicationConfig) Validate(groups map[string]ValueProposer) error {
78+
ac.applicationOrgs = make(map[string]ApplicationOrg)
8079
var ok bool
8180
for key, value := range groups {
8281
ac.applicationOrgs[key], ok = value.(*ApplicationOrgGroup)
@@ -92,6 +91,6 @@ func (ac *ApplicationConfig) Commit() {
9291
}
9392

9493
// Organizations returns a map of org ID to ApplicationOrg
95-
func (ac *ApplicationConfig) Organizations() map[string]api.ApplicationOrg {
94+
func (ac *ApplicationConfig) Organizations() map[string]ApplicationOrg {
9695
return ac.applicationOrgs
9796
}

common/configvalues/root/application_test.go common/config/application_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package config
1919
import (
2020
"testing"
2121

22-
api "github.com/hyperledger/fabric/common/configvalues"
23-
2422
logging "github.com/op/go-logging"
2523
)
2624

@@ -29,5 +27,5 @@ func init() {
2927
}
3028

3129
func TestApplicationInterface(t *testing.T) {
32-
_ = api.Application((*ApplicationGroup)(nil))
30+
_ = Application((*ApplicationGroup)(nil))
3331
}
File renamed without changes.

common/configvalues/root/applicationorg.go common/config/applicationorg.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
api "github.com/hyperledger/fabric/common/configvalues"
21-
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
20+
mspconfig "github.com/hyperledger/fabric/common/config/msp"
2221
pb "github.com/hyperledger/fabric/protos/peer"
2322

2423
logging "github.com/op/go-logging"
@@ -87,7 +86,7 @@ func NewApplicationOrgConfig(aog *ApplicationOrgGroup) *ApplicationOrgConfig {
8786
return aoc
8887
}
8988

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

common/configvalues/root/applicationorg_test.go common/config/applicationorg_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ package config
1818

1919
import (
2020
"testing"
21-
22-
api "github.com/hyperledger/fabric/common/configvalues"
2321
)
2422

2523
func TestApplicationOrgInterface(t *testing.T) {
26-
_ = api.ValueProposer(NewApplicationOrgGroup("id", nil))
24+
_ = ValueProposer(NewApplicationOrgGroup("id", nil))
2725
}

common/configvalues/root/channel.go common/config/channel.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import (
2121
"math"
2222

2323
"github.com/hyperledger/fabric/bccsp"
24-
api "github.com/hyperledger/fabric/common/configvalues"
25-
"github.com/hyperledger/fabric/common/configvalues/msp"
24+
"github.com/hyperledger/fabric/common/config/msp"
2625
"github.com/hyperledger/fabric/common/util"
2726
cb "github.com/hyperledger/fabric/protos/common"
2827
)
@@ -107,7 +106,7 @@ func (cg *ChannelGroup) ApplicationConfig() *ApplicationGroup {
107106
}
108107

109108
// NewGroup instantiates either a new application or orderer config
110-
func (cg *ChannelGroup) NewGroup(group string) (api.ValueProposer, error) {
109+
func (cg *ChannelGroup) NewGroup(group string) (ValueProposer, error) {
111110
switch group {
112111
case ApplicationGroupKey:
113112
return NewApplicationGroup(cg.mspConfigHandler), nil
@@ -160,7 +159,7 @@ func (cc *ChannelConfig) OrdererAddresses() []string {
160159

161160
// Validate inspects the generated configuration protos, ensures that the values are correct, and
162161
// sets the ChannelConfig fields that may be referenced after Commit
163-
func (cc *ChannelConfig) Validate(groups map[string]api.ValueProposer) error {
162+
func (cc *ChannelConfig) Validate(groups map[string]ValueProposer) error {
164163
for _, validator := range []func() error{
165164
cc.validateHashingAlgorithm,
166165
cc.validateBlockDataHashingStructure,

common/configvalues/root/channel_test.go common/config/channel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() {
3232
}
3333

3434
func TestInterface(t *testing.T) {
35-
_ = ChannelValues(NewChannelGroup(nil))
35+
_ = Channel(NewChannelGroup(nil))
3636
}
3737

3838
func TestHashingAlgorithm(t *testing.T) {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

common/configvalues/root/orderer.go common/config/orderer.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323
"strings"
2424
"time"
2525

26-
api "github.com/hyperledger/fabric/common/configvalues"
27-
"github.com/hyperledger/fabric/common/configvalues/msp"
26+
"github.com/hyperledger/fabric/common/config/msp"
2827
ab "github.com/hyperledger/fabric/protos/orderer"
2928
)
3029

@@ -78,7 +77,7 @@ func NewOrdererGroup(mspConfig *msp.MSPConfigHandler) *OrdererGroup {
7877
}
7978

8079
// NewGroup returns an Org instance
81-
func (og *OrdererGroup) NewGroup(name string) (api.ValueProposer, error) {
80+
func (og *OrdererGroup) NewGroup(name string) (ValueProposer, error) {
8281
return NewOrganizationGroup(name, og.mspConfig), nil
8382
}
8483

@@ -143,7 +142,7 @@ func (oc *OrdererConfig) KafkaBrokers() []string {
143142
return oc.protos.KafkaBrokers.Brokers
144143
}
145144

146-
func (oc *OrdererConfig) Validate(groups map[string]api.ValueProposer) error {
145+
func (oc *OrdererConfig) Validate(groups map[string]ValueProposer) error {
147146
for _, validator := range []func() error{
148147
oc.validateConsensusType,
149148
oc.validateBatchSize,
File renamed without changes.
File renamed without changes.

common/configvalues/root/organization.go common/config/organization.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ package config
1919
import (
2020
"fmt"
2121

22-
api "github.com/hyperledger/fabric/common/configvalues"
23-
mspconfig "github.com/hyperledger/fabric/common/configvalues/msp"
22+
mspconfig "github.com/hyperledger/fabric/common/config/msp"
2423
"github.com/hyperledger/fabric/msp"
2524
mspprotos "github.com/hyperledger/fabric/protos/msp"
2625
)
@@ -74,7 +73,7 @@ func (og *OrganizationGroup) MSPID() string {
7473
}
7574

7675
// NewGroup always errors
77-
func (og *OrganizationGroup) NewGroup(name string) (api.ValueProposer, error) {
76+
func (og *OrganizationGroup) NewGroup(name string) (ValueProposer, error) {
7877
return nil, fmt.Errorf("Organization does not support subgroups")
7978
}
8079

@@ -99,7 +98,7 @@ func NewOrganizationConfig(og *OrganizationGroup) *OrganizationConfig {
9998
}
10099

101100
// Validate returns whether the configuration is valid
102-
func (oc *OrganizationConfig) Validate(groups map[string]api.ValueProposer) error {
101+
func (oc *OrganizationConfig) Validate(groups map[string]ValueProposer) error {
103102
return oc.validateMSP()
104103
}
105104

common/configvalues/root/proposer.go common/config/proposer.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package config
1919
import (
2020
"fmt"
2121

22-
api "github.com/hyperledger/fabric/common/configvalues"
2322
cb "github.com/hyperledger/fabric/protos/common"
2423

2524
"github.com/golang/protobuf/proto"
@@ -36,7 +35,7 @@ type Values interface {
3635

3736
// Validate should ensure that the values set into the proto messages are correct
3837
// and that the new group values are allowed
39-
Validate(map[string]api.ValueProposer) error
38+
Validate(map[string]ValueProposer) error
4039

4140
// Commit should call back into the Value handler to update the config
4241
Commit()
@@ -45,12 +44,12 @@ type Values interface {
4544
// Handler
4645
type Handler interface {
4746
Allocate() Values
48-
NewGroup(name string) (api.ValueProposer, error)
47+
NewGroup(name string) (ValueProposer, error)
4948
}
5049

5150
type config struct {
5251
allocated Values
53-
groups map[string]api.ValueProposer
52+
groups map[string]ValueProposer
5453
}
5554

5655
type Proposer struct {
@@ -67,20 +66,20 @@ func NewProposer(vh Handler) *Proposer {
6766
}
6867

6968
// BeginValueProposals called when a config proposal is begun
70-
func (p *Proposer) BeginValueProposals(groups []string) ([]api.ValueProposer, error) {
69+
func (p *Proposer) BeginValueProposals(groups []string) ([]ValueProposer, error) {
7170
if p.pending != nil {
7271
logger.Panicf("Duplicated BeginValueProposals without Rollback or Commit")
7372
}
7473

75-
result := make([]api.ValueProposer, len(groups))
74+
result := make([]ValueProposer, len(groups))
7675

7776
p.pending = &config{
7877
allocated: p.vh.Allocate(),
79-
groups: make(map[string]api.ValueProposer),
78+
groups: make(map[string]ValueProposer),
8079
}
8180

8281
for i, groupName := range groups {
83-
var group api.ValueProposer
82+
var group ValueProposer
8483
var ok bool
8584

8685
if p.current == nil {

common/configvalues/root/proposer_test.go common/config/proposer_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"testing"
2222

23-
api "github.com/hyperledger/fabric/common/configvalues"
2423
cb "github.com/hyperledger/fabric/protos/common"
2524
"github.com/hyperledger/fabric/protos/utils"
2625

@@ -43,7 +42,7 @@ func (v *mockValues) ProtoMsg(key string) (proto.Message, bool) {
4342
return msg, ok
4443
}
4544

46-
func (v *mockValues) Validate(map[string]api.ValueProposer) error {
45+
func (v *mockValues) Validate(map[string]ValueProposer) error {
4746
return v.ValidateReturn
4847
}
4948

@@ -57,15 +56,15 @@ func newMockValues() *mockValues {
5756

5857
type mockHandler struct {
5958
AllocateReturn *mockValues
60-
NewGroupMap map[string]api.ValueProposer
59+
NewGroupMap map[string]ValueProposer
6160
NewGroupError error
6261
}
6362

6463
func (h *mockHandler) Allocate() Values {
6564
return h.AllocateReturn
6665
}
6766

68-
func (h *mockHandler) NewGroup(name string) (api.ValueProposer, error) {
67+
func (h *mockHandler) NewGroup(name string) (ValueProposer, error) {
6968
group, ok := h.NewGroupMap[name]
7069
if !ok {
7170
return nil, fmt.Errorf("Missing group implies error")
@@ -76,7 +75,7 @@ func (h *mockHandler) NewGroup(name string) (api.ValueProposer, error) {
7675
func newMockHandler() *mockHandler {
7776
return &mockHandler{
7877
AllocateReturn: newMockValues(),
79-
NewGroupMap: make(map[string]api.ValueProposer),
78+
NewGroupMap: make(map[string]ValueProposer),
8079
}
8180
}
8281

@@ -149,7 +148,7 @@ func TestGroups(t *testing.T) {
149148
assert.NoError(t, err, "Both groups were present")
150149
p.CommitProposals()
151150

152-
mh.NewGroupMap = make(map[string]api.ValueProposer)
151+
mh.NewGroupMap = make(map[string]ValueProposer)
153152
_, err = p.BeginValueProposals([]string{"foo", "bar"})
154153
assert.NoError(t, err, "Should not have tried to recreate the groups")
155154
p.CommitProposals()

common/configvalues/root/root.go common/config/root.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ package config
1919
import (
2020
"fmt"
2121

22-
configvaluesapi "github.com/hyperledger/fabric/common/configvalues"
23-
"github.com/hyperledger/fabric/common/configvalues/msp"
22+
"github.com/hyperledger/fabric/common/config/msp"
2423
cb "github.com/hyperledger/fabric/protos/common"
2524
)
2625

@@ -32,7 +31,7 @@ type Root struct {
3231
mspConfigHandler *msp.MSPConfigHandler
3332
}
3433

35-
// NewRoot creates a new instance of the configvalues Root
34+
// NewRoot creates a new instance of the Root
3635
func NewRoot(mspConfigHandler *msp.MSPConfigHandler) *Root {
3736
return &Root{
3837
channel: NewChannelGroup(mspConfigHandler),
@@ -41,15 +40,15 @@ func NewRoot(mspConfigHandler *msp.MSPConfigHandler) *Root {
4140
}
4241

4342
// BeginValueProposals is used to start a new config proposal
44-
func (r *Root) BeginValueProposals(groups []string) ([]configvaluesapi.ValueProposer, error) {
43+
func (r *Root) BeginValueProposals(groups []string) ([]ValueProposer, error) {
4544
if len(groups) != 1 {
4645
return nil, fmt.Errorf("Root config only supports having one base group")
4746
}
4847
if groups[0] != ChannelGroupKey {
4948
return nil, fmt.Errorf("Root group must have channel")
5049
}
5150
r.mspConfigHandler.BeginConfig()
52-
return []configvaluesapi.ValueProposer{r.channel}, nil
51+
return []ValueProposer{r.channel}, nil
5352
}
5453

5554
// RollbackConfig is used to abandon a new config proposal

common/configvalues/root/root_test.go common/config/root_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package config
1919
import (
2020
"testing"
2121

22-
"github.com/hyperledger/fabric/common/configvalues/msp"
22+
"github.com/hyperledger/fabric/common/config/msp"
2323

2424
logging "github.com/op/go-logging"
2525
"github.com/stretchr/testify/assert"
File renamed without changes.

common/configtx/api/api.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ limitations under the License.
1717
package api
1818

1919
import (
20-
configvalues "github.com/hyperledger/fabric/common/configvalues"
21-
config "github.com/hyperledger/fabric/common/configvalues/root"
20+
"github.com/hyperledger/fabric/common/config"
2221
"github.com/hyperledger/fabric/common/policies"
2322
"github.com/hyperledger/fabric/msp"
2423
cb "github.com/hyperledger/fabric/protos/common"
@@ -52,13 +51,13 @@ type Resources interface {
5251
PolicyManager() policies.Manager
5352

5453
// ChannelConfig returns the ChannelConfig for the chain
55-
ChannelConfig() config.ChannelValues
54+
ChannelConfig() config.Channel
5655

5756
// OrdererConfig returns the configtxorderer.SharedConfig for the channel
58-
OrdererConfig() configvalues.Orderer
57+
OrdererConfig() config.Orderer
5958

6059
// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
61-
ApplicationConfig() configvalues.Application
60+
ApplicationConfig() config.Application
6261

6362
// MSPManager returns the msp.MSPManager for the chain
6463
MSPManager() msp.MSPManager
@@ -89,7 +88,7 @@ type PolicyHandler interface {
8988
// for single Handlers to handle multiple paths
9089
type Initializer interface {
9190
// ValueProposer return the root value proposer
92-
ValueProposer() configvalues.ValueProposer
91+
ValueProposer() config.ValueProposer
9392

9493
// PolicyProposer return the root policy proposer
9594
PolicyProposer() policies.Proposer

0 commit comments

Comments
 (0)