Skip to content

Commit

Permalink
[FAB-2150] Move channel config to GroupConfig
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 12, 2017
1 parent 3afbc13 commit ca44f11
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
18 changes: 10 additions & 8 deletions common/configtx/handlers/channel/sharedconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
38 changes: 17 additions & 21 deletions common/configtx/handlers/channel/sharedconfig_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 5 additions & 5 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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),
Expand Down

0 comments on commit ca44f11

Please sign in to comment.