Skip to content

Commit fee7c6c

Browse files
author
Jason Yellick
committed
[FAB-2312] configtx value handlers to own package
https://jira.hyperledger.org/browse/FAB-2312 There used to be a single type for configuration, 'ConfigItem', but that has bifurcated into 'ConfigValue', 'ConfigGroup', and 'ConfigPolicy'. In order to handle the 'ConfigValue' and the 'ConfigPolicy' in similar ways, the 'ConfigValue' handling needs to be pushed out into its own package just like policy handling is. This CR accomplishes that. This is in preparation for treating the PolicyHandler as more of a first class object and to eliminate the need for hacky importing. Change-Id: I690a33e09843eb4c29611319f2e3942baae2dfdb Signed-off-by: Jason Yellick <[email protected]>
1 parent 3b9cc55 commit fee7c6c

Some content is hidden

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

48 files changed

+419
-380
lines changed

common/cauthdsl/policy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func addPolicy(manager *policies.ManagerImpl, id string, policy *cb.Policy) {
6464
if err != nil {
6565
panic(err)
6666
}
67-
manager.CommitConfig()
67+
manager.CommitProposals()
6868
}
6969

7070
func providerMap() map[int32]policies.Provider {

common/configtx/api/api.go

+15-85
Original file line numberDiff line numberDiff line change
@@ -17,87 +17,12 @@ limitations under the License.
1717
package api
1818

1919
import (
20-
"time"
21-
20+
configvalues "github.com/hyperledger/fabric/common/configvalues/api"
2221
"github.com/hyperledger/fabric/common/policies"
2322
"github.com/hyperledger/fabric/msp"
2423
cb "github.com/hyperledger/fabric/protos/common"
25-
ab "github.com/hyperledger/fabric/protos/orderer"
26-
pb "github.com/hyperledger/fabric/protos/peer"
2724
)
2825

29-
// ChannelConfig stores the common channel config
30-
type ChannelConfig interface {
31-
// HashingAlgorithm returns the default algorithm to be used when hashing
32-
// such as computing block hashes, and CreationPolicy digests
33-
HashingAlgorithm() func(input []byte) []byte
34-
35-
// BlockDataHashingStructureWidth returns the width to use when constructing the
36-
// Merkle tree to compute the BlockData hash
37-
BlockDataHashingStructureWidth() uint32
38-
39-
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
40-
OrdererAddresses() []string
41-
}
42-
43-
type OrgConfig interface {
44-
// Name returns the name this org is referred to in config
45-
Name() string
46-
47-
// MSPID returns the MSP ID associated with this org
48-
MSPID() string
49-
}
50-
51-
// ApplicationOrgConfig stores the per org application config
52-
type ApplicationOrgConfig interface {
53-
OrgConfig
54-
55-
// AnchorPeers returns the list of gossip anchor peers
56-
AnchorPeers() []*pb.AnchorPeer
57-
}
58-
59-
// ApplicationConfig stores the common shared application config
60-
type ApplicationConfig interface {
61-
// Organizations returns a map of org ID to ApplicationOrgConfig
62-
Organizations() map[string]ApplicationOrgConfig
63-
}
64-
65-
// OrdererConfig stores the common shared orderer config
66-
type OrdererConfig interface {
67-
// ConsensusType returns the configured consensus type
68-
ConsensusType() string
69-
70-
// BatchSize returns the maximum number of messages to include in a block
71-
BatchSize() *ab.BatchSize
72-
73-
// BatchTimeout returns the amount of time to wait before creating a batch
74-
BatchTimeout() time.Duration
75-
76-
// ChainCreationPolicyNames returns the policy names which are allowed for chain creation
77-
// This field is only set for the system ordering chain
78-
ChainCreationPolicyNames() []string
79-
80-
// KafkaBrokers returns the addresses (IP:port notation) of a set of "bootstrap"
81-
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
82-
// used for ordering
83-
KafkaBrokers() []string
84-
85-
// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
86-
IngressPolicyNames() []string
87-
88-
// EgressPolicyNames returns the name of the policy to validate incoming broadcast messages against
89-
EgressPolicyNames() []string
90-
}
91-
92-
// Handler provides a hook which allows other pieces of code to participate in config proposals
93-
// TODO, this should probably be renamed to ValueHandler
94-
type Handler interface {
95-
Transactional
96-
97-
// ProposeConfig called when config is added to a proposal
98-
ProposeConfig(key string, configValue *cb.ConfigValue) error
99-
}
100-
10126
// Manager provides a mechanism to query and update config
10227
type Manager interface {
10328
Resources
@@ -126,41 +51,46 @@ type Resources interface {
12651
PolicyManager() policies.Manager
12752

12853
// ChannelConfig returns the ChannelConfig for the chain
129-
ChannelConfig() ChannelConfig
54+
ChannelConfig() configvalues.Channel
13055

13156
// OrdererConfig returns the configtxorderer.SharedConfig for the channel
132-
OrdererConfig() OrdererConfig
57+
OrdererConfig() configvalues.Orderer
13358

13459
// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
135-
ApplicationConfig() ApplicationConfig
60+
ApplicationConfig() configvalues.Application
13661

13762
// MSPManager returns the msp.MSPManager for the chain
13863
MSPManager() msp.MSPManager
13964
}
14065

14166
// Transactional is an interface which allows for an update to be proposed and rolled back
14267
type Transactional interface {
143-
// BeginConfig called when a config proposal is begun
144-
BeginConfig(groups []string) ([]Handler, error)
145-
14668
// RollbackConfig called when a config proposal is abandoned
147-
RollbackConfig()
69+
RollbackProposals()
14870

14971
// CommitConfig called when a config proposal is committed
150-
CommitConfig()
72+
CommitProposals()
15173
}
15274

15375
// PolicyHandler is used for config updates to policy
15476
type PolicyHandler interface {
15577
Transactional
15678

79+
BeginConfig(groups []string) ([]PolicyHandler, error)
80+
15781
ProposePolicy(key string, path []string, policy *cb.ConfigPolicy) error
15882
}
15983

16084
// Initializer is used as indirection between Manager and Handler to allow
16185
// for single Handlers to handle multiple paths
16286
type Initializer interface {
163-
Handler
87+
// ProposeValue is used for propsing group values
88+
ProposeValue(key string, configValue *cb.ConfigValue) error
89+
90+
// BeginValueProposals is called when a config proposal is begun
91+
BeginValueProposals(groups []string) ([]configvalues.ValueProposer, error)
92+
93+
Transactional
16494

16595
Resources
16696

common/configtx/config.go

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

2222
"github.com/hyperledger/fabric/common/configtx/api"
23+
configvaluesapi "github.com/hyperledger/fabric/common/configvalues/api"
2324
cb "github.com/hyperledger/fabric/protos/common"
2425
)
2526

@@ -32,21 +33,21 @@ func (cr *configResult) commit() {
3233
for _, subResult := range cr.subResults {
3334
subResult.commit()
3435
}
35-
cr.handler.CommitConfig()
36+
cr.handler.CommitProposals()
3637
}
3738

3839
func (cr *configResult) rollback() {
3940
for _, subResult := range cr.subResults {
4041
subResult.rollback()
4142
}
42-
cr.handler.RollbackConfig()
43+
cr.handler.RollbackProposals()
4344
}
4445

4546
// proposeGroup proposes a group configuration with a given handler
4647
// it will in turn recursively call itself until all groups have been exhausted
4748
// at each call, it returns the handler that was passed in, plus any handlers returned
4849
// by recursive calls into proposeGroup
49-
func (cm *configManager) proposeGroup(name string, group *cb.ConfigGroup, handler api.Handler) (*configResult, error) {
50+
func (cm *configManager) proposeGroup(name string, group *cb.ConfigGroup, handler configvaluesapi.ValueProposer) (*configResult, error) {
5051
subGroups := make([]string, len(group.Groups))
5152
i := 0
5253
for subGroup := range group.Groups {
@@ -55,7 +56,7 @@ func (cm *configManager) proposeGroup(name string, group *cb.ConfigGroup, handle
5556
}
5657

5758
logger.Debugf("Beginning new config for channel %s and group %s", cm.chainID, name)
58-
subHandlers, err := handler.BeginConfig(subGroups)
59+
subHandlers, err := handler.BeginValueProposals(subGroups)
5960
if err != nil {
6061
return nil, err
6162
}
@@ -79,7 +80,7 @@ func (cm *configManager) proposeGroup(name string, group *cb.ConfigGroup, handle
7980
}
8081

8182
for key, value := range group.Values {
82-
if err := handler.ProposeConfig(key, value); err != nil {
83+
if err := handler.ProposeValue(key, value); err != nil {
8384
result.rollback()
8485
return nil, err
8586
}
@@ -94,7 +95,7 @@ func (cm *configManager) proposePolicies(rootGroup *cb.ConfigGroup) (*configResu
9495
for key, policy := range rootGroup.Policies {
9596
logger.Debugf("Proposing policy: %s", key)
9697
if err := cm.initializer.PolicyHandler().ProposePolicy(key, []string{RootGroupKey}, policy); err != nil {
97-
cm.initializer.PolicyHandler().RollbackConfig()
98+
cm.initializer.PolicyHandler().RollbackProposals()
9899
return nil, err
99100
}
100101
}

common/configtx/initializer.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121

2222
"github.com/hyperledger/fabric/common/cauthdsl"
2323
"github.com/hyperledger/fabric/common/configtx/api"
24-
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
25-
configtxchannel "github.com/hyperledger/fabric/common/configtx/handlers/channel"
26-
configtxmsp "github.com/hyperledger/fabric/common/configtx/handlers/msp"
27-
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
24+
configvaluesapi "github.com/hyperledger/fabric/common/configvalues/api"
25+
configtxchannel "github.com/hyperledger/fabric/common/configvalues/channel"
26+
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
27+
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
28+
configtxmsp "github.com/hyperledger/fabric/common/configvalues/msp"
2829
"github.com/hyperledger/fabric/common/policies"
2930
"github.com/hyperledger/fabric/msp"
3031
cb "github.com/hyperledger/fabric/protos/common"
@@ -44,17 +45,17 @@ func (r *resources) PolicyManager() policies.Manager {
4445
}
4546

4647
// ChannelConfig returns the api.ChannelConfig for the chain
47-
func (r *resources) ChannelConfig() api.ChannelConfig {
48+
func (r *resources) ChannelConfig() configvaluesapi.Channel {
4849
return r.channelConfig
4950
}
5051

5152
// OrdererConfig returns the api.OrdererConfig for the chain
52-
func (r *resources) OrdererConfig() api.OrdererConfig {
53+
func (r *resources) OrdererConfig() configvaluesapi.Orderer {
5354
return r.ordererConfig
5455
}
5556

5657
// ApplicationConfig returns the api.ApplicationConfig for the chain
57-
func (r *resources) ApplicationConfig() api.ApplicationConfig {
58+
func (r *resources) ApplicationConfig() configvaluesapi.Application {
5859
return r.applicationConfig
5960
}
6061

@@ -104,35 +105,35 @@ func NewInitializer() api.Initializer {
104105
}
105106
}
106107

107-
// BeginConfig is used to start a new config proposal
108-
func (i *initializer) BeginConfig(groups []string) ([]api.Handler, error) {
108+
// BeginValueProposals is used to start a new config proposal
109+
func (i *initializer) BeginValueProposals(groups []string) ([]configvaluesapi.ValueProposer, error) {
109110
if len(groups) != 1 {
110111
logger.Panicf("Initializer only supports having one root group")
111112
}
112113
i.mspConfigHandler.BeginConfig()
113-
return []api.Handler{i.channelConfig}, nil
114+
return []configvaluesapi.ValueProposer{i.channelConfig}, nil
114115
}
115116

116117
// RollbackConfig is used to abandon a new config proposal
117-
func (i *initializer) RollbackConfig() {
118-
i.mspConfigHandler.RollbackConfig()
118+
func (i *initializer) RollbackProposals() {
119+
i.mspConfigHandler.RollbackProposals()
119120
}
120121

121122
// CommitConfig is used to commit a new config proposal
122-
func (i *initializer) CommitConfig() {
123-
i.mspConfigHandler.CommitConfig()
123+
func (i *initializer) CommitProposals() {
124+
i.mspConfigHandler.CommitProposals()
124125
}
125126

126127
type importHack struct {
127128
*policies.ManagerImpl
128129
}
129130

130-
func (ih importHack) BeginConfig(groups []string) ([]api.Handler, error) {
131+
func (ih importHack) BeginConfig(groups []string) ([]api.PolicyHandler, error) {
131132
policyManagers, err := ih.ManagerImpl.BeginConfig(groups)
132133
if err != nil {
133134
return nil, err
134135
}
135-
handlers := make([]api.Handler, len(policyManagers))
136+
handlers := make([]api.PolicyHandler, len(policyManagers))
136137
for i, policyManager := range policyManagers {
137138
handlers[i] = &importHack{ManagerImpl: policyManager}
138139
}
@@ -147,6 +148,6 @@ func (i *initializer) PolicyHandler() api.PolicyHandler {
147148
return importHack{ManagerImpl: i.policyManager}
148149
}
149150

150-
func (i *initializer) ProposeConfig(key string, value *cb.ConfigValue) error {
151+
func (i *initializer) ProposeValue(key string, value *cb.ConfigValue) error {
151152
return fmt.Errorf("Programming error, this should never be invoked")
152153
}

common/configtx/template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package configtx
1818

1919
import (
20-
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
20+
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
2121
"github.com/hyperledger/fabric/common/util"
2222
cb "github.com/hyperledger/fabric/protos/common"
2323
ab "github.com/hyperledger/fabric/protos/orderer"

common/configtx/template_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/golang/protobuf/proto"
24-
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
24+
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
2525
cb "github.com/hyperledger/fabric/protos/common"
2626
ab "github.com/hyperledger/fabric/protos/orderer"
2727

common/configtx/test/helper.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
"path/filepath"
2222

2323
"github.com/hyperledger/fabric/common/configtx"
24-
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
25-
configtxmsp "github.com/hyperledger/fabric/common/configtx/handlers/msp"
26-
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
2724
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2825
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
26+
configtxapplication "github.com/hyperledger/fabric/common/configvalues/channel/application"
27+
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
28+
configtxmsp "github.com/hyperledger/fabric/common/configvalues/msp"
2929
"github.com/hyperledger/fabric/common/genesis"
3030
"github.com/hyperledger/fabric/msp"
3131
cb "github.com/hyperledger/fabric/protos/common"

common/configtx/tool/provisional/provisional.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121

2222
"github.com/hyperledger/fabric/common/cauthdsl"
2323
"github.com/hyperledger/fabric/common/configtx"
24-
configtxchannel "github.com/hyperledger/fabric/common/configtx/handlers/channel"
25-
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
2624
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
25+
configtxchannel "github.com/hyperledger/fabric/common/configvalues/channel"
26+
configtxorderer "github.com/hyperledger/fabric/common/configvalues/channel/orderer"
2727
"github.com/hyperledger/fabric/common/genesis"
2828
"github.com/hyperledger/fabric/orderer/common/bootstrap"
2929
cb "github.com/hyperledger/fabric/protos/common"

0 commit comments

Comments
 (0)