Skip to content

Commit 417eccb

Browse files
author
Jason Yellick
committed
[FAB-2130] Initialize configtx Handlers together
https://jira.hyperledger.org/browse/FAB-2130 Now that the assorted configtx Handlers have been consolidated, the piecemeal instantiation across peer/orderer is no longer necessary and all components can be instantiated together. This is needed in preparation of the pending configtx overhaul. Change-Id: Ie3a607d38cbaea75cd6497666a12ed6664c52af2 Signed-off-by: Jason Yellick <[email protected]>
1 parent 4ae2508 commit 417eccb

File tree

6 files changed

+63
-27
lines changed

6 files changed

+63
-27
lines changed

common/configtx/api/api.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,22 @@ type Manager interface {
105105
Sequence() uint64
106106
}
107107

108-
// Resources is the common set of config resources for all chains
108+
// Resources is the common set of config resources for all channels
109109
// Depending on whether chain is used at the orderer or at the peer, other
110110
// config resources may be available
111111
type Resources interface {
112-
// PolicyManager returns the policies.Manager for the chain
112+
// PolicyManager returns the policies.Manager for the channel
113113
PolicyManager() policies.Manager
114114

115115
// ChannelConfig returns the ChannelConfig for the chain
116116
ChannelConfig() ChannelConfig
117117

118+
// OrdererConfig returns the configtxorderer.SharedConfig for the channel
119+
OrdererConfig() OrdererConfig
120+
121+
// ApplicationConfig returns the configtxapplication.SharedConfig for the channel
122+
ApplicationConfig() ApplicationConfig
123+
118124
// MSPManager returns the msp.MSPManager for the chain
119125
MSPManager() msp.MSPManager
120126
}

common/configtx/handlers/application/template_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package application
17+
package application_test
1818

1919
import (
2020
"testing"
2121

22+
. "github.com/hyperledger/fabric/common/configtx/handlers/application"
2223
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
2324
)
2425

common/configtx/resources.go

+32-10
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ package configtx
1919
import (
2020
"github.com/hyperledger/fabric/common/cauthdsl"
2121
"github.com/hyperledger/fabric/common/configtx/api"
22-
"github.com/hyperledger/fabric/common/configtx/handlers/channel"
22+
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
23+
configtxchannel "github.com/hyperledger/fabric/common/configtx/handlers/channel"
2324
configtxmsp "github.com/hyperledger/fabric/common/configtx/handlers/msp"
25+
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
2426
"github.com/hyperledger/fabric/common/policies"
2527
"github.com/hyperledger/fabric/msp"
2628
cb "github.com/hyperledger/fabric/protos/common"
2729
)
2830

2931
type resources struct {
30-
handlers map[cb.ConfigItem_ConfigType]api.Handler
31-
policyManager policies.Manager
32-
channelConfig api.ChannelConfig
33-
mspConfigHandler *configtxmsp.MSPConfigHandler
32+
handlers map[cb.ConfigItem_ConfigType]api.Handler
33+
policyManager policies.Manager
34+
channelConfig api.ChannelConfig
35+
ordererConfig api.OrdererConfig
36+
applicationConfig api.ApplicationConfig
37+
mspConfigHandler *configtxmsp.MSPConfigHandler
3438
}
3539

3640
// PolicyManager returns the policies.Manager for the chain
@@ -43,6 +47,16 @@ func (r *resources) ChannelConfig() api.ChannelConfig {
4347
return r.channelConfig
4448
}
4549

50+
// OrdererConfig returns the api.OrdererConfig for the chain
51+
func (r *resources) OrdererConfig() api.OrdererConfig {
52+
return r.ordererConfig
53+
}
54+
55+
// ApplicationConfig returns the api.ApplicationConfig for the chain
56+
func (r *resources) ApplicationConfig() api.ApplicationConfig {
57+
return r.applicationConfig
58+
}
59+
4660
// MSPManager returns the msp.MSPManager for the chain
4761
func (r *resources) MSPManager() msp.MSPManager {
4862
return r.mspConfigHandler
@@ -70,14 +84,20 @@ func NewInitializer() api.Initializer {
7084
}
7185

7286
policyManager := policies.NewManagerImpl(policyProviderMap)
73-
channelConfig := channel.NewSharedConfigImpl()
87+
channelConfig := configtxchannel.NewSharedConfigImpl()
88+
ordererConfig := configtxorderer.NewManagerImpl()
89+
applicationConfig := configtxapplication.NewSharedConfigImpl()
7490
handlers := make(map[cb.ConfigItem_ConfigType]api.Handler)
7591

7692
for ctype := range cb.ConfigItem_ConfigType_name {
7793
rtype := cb.ConfigItem_ConfigType(ctype)
7894
switch rtype {
7995
case cb.ConfigItem_CHAIN:
8096
handlers[rtype] = channelConfig
97+
case cb.ConfigItem_ORDERER:
98+
handlers[rtype] = ordererConfig
99+
case cb.ConfigItem_PEER:
100+
handlers[rtype] = applicationConfig
81101
case cb.ConfigItem_POLICY:
82102
handlers[rtype] = policyManager
83103
case cb.ConfigItem_MSP:
@@ -88,9 +108,11 @@ func NewInitializer() api.Initializer {
88108
}
89109

90110
return &resources{
91-
handlers: handlers,
92-
policyManager: policyManager,
93-
channelConfig: channelConfig,
94-
mspConfigHandler: mspConfigHandler,
111+
handlers: handlers,
112+
policyManager: policyManager,
113+
channelConfig: channelConfig,
114+
ordererConfig: ordererConfig,
115+
applicationConfig: applicationConfig,
116+
mspConfigHandler: mspConfigHandler,
95117
}
96118
}

common/mocks/configtx/configtx.go

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ type Initializer struct {
3333
// ChannelConfigVal is returned as the result of ChannelConfig()
3434
ChannelConfigVal configtxapi.ChannelConfig
3535

36+
// OrdererConfigVal is returned as the result of OrdererConfig()
37+
OrdererConfigVal configtxapi.OrdererConfig
38+
39+
// ApplicationConfigVal is returned as the result of ApplicationConfig()
40+
ApplicationConfigVal configtxapi.ApplicationConfig
41+
3642
// MSPManagerVal is returned as the result of MSPManager()
3743
MSPManagerVal msp.MSPManager
3844
}
@@ -52,6 +58,16 @@ func (i *Initializer) ChannelConfig() configtxapi.ChannelConfig {
5258
return i.ChannelConfigVal
5359
}
5460

61+
// Returns the OrdererConfigVal
62+
func (i *Initializer) OrdererConfig() configtxapi.OrdererConfig {
63+
return i.OrdererConfigVal
64+
}
65+
66+
// Returns the ApplicationConfigVal
67+
func (i *Initializer) ApplicationConfig() configtxapi.ApplicationConfig {
68+
return i.ApplicationConfigVal
69+
}
70+
5571
// Returns the MSPManagerVal
5672
func (i *Initializer) MSPManager() msp.MSPManager {
5773
return i.MSPManagerVal

core/peer/peer.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/hyperledger/fabric/common/configtx"
2626
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
27-
configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application"
2827
"github.com/hyperledger/fabric/core/comm"
2928
"github.com/hyperledger/fabric/core/committer"
3029
"github.com/hyperledger/fabric/core/committer/txvalidator"
@@ -160,19 +159,17 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
160159
return err
161160
}
162161

163-
sharedConfigHandler := configtxapplication.NewSharedConfigImpl()
162+
configtxInitializer := configtx.NewInitializer()
164163

165164
gossipEventer := service.GetGossipService().NewConfigEventer()
166165

167166
gossipCallbackWrapper := func(cm configtxapi.Manager) {
168167
gossipEventer.ProcessConfigUpdate(&chainSupport{
169168
Manager: cm,
170-
ApplicationConfig: sharedConfigHandler,
169+
ApplicationConfig: configtxInitializer.ApplicationConfig(),
171170
})
172171
}
173172

174-
configtxInitializer := configtx.NewInitializer()
175-
configtxInitializer.Handlers()[common.ConfigItem_PEER] = sharedConfigHandler
176173
configtxManager, err := configtx.NewManagerImplNext(
177174
configEnvelope,
178175
configtxInitializer,
@@ -187,7 +184,7 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error {
187184

188185
cs := &chainSupport{
189186
Manager: configtxManager,
190-
ApplicationConfig: sharedConfigHandler,
187+
ApplicationConfig: configtxManager.ApplicationConfig(), // TODO, refactor as this is accessible through Manager
191188
ledger: ledger,
192189
}
193190

orderer/multichain/manager.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/hyperledger/fabric/common/configtx"
2323
configtxapi "github.com/hyperledger/fabric/common/configtx/api"
24-
configtxorderer "github.com/hyperledger/fabric/common/configtx/handlers/orderer"
2524
ordererledger "github.com/hyperledger/fabric/orderer/ledger"
2625
cb "github.com/hyperledger/fabric/protos/common"
2726
"github.com/hyperledger/fabric/protos/utils"
@@ -46,11 +45,10 @@ type Manager interface {
4645

4746
type configResources struct {
4847
configtxapi.Manager
49-
sharedConfig configtxapi.OrdererConfig
5048
}
5149

5250
func (cr *configResources) SharedConfig() configtxapi.OrdererConfig {
53-
return cr.sharedConfig
51+
return cr.OrdererConfig()
5452
}
5553

5654
type ledgerResources struct {
@@ -148,18 +146,14 @@ func (ml *multiLedger) GetChain(chainID string) (ChainSupport, bool) {
148146
}
149147

150148
func newConfigResources(configEnvelope *cb.ConfigEnvelope) (*configResources, error) {
151-
sharedConfigManager := configtxorderer.NewManagerImpl()
152149
initializer := configtx.NewInitializer()
153-
initializer.Handlers()[cb.ConfigItem_ORDERER] = sharedConfigManager
154-
155150
configManager, err := configtx.NewManagerImplNext(configEnvelope, initializer, nil)
156151
if err != nil {
157152
return nil, fmt.Errorf("Error unpacking config transaction: %s", err)
158153
}
159154

160155
return &configResources{
161-
Manager: configManager,
162-
sharedConfig: sharedConfigManager,
156+
Manager: configManager,
163157
}, nil
164158
}
165159

0 commit comments

Comments
 (0)