Skip to content

Commit f5ab160

Browse files
author
Jason Yellick
committed
[FAB-2152] Migrate app config to ConfigGroup
https://jira.hyperledger.org/browse/FAB-2152 The ConfigItem proto is deprecated, pending removal. This CR migrates the application config to the newer ConfigGroup mechanism. Change-Id: Ic48125dd4930afccae42cffda02211718559311e Signed-off-by: Jason Yellick <[email protected]>
1 parent 63e54d1 commit f5ab160

File tree

5 files changed

+20
-40
lines changed

5 files changed

+20
-40
lines changed

common/configtx/handlers/application/sharedconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var Schema = &cb.ConfigGroupSchema{
5757

5858
// Peer config keys
5959
const (
60-
// AnchorPeersKey is the cb.ConfigItem type key name for the AnchorPeers message
60+
// AnchorPeersKey is the key name for the AnchorPeers ConfigValue
6161
AnchorPeersKey = "AnchorPeers"
6262
)
6363

common/configtx/handlers/application/sharedconfig_test.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ func makeInvalidConfigValue() *cb.ConfigValue {
3737
}
3838
}
3939

40-
func itemToValue(configItem *cb.ConfigItem) (string, *cb.ConfigValue) {
41-
return configItem.Key, &cb.ConfigValue{Value: configItem.Value}
40+
func groupToKeyValue(configGroup *cb.ConfigGroup) (string, *cb.ConfigValue) {
41+
for key, value := range configGroup.Groups[GroupKey].Values {
42+
return key, value
43+
}
44+
panic("No value encoded")
4245
}
4346

4447
func TestInterface(t *testing.T) {
@@ -92,7 +95,7 @@ func TestAnchorPeers(t *testing.T) {
9295
t.Fatalf("Should have failed on invalid message")
9396
}
9497

95-
err = m.ProposeConfig(itemToValue(validMessage))
98+
err = m.ProposeConfig(groupToKeyValue(validMessage))
9699
if err != nil {
97100
t.Fatalf("Error applying valid config: %s", err)
98101
}

common/configtx/handlers/application/sharedconfig_util.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ import (
2424

2525
var defaultAnchorPeers = []*pb.AnchorPeer{}
2626

27-
// TemplateAnchorPeers creates a headerless config item representing the anchor peers
28-
func TemplateAnchorPeers(anchorPeers []*pb.AnchorPeer) *cb.ConfigItem {
29-
return &cb.ConfigItem{
30-
Type: cb.ConfigItem_PEER,
31-
Key: AnchorPeersKey,
32-
Value: utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}),
27+
func configGroup(key string, value []byte) *cb.ConfigGroup {
28+
result := cb.NewConfigGroup()
29+
result.Groups[GroupKey] = cb.NewConfigGroup()
30+
result.Groups[GroupKey].Values[key] = &cb.ConfigValue{
31+
Value: value,
3332
}
33+
return result
34+
}
35+
36+
// TemplateAnchorPeers creates a headerless config item representing the anchor peers
37+
func TemplateAnchorPeers(anchorPeers []*pb.AnchorPeer) *cb.ConfigGroup {
38+
return configGroup(AnchorPeersKey, utils.MarshalOrPanic(&pb.AnchorPeers{AnchorPeers: anchorPeers}))
3439
}
3540

3641
// DefaultAnchorPeers creates a headerless config item for the default orderer addresses
37-
func DefaultAnchorPeers() *cb.ConfigItem {
42+
func DefaultAnchorPeers() *cb.ConfigGroup {
3843
return TemplateAnchorPeers(defaultAnchorPeers)
3944
}

common/configtx/handlers/application/template_test.go

-28
This file was deleted.

peer/channel/create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func sendCreateChainTransaction(cf *ChannelCmdFactory) error {
5555
//TODO this is a temporary hack until `orderer.template` and 'msp.template' is supplied from the CLI
5656
oTemplate := configtxtest.OrdererTemplate()
5757
mspTemplate := configtxtest.MSPTemplate()
58-
gossTemplate := configtx.NewSimpleTemplate(configtxapplication.TemplateAnchorPeers(anchorPeers))
58+
gossTemplate := configtx.NewSimpleTemplateNext(configtxapplication.TemplateAnchorPeers(anchorPeers))
5959
chCrtTemp := configtx.NewCompositeTemplate(oTemplate, mspTemplate, gossTemplate)
6060

6161
signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()

0 commit comments

Comments
 (0)