Skip to content

Commit 63e54d1

Browse files
author
Jason Yellick
committed
[FAB-2151] Migrate orderer config to ConfigGroup
https://jira.hyperledger.org/browse/FAB-2151 The ConfigItem is deprecated and pending removal. This CR migrates the orderer configuration from this deprecated format to the new ConfigGroup format. Change-Id: Ic43bed7066e2fe8f1e092cf646db259fbe25ffb4 Signed-off-by: Jason Yellick <[email protected]>
1 parent ca44f11 commit 63e54d1

File tree

6 files changed

+72
-93
lines changed

6 files changed

+72
-93
lines changed

common/configtx/handlers/application/sharedconfig.go

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import (
2828
"github.com/op/go-logging"
2929
)
3030

31+
const (
32+
// GroupKey is the group name for the Application config
33+
GroupKey = "Application"
34+
)
35+
3136
var orgSchema = &cb.ConfigGroupSchema{
3237
Groups: map[string]*cb.ConfigGroupSchema{},
3338
Values: map[string]*cb.ConfigValueSchema{

common/configtx/handlers/channel/sharedconfig.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,10 @@ import (
3030
"github.com/op/go-logging"
3131
)
3232

33-
const (
34-
// ApplicationGroupKey is the group name for the application config
35-
ApplicationGroupKey = "Application"
36-
37-
// OrdererGroupKey is the group name for the orderer config
38-
OrdererGroupKey = "Orderer"
39-
)
40-
4133
var Schema = &cb.ConfigGroupSchema{
4234
Groups: map[string]*cb.ConfigGroupSchema{
43-
ApplicationGroupKey: application.Schema,
44-
OrdererGroupKey: orderer.Schema,
35+
application.GroupKey: application.Schema,
36+
orderer.GroupKey: orderer.Schema,
4537
},
4638
Values: map[string]*cb.ConfigValueSchema{
4739
HashingAlgorithmKey: nil,
@@ -181,9 +173,9 @@ func (pm *SharedConfigImpl) Handler(path []string) (api.Handler, error) {
181173
var initializer api.SubInitializer
182174

183175
switch path[0] {
184-
case ApplicationGroupKey:
176+
case application.GroupKey:
185177
initializer = pm.applicationConfig
186-
case OrdererGroupKey:
178+
case orderer.GroupKey:
187179
initializer = pm.ordererConfig
188180
default:
189181
return nil, fmt.Errorf("Disallowed channel group: %s", path[0])

common/configtx/handlers/orderer/sharedconfig.go

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ import (
3232
"github.com/op/go-logging"
3333
)
3434

35+
const (
36+
// GroupKey is the group name for the orderer config
37+
GroupKey = "Orderer"
38+
)
39+
3540
var orgSchema = &cb.ConfigGroupSchema{
3641
Groups: map[string]*cb.ConfigGroupSchema{},
3742
Values: map[string]*cb.ConfigValueSchema{

common/configtx/handlers/orderer/sharedconfig_test.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ func invalidMessage() *cb.ConfigValue {
4141
}
4242
}
4343

44-
// A temporary method while ConfigItem is being deprecated
45-
func itemToValue(configItem *cb.ConfigItem) (string, *cb.ConfigValue) {
46-
return configItem.Key, &cb.ConfigValue{Value: configItem.Value}
44+
func groupToKeyValue(configGroup *cb.ConfigGroup) (string, *cb.ConfigValue) {
45+
for key, value := range configGroup.Groups[GroupKey].Values {
46+
return key, value
47+
}
48+
panic("No value encoded")
4749
}
4850

4951
func doesFuncCrash(crasher func(), test string) bool {
@@ -102,7 +104,7 @@ func TestConsensusType(t *testing.T) {
102104
m := NewManagerImpl(nil)
103105
m.BeginConfig()
104106

105-
err := m.ProposeConfig(itemToValue(validMessage))
107+
err := m.ProposeConfig(groupToKeyValue(validMessage))
106108
if err != nil {
107109
t.Fatalf("Error applying valid config: %s", err)
108110
}
@@ -115,12 +117,12 @@ func TestConsensusType(t *testing.T) {
115117
t.Fatalf("Should have failed on invalid message")
116118
}
117119

118-
err = m.ProposeConfig(itemToValue(validMessage))
120+
err = m.ProposeConfig(groupToKeyValue(validMessage))
119121
if err != nil {
120122
t.Fatalf("Error re-applying valid config: %s", err)
121123
}
122124

123-
err = m.ProposeConfig(itemToValue(otherValidMessage))
125+
err = m.ProposeConfig(groupToKeyValue(otherValidMessage))
124126
if err == nil {
125127
t.Fatalf("Should not have applied config with different consensus type after it was initially set")
126128
}
@@ -142,7 +144,7 @@ func TestBatchSize(t *testing.T) {
142144
m := NewManagerImpl(nil)
143145
m.BeginConfig()
144146
err := m.ProposeConfig(
145-
itemToValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validPreferredMaxBytes})),
147+
groupToKeyValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validPreferredMaxBytes})),
146148
)
147149
assert.Nil(t, err, "Error applying valid config: %s", err)
148150
m.CommitConfig()
@@ -168,23 +170,23 @@ func TestBatchSize(t *testing.T) {
168170
t.Run("ZeroMaxMessageCount", func(t *testing.T) {
169171
m := NewManagerImpl(nil)
170172
m.BeginConfig()
171-
err := m.ProposeConfig(itemToValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: 0, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validPreferredMaxBytes})))
173+
err := m.ProposeConfig(groupToKeyValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: 0, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validPreferredMaxBytes})))
172174
assert.NotNil(t, err, "Should have rejected batch size max message count of 0")
173175
m.CommitConfig()
174176
})
175177

176178
t.Run("ZeroAbsoluteMaxBytes", func(t *testing.T) {
177179
m := NewManagerImpl(nil)
178180
m.BeginConfig()
179-
err := m.ProposeConfig(itemToValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: 0, PreferredMaxBytes: validPreferredMaxBytes})))
181+
err := m.ProposeConfig(groupToKeyValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: 0, PreferredMaxBytes: validPreferredMaxBytes})))
180182
assert.NotNil(t, err, "Should have rejected batch size absolute max message bytes of 0")
181183
m.CommitConfig()
182184
})
183185

184186
t.Run("TooLargePreferredMaxBytes", func(t *testing.T) {
185187
m := NewManagerImpl(nil)
186188
m.BeginConfig()
187-
err := m.ProposeConfig(itemToValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validAbsoluteMaxBytes + 1})))
189+
err := m.ProposeConfig(groupToKeyValue(TemplateBatchSize(&ab.BatchSize{MaxMessageCount: validMaxMessageCount, AbsoluteMaxBytes: validAbsoluteMaxBytes, PreferredMaxBytes: validAbsoluteMaxBytes + 1})))
188190
assert.NotNil(t, err, "Should have rejected batch size preferred max message bytes greater than absolute max message bytes")
189191
m.CommitConfig()
190192
})
@@ -200,7 +202,7 @@ func TestBatchTimeout(t *testing.T) {
200202
m := NewManagerImpl(nil)
201203
m.BeginConfig()
202204

203-
err := m.ProposeConfig(itemToValue(validMessage))
205+
err := m.ProposeConfig(groupToKeyValue(validMessage))
204206
if err != nil {
205207
t.Fatalf("Error applying valid config: %s", err)
206208
}
@@ -210,12 +212,12 @@ func TestBatchTimeout(t *testing.T) {
210212
t.Fatalf("Should have failed on invalid message")
211213
}
212214

213-
err = m.ProposeConfig(itemToValue(negativeBatchTimeout))
215+
err = m.ProposeConfig(groupToKeyValue(negativeBatchTimeout))
214216
if err == nil {
215217
t.Fatalf("Should have rejected negative batch timeout: %s", err)
216218
}
217219

218-
err = m.ProposeConfig(itemToValue(zeroBatchTimeout))
220+
err = m.ProposeConfig(groupToKeyValue(zeroBatchTimeout))
219221
if err == nil {
220222
t.Fatalf("Should have rejected batch timeout of 0")
221223
}
@@ -233,7 +235,7 @@ func TestKafkaBrokers(t *testing.T) {
233235
invalidMessage := invalidMessage()
234236
zeroBrokers := TemplateKafkaBrokers([]string{})
235237
badList := []string{"127.0.0.1", "foo.bar", "127.0.0.1:-1", "localhost:65536", "foo.bar.:9092", ".127.0.0.1:9092", "-foo.bar:9092"}
236-
badMessages := []*cb.ConfigItem{}
238+
badMessages := []*cb.ConfigGroup{}
237239
for _, badAddress := range badList {
238240
badMessages = append(badMessages, TemplateKafkaBrokers([]string{badAddress}))
239241
}
@@ -243,7 +245,7 @@ func TestKafkaBrokers(t *testing.T) {
243245
m := NewManagerImpl(nil)
244246
m.BeginConfig()
245247

246-
err := m.ProposeConfig(itemToValue(validMessage))
248+
err := m.ProposeConfig(groupToKeyValue(validMessage))
247249
if err != nil {
248250
t.Fatalf("Error applying valid config: %s", err)
249251
}
@@ -253,13 +255,13 @@ func TestKafkaBrokers(t *testing.T) {
253255
t.Fatalf("Should have failed on invalid message")
254256
}
255257

256-
err = m.ProposeConfig(itemToValue(zeroBrokers))
258+
err = m.ProposeConfig(groupToKeyValue(zeroBrokers))
257259
if err == nil {
258260
t.Fatalf("Should have rejected empty brokers list")
259261
}
260262

261263
for i := range badMessages {
262-
err = m.ProposeConfig(itemToValue(badMessages[i]))
264+
err = m.ProposeConfig(groupToKeyValue(badMessages[i]))
263265
if err == nil {
264266
t.Fatalf("Should have rejected broker address which is obviously malformed")
265267
}
@@ -276,14 +278,14 @@ func TestKafkaBrokers(t *testing.T) {
276278
}
277279
}
278280

279-
func testPolicyNames(m *ManagerImpl, key string, initializer func(val []string) *cb.ConfigItem, retriever func() []string, t *testing.T) {
281+
func testPolicyNames(m *ManagerImpl, key string, initializer func(val []string) *cb.ConfigGroup, retriever func() []string, t *testing.T) {
280282
endPolicy := []string{"foo", "bar"}
281283
invalidMessage := invalidMessage()
282284
validMessage := initializer(endPolicy)
283285

284286
m.BeginConfig()
285287

286-
err := m.ProposeConfig(itemToValue(validMessage))
288+
err := m.ProposeConfig(groupToKeyValue(validMessage))
287289
if err != nil {
288290
t.Fatalf("Error applying valid config: %s", err)
289291
}
@@ -296,7 +298,7 @@ func testPolicyNames(m *ManagerImpl, key string, initializer func(val []string)
296298
t.Fatalf("Should have failed on invalid message")
297299
}
298300

299-
err = m.ProposeConfig(itemToValue(validMessage))
301+
err = m.ProposeConfig(groupToKeyValue(validMessage))
300302
if err != nil {
301303
t.Fatalf("Error re-applying valid config: %s", err)
302304
}
@@ -328,7 +330,7 @@ func TestEmptyChainCreationPolicyNames(t *testing.T) {
328330

329331
m.BeginConfig()
330332

331-
err := m.ProposeConfig(itemToValue(TemplateChainCreationPolicyNames(nil)))
333+
err := m.ProposeConfig(groupToKeyValue(TemplateChainCreationPolicyNames(nil)))
332334
if err != nil {
333335
t.Fatalf("Error applying valid config: %s", err)
334336
}

common/configtx/handlers/orderer/sharedconfig_util.go

+23-42
Original file line numberDiff line numberDiff line change
@@ -22,65 +22,46 @@ import (
2222
"github.com/hyperledger/fabric/protos/utils"
2323
)
2424

25-
// TemplateConsensusType creates a headerless config item representing the consensus type
26-
func TemplateConsensusType(typeValue string) *cb.ConfigItem {
27-
return &cb.ConfigItem{
28-
Type: cb.ConfigItem_ORDERER,
29-
Key: ConsensusTypeKey,
30-
Value: utils.MarshalOrPanic(&ab.ConsensusType{Type: typeValue}),
25+
func configGroup(key string, value []byte) *cb.ConfigGroup {
26+
result := cb.NewConfigGroup()
27+
result.Groups[GroupKey] = cb.NewConfigGroup()
28+
result.Groups[GroupKey].Values[key] = &cb.ConfigValue{
29+
Value: value,
3130
}
31+
return result
32+
}
33+
34+
// TemplateConsensusType creates a headerless config item representing the consensus type
35+
func TemplateConsensusType(typeValue string) *cb.ConfigGroup {
36+
return configGroup(ConsensusTypeKey, utils.MarshalOrPanic(&ab.ConsensusType{Type: typeValue}))
3237
}
3338

3439
// TemplateBatchSize creates a headerless config item representing the batch size
35-
func TemplateBatchSize(batchSize *ab.BatchSize) *cb.ConfigItem {
36-
return &cb.ConfigItem{
37-
Type: cb.ConfigItem_ORDERER,
38-
Key: BatchSizeKey,
39-
Value: utils.MarshalOrPanic(batchSize),
40-
}
40+
func TemplateBatchSize(batchSize *ab.BatchSize) *cb.ConfigGroup {
41+
return configGroup(BatchSizeKey, utils.MarshalOrPanic(batchSize))
4142
}
4243

4344
// TemplateBatchTimeout creates a headerless config item representing the batch timeout
44-
func TemplateBatchTimeout(batchTimeout string) *cb.ConfigItem {
45-
return &cb.ConfigItem{
46-
Type: cb.ConfigItem_ORDERER,
47-
Key: BatchTimeoutKey,
48-
Value: utils.MarshalOrPanic(&ab.BatchTimeout{Timeout: batchTimeout}),
49-
}
45+
func TemplateBatchTimeout(batchTimeout string) *cb.ConfigGroup {
46+
return configGroup(BatchTimeoutKey, utils.MarshalOrPanic(&ab.BatchTimeout{Timeout: batchTimeout}))
5047
}
5148

5249
// TemplateChainCreationPolicyNames creates a headerless configuraiton item representing the chain creation policy names
53-
func TemplateChainCreationPolicyNames(names []string) *cb.ConfigItem {
54-
return &cb.ConfigItem{
55-
Type: cb.ConfigItem_ORDERER,
56-
Key: ChainCreationPolicyNamesKey,
57-
Value: utils.MarshalOrPanic(&ab.ChainCreationPolicyNames{Names: names}),
58-
}
50+
func TemplateChainCreationPolicyNames(names []string) *cb.ConfigGroup {
51+
return configGroup(ChainCreationPolicyNamesKey, utils.MarshalOrPanic(&ab.ChainCreationPolicyNames{Names: names}))
5952
}
6053

6154
// TemplateIngressPolicyNames creates a headerless config item representing the ingress policy names
62-
func TemplateIngressPolicyNames(names []string) *cb.ConfigItem {
63-
return &cb.ConfigItem{
64-
Type: cb.ConfigItem_ORDERER,
65-
Key: IngressPolicyNamesKey,
66-
Value: utils.MarshalOrPanic(&ab.IngressPolicyNames{Names: names}),
67-
}
55+
func TemplateIngressPolicyNames(names []string) *cb.ConfigGroup {
56+
return configGroup(IngressPolicyNamesKey, utils.MarshalOrPanic(&ab.IngressPolicyNames{Names: names}))
6857
}
6958

7059
// TemplateEgressPolicyNames creates a headerless config item representing the egress policy names
71-
func TemplateEgressPolicyNames(names []string) *cb.ConfigItem {
72-
return &cb.ConfigItem{
73-
Type: cb.ConfigItem_ORDERER,
74-
Key: EgressPolicyNamesKey,
75-
Value: utils.MarshalOrPanic(&ab.EgressPolicyNames{Names: names}),
76-
}
60+
func TemplateEgressPolicyNames(names []string) *cb.ConfigGroup {
61+
return configGroup(EgressPolicyNamesKey, utils.MarshalOrPanic(&ab.EgressPolicyNames{Names: names}))
7762
}
7863

7964
// TemplateKafkaBrokers creates a headerless config item representing the kafka brokers
80-
func TemplateKafkaBrokers(brokers []string) *cb.ConfigItem {
81-
return &cb.ConfigItem{
82-
Type: cb.ConfigItem_ORDERER,
83-
Key: KafkaBrokersKey,
84-
Value: utils.MarshalOrPanic(&ab.KafkaBrokers{Brokers: brokers}),
85-
}
65+
func TemplateKafkaBrokers(brokers []string) *cb.ConfigGroup {
66+
return configGroup(KafkaBrokersKey, utils.MarshalOrPanic(&ab.KafkaBrokers{Brokers: brokers}))
8667
}

orderer/common/bootstrap/provisional/provisional.go

+12-18
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@ const (
6060
var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey}
6161

6262
type bootstrapper struct {
63-
minimalItems []*cb.ConfigItem
64-
minimalGroups []*cb.ConfigGroup
65-
systemChainItems []*cb.ConfigItem
63+
minimalGroups []*cb.ConfigGroup
64+
systemChainGroups []*cb.ConfigGroup
6665
}
6766

6867
// New returns a new provisional bootstrap helper.
6968
func New(conf *config.TopLevel) Generator {
7069
bs := &bootstrapper{
71-
minimalItems: []*cb.ConfigItem{
70+
minimalGroups: []*cb.ConfigGroup{
71+
// Chain Config Types
72+
configtxchannel.DefaultHashingAlgorithm(),
73+
configtxchannel.DefaultBlockDataHashingStructure(),
74+
configtxchannel.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}),
75+
7276
// Orderer Config Types
7377
configtxorderer.TemplateConsensusType(conf.Genesis.OrdererType),
7478
configtxorderer.TemplateBatchSize(&ab.BatchSize{
@@ -79,28 +83,21 @@ func New(conf *config.TopLevel) Generator {
7983
configtxorderer.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
8084
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
8185
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
82-
},
83-
84-
minimalGroups: []*cb.ConfigGroup{
85-
// Chain Config Types
86-
configtxchannel.DefaultHashingAlgorithm(),
87-
configtxchannel.DefaultBlockDataHashingStructure(),
88-
configtxchannel.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}),
8986

9087
// Policies
9188
cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy),
9289
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
9390
},
9491

95-
systemChainItems: []*cb.ConfigItem{
92+
systemChainGroups: []*cb.ConfigGroup{
9693
configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
9794
},
9895
}
9996

10097
switch conf.Genesis.OrdererType {
10198
case ConsensusTypeSolo, ConsensusTypeSbft:
10299
case ConsensusTypeKafka:
103-
bs.minimalItems = append(bs.minimalItems, configtxorderer.TemplateKafkaBrokers(conf.Kafka.Brokers))
100+
bs.minimalGroups = append(bs.minimalGroups, configtxorderer.TemplateKafkaBrokers(conf.Kafka.Brokers))
104101
default:
105102
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Genesis.OrdererType))
106103
}
@@ -109,16 +106,13 @@ func New(conf *config.TopLevel) Generator {
109106
}
110107

111108
func (bs *bootstrapper) ChannelTemplate() configtx.Template {
112-
return configtx.NewCompositeTemplate(
113-
configtx.NewSimpleTemplate(bs.minimalItems...),
114-
configtx.NewSimpleTemplateNext(bs.minimalGroups...),
115-
)
109+
return configtx.NewSimpleTemplateNext(bs.minimalGroups...)
116110
}
117111

118112
func (bs *bootstrapper) GenesisBlock() *cb.Block {
119113
block, err := genesis.NewFactoryImpl(
120114
configtx.NewCompositeTemplate(
121-
configtx.NewSimpleTemplate(bs.systemChainItems...),
115+
configtx.NewSimpleTemplateNext(bs.systemChainGroups...),
122116
bs.ChannelTemplate(),
123117
),
124118
).Block(TestChainID)

0 commit comments

Comments
 (0)