Skip to content

Commit ca44f11

Browse files
author
Jason Yellick
committed
[FAB-2150] Move channel config to GroupConfig
https://jira.hyperledger.org/browse/FAB-2150 The ConfigItem is deprecated, this CR migrates the channel config to use the newer ConfigGroup interface. Change-Id: I0b7bb37bb63986f89e85f05fbf34627c703e7548 Signed-off-by: Jason Yellick <[email protected]>
1 parent 3afbc13 commit ca44f11

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

common/configtx/handlers/channel/sharedconfig_test.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ func init() {
3030
logging.SetLevel(logging.DEBUG, "")
3131
}
3232

33-
// A temporary method while ConfigItem is being removed
34-
func itemToValue(configItem *cb.ConfigItem) (string, *cb.ConfigValue) {
35-
return configItem.Key, &cb.ConfigValue{Value: configItem.Value}
33+
func groupToKeyValue(configGroup *cb.ConfigGroup) (string, *cb.ConfigValue) {
34+
for key, value := range configGroup.Values {
35+
return key, value
36+
}
37+
panic("No value encoded")
3638
}
3739

3840
func makeInvalidConfigItem() *cb.ConfigValue {
@@ -90,12 +92,12 @@ func TestHashingAlgorithm(t *testing.T) {
9092
t.Fatalf("Should have failed on invalid message")
9193
}
9294

93-
err = m.ProposeConfig(itemToValue(invalidAlgorithm))
95+
err = m.ProposeConfig(groupToKeyValue(invalidAlgorithm))
9496
if err == nil {
9597
t.Fatalf("Should have failed on invalid algorithm")
9698
}
9799

98-
err = m.ProposeConfig(itemToValue(validAlgorithm))
100+
err = m.ProposeConfig(groupToKeyValue(validAlgorithm))
99101
if err != nil {
100102
t.Fatalf("Error applying valid config: %s", err)
101103
}
@@ -120,12 +122,12 @@ func TestBlockDataHashingStructure(t *testing.T) {
120122
t.Fatalf("Should have failed on invalid message")
121123
}
122124

123-
err = m.ProposeConfig(itemToValue(invalidWidth))
125+
err = m.ProposeConfig(groupToKeyValue(invalidWidth))
124126
if err == nil {
125127
t.Fatalf("Should have failed on invalid width")
126128
}
127129

128-
err = m.ProposeConfig(itemToValue(validWidth))
130+
err = m.ProposeConfig(groupToKeyValue(validWidth))
129131
if err != nil {
130132
t.Fatalf("Error applying valid config: %s", err)
131133
}
@@ -148,7 +150,7 @@ func TestOrdererAddresses(t *testing.T) {
148150
t.Fatalf("Should have failed on invalid message")
149151
}
150152

151-
err = m.ProposeConfig(itemToValue(validMessage))
153+
err = m.ProposeConfig(groupToKeyValue(validMessage))
152154
if err != nil {
153155
t.Fatalf("Error applying valid config: %s", err)
154156
}

common/configtx/handlers/channel/sharedconfig_util.go

+17-21
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,45 @@ import (
2525

2626
const defaultHashingAlgorithm = SHA3Shake256
2727

28-
// TemplateHashingAlgorithm creates a headerless config item representing the hashing algorithm
29-
func TemplateHashingAlgorithm(name string) *cb.ConfigItem {
30-
return &cb.ConfigItem{
31-
Type: cb.ConfigItem_CHAIN,
32-
Key: HashingAlgorithmKey,
33-
Value: utils.MarshalOrPanic(&cb.HashingAlgorithm{Name: name}),
28+
func configGroup(key string, value []byte) *cb.ConfigGroup {
29+
result := cb.NewConfigGroup()
30+
result.Values[key] = &cb.ConfigValue{
31+
Value: value,
3432
}
33+
return result
34+
}
35+
36+
// TemplateHashingAlgorithm creates a ConfigGroup representing the HashingAlgorithm
37+
func TemplateHashingAlgorithm(name string) *cb.ConfigGroup {
38+
return configGroup(HashingAlgorithmKey, utils.MarshalOrPanic(&cb.HashingAlgorithm{Name: name}))
3539

3640
}
3741

3842
// DefaultHashingAlgorithm creates a headerless config item for the default hashing algorithm
39-
func DefaultHashingAlgorithm() *cb.ConfigItem {
43+
func DefaultHashingAlgorithm() *cb.ConfigGroup {
4044
return TemplateHashingAlgorithm(defaultHashingAlgorithm)
4145
}
4246

4347
const defaultBlockDataHashingStructureWidth = math.MaxUint32
4448

4549
// TemplateBlockDataHashingStructure creates a headerless config item representing the block data hashing structure
46-
func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigItem {
47-
return &cb.ConfigItem{
48-
Type: cb.ConfigItem_CHAIN,
49-
Key: BlockDataHashingStructureKey,
50-
Value: utils.MarshalOrPanic(&cb.BlockDataHashingStructure{Width: width}),
51-
}
50+
func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigGroup {
51+
return configGroup(BlockDataHashingStructureKey, utils.MarshalOrPanic(&cb.BlockDataHashingStructure{Width: width}))
5252
}
5353

5454
// DefaultBlockDatahashingStructure creates a headerless config item for the default block data hashing structure
55-
func DefaultBlockDataHashingStructure() *cb.ConfigItem {
55+
func DefaultBlockDataHashingStructure() *cb.ConfigGroup {
5656
return TemplateBlockDataHashingStructure(defaultBlockDataHashingStructureWidth)
5757
}
5858

5959
var defaultOrdererAddresses = []string{"127.0.0.1:7050"}
6060

6161
// TemplateOrdererAddressess creates a headerless config item representing the orderer addresses
62-
func TemplateOrdererAddresses(addresses []string) *cb.ConfigItem {
63-
return &cb.ConfigItem{
64-
Type: cb.ConfigItem_CHAIN,
65-
Key: OrdererAddressesKey,
66-
Value: utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: addresses}),
67-
}
62+
func TemplateOrdererAddresses(addresses []string) *cb.ConfigGroup {
63+
return configGroup(OrdererAddressesKey, utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: addresses}))
6864
}
6965

7066
// DefaultOrdererAddresses creates a headerless config item for the default orderer addresses
71-
func DefaultOrdererAddresses() *cb.ConfigItem {
67+
func DefaultOrdererAddresses() *cb.ConfigGroup {
7268
return TemplateOrdererAddresses(defaultOrdererAddresses)
7369
}

orderer/common/bootstrap/provisional/provisional.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ type bootstrapper struct {
6969
func New(conf *config.TopLevel) Generator {
7070
bs := &bootstrapper{
7171
minimalItems: []*cb.ConfigItem{
72-
// Chain Config Types
73-
configtxchannel.DefaultHashingAlgorithm(),
74-
configtxchannel.DefaultBlockDataHashingStructure(),
75-
configtxchannel.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}),
76-
7772
// Orderer Config Types
7873
configtxorderer.TemplateConsensusType(conf.Genesis.OrdererType),
7974
configtxorderer.TemplateBatchSize(&ab.BatchSize{
@@ -87,6 +82,11 @@ func New(conf *config.TopLevel) Generator {
8782
},
8883

8984
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)}),
89+
9090
// Policies
9191
cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy),
9292
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),

0 commit comments

Comments
 (0)