Skip to content

Commit c16f5b3

Browse files
author
Jason Yellick
committed
[FAB-2176] Add ConfigUpdate proto
https://jira.hyperledger.org/browse/FAB-2176 In order to stabilize the protos, the ConfigUpdate protos need to go in first. The existing code can be adapted simply to depend on a ConfigUpdate write set which includes the entire config. Then, the actual partial config updates can be built on top of it. Change-Id: Ib718ebb056c64ae27c84088ca0da82f73d632e54 Signed-off-by: Jason Yellick <[email protected]>
1 parent 28e0d18 commit c16f5b3

14 files changed

+287
-152
lines changed

common/configtx/manager.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func computeSequence(configGroup *cb.ConfigGroup) uint64 {
7979

8080
// computeChannelIdAndSequence returns the chain id and the sequence number for a config envelope
8181
// or an error if there is a problem with the config envelope
82-
func computeChannelIdAndSequence(config *cb.Config) (string, uint64, error) {
83-
if config.Channel == nil {
82+
func computeChannelIdAndSequence(config *cb.ConfigUpdate) (string, uint64, error) {
83+
if config.WriteSet == nil {
8484
return "", 0, errors.New("Empty envelope unsupported")
8585
}
8686

@@ -98,7 +98,7 @@ func computeChannelIdAndSequence(config *cb.Config) (string, uint64, error) {
9898
return "", 0, err
9999
}
100100

101-
m := computeSequence(config.Channel)
101+
m := computeSequence(config.WriteSet)
102102

103103
return chainID, m, nil
104104
}
@@ -134,7 +134,13 @@ func validateChainID(chainID string) error {
134134
}
135135

136136
func NewManagerImpl(configtx *cb.ConfigEnvelope, initializer api.Initializer, callOnUpdate []func(api.Manager)) (api.Manager, error) {
137-
config, err := UnmarshalConfig(configtx.Config)
137+
// XXX as a temporary hack to get the new protos working, we assume entire config is always in the ConfigUpdate.WriteSet
138+
139+
if configtx.LastUpdate == nil {
140+
return nil, fmt.Errorf("Must have ConfigEnvelope.LastUpdate set")
141+
}
142+
143+
config, err := UnmarshalConfigUpdate(configtx.LastUpdate.ConfigUpdate)
138144
if err != nil {
139145
return nil, err
140146
}
@@ -240,7 +246,13 @@ func (cm *configManager) recurseConfig(result map[string]comparable, path []stri
240246
}
241247

242248
func (cm *configManager) processConfig(configtx *cb.ConfigEnvelope) (configMap map[string]comparable, err error) {
243-
config, err := UnmarshalConfig(configtx.Config)
249+
// XXX as a temporary hack to get the new protos working, we assume entire config is always in the ConfigUpdate.WriteSet
250+
251+
if configtx.LastUpdate == nil {
252+
return nil, fmt.Errorf("Must have ConfigEnvelope.LastUpdate set")
253+
}
254+
255+
config, err := UnmarshalConfigUpdate(configtx.LastUpdate.ConfigUpdate)
244256
if err != nil {
245257
return nil, err
246258
}
@@ -250,7 +262,7 @@ func (cm *configManager) processConfig(configtx *cb.ConfigEnvelope) (configMap m
250262
return nil, err
251263
}
252264

253-
signedData, err := configtx.AsSignedData()
265+
signedData, err := configtx.LastUpdate.AsSignedData()
254266
if err != nil {
255267
return nil, err
256268
}
@@ -274,7 +286,7 @@ func (cm *configManager) processConfig(configtx *cb.ConfigEnvelope) (configMap m
274286

275287
configMap = make(map[string]comparable)
276288

277-
if err := cm.recurseConfig(configMap, []string{}, config.Channel); err != nil {
289+
if err := cm.recurseConfig(configMap, []string{}, config.WriteSet); err != nil {
278290
return nil, err
279291
}
280292

common/configtx/manager_test.go

+36-30
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,21 @@ func makeConfigPair(id, modificationPolicy string, lastModified uint64, data []b
5656
}
5757
}
5858

59-
func makeMarshaledConfig(chainID string, configPairs ...*configPair) []byte {
59+
func makeConfigUpdateEnvelope(chainID string, configPairs ...*configPair) *cb.ConfigUpdateEnvelope {
6060
values := make(map[string]*cb.ConfigValue)
6161
for _, pair := range configPairs {
6262
values[pair.key] = pair.value
6363
}
6464

65-
config := &cb.Config{
65+
config := &cb.ConfigUpdate{
6666
Header: &cb.ChannelHeader{ChannelId: chainID},
67-
Channel: &cb.ConfigGroup{
67+
WriteSet: &cb.ConfigGroup{
6868
Values: values,
6969
},
7070
}
71-
return utils.MarshalOrPanic(config)
71+
return &cb.ConfigUpdateEnvelope{
72+
ConfigUpdate: utils.MarshalOrPanic(config),
73+
}
7274
}
7375

7476
func TestCallback(t *testing.T) {
@@ -78,7 +80,7 @@ func TestCallback(t *testing.T) {
7880
}
7981

8082
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
81-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
83+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
8284
}, defaultInitializer(), []func(api.Manager){callback})
8385

8486
if err != nil {
@@ -93,15 +95,15 @@ func TestCallback(t *testing.T) {
9395
// TestDifferentChainID tests that a config update for a different chain ID fails
9496
func TestDifferentChainID(t *testing.T) {
9597
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
96-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
98+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
9799
}, defaultInitializer(), nil)
98100

99101
if err != nil {
100102
t.Fatalf("Error constructing config manager: %s", err)
101103
}
102104

103105
newConfig := &cb.ConfigEnvelope{
104-
Config: makeMarshaledConfig("wrongChain", makeConfigPair("foo", "foo", 1, []byte("foo"))),
106+
LastUpdate: makeConfigUpdateEnvelope("wrongChain", makeConfigPair("foo", "foo", 1, []byte("foo"))),
105107
}
106108

107109
err = cm.Validate(newConfig)
@@ -118,15 +120,15 @@ func TestDifferentChainID(t *testing.T) {
118120
// TestOldConfigReplay tests that resubmitting a config for a sequence number which is not newer is ignored
119121
func TestOldConfigReplay(t *testing.T) {
120122
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
121-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
123+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
122124
}, defaultInitializer(), nil)
123125

124126
if err != nil {
125127
t.Fatalf("Error constructing config manager: %s", err)
126128
}
127129

128130
newConfig := &cb.ConfigEnvelope{
129-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
131+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
130132
}
131133

132134
err = cm.Validate(newConfig)
@@ -143,7 +145,9 @@ func TestOldConfigReplay(t *testing.T) {
143145
// TestInvalidInitialConfigByStructure tests to make sure that if the config contains corrupted config that construction results in error
144146
func TestInvalidInitialConfigByStructure(t *testing.T) {
145147
_, err := NewManagerImpl(&cb.ConfigEnvelope{
146-
Config: []byte("Corrupted"),
148+
LastUpdate: &cb.ConfigUpdateEnvelope{
149+
ConfigUpdate: []byte("Corrupted"),
150+
},
147151
}, defaultInitializer(), nil)
148152

149153
if err == nil {
@@ -154,15 +158,15 @@ func TestInvalidInitialConfigByStructure(t *testing.T) {
154158
// TestValidConfigChange tests the happy path of updating a config value with no defaultModificationPolicy
155159
func TestValidConfigChange(t *testing.T) {
156160
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
157-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
161+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
158162
}, defaultInitializer(), nil)
159163

160164
if err != nil {
161165
t.Fatalf("Error constructing config manager: %s", err)
162166
}
163167

164168
newConfig := &cb.ConfigEnvelope{
165-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
169+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
166170
}
167171

168172
err = cm.Validate(newConfig)
@@ -180,15 +184,15 @@ func TestValidConfigChange(t *testing.T) {
180184
// config values while advancing another
181185
func TestConfigChangeRegressedSequence(t *testing.T) {
182186
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
183-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
187+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
184188
}, defaultInitializer(), nil)
185189

186190
if err != nil {
187191
t.Fatalf("Error constructing config manager: %s", err)
188192
}
189193

190194
newConfig := &cb.ConfigEnvelope{
191-
Config: makeMarshaledConfig(
195+
LastUpdate: makeConfigUpdateEnvelope(
192196
defaultChain,
193197
makeConfigPair("foo", "foo", 0, []byte("foo")),
194198
makeConfigPair("bar", "bar", 2, []byte("bar")),
@@ -210,15 +214,15 @@ func TestConfigChangeRegressedSequence(t *testing.T) {
210214
// config values while advancing another
211215
func TestConfigChangeOldSequence(t *testing.T) {
212216
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
213-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
217+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
214218
}, defaultInitializer(), nil)
215219

216220
if err != nil {
217221
t.Fatalf("Error constructing config manager: %s", err)
218222
}
219223

220224
newConfig := &cb.ConfigEnvelope{
221-
Config: makeMarshaledConfig(
225+
LastUpdate: makeConfigUpdateEnvelope(
222226
defaultChain,
223227
makeConfigPair("foo", "foo", 2, []byte("foo")),
224228
makeConfigPair("bar", "bar", 1, []byte("bar")),
@@ -240,7 +244,7 @@ func TestConfigChangeOldSequence(t *testing.T) {
240244
// by omitting them in the new config
241245
func TestConfigImplicitDelete(t *testing.T) {
242246
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
243-
Config: makeMarshaledConfig(
247+
LastUpdate: makeConfigUpdateEnvelope(
244248
defaultChain,
245249
makeConfigPair("foo", "foo", 0, []byte("foo")),
246250
makeConfigPair("bar", "bar", 0, []byte("bar")),
@@ -252,7 +256,7 @@ func TestConfigImplicitDelete(t *testing.T) {
252256
}
253257

254258
newConfig := &cb.ConfigEnvelope{
255-
Config: makeMarshaledConfig(
259+
LastUpdate: makeConfigUpdateEnvelope(
256260
defaultChain,
257261
makeConfigPair("bar", "bar", 1, []byte("bar")),
258262
),
@@ -272,7 +276,7 @@ func TestConfigImplicitDelete(t *testing.T) {
272276
// TestEmptyConfigUpdate tests to make sure that an empty config is rejected as an update
273277
func TestEmptyConfigUpdate(t *testing.T) {
274278
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
275-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
279+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
276280
}, defaultInitializer(), nil)
277281

278282
if err != nil {
@@ -297,7 +301,7 @@ func TestEmptyConfigUpdate(t *testing.T) {
297301
// increasing the config item's LastModified
298302
func TestSilentConfigModification(t *testing.T) {
299303
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
300-
Config: makeMarshaledConfig(
304+
LastUpdate: makeConfigUpdateEnvelope(
301305
defaultChain,
302306
makeConfigPair("foo", "foo", 0, []byte("foo")),
303307
makeConfigPair("bar", "bar", 0, []byte("bar")),
@@ -309,7 +313,7 @@ func TestSilentConfigModification(t *testing.T) {
309313
}
310314

311315
newConfig := &cb.ConfigEnvelope{
312-
Config: makeMarshaledConfig(
316+
LastUpdate: makeConfigUpdateEnvelope(
313317
defaultChain,
314318
makeConfigPair("foo", "foo", 0, []byte("different")),
315319
makeConfigPair("bar", "bar", 1, []byte("bar")),
@@ -333,7 +337,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
333337
initializer := defaultInitializer()
334338
initializer.Resources.PolicyManagerVal.Policy.Err = fmt.Errorf("err")
335339
_, err := NewManagerImpl(&cb.ConfigEnvelope{
336-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
340+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
337341
}, initializer, nil)
338342

339343
if err == nil {
@@ -346,7 +350,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
346350
func TestConfigChangeViolatesPolicy(t *testing.T) {
347351
initializer := defaultInitializer()
348352
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
349-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
353+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
350354
}, initializer, nil)
351355

352356
if err != nil {
@@ -356,7 +360,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
356360
initializer.Resources.PolicyManagerVal.Policy.Err = fmt.Errorf("err")
357361

358362
newConfig := &cb.ConfigEnvelope{
359-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
363+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
360364
}
361365

362366
err = cm.Validate(newConfig)
@@ -375,7 +379,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
375379
func TestUnchangedConfigViolatesPolicy(t *testing.T) {
376380
initializer := defaultInitializer()
377381
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
378-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
382+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
379383
}, initializer, nil)
380384

381385
if err != nil {
@@ -387,7 +391,7 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
387391
initializer.Resources.PolicyManagerVal.PolicyMap["foo"] = &mockpolicies.Policy{Err: fmt.Errorf("err")}
388392

389393
newConfig := &cb.ConfigEnvelope{
390-
Config: makeMarshaledConfig(
394+
LastUpdate: makeConfigUpdateEnvelope(
391395
defaultChain,
392396
makeConfigPair("foo", "foo", 0, []byte("foo")),
393397
makeConfigPair("bar", "bar", 1, []byte("foo")),
@@ -410,7 +414,7 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
410414
func TestInvalidProposal(t *testing.T) {
411415
initializer := defaultInitializer()
412416
cm, err := NewManagerImpl(&cb.ConfigEnvelope{
413-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
417+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 0, []byte("foo"))),
414418
}, initializer, nil)
415419

416420
if err != nil {
@@ -420,7 +424,7 @@ func TestInvalidProposal(t *testing.T) {
420424
initializer.HandlerVal = &mockconfigtx.Handler{ErrorForProposeConfig: fmt.Errorf("err")}
421425

422426
newConfig := &cb.ConfigEnvelope{
423-
Config: makeMarshaledConfig(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
427+
LastUpdate: makeConfigUpdateEnvelope(defaultChain, makeConfigPair("foo", "foo", 1, []byte("foo"))),
424428
}
425429

426430
err = cm.Validate(newConfig)
@@ -440,7 +444,9 @@ func TestMissingHeader(t *testing.T) {
440444
group.Values["foo"] = &cb.ConfigValue{}
441445
data := utils.MarshalOrPanic(&cb.Config{Channel: group})
442446
_, err := NewManagerImpl(&cb.ConfigEnvelope{
443-
Config: data,
447+
LastUpdate: &cb.ConfigUpdateEnvelope{
448+
ConfigUpdate: data,
449+
},
444450
}, defaultInitializer(), nil)
445451

446452
if err == nil {
@@ -451,7 +457,7 @@ func TestMissingHeader(t *testing.T) {
451457
// TestMissingChainID checks that a config item with a missing chainID causes the config to be rejected
452458
func TestMissingChainID(t *testing.T) {
453459
_, err := NewManagerImpl(&cb.ConfigEnvelope{
454-
Config: makeMarshaledConfig("", makeConfigPair("foo", "foo", 0, []byte("foo"))),
460+
LastUpdate: makeConfigUpdateEnvelope("", makeConfigPair("foo", "foo", 0, []byte("foo"))),
455461
}, defaultInitializer(), nil)
456462

457463
if err == nil {

0 commit comments

Comments
 (0)