Skip to content

Commit 3afbc13

Browse files
author
Jason Yellick
committed
[FAB-2149] Change policies to use ConfigGroup
https://jira.hyperledger.org/browse/FAB-2149 This CR migrates the policy framework off of ConfigItem and on to ConfigGroup (as ConfigItem is deprecated and pending removal). Change-Id: Ief9ed46422275e2c48f84700e275e3fd764aea6f Signed-off-by: Jason Yellick <[email protected]>
1 parent a052b61 commit 3afbc13

File tree

7 files changed

+55
-53
lines changed

7 files changed

+55
-53
lines changed

common/cauthdsl/policy_util.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
)
2323

2424
// TemplatePolicy creates a headerless configuration item representing a policy for a given key
25-
func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.ConfigItem {
26-
return &cb.ConfigItem{
27-
Type: cb.ConfigItem_POLICY,
28-
Key: key,
29-
Value: utils.MarshalOrPanic(&cb.Policy{
25+
func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.ConfigGroup {
26+
configGroup := cb.NewConfigGroup()
27+
configGroup.Policies[key] = &cb.ConfigPolicy{
28+
Policy: &cb.Policy{
3029
Type: int32(cb.Policy_SIGNATURE),
3130
Policy: utils.MarshalOrPanic(sigPolicyEnv),
32-
}),
31+
},
3332
}
33+
return configGroup
3434
}

common/configtx/template.go

+34-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,40 @@ type Template interface {
4444
Envelope(chainID string) (*cb.ConfigEnvelope, error)
4545
}
4646

47+
type simpleTemplateNext struct {
48+
configGroup *cb.ConfigGroup
49+
}
50+
51+
// NewSimpleTemplateNext creates a Template using the supplied ConfigGroup
52+
func NewSimpleTemplateNext(configGroups ...*cb.ConfigGroup) Template {
53+
sts := make([]Template, len(configGroups))
54+
for i, group := range configGroups {
55+
sts[i] = &simpleTemplateNext{
56+
configGroup: group,
57+
}
58+
}
59+
return NewCompositeTemplate(sts...)
60+
}
61+
62+
// Envelope returns a ConfigEnvelopes for the given chainID
63+
func (st *simpleTemplateNext) Envelope(chainID string) (*cb.ConfigEnvelope, error) {
64+
config, err := proto.Marshal(&cb.ConfigNext{
65+
Header: &cb.ChannelHeader{
66+
ChannelId: chainID,
67+
Type: int32(cb.HeaderType_CONFIGURATION_ITEM),
68+
},
69+
Channel: st.configGroup,
70+
})
71+
72+
if err != nil {
73+
return nil, err
74+
}
75+
76+
return &cb.ConfigEnvelope{
77+
Config: config,
78+
}, nil
79+
}
80+
4781
type simpleTemplate struct {
4882
items []*cb.ConfigItem
4983
}
@@ -153,8 +187,6 @@ func copyGroup(source *cb.ConfigGroup, target *cb.ConfigGroup) error {
153187
// Items returns a set of ConfigEnvelopes for the given chainID, and errors only on marshaling errors
154188
func (ct *compositeTemplate) Envelope(chainID string) (*cb.ConfigEnvelope, error) {
155189
channel := cb.NewConfigGroup()
156-
channel.Groups[ApplicationGroup] = cb.NewConfigGroup()
157-
channel.Groups[OrdererGroup] = cb.NewConfigGroup()
158190

159191
for i := range ct.templates {
160192
configEnv, err := ct.templates[i].Envelope(chainID)

common/configtx/test/orderer.template

-64 Bytes
Binary file not shown.

orderer/common/bootstrap/provisional/provisional.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
type Generator interface {
3535
bootstrap.Helper
3636

37-
// TemplateItems returns a set of config items which can be used to initialize a template
38-
TemplateItems() []*cb.ConfigItem
37+
// ChannelTemplate returns a template which can be used to help initialize a channel
38+
ChannelTemplate() configtx.Template
3939
}
4040

4141
const (
@@ -61,6 +61,7 @@ var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey}
6161

6262
type bootstrapper struct {
6363
minimalItems []*cb.ConfigItem
64+
minimalGroups []*cb.ConfigGroup
6465
systemChainItems []*cb.ConfigItem
6566
}
6667

@@ -83,7 +84,9 @@ func New(conf *config.TopLevel) Generator {
8384
configtxorderer.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
8485
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
8586
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
87+
},
8688

89+
minimalGroups: []*cb.ConfigGroup{
8790
// Policies
8891
cauthdsl.TemplatePolicy(configtx.NewConfigItemPolicyKey, cauthdsl.RejectAllPolicy),
8992
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
@@ -105,15 +108,18 @@ func New(conf *config.TopLevel) Generator {
105108
return bs
106109
}
107110

108-
func (bs *bootstrapper) TemplateItems() []*cb.ConfigItem {
109-
return bs.minimalItems
111+
func (bs *bootstrapper) ChannelTemplate() configtx.Template {
112+
return configtx.NewCompositeTemplate(
113+
configtx.NewSimpleTemplate(bs.minimalItems...),
114+
configtx.NewSimpleTemplateNext(bs.minimalGroups...),
115+
)
110116
}
111117

112118
func (bs *bootstrapper) GenesisBlock() *cb.Block {
113119
block, err := genesis.NewFactoryImpl(
114120
configtx.NewCompositeTemplate(
115-
configtx.NewSimpleTemplate(bs.minimalItems...),
116121
configtx.NewSimpleTemplate(bs.systemChainItems...),
122+
bs.ChannelTemplate(),
117123
),
118124
).Block(TestChainID)
119125

orderer/common/bootstrap/provisional/template_test.go

-34
This file was deleted.

orderer/multichain/manager_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,13 @@ func TestNewChain(t *testing.T) {
226226
manager := NewManagerImpl(lf, consenters, &mockCryptoHelper{})
227227

228228
generator := provisional.New(conf)
229-
items := generator.TemplateItems()
230-
simpleTemplate := configtx.NewSimpleTemplate(items...)
229+
channelTemplate := generator.ChannelTemplate()
231230

232231
signer, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
233232
assert.NoError(t, err)
234233

235234
newChainID := "TestNewChain"
236-
newChainMessage, err := configtx.MakeChainCreationTransaction(provisional.AcceptAllPolicyKey, newChainID, signer, simpleTemplate)
235+
newChainMessage, err := configtx.MakeChainCreationTransaction(provisional.AcceptAllPolicyKey, newChainID, signer, channelTemplate)
237236
if err != nil {
238237
t.Fatalf("Error producing config transaction: %s", err)
239238
}

orderer/sample_clients/broadcast_config/newchain.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import (
2626
func newChainRequest(consensusType, creationPolicy, newChannelId string) *cb.Envelope {
2727
conf.Genesis.OrdererType = consensusType
2828
generator := provisional.New(conf)
29-
items := generator.TemplateItems()
30-
simpleTemplate := configtx.NewSimpleTemplate(items...)
29+
channelTemplate := generator.ChannelTemplate()
3130

3231
signer, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
3332
if err != nil {
3433
panic(err)
3534
}
3635

37-
env, err := configtx.MakeChainCreationTransaction(creationPolicy, newChannelId, signer, simpleTemplate)
36+
env, err := configtx.MakeChainCreationTransaction(creationPolicy, newChannelId, signer, channelTemplate)
3837
if err != nil {
3938
panic(err)
4039
}

0 commit comments

Comments
 (0)