Skip to content

Commit b78e929

Browse files
author
Jason Yellick
committed
[FAB-2342] Encode MSPs via configtxgen tool
https://jira.hyperledger.org/browse/FAB-2342 This CR adds utilizes the MSP and anchor peer information in the genesis.yaml to additional encode these parameters into a genesis block. This additionally adds sample configtx profiles which may be specified when using the configtx tool to generate a genesis config. Change-Id: I57a5caf5f02f510ef4bf6e4799403dbfa40d8478 Signed-off-by: Jason Yellick <[email protected]>
1 parent 6f4a391 commit b78e929

File tree

24 files changed

+237
-116
lines changed

24 files changed

+237
-116
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ build/image/javaenv/payload: build/javashim.tar.bz2 \
178178
build/image/peer/payload: build/docker/bin/peer \
179179
peer/core.yaml \
180180
build/msp-sampleconfig.tar.bz2 \
181-
common/configtx/tool/genesis.yaml
181+
common/configtx/tool/configtx.yaml
182182
build/image/orderer/payload: build/docker/bin/orderer \
183183
build/msp-sampleconfig.tar.bz2 \
184184
orderer/orderer.yaml \
185-
common/configtx/tool/genesis.yaml
185+
common/configtx/tool/configtx.yaml
186186
build/image/buildenv/payload: build/gotools.tar.bz2 \
187187
build/docker/gotools/bin/protoc-gen-go
188188
build/image/testenv/payload: build/docker/bin/orderer \
189189
orderer/orderer.yaml \
190-
common/configtx/tool/genesis.yaml \
190+
common/configtx/tool/configtx.yaml \
191191
build/docker/bin/peer \
192192
peer/core.yaml \
193193
build/msp-sampleconfig.tar.bz2 \

common/configtx/test/helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func MakeGenesisBlock(chainID string) (*cb.Block, error) {
8181

8282
// OrderererTemplate returns the test orderer template
8383
func OrdererTemplate() configtx.Template {
84-
genConf := genesisconfig.Load()
84+
genConf := genesisconfig.Load(genesisconfig.SampleInsecureProfile)
8585
return provisional.New(genConf).ChannelTemplate()
8686
}
8787

common/configtx/test/helper_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ limitations under the License.
1717
package test
1818

1919
import (
20+
"os"
21+
"path/filepath"
2022
"testing"
2123

2224
logging "github.com/op/go-logging"
2325
)
2426

2527
func init() {
28+
// Configuration is always specified relative to $GOPATH/github.com/hyperledger/fabric
29+
// This test will fail with the default configuration if executed in the package dir
30+
// We are in common/configtx/test
31+
os.Chdir(filepath.Join("..", "..", ".."))
32+
2633
logging.SetLevel(logging.DEBUG, "")
2734
}
2835

common/configtx/tool/genesis.yaml common/configtx/tool/configtx.yaml

+36-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
---
2+
################################################################################
3+
#
4+
# Profile
5+
#
6+
# - Different configuration profiles may be encoded here to be specified
7+
# as parameters to the configtxgen tool
8+
#
9+
################################################################################
10+
Profiles:
11+
12+
# SampleInsecureSol defines a configuration which contains no MSP definitions
13+
# and allows all transactions and channel creation requests
14+
SampleInsecureSolo:
15+
Orderer:
16+
<<: *OrdererDefaults
17+
Application:
18+
<<: *ApplicationDefaults
19+
20+
# SampleSingleMSPSolo defines a configuration which contains a single MSP
21+
# definition (the MSP sampleconfig).
22+
SampleSingleMSPSolo:
23+
Orderer:
24+
<<: *OrdererDefaults
25+
Organizations:
26+
- *SampleOrg
27+
Application:
28+
<<: *ApplicationDefaults
29+
Organizations:
30+
- *SampleOrg
31+
232
################################################################################
333
#
434
# Section: Organizations
@@ -9,18 +39,19 @@
939
################################################################################
1040
Organizations:
1141

12-
- &defaultOrg
42+
# SampleOrg defines an MSP using the sampleconfig. It should never be used
43+
# in production but may be used as a template for other definitions
44+
- &SampleOrg
1345
# DefaultOrg defines the organization which is used in the sampleconfig
1446
# of the fabric.git development environment
15-
Name: defaultOrg
47+
Name: SampleOrg
1648

1749
# ID to load the MSP definition as
1850
ID: DEFAULT
1951

2052
# MSPDir is the filesystem path which contains the MSP configuration
2153
MSPDir: msp/sampleconfig
2254

23-
2455
AnchorPeers:
2556
# AnchorPeers defines the location of peers which can be used
2657
# for cross org gossip communication. Note, this value is only
@@ -36,7 +67,7 @@ Organizations:
3667
# genesis block for orderer related parameters
3768
#
3869
################################################################################
39-
Orderer:
70+
Orderer: &OrdererDefaults
4071

4172
# Orderer Type: The orderer implementation to start
4273
# Available types are "solo" and "kafka"
@@ -73,9 +104,6 @@ Orderer:
73104
# the orderer side of the network
74105
Organizations:
75106

76-
# The default organization as defined in the organization section
77-
- *defaultOrg
78-
79107
################################################################################
80108
#
81109
# SECTION: Application
@@ -84,11 +112,8 @@ Orderer:
84112
# genesis block for application related parameters
85113
#
86114
################################################################################
87-
Application:
115+
Application: &ApplicationDefaults
88116

89117
# Organizations is the list of orgs which are defined as participants on
90118
# the application side of the network
91119
Organizations:
92-
93-
# The default organization as defined in the organization section
94-
- *defaultOrg

common/configtx/tool/localconfig/config.go

+31-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ import (
2929
"github.com/spf13/viper"
3030
)
3131

32+
const (
33+
// SampleInsecureProfile references the sample profile which does not include any MSPs and uses solo for consensus
34+
SampleInsecureProfile = "SampleInsecureSolo"
35+
36+
// SampleSingleMSPSoloProfile references the sample profile which includes only the sample MSP and uses solo for consensus
37+
SampleSingleMSPSoloProfile = "SampleSingleMSPSolo"
38+
)
39+
3240
var logger = logging.MustGetLogger("configtx/tool/localconfig")
3341

3442
func init() {
@@ -40,11 +48,19 @@ const Prefix string = "CONFIGTX"
4048

4149
// TopLevel contains the genesis structures for use by the provisional bootstrapper
4250
type TopLevel struct {
43-
Application Application
51+
Profiles map[string]*Profile
4452
Organizations []*Organization
45-
Orderer Orderer
53+
Application *Application
54+
Orderer *Orderer
4655
}
4756

57+
// TopLevel contains the genesis structures for use by the provisional bootstrapper
58+
type Profile struct {
59+
Application *Application
60+
Orderer *Orderer
61+
}
62+
63+
// Application encodes the configuration needed for the config transaction
4864
type Application struct {
4965
Organizations []*Organization
5066
}
@@ -92,7 +108,7 @@ type Kafka struct {
92108
}
93109

94110
var genesisDefaults = TopLevel{
95-
Orderer: Orderer{
111+
Orderer: &Orderer{
96112
OrdererType: "solo",
97113
Addresses: []string{"127.0.0.1:7050"},
98114
BatchTimeout: 10 * time.Second,
@@ -107,7 +123,7 @@ var genesisDefaults = TopLevel{
107123
},
108124
}
109125

110-
func (g *TopLevel) completeInitialization() {
126+
func (g *Profile) completeInitialization() {
111127
for {
112128
switch {
113129
case g.Orderer.OrdererType == "":
@@ -140,10 +156,10 @@ func (g *TopLevel) completeInitialization() {
140156
}
141157
}
142158

143-
func Load() *TopLevel {
159+
func Load(profile string) *Profile {
144160
config := viper.New()
145161

146-
config.SetConfigName("genesis")
162+
config.SetConfigName("configtx")
147163
var cfgPath string
148164

149165
// Path to look for the config file in based on GOPATH
@@ -157,16 +173,16 @@ func Load() *TopLevel {
157173
}
158174

159175
for _, genesisPath := range searchPath {
160-
logger.Infof("Checking for genesis.yaml at: %s", genesisPath)
161-
if _, err := os.Stat(filepath.Join(genesisPath, "genesis.yaml")); err != nil {
176+
logger.Infof("Checking for configtx.yaml at: %s", genesisPath)
177+
if _, err := os.Stat(filepath.Join(genesisPath, "configtx.yaml")); err != nil {
162178
// The yaml file does not exist in this component of the path
163179
continue
164180
}
165181
cfgPath = genesisPath
166182
}
167183

168184
if cfgPath == "" {
169-
logger.Fatalf("Could not find genesis.yaml in paths of %s. Try setting ORDERER_CFG_PATH, PEER_CFG_PATH, or GOPATH correctly", searchPath)
185+
logger.Fatalf("Could not find configtx.yaml in paths of %s. Try setting ORDERER_CFG_PATH, PEER_CFG_PATH, or GOPATH correctly", searchPath)
170186
}
171187
config.AddConfigPath(cfgPath) // Path to look for the config file in
172188

@@ -188,7 +204,11 @@ func Load() *TopLevel {
188204
panic(fmt.Errorf("Error unmarshaling into structure: %s", err))
189205
}
190206

191-
uconf.completeInitialization()
207+
result, ok := uconf.Profiles[profile]
208+
if !ok {
209+
logger.Panicf("Could not find profile %s", profile)
210+
}
211+
result.completeInitialization()
192212

193-
return &uconf
213+
return result
194214
}

common/configtx/tool/provisional/provisional.go

+64-27
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ import (
2828
configvaluesmsp "github.com/hyperledger/fabric/common/configvalues/msp"
2929
"github.com/hyperledger/fabric/common/genesis"
3030
"github.com/hyperledger/fabric/common/policies"
31+
"github.com/hyperledger/fabric/msp"
3132
"github.com/hyperledger/fabric/orderer/common/bootstrap"
3233
cb "github.com/hyperledger/fabric/protos/common"
3334
ab "github.com/hyperledger/fabric/protos/orderer"
35+
36+
logging "github.com/op/go-logging"
3437
)
3538

39+
var logger = logging.MustGetLogger("common/configtx/tool/provisional")
40+
3641
// Generator can either create an orderer genesis block or config template
3742
type Generator interface {
3843
bootstrap.Helper
@@ -63,19 +68,33 @@ const (
6368
var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey}
6469

6570
type bootstrapper struct {
66-
minimalGroups []*cb.ConfigGroup
67-
systemChainGroups []*cb.ConfigGroup
71+
channelGroups []*cb.ConfigGroup
72+
ordererGroups []*cb.ConfigGroup
73+
applicationGroups []*cb.ConfigGroup
74+
ordererSystemChannelGroups []*cb.ConfigGroup
6875
}
6976

7077
// New returns a new provisional bootstrap helper.
71-
func New(conf *genesisconfig.TopLevel) Generator {
78+
func New(conf *genesisconfig.Profile) Generator {
7279
bs := &bootstrapper{
73-
minimalGroups: []*cb.ConfigGroup{
80+
channelGroups: []*cb.ConfigGroup{
7481
// Chain Config Types
7582
configtxchannel.DefaultHashingAlgorithm(),
7683
configtxchannel.DefaultBlockDataHashingStructure(),
77-
configtxchannel.TemplateOrdererAddresses(conf.Orderer.Addresses),
84+
configtxchannel.TemplateOrdererAddresses(conf.Orderer.Addresses), // TODO, move to conf.Channel when it exists
7885

86+
// Default policies
87+
policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.ReadersPolicyKey),
88+
policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.WritersPolicyKey),
89+
policies.TemplateImplicitMetaMajorityPolicy([]string{}, configvaluesmsp.AdminsPolicyKey),
90+
91+
// Temporary AcceptAllPolicy XXX, remove
92+
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
93+
},
94+
}
95+
96+
if conf.Orderer != nil {
97+
bs.ordererGroups = []*cb.ConfigGroup{
7998
// Orderer Config Types
8099
configtxorderer.TemplateConsensusType(conf.Orderer.OrdererType),
81100
configtxorderer.TemplateBatchSize(&ab.BatchSize{
@@ -87,49 +106,67 @@ func New(conf *genesisconfig.TopLevel) Generator {
87106
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
88107
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
89108

90-
// Policies
91-
cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy),
92-
93-
// Initialize the default Reader/Writer/Admins channel policies
94-
policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.ReadersPolicyKey),
95-
policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.WritersPolicyKey),
96-
policies.TemplateImplicitMetaMajorityPolicy([]string{}, configvaluesmsp.AdminsPolicyKey),
97-
98109
// Initialize the default Reader/Writer/Admins orderer policies
99110
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.ReadersPolicyKey),
100111
policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.WritersPolicyKey),
101112
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.AdminsPolicyKey),
113+
}
114+
115+
for _, org := range conf.Orderer.Organizations {
116+
mspConfig, err := msp.GetLocalMspConfig(org.MSPDir, org.ID)
117+
if err != nil {
118+
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
119+
}
120+
bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{configtxorderer.GroupKey, org.Name}, mspConfig))
121+
}
122+
123+
switch conf.Orderer.OrdererType {
124+
case ConsensusTypeSolo, ConsensusTypeSbft:
125+
case ConsensusTypeKafka:
126+
bs.ordererGroups = append(bs.ordererGroups, configtxorderer.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers))
127+
default:
128+
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType))
129+
}
130+
131+
bs.ordererSystemChannelGroups = []*cb.ConfigGroup{
132+
// Policies
133+
configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
134+
}
135+
}
102136

137+
if conf.Application != nil {
138+
139+
bs.applicationGroups = []*cb.ConfigGroup{
103140
// Initialize the default Reader/Writer/Admins application policies
104141
policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.ReadersPolicyKey),
105142
policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.WritersPolicyKey),
106143
policies.TemplateImplicitMetaMajorityPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.AdminsPolicyKey),
107-
},
108-
109-
systemChainGroups: []*cb.ConfigGroup{
110-
configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames),
111-
},
112-
}
144+
}
145+
for _, org := range conf.Application.Organizations {
146+
mspConfig, err := msp.GetLocalMspConfig(org.MSPDir, org.ID)
147+
if err != nil {
148+
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
149+
}
150+
bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey, org.Name}, mspConfig))
151+
}
113152

114-
switch conf.Orderer.OrdererType {
115-
case ConsensusTypeSolo, ConsensusTypeSbft:
116-
case ConsensusTypeKafka:
117-
bs.minimalGroups = append(bs.minimalGroups, configtxorderer.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers))
118-
default:
119-
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType))
120153
}
121154

122155
return bs
123156
}
124157

125158
func (bs *bootstrapper) ChannelTemplate() configtx.Template {
126-
return configtx.NewSimpleTemplate(bs.minimalGroups...)
159+
return configtx.NewCompositeTemplate(
160+
configtx.NewSimpleTemplate(bs.channelGroups...),
161+
configtx.NewSimpleTemplate(bs.ordererGroups...),
162+
configtx.NewSimpleTemplate(bs.applicationGroups...),
163+
)
127164
}
128165

129166
func (bs *bootstrapper) GenesisBlock() *cb.Block {
130167
block, err := genesis.NewFactoryImpl(
131168
configtx.NewCompositeTemplate(
132-
configtx.NewSimpleTemplate(bs.systemChainGroups...),
169+
configtx.NewSimpleTemplate(bs.ordererSystemChannelGroups...),
133170
bs.ChannelTemplate(),
134171
),
135172
).Block(TestChainID)

0 commit comments

Comments
 (0)