Skip to content

Commit 5761146

Browse files
author
Jason Yellick
committed
[FAB-6840] Consolidate configtxapi to configtx
Once upon a time, the configtx package did far too much. It exposed the channel configuration for each component, it handled transactional state for the policy manager, and the other transaction components, and generally became something that too many packages linked to. Because of all the different packages which linked to it, the interface definitions were factored out into their own package configtxapi. Since then, the vast majority of this function has been factored out into other more appropriate places, and there are no longer dependency cycles. This CR moves the interface definitions back into the package, and changes the rather generic 'configtx.Manager' name to 'configtx.Validator' (as its only purpose now is to validate configtx updates before generating a new configuration). This renaming ripples throughout a fair bit of the code, but should be reasonably easy to review. Change-Id: Icd8494fc727a2474fc28f15945da7d0548f49f23 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 5d410fe commit 5761146

30 files changed

+192
-289
lines changed

common/channelconfig/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package channelconfig
99
import (
1010
"time"
1111

12-
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
12+
"github.com/hyperledger/fabric/common/configtx"
1313
"github.com/hyperledger/fabric/common/policies"
1414
"github.com/hyperledger/fabric/msp"
1515
cb "github.com/hyperledger/fabric/protos/common"
@@ -139,8 +139,8 @@ type OrdererCapabilities interface {
139139
// Depending on whether chain is used at the orderer or at the peer, other
140140
// config resources may be available
141141
type Resources interface {
142-
// ConfigtxManager returns the configtx.Manager for the channel
143-
ConfigtxManager() configtxapi.Manager
142+
// ConfigtxValidator returns the configtx.Validator for the channel
143+
ConfigtxValidator() configtx.Validator
144144

145145
// PolicyManager returns the policies.Manager for the channel
146146
PolicyManager() policies.Manager

common/channelconfig/bundle.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package channelconfig
99
import (
1010
"github.com/hyperledger/fabric/common/cauthdsl"
1111
"github.com/hyperledger/fabric/common/configtx"
12-
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
1312
"github.com/hyperledger/fabric/common/flogging"
1413
"github.com/hyperledger/fabric/common/policies"
1514
"github.com/hyperledger/fabric/msp"
@@ -34,7 +33,7 @@ type Bundle struct {
3433
policyManager policies.Manager
3534
mspManager msp.MSPManager
3635
channelConfig *ChannelConfig
37-
configtxManager configtxapi.Manager
36+
configtxManager configtx.Validator
3837
}
3938

4039
// PolicyManager returns the policy manager constructed for this config
@@ -73,8 +72,8 @@ func (b *Bundle) ApplicationConfig() (Application, bool) {
7372
return result, result != nil
7473
}
7574

76-
// ConfigtxManager returns the configtx.Manager for the channel
77-
func (b *Bundle) ConfigtxManager() configtxapi.Manager {
75+
// ConfigtxValidator returns the configtx.Validator for the channel
76+
func (b *Bundle) ConfigtxValidator() configtx.Validator {
7877
return b.configtxManager
7978
}
8079

@@ -149,20 +148,6 @@ func (b *Bundle) ValidateNew(nb Resources) error {
149148
return nil
150149
}
151150

152-
type simpleProposer struct {
153-
policyManager policies.Manager
154-
}
155-
156-
// RootGroupKey returns RootGroupKey constant
157-
func (sp simpleProposer) RootGroupKey() string {
158-
return RootGroupKey
159-
}
160-
161-
// PolicyManager() returns the policy manager for considering config changes
162-
func (sp simpleProposer) PolicyManager() policies.Manager {
163-
return sp.policyManager
164-
}
165-
166151
// NewBundleFromEnvelope wraps the NewBundle function, extracting the needed
167152
// information from a full configtx
168153
func NewBundleFromEnvelope(env *cb.Envelope) (*Bundle, error) {
@@ -217,9 +202,7 @@ func NewBundle(channelID string, config *cb.Config) (*Bundle, error) {
217202
return nil, errors.Wrap(err, "initializing policymanager failed")
218203
}
219204

220-
configtxManager, err := configtx.NewManagerImpl(channelID, config, simpleProposer{
221-
policyManager: policyManager,
222-
})
205+
configtxManager, err := configtx.NewValidatorImpl(channelID, config, RootGroupKey, policyManager)
223206
if err != nil {
224207
return nil, errors.Wrap(err, "initializing configtx manager failed")
225208
}

common/channelconfig/bundlesource.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package channelconfig
99
import (
1010
"sync/atomic"
1111

12-
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
12+
"github.com/hyperledger/fabric/common/configtx"
1313
"github.com/hyperledger/fabric/common/policies"
1414
"github.com/hyperledger/fabric/msp"
1515
)
@@ -83,15 +83,15 @@ func (bs *BundleSource) ConsortiumsConfig() (Consortiums, bool) {
8383
return bs.StableBundle().ConsortiumsConfig()
8484
}
8585

86-
// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
86+
// ApplicationConfig returns the Application config for the channel
8787
// and whether the Application config exists
8888
func (bs *BundleSource) ApplicationConfig() (Application, bool) {
8989
return bs.StableBundle().ApplicationConfig()
9090
}
9191

92-
// ConfigtxManager returns the configtx.Manager for the channel
93-
func (bs *BundleSource) ConfigtxManager() configtxapi.Manager {
94-
return bs.StableBundle().ConfigtxManager()
92+
// ConfigtxValidator returns the configtx.Validator for the channel
93+
func (bs *BundleSource) ConfigtxValidator() configtx.Validator {
94+
return bs.StableBundle().ConfigtxValidator()
9595
}
9696

9797
// ValidateNew passes through to the current bundle

common/configtx/api/api.go renamed to common/configtx/configtx.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package api
7+
package configtx
88

99
import (
10-
"github.com/hyperledger/fabric/common/policies"
1110
cb "github.com/hyperledger/fabric/protos/common"
1211
)
1312

14-
// Manager provides a mechanism to query and update config
15-
type Manager interface {
13+
// Validator provides a mechanism to propose config updates, see the config update results
14+
// and validate the results of a config update.
15+
type Validator interface {
1616
// Validate attempts to apply a configtx to become the new config
1717
Validate(configEnv *cb.ConfigEnvelope) error
1818

@@ -28,13 +28,3 @@ type Manager interface {
2828
// Sequence returns the current sequence number of the config
2929
Sequence() uint64
3030
}
31-
32-
// Proposer contains the references necessary to appropriately unmarshal
33-
// a cb.ConfigGroup
34-
type Proposer interface {
35-
// RootGroupKey is the string to use to namespace the root group
36-
RootGroupKey() string
37-
38-
// PolicyManager() returns the policy manager for considering config changes
39-
PolicyManager() policies.Manager
40-
}

common/configtx/manager.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"fmt"
1111
"regexp"
1212

13-
"github.com/hyperledger/fabric/common/configtx/api"
1413
"github.com/hyperledger/fabric/common/flogging"
14+
"github.com/hyperledger/fabric/common/policies"
1515
cb "github.com/hyperledger/fabric/protos/common"
1616

1717
"github.com/golang/protobuf/proto"
@@ -37,9 +37,10 @@ type configSet struct {
3737
configProto *cb.Config
3838
}
3939

40-
type configManager struct {
41-
initializer api.Proposer
42-
current *configSet
40+
type ValidatorImpl struct {
41+
namespace string
42+
pm policies.Manager
43+
current *configSet
4344
}
4445

4546
// validateConfigID makes sure that the config element names (ie map key of
@@ -98,7 +99,7 @@ func validateChannelID(channelID string) error {
9899
return nil
99100
}
100101

101-
func NewManagerImpl(channelID string, config *cb.Config, initializer api.Proposer) (api.Manager, error) {
102+
func NewValidatorImpl(channelID string, config *cb.Config, namespace string, pm policies.Manager) (*ValidatorImpl, error) {
102103
if config == nil {
103104
return nil, fmt.Errorf("Nil config envelope Config")
104105
}
@@ -111,13 +112,14 @@ func NewManagerImpl(channelID string, config *cb.Config, initializer api.Propose
111112
return nil, fmt.Errorf("Bad channel id: %s", err)
112113
}
113114

114-
configMap, err := MapConfig(config.ChannelGroup, initializer.RootGroupKey())
115+
configMap, err := MapConfig(config.ChannelGroup, namespace)
115116
if err != nil {
116117
return nil, fmt.Errorf("Error converting config to map: %s", err)
117118
}
118119

119-
return &configManager{
120-
initializer: initializer,
120+
return &ValidatorImpl{
121+
namespace: namespace,
122+
pm: pm,
121123
current: &configSet{
122124
sequence: config.Sequence,
123125
configMap: configMap,
@@ -129,11 +131,11 @@ func NewManagerImpl(channelID string, config *cb.Config, initializer api.Propose
129131

130132
// ProposeConfigUpdate takes in an Envelope of type CONFIG_UPDATE and produces a
131133
// ConfigEnvelope to be used as the Envelope Payload Data of a CONFIG message
132-
func (cm *configManager) ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
134+
func (cm *ValidatorImpl) ProposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
133135
return cm.proposeConfigUpdate(configtx)
134136
}
135137

136-
func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
138+
func (cm *ValidatorImpl) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigEnvelope, error) {
137139
configUpdateEnv, err := envelopeToConfigUpdate(configtx)
138140
if err != nil {
139141
return nil, fmt.Errorf("Error converting envelope to config update: %s", err)
@@ -144,7 +146,7 @@ func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigE
144146
return nil, fmt.Errorf("Error authorizing update: %s", err)
145147
}
146148

147-
channelGroup, err := configMapToConfig(configMap, cm.initializer.RootGroupKey())
149+
channelGroup, err := configMapToConfig(configMap, cm.namespace)
148150
if err != nil {
149151
return nil, fmt.Errorf("Could not turn configMap back to channelGroup: %s", err)
150152
}
@@ -159,7 +161,7 @@ func (cm *configManager) proposeConfigUpdate(configtx *cb.Envelope) (*cb.ConfigE
159161
}
160162

161163
// Validate simulates applying a ConfigEnvelope to become the new config
162-
func (cm *configManager) Validate(configEnv *cb.ConfigEnvelope) error {
164+
func (cm *ValidatorImpl) Validate(configEnv *cb.ConfigEnvelope) error {
163165
if configEnv == nil {
164166
return fmt.Errorf("config envelope is nil")
165167
}
@@ -182,7 +184,7 @@ func (cm *configManager) Validate(configEnv *cb.ConfigEnvelope) error {
182184
return err
183185
}
184186

185-
channelGroup, err := configMapToConfig(configMap, cm.initializer.RootGroupKey())
187+
channelGroup, err := configMapToConfig(configMap, cm.namespace)
186188
if err != nil {
187189
return fmt.Errorf("Could not turn configMap back to channelGroup: %s", err)
188190
}
@@ -196,16 +198,16 @@ func (cm *configManager) Validate(configEnv *cb.ConfigEnvelope) error {
196198
}
197199

198200
// ChainID retrieves the chain ID associated with this manager
199-
func (cm *configManager) ChainID() string {
201+
func (cm *ValidatorImpl) ChainID() string {
200202
return cm.current.channelID
201203
}
202204

203205
// Sequence returns the current sequence number of the config
204-
func (cm *configManager) Sequence() uint64 {
206+
func (cm *ValidatorImpl) Sequence() uint64 {
205207
return cm.current.sequence
206208
}
207209

208210
// ConfigEnvelope returns the current config envelope
209-
func (cm *configManager) ConfigProto() *cb.Config {
211+
func (cm *ValidatorImpl) ConfigProto() *cb.Config {
210212
return cm.current.configProto
211213
}

0 commit comments

Comments
 (0)