Skip to content

Commit 2802430

Browse files
author
Jason Yellick
committedOct 13, 2017
[FAB-6143] Cleanup dead code
Now that almost all references the config templating code is gone, it should be removed entirely from the codebase. This final CR in the channel config generation cleanup series shows a net decrease of over 400 lines, with an even larger shift of lines of code from the orderer/peer production binaries and into the configtxgen binary. Change-Id: I614a10113c0f90b822da5103319a91f2f28b66b5 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 2ef4823 commit 2802430

18 files changed

+45
-863
lines changed
 

‎common/channelconfig/application_util.go

-42
This file was deleted.

‎common/channelconfig/channel_util.go

-82
This file was deleted.

‎common/channelconfig/consortium.go

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15+
const (
16+
// ChannelCreationPolicyKey is the key used in the consortium config to denote the policy
17+
// to be used in evaluating whether a channel creation request is authorized
18+
ChannelCreationPolicyKey = "ChannelCreationPolicy"
19+
)
20+
1521
// ConsortiumProtos holds the config protos for the consortium config
1622
type ConsortiumProtos struct {
1723
ChannelCreationPolicy *cb.Policy

‎common/channelconfig/consortiums_util.go

-34
This file was deleted.

‎common/channelconfig/msp_test.go

-33
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ import (
1010
"testing"
1111

1212
"github.com/hyperledger/fabric/common/capabilities"
13-
"github.com/hyperledger/fabric/common/cauthdsl"
1413
"github.com/hyperledger/fabric/core/config"
1514
"github.com/hyperledger/fabric/msp"
16-
cb "github.com/hyperledger/fabric/protos/common"
1715
mspprotos "github.com/hyperledger/fabric/protos/msp"
18-
"github.com/hyperledger/fabric/protos/utils"
1916
"github.com/stretchr/testify/assert"
2017
)
2118

@@ -58,33 +55,3 @@ func TestMSPConfigFailure(t *testing.T) {
5855
assert.Error(t, err)
5956
})
6057
}
61-
62-
func TestTemplates(t *testing.T) {
63-
mspDir, err := config.GetDevMspDir()
64-
assert.NoError(t, err)
65-
mspConf, err := msp.GetLocalMspConfig(mspDir, nil, "DEFAULT")
66-
assert.NoError(t, err)
67-
68-
expectedMSPValue := &cb.ConfigValue{
69-
Value: utils.MarshalOrPanic(mspConf),
70-
}
71-
configGroup := TemplateGroupMSP([]string{"TestPath"}, mspConf)
72-
testGroup, ok := configGroup.Groups["TestPath"]
73-
assert.Equal(t, true, ok, "Failed to find group key")
74-
assert.Equal(t, expectedMSPValue, testGroup.Values[MSPKey], "MSPKey did not match expected value")
75-
76-
configGroup = TemplateGroupMSPWithAdminRolePrincipal([]string{"TestPath"}, mspConf, false)
77-
expectedPolicyValue := utils.MarshalOrPanic(cauthdsl.SignedByMspMember("DEFAULT"))
78-
actualPolicyValue := configGroup.Groups["TestPath"].Policies[AdminsPolicyKey].Policy.Value
79-
assert.Equal(t, expectedPolicyValue, actualPolicyValue, "Expected SignedByMspMemberPolicy")
80-
81-
mspConf = &mspprotos.MSPConfig{}
82-
assert.Panics(t, func() {
83-
configGroup = TemplateGroupMSPWithAdminRolePrincipal([]string{"TestPath"}, mspConf, false)
84-
}, "Expected panic with bad msp config")
85-
mspConf.Type = int32(10)
86-
assert.Panics(t, func() {
87-
configGroup = TemplateGroupMSPWithAdminRolePrincipal([]string{"TestPath"}, mspConf, false)
88-
}, "Expected panic with bad msp config")
89-
90-
}

‎common/channelconfig/msp_util.go

-100
This file was deleted.

‎common/channelconfig/orderer_util.go

-52
This file was deleted.

‎common/channelconfig/organization.go

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import (
1616
"github.com/pkg/errors"
1717
)
1818

19+
const (
20+
// MSPKey is the key for the MSP definition in orderer groups
21+
MSPKey = "MSP"
22+
)
23+
1924
// OrganizationProtos are used to deserialize the organization config
2025
type OrganizationProtos struct {
2126
MSP *mspprotos.MSPConfig

‎common/channelconfig/template.go

-97
This file was deleted.

‎common/channelconfig/template_test.go

-51
This file was deleted.

‎common/channelconfig/util.go

+18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ SPDX-License-Identifier: Apache-2.0
77
package channelconfig
88

99
import (
10+
"math"
11+
12+
"github.com/hyperledger/fabric/bccsp"
1013
cb "github.com/hyperledger/fabric/protos/common"
1114
mspprotos "github.com/hyperledger/fabric/protos/msp"
1215
ab "github.com/hyperledger/fabric/protos/orderer"
@@ -15,6 +18,21 @@ import (
1518
"github.com/golang/protobuf/proto"
1619
)
1720

21+
const (
22+
// ReadersPolicyKey is the key used for the read policy
23+
ReadersPolicyKey = "Readers"
24+
25+
// WritersPolicyKey is the key used for the read policy
26+
WritersPolicyKey = "Writers"
27+
28+
// AdminsPolicyKey is the key used for the read policy
29+
AdminsPolicyKey = "Admins"
30+
31+
defaultHashingAlgorithm = bccsp.SHA256
32+
33+
defaultBlockDataHashingStructureWidth = math.MaxUint32
34+
)
35+
1836
// ConfigValue defines a common representation for different *cb.ConfigValue values.
1937
type ConfigValue interface {
2038
// Key is the key this value should be stored in the *cb.ConfigGroup.Values map.

‎common/channelconfig/util_test.go

-26
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
cb "github.com/hyperledger/fabric/protos/common"
1313
mspprotos "github.com/hyperledger/fabric/protos/msp"
14-
ab "github.com/hyperledger/fabric/protos/orderer"
1514
pb "github.com/hyperledger/fabric/protos/peer"
1615

1716
"github.com/stretchr/testify/assert"
@@ -23,31 +22,6 @@ import (
2322
// in the test, which also provides no value. But, not including these produces an artificially
2423
// low code coverage count, so here they are.
2524

26-
func TestChannelUtils(t *testing.T) {
27-
assert.NotNil(t, TemplateConsortium("test"))
28-
assert.NotNil(t, DefaultHashingAlgorithm())
29-
assert.NotNil(t, DefaultBlockDataHashingStructure())
30-
assert.NotNil(t, DefaultOrdererAddresses())
31-
32-
}
33-
34-
func TestOrdererUtils(t *testing.T) {
35-
assert.NotNil(t, TemplateConsensusType("foo"))
36-
assert.NotNil(t, TemplateBatchSize(&ab.BatchSize{}))
37-
assert.NotNil(t, TemplateBatchTimeout("3s"))
38-
assert.NotNil(t, TemplateChannelRestrictions(0))
39-
assert.NotNil(t, TemplateKafkaBrokers([]string{"foo"}))
40-
}
41-
42-
func TestApplicationUtils(t *testing.T) {
43-
assert.NotNil(t, TemplateAnchorPeers("foo", nil))
44-
}
45-
46-
func TestConsortiumsUtils(t *testing.T) {
47-
assert.NotNil(t, TemplateConsortiumsGroup())
48-
assert.NotNil(t, TemplateConsortiumChannelCreationPolicy("foo", &cb.Policy{}))
49-
}
50-
5125
func basicTest(t *testing.T, sv *StandardConfigValue) {
5226
assert.NotNil(t, sv)
5327
assert.NotEmpty(t, sv.Key())

‎common/configtx/template.go

-199
This file was deleted.

‎common/configtx/template_test.go

-115
This file was deleted.

‎common/tools/configtxgen/encoder/encoder_test.go

-22
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,6 @@ func TestNegativeChannelCreateConfigUpdate(t *testing.T) {
121121
})
122122
}
123123

124-
// This is a temporary test to make sure that the newly implement channel creation method properly replicates
125-
// the old behavior
126-
func TestCompatability(t *testing.T) {
127-
config := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile)
128-
group, err := NewChannelGroup(config)
129-
assert.NoError(t, err)
130-
assert.NotNil(t, group)
131-
132-
channelID := "channel.id"
133-
orgs := []string{genesisconfig.SampleOrgName}
134-
configUpdate, err := NewChannelCreateConfigUpdate(channelID, genesisconfig.SampleConsortiumName, orgs, group)
135-
assert.NoError(t, err)
136-
assert.NotNil(t, configUpdate)
137-
138-
template := channelconfig.NewChainCreationTemplate(genesisconfig.SampleConsortiumName, orgs)
139-
configEnv, err := template.Envelope(channelID)
140-
assert.NoError(t, err)
141-
oldUpdate := configtx.UnmarshalConfigUpdateOrPanic(configEnv.ConfigUpdate)
142-
oldUpdate.IsolatedData = nil
143-
assert.True(t, proto.Equal(oldUpdate, configUpdate))
144-
}
145-
146124
func TestMakeChannelCreationTransactionWithSigner(t *testing.T) {
147125
channelID := "foo"
148126

‎common/tools/configtxgen/main.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ func doOutputAnchorPeersUpdate(conf *genesisconfig.Profile, channelID string, ou
108108
}
109109
}
110110

111-
configGroup := channelconfig.TemplateAnchorPeers(org.Name, anchorPeers)
112-
configGroup.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Values[channelconfig.AnchorPeersKey].ModPolicy = channelconfig.AdminsPolicyKey
113111
configUpdate := &cb.ConfigUpdate{
114112
ChannelId: channelID,
115-
WriteSet: configGroup,
113+
WriteSet: cb.NewConfigGroup(),
116114
ReadSet: cb.NewConfigGroup(),
117115
}
118116

@@ -127,14 +125,20 @@ func doOutputAnchorPeersUpdate(conf *genesisconfig.Profile, channelID string, ou
127125
configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[channelconfig.AdminsPolicyKey] = &cb.ConfigPolicy{}
128126

129127
// Add all the existing at the same versions to the writeset
128+
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey] = cb.NewConfigGroup()
130129
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Version = 1
131130
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].ModPolicy = channelconfig.AdminsPolicyKey
131+
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name] = cb.NewConfigGroup()
132132
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Version = 1
133133
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].ModPolicy = channelconfig.AdminsPolicyKey
134134
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Values[channelconfig.MSPKey] = &cb.ConfigValue{}
135135
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[channelconfig.ReadersPolicyKey] = &cb.ConfigPolicy{}
136136
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[channelconfig.WritersPolicyKey] = &cb.ConfigPolicy{}
137137
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[channelconfig.AdminsPolicyKey] = &cb.ConfigPolicy{}
138+
configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Values[channelconfig.AnchorPeersKey] = &cb.ConfigValue{
139+
Value: utils.MarshalOrPanic(channelconfig.AnchorPeersValue(anchorPeers).Value()),
140+
ModPolicy: channelconfig.AdminsPolicyKey,
141+
}
138142

139143
configUpdateEnvelope := &cb.ConfigUpdateEnvelope{
140144
ConfigUpdate: utils.MarshalOrPanic(configUpdate),

‎orderer/common/msgprocessor/systemchannel.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,10 @@ func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (chan
316316
// Set the new config orderer group to the system channel orderer group and the application group to the new application group
317317
channelGroup.Groups[channelconfig.OrdererGroupKey] = systemChannelGroup.Groups[channelconfig.OrdererGroupKey]
318318
channelGroup.Groups[channelconfig.ApplicationGroupKey] = applicationGroup
319-
channelGroup.Values[channelconfig.ConsortiumKey] = channelconfig.TemplateConsortium(consortium.Name).Values[channelconfig.ConsortiumKey]
319+
channelGroup.Values[channelconfig.ConsortiumKey] = &cb.ConfigValue{
320+
Value: utils.MarshalOrPanic(channelconfig.ConsortiumValue(consortium.Name).Value()),
321+
ModPolicy: channelconfig.AdminsPolicyKey,
322+
}
320323

321324
// Non-backwards compatible bugfix introduced in v1.1
322325
// The capability check should be removed once v1.0 is deprecated

‎orderer/common/multichannel/util_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ func makeConfigTx(chainID string, i int) *cb.Envelope {
109109
group.Groups[channelconfig.OrdererGroupKey].Values[fmt.Sprintf("%d", i)] = &cb.ConfigValue{
110110
Value: []byte(fmt.Sprintf("%d", i)),
111111
}
112-
configTemplate := configtx.NewSimpleTemplate(group)
113-
configEnv, err := configTemplate.Envelope(chainID)
114-
if err != nil {
115-
panic(err)
116-
}
117-
return makeConfigTxFromConfigUpdateEnvelope(chainID, configEnv)
112+
return makeConfigTxFromConfigUpdateEnvelope(chainID, &cb.ConfigUpdateEnvelope{
113+
ConfigUpdate: utils.MarshalOrPanic(&cb.ConfigUpdate{
114+
WriteSet: group,
115+
}),
116+
})
118117
}
119118

120119
func wrapConfigTx(env *cb.Envelope) *cb.Envelope {

0 commit comments

Comments
 (0)
Please sign in to comment.