Skip to content

Commit 7b8831f

Browse files
author
Jason Yellick
committed
[FAB-2410] Encode block validation policy
https://jira.hyperledger.org/browse/FAB-2410 This CR encodes a default block validation policy which requires that some orderer writer have signed blocks for them to be valid. Change-Id: I7ecbdfd4dda8d1d25c80d13c5a1ad0d150db6f3b Signed-off-by: Jason Yellick <[email protected]>
1 parent 4eec836 commit 7b8831f

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

common/configtx/tool/provisional/provisional.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const (
6363

6464
// AcceptAllPolicyKey is the key of the AcceptAllPolicy.
6565
AcceptAllPolicyKey = "AcceptAllPolicy"
66+
67+
// BlockValidationPolicyKey
68+
BlockValidationPolicyKey = "BlockValidation"
6669
)
6770

6871
// DefaultChainCreationPolicyNames is the default value of ChainCreatorsKey.
@@ -107,7 +110,8 @@ func New(conf *genesisconfig.Profile) Generator {
107110
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
108111
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
109112

110-
// Initialize the default Reader/Writer/Admins orderer policies
113+
// Initialize the default Reader/Writer/Admins orderer policies, as well as block validation policy
114+
policies.TemplateImplicitMetaPolicyWithSubPolicy([]string{configtxorderer.GroupKey}, BlockValidationPolicyKey, configvaluesmsp.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY),
111115
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.ReadersPolicyKey),
112116
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.WritersPolicyKey),
113117
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.AdminsPolicyKey),

common/policies/implicitmeta_util.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import (
2121
"github.com/hyperledger/fabric/protos/utils"
2222
)
2323

24-
// TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName
25-
// It utilizes the policyName for the subPolicyName as well, as this is the standard usage pattern
26-
func TemplateImplicitMetaPolicy(path []string, policyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
24+
// TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName and subPolicyName
25+
func TemplateImplicitMetaPolicyWithSubPolicy(path []string, policyName string, subPolicyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
2726
root := cb.NewConfigGroup()
2827
group := root
2928
for _, element := range path {
@@ -36,13 +35,19 @@ func TemplateImplicitMetaPolicy(path []string, policyName string, rule cb.Implic
3635
Type: int32(cb.Policy_IMPLICIT_META),
3736
Policy: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
3837
Rule: rule,
39-
SubPolicy: policyName,
38+
SubPolicy: subPolicyName,
4039
}),
4140
},
4241
}
4342
return root
4443
}
4544

45+
// TemplateImplicitMetaPolicy creates a policy at the specified path with the given policyName
46+
// It utilizes the policyName for the subPolicyName as well, as this is the standard usage pattern
47+
func TemplateImplicitMetaPolicy(path []string, policyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.ConfigGroup {
48+
return TemplateImplicitMetaPolicyWithSubPolicy(path, policyName, policyName, rule)
49+
}
50+
4651
// TempateImplicitMetaAnyPolicy returns TemplateImplicitMetaPolicy with cb.ImplicitMetaPolicy_ANY as the rule
4752
func TemplateImplicitMetaAnyPolicy(path []string, policyName string) *cb.ConfigGroup {
4853
return TemplateImplicitMetaPolicy(path, policyName, cb.ImplicitMetaPolicy_ANY)

common/policies/policy.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ const (
3535
// ApplicationPrefix is used in the path of standard application policy paths
3636
ApplicationPrefix = "Application"
3737

38+
// OrdererPrefix is used in the path of standard orderer policy paths
39+
OrdererPrefix = "Orderer"
40+
3841
// ChannelApplicationReaders is the label for the channel's application readers policy
39-
ChannelApplicationReaders = "/" + ChannelPrefix + "/" + ApplicationPrefix + "/Readers"
42+
ChannelApplicationReaders = PathSeparator + ChannelPrefix + PathSeparator + ApplicationPrefix + PathSeparator + "Readers"
4043

4144
// ChannelApplicationWriters is the label for the channel's application writers policy
42-
ChannelApplicationWriters = "/" + ChannelPrefix + "/" + ApplicationPrefix + "/Writers"
45+
ChannelApplicationWriters = PathSeparator + ChannelPrefix + PathSeparator + ApplicationPrefix + PathSeparator + "Writers"
4346

4447
// ChannelApplicationAdmins is the label for the channel's application admin policy
45-
ChannelApplicationAdmins = "/" + ChannelPrefix + "/" + ApplicationPrefix + "/Admins"
48+
ChannelApplicationAdmins = PathSeparator + ChannelPrefix + PathSeparator + ApplicationPrefix + PathSeparator + "Admins"
49+
50+
// BlockValidation is the label for the policy which should validate the block signatures for the channel
51+
BlockValidation = PathSeparator + ChannelPrefix + PathSeparator + OrdererPrefix + PathSeparator + "BlockValidation"
4652
)
4753

4854
var logger = logging.MustGetLogger("common/policies")
@@ -266,6 +272,16 @@ func (pm *ManagerImpl) CommitProposals() {
266272
}
267273
}
268274
}
275+
if _, ok := pm.config.managers[OrdererPrefix]; ok {
276+
for _, policyName := range []string{BlockValidation} {
277+
_, ok := pm.GetPolicy(policyName)
278+
if !ok {
279+
logger.Warningf("Current configuration has no policy '%s', this will likely cause problems in production systems", policyName)
280+
} else {
281+
logger.Debugf("As expected, current configuration has policy '%s'", policyName)
282+
}
283+
}
284+
}
269285
}
270286
}
271287

0 commit comments

Comments
 (0)