Skip to content

Commit ae01f15

Browse files
author
Jason Yellick
committed
[FAB-2699] ConfigGroup mod policy resolve error
https://jira.hyperledger.org/browse/FAB-2699 The ConfigGroup mod policy is currently resolved like the ConfigValue and ConfigPolicy mod policies. For ConfigValue and ConfigPolicy mod policies, they look for the policy manager managing their config path. However, ConfigGroups represents nodes in the config path, and therefore they must resolve their policy manager by looking at their config path plus their key value. For example, the group /Channel/Orderer should resolve a mod policy of Admins to /Channel/Orderer/Admins but it currently resolves it to /Channel/Admins. While on the other hand the value /Channel/Orderer/foo should resolve a mod policy of Admins to /Channel/Orderer/Admins and not /Channel/Orderer/foo/Admins (because foo is not a group node in the config). This CR fixes this mistake, enhances logging slightly, and adds a test case. Change-Id: I0d8b58f8ca21f78a8a2d7331e330fea4768ab973 Signed-off-by: Jason Yellick <[email protected]>
1 parent f086f8b commit ae01f15

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

common/config/standardvalues.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewStandardValues(protosStructs ...interface{}) (*standardValues, error) {
5353
func (sv *standardValues) Deserialize(key string, value []byte) (proto.Message, error) {
5454
msg, ok := sv.lookup[key]
5555
if !ok {
56-
return nil, fmt.Errorf("Not found")
56+
return nil, fmt.Errorf("Unexpected key %s", key)
5757
}
5858

5959
err := proto.Unmarshal(value, msg)

common/configtx/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func proposeGroup(result *configResult) error {
210210
msg, err := valueDeserializer.Deserialize(key, value.Value)
211211
if err != nil {
212212
result.rollback()
213-
return err
213+
return fmt.Errorf("Error deserializing key %s for group %s: %s", key, result.groupName, err)
214214
}
215215
result.deserializedValues[key] = msg
216216
}

common/configtx/update.go

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ func (cm *configManager) policyForItem(item comparable) (policies.Policy, bool)
145145
if !ok {
146146
return nil, ok
147147
}
148+
149+
// In the case of the group type, its key is part of its path for the purposes of finding the policy manager
150+
if item.ConfigGroup != nil {
151+
manager, ok = manager.Manager([]string{item.key})
152+
}
153+
if !ok {
154+
return nil, ok
155+
}
148156
return manager.GetPolicy(item.modPolicy())
149157
}
150158

common/configtx/update_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,14 @@ func TestPolicyForItem(t *testing.T) {
165165
})
166166
assert.True(t, ok)
167167
assert.Equal(t, policy, fooPolicy, "Should not have found relative foo policy the foo manager")
168+
169+
policy, ok = cm.policyForItem(comparable{
170+
key: "foo",
171+
path: []string{"root"},
172+
ConfigGroup: &cb.ConfigGroup{
173+
ModPolicy: "foo",
174+
},
175+
})
176+
assert.True(t, ok)
177+
assert.Equal(t, policy, fooPolicy, "Should have found relative foo policy for foo group")
168178
}

0 commit comments

Comments
 (0)