From ca44f11eb090993808f440375e2e220d5a10ec88 Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Thu, 9 Feb 2017 12:51:46 -0500 Subject: [PATCH] [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 --- .../handlers/channel/sharedconfig_test.go | 18 +++++---- .../handlers/channel/sharedconfig_util.go | 38 +++++++++---------- .../bootstrap/provisional/provisional.go | 10 ++--- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/common/configtx/handlers/channel/sharedconfig_test.go b/common/configtx/handlers/channel/sharedconfig_test.go index ffcc4310f54..1d20a16572b 100644 --- a/common/configtx/handlers/channel/sharedconfig_test.go +++ b/common/configtx/handlers/channel/sharedconfig_test.go @@ -30,9 +30,11 @@ func init() { logging.SetLevel(logging.DEBUG, "") } -// A temporary method while ConfigItem is being removed -func itemToValue(configItem *cb.ConfigItem) (string, *cb.ConfigValue) { - return configItem.Key, &cb.ConfigValue{Value: configItem.Value} +func groupToKeyValue(configGroup *cb.ConfigGroup) (string, *cb.ConfigValue) { + for key, value := range configGroup.Values { + return key, value + } + panic("No value encoded") } func makeInvalidConfigItem() *cb.ConfigValue { @@ -90,12 +92,12 @@ func TestHashingAlgorithm(t *testing.T) { t.Fatalf("Should have failed on invalid message") } - err = m.ProposeConfig(itemToValue(invalidAlgorithm)) + err = m.ProposeConfig(groupToKeyValue(invalidAlgorithm)) if err == nil { t.Fatalf("Should have failed on invalid algorithm") } - err = m.ProposeConfig(itemToValue(validAlgorithm)) + err = m.ProposeConfig(groupToKeyValue(validAlgorithm)) if err != nil { t.Fatalf("Error applying valid config: %s", err) } @@ -120,12 +122,12 @@ func TestBlockDataHashingStructure(t *testing.T) { t.Fatalf("Should have failed on invalid message") } - err = m.ProposeConfig(itemToValue(invalidWidth)) + err = m.ProposeConfig(groupToKeyValue(invalidWidth)) if err == nil { t.Fatalf("Should have failed on invalid width") } - err = m.ProposeConfig(itemToValue(validWidth)) + err = m.ProposeConfig(groupToKeyValue(validWidth)) if err != nil { t.Fatalf("Error applying valid config: %s", err) } @@ -148,7 +150,7 @@ func TestOrdererAddresses(t *testing.T) { t.Fatalf("Should have failed on invalid message") } - err = m.ProposeConfig(itemToValue(validMessage)) + err = m.ProposeConfig(groupToKeyValue(validMessage)) if err != nil { t.Fatalf("Error applying valid config: %s", err) } diff --git a/common/configtx/handlers/channel/sharedconfig_util.go b/common/configtx/handlers/channel/sharedconfig_util.go index 8496b32095c..dce4345d39e 100644 --- a/common/configtx/handlers/channel/sharedconfig_util.go +++ b/common/configtx/handlers/channel/sharedconfig_util.go @@ -25,49 +25,45 @@ import ( const defaultHashingAlgorithm = SHA3Shake256 -// TemplateHashingAlgorithm creates a headerless config item representing the hashing algorithm -func TemplateHashingAlgorithm(name string) *cb.ConfigItem { - return &cb.ConfigItem{ - Type: cb.ConfigItem_CHAIN, - Key: HashingAlgorithmKey, - Value: utils.MarshalOrPanic(&cb.HashingAlgorithm{Name: name}), +func configGroup(key string, value []byte) *cb.ConfigGroup { + result := cb.NewConfigGroup() + result.Values[key] = &cb.ConfigValue{ + Value: value, } + return result +} + +// TemplateHashingAlgorithm creates a ConfigGroup representing the HashingAlgorithm +func TemplateHashingAlgorithm(name string) *cb.ConfigGroup { + return configGroup(HashingAlgorithmKey, utils.MarshalOrPanic(&cb.HashingAlgorithm{Name: name})) } // DefaultHashingAlgorithm creates a headerless config item for the default hashing algorithm -func DefaultHashingAlgorithm() *cb.ConfigItem { +func DefaultHashingAlgorithm() *cb.ConfigGroup { return TemplateHashingAlgorithm(defaultHashingAlgorithm) } const defaultBlockDataHashingStructureWidth = math.MaxUint32 // TemplateBlockDataHashingStructure creates a headerless config item representing the block data hashing structure -func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigItem { - return &cb.ConfigItem{ - Type: cb.ConfigItem_CHAIN, - Key: BlockDataHashingStructureKey, - Value: utils.MarshalOrPanic(&cb.BlockDataHashingStructure{Width: width}), - } +func TemplateBlockDataHashingStructure(width uint32) *cb.ConfigGroup { + return configGroup(BlockDataHashingStructureKey, utils.MarshalOrPanic(&cb.BlockDataHashingStructure{Width: width})) } // DefaultBlockDatahashingStructure creates a headerless config item for the default block data hashing structure -func DefaultBlockDataHashingStructure() *cb.ConfigItem { +func DefaultBlockDataHashingStructure() *cb.ConfigGroup { return TemplateBlockDataHashingStructure(defaultBlockDataHashingStructureWidth) } var defaultOrdererAddresses = []string{"127.0.0.1:7050"} // TemplateOrdererAddressess creates a headerless config item representing the orderer addresses -func TemplateOrdererAddresses(addresses []string) *cb.ConfigItem { - return &cb.ConfigItem{ - Type: cb.ConfigItem_CHAIN, - Key: OrdererAddressesKey, - Value: utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: addresses}), - } +func TemplateOrdererAddresses(addresses []string) *cb.ConfigGroup { + return configGroup(OrdererAddressesKey, utils.MarshalOrPanic(&cb.OrdererAddresses{Addresses: addresses})) } // DefaultOrdererAddresses creates a headerless config item for the default orderer addresses -func DefaultOrdererAddresses() *cb.ConfigItem { +func DefaultOrdererAddresses() *cb.ConfigGroup { return TemplateOrdererAddresses(defaultOrdererAddresses) } diff --git a/orderer/common/bootstrap/provisional/provisional.go b/orderer/common/bootstrap/provisional/provisional.go index 66816d76983..a8e356d2337 100644 --- a/orderer/common/bootstrap/provisional/provisional.go +++ b/orderer/common/bootstrap/provisional/provisional.go @@ -69,11 +69,6 @@ type bootstrapper struct { func New(conf *config.TopLevel) Generator { bs := &bootstrapper{ minimalItems: []*cb.ConfigItem{ - // Chain Config Types - configtxchannel.DefaultHashingAlgorithm(), - configtxchannel.DefaultBlockDataHashingStructure(), - configtxchannel.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}), - // Orderer Config Types configtxorderer.TemplateConsensusType(conf.Genesis.OrdererType), configtxorderer.TemplateBatchSize(&ab.BatchSize{ @@ -87,6 +82,11 @@ func New(conf *config.TopLevel) Generator { }, minimalGroups: []*cb.ConfigGroup{ + // Chain Config Types + configtxchannel.DefaultHashingAlgorithm(), + configtxchannel.DefaultBlockDataHashingStructure(), + configtxchannel.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}), + // Policies cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy), cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),