@@ -31,60 +31,74 @@ import (
31
31
bccsp "github.com/hyperledger/fabric/bccsp/factory"
32
32
)
33
33
34
+ var logger = logging .MustGetLogger ("configtx/tool/localconfig" )
35
+
34
36
const (
35
- // SampleInsecureProfile references the sample profile which does not include any MSPs and uses solo for consensus
37
+ // SampleInsecureProfile references the sample profile which does not include any MSPs and uses solo for ordering.
36
38
SampleInsecureProfile = "SampleInsecureSolo"
37
-
38
- // SampleSingleMSPSoloProfile references the sample profile which includes only the sample MSP and uses solo for consensus
39
+ // SampleSingleMSPSoloProfile references the sample profile which includes only the sample MSP and uses solo for ordering.
39
40
SampleSingleMSPSoloProfile = "SampleSingleMSPSolo"
41
+
42
+ // Prefix identifies the prefix for the configtxgen-related ENV vars.
43
+ Prefix string = "CONFIGTX"
40
44
)
41
45
42
- var logger = logging .MustGetLogger ("configtx/tool/localconfig" )
46
+ var (
47
+ configName string
48
+ configFileName string
49
+ )
43
50
44
- // Prefix is the default config prefix for the orderer
45
- const Prefix string = "CONFIGTX"
51
+ func init () {
52
+ configName = strings .ToLower (Prefix )
53
+ configFileName = configName + ".yaml"
54
+ }
46
55
47
- // TopLevel contains the genesis structures for use by the provisional bootstrapper
56
+ // TopLevel consists of the structs used by the configtxgen tool.
48
57
type TopLevel struct {
49
58
Profiles map [string ]* Profile `yaml:"Profiles"`
50
59
Organizations []* Organization `yaml:"Organizations"`
51
60
Application * Application `yaml:"Application"`
52
61
Orderer * Orderer `yaml:"Orderer"`
53
62
}
54
63
55
- // TopLevel contains the genesis structures for use by the provisional bootstrapper
64
+ // Profile encodes orderer/application configuration combinations for the configtxgen tool.
56
65
type Profile struct {
57
66
Application * Application `yaml:"Application"`
58
67
Orderer * Orderer `yaml:"Orderer"`
59
68
}
60
69
61
- // Application encodes the configuration needed for the config transaction
70
+ // Application encodes the application-level configuration needed in config transactions.
62
71
type Application struct {
63
72
Organizations []* Organization `yaml:"Organizations"`
64
73
}
65
74
75
+ // Organization encodes the organization-level configuration needed in config transactions.
66
76
type Organization struct {
67
77
Name string `yaml:"Name"`
68
78
ID string `yaml:"ID"`
69
79
MSPDir string `yaml:"MSPDir"`
70
80
BCCSP * bccsp.FactoryOpts `yaml:"BCCSP"`
71
81
72
- // Note, the viper deserialization does not seem to care for
73
- // embedding of types, so we use one organization structure for
74
- // both orderers and applications
82
+ // Note: Viper deserialization does not seem to care for
83
+ // embedding of types, so we use one organization struct
84
+ // for both orderers and applications.
75
85
AnchorPeers []* AnchorPeer `yaml:"AnchorPeers"`
76
86
}
77
87
88
+ // AnchorPeer encodes the necessary fields to identify an anchor peer.
78
89
type AnchorPeer struct {
79
90
Host string `yaml:"Host"`
80
91
Port int `yaml:"Port"`
81
92
}
82
93
94
+ // ApplicationOrganization ...
95
+ // TODO This should probably be removed
83
96
type ApplicationOrganization struct {
84
97
Organization `yaml:"Organization"`
85
98
}
86
99
87
- // Orderer contains config which is used for orderer genesis by the provisional bootstrapper
100
+ // Orderer contains configuration which is used for the
101
+ // bootstrapping of an orderer by the provisional bootstrapper.
88
102
type Orderer struct {
89
103
OrdererType string `yaml:"OrdererType"`
90
104
Addresses []string `yaml:"Addresses"`
@@ -95,14 +109,14 @@ type Orderer struct {
95
109
MaxChannels uint64 `yaml:"MaxChannels"`
96
110
}
97
111
98
- // BatchSize contains configuration affecting the size of batches
112
+ // BatchSize contains configuration affecting the size of batches.
99
113
type BatchSize struct {
100
114
MaxMessageCount uint32 `yaml:"MaxMessageSize"`
101
115
AbsoluteMaxBytes uint32 `yaml:"AbsoluteMaxBytes"`
102
116
PreferredMaxBytes uint32 `yaml:"PreferredMaxBytes"`
103
117
}
104
118
105
- // Kafka contains config for the Kafka orderer
119
+ // Kafka contains configuration for the Kafka-based orderer.
106
120
type Kafka struct {
107
121
Brokers []string `yaml:"Brokers"`
108
122
}
@@ -111,7 +125,7 @@ var genesisDefaults = TopLevel{
111
125
Orderer : & Orderer {
112
126
OrdererType : "solo" ,
113
127
Addresses : []string {"127.0.0.1:7050" },
114
- BatchTimeout : 10 * time .Second ,
128
+ BatchTimeout : 2 * time .Second ,
115
129
BatchSize : BatchSize {
116
130
MaxMessageCount : 10 ,
117
131
AbsoluteMaxBytes : 100000000 ,
@@ -123,43 +137,44 @@ var genesisDefaults = TopLevel{
123
137
},
124
138
}
125
139
126
- func (g * Profile ) completeInitialization () {
140
+ func (p * Profile ) completeInitialization () {
127
141
for {
128
142
switch {
129
- case g .Orderer .OrdererType == "" :
143
+ case p .Orderer .OrdererType == "" :
130
144
logger .Infof ("Orderer.OrdererType unset, setting to %s" , genesisDefaults .Orderer .OrdererType )
131
- g .Orderer .OrdererType = genesisDefaults .Orderer .OrdererType
132
- case g .Orderer .Addresses == nil :
145
+ p .Orderer .OrdererType = genesisDefaults .Orderer .OrdererType
146
+ case p .Orderer .Addresses == nil :
133
147
logger .Infof ("Orderer.Addresses unset, setting to %s" , genesisDefaults .Orderer .Addresses )
134
- g .Orderer .Addresses = genesisDefaults .Orderer .Addresses
135
- case g .Orderer .BatchTimeout == 0 :
148
+ p .Orderer .Addresses = genesisDefaults .Orderer .Addresses
149
+ case p .Orderer .BatchTimeout == 0 :
136
150
logger .Infof ("Orderer.BatchTimeout unset, setting to %s" , genesisDefaults .Orderer .BatchTimeout )
137
- g .Orderer .BatchTimeout = genesisDefaults .Orderer .BatchTimeout
138
- case g .Orderer .BatchSize .MaxMessageCount == 0 :
151
+ p .Orderer .BatchTimeout = genesisDefaults .Orderer .BatchTimeout
152
+ case p .Orderer .BatchSize .MaxMessageCount == 0 :
139
153
logger .Infof ("Orderer.BatchSize.MaxMessageCount unset, setting to %s" , genesisDefaults .Orderer .BatchSize .MaxMessageCount )
140
- g .Orderer .BatchSize .MaxMessageCount = genesisDefaults .Orderer .BatchSize .MaxMessageCount
141
- case g .Orderer .BatchSize .AbsoluteMaxBytes == 0 :
154
+ p .Orderer .BatchSize .MaxMessageCount = genesisDefaults .Orderer .BatchSize .MaxMessageCount
155
+ case p .Orderer .BatchSize .AbsoluteMaxBytes == 0 :
142
156
logger .Infof ("Orderer.BatchSize.AbsoluteMaxBytes unset, setting to %s" , genesisDefaults .Orderer .BatchSize .AbsoluteMaxBytes )
143
- g .Orderer .BatchSize .AbsoluteMaxBytes = genesisDefaults .Orderer .BatchSize .AbsoluteMaxBytes
144
- case g .Orderer .BatchSize .PreferredMaxBytes == 0 :
157
+ p .Orderer .BatchSize .AbsoluteMaxBytes = genesisDefaults .Orderer .BatchSize .AbsoluteMaxBytes
158
+ case p .Orderer .BatchSize .PreferredMaxBytes == 0 :
145
159
logger .Infof ("Orderer.BatchSize.PreferredMaxBytes unset, setting to %s" , genesisDefaults .Orderer .BatchSize .PreferredMaxBytes )
146
- g .Orderer .BatchSize .PreferredMaxBytes = genesisDefaults .Orderer .BatchSize .PreferredMaxBytes
147
- case g .Orderer .Kafka .Brokers == nil :
160
+ p .Orderer .BatchSize .PreferredMaxBytes = genesisDefaults .Orderer .BatchSize .PreferredMaxBytes
161
+ case p .Orderer .Kafka .Brokers == nil :
148
162
logger .Infof ("Orderer.Kafka.Brokers unset, setting to %v" , genesisDefaults .Orderer .Kafka .Brokers )
149
- g .Orderer .Kafka .Brokers = genesisDefaults .Orderer .Kafka .Brokers
163
+ p .Orderer .Kafka .Brokers = genesisDefaults .Orderer .Kafka .Brokers
150
164
default :
151
165
return
152
166
}
153
167
}
154
168
}
155
169
170
+ // Load returns the orderer/application config combination that corresponds to a given profile.
156
171
func Load (profile string ) * Profile {
157
172
config := viper .New ()
158
173
159
174
config .SetConfigName ("configtx" )
160
175
var cfgPath string
161
176
162
- // Path to look for the config file in based on GOPATH
177
+ // Candidate paths to look for the config file in, based on GOPATH
163
178
searchPath := []string {
164
179
os .Getenv ("ORDERER_CFG_PATH" ),
165
180
os .Getenv ("PEER_CFG_PATH" ),
@@ -169,21 +184,30 @@ func Load(profile string) *Profile {
169
184
searchPath = append (searchPath , filepath .Join (p , "src/github.com/hyperledger/fabric/common/configtx/tool/" ))
170
185
}
171
186
172
- for _ , genesisPath := range searchPath {
173
- logger .Infof ("Checking for configtx.yaml at: %s" , genesisPath )
174
- if _ , err := os .Stat (filepath .Join (genesisPath , "configtx.yaml" )); err != nil {
175
- // The yaml file does not exist in this component of the path
187
+ for _ , path := range searchPath {
188
+ if len (path ) == 0 {
189
+ // No point printing a "checking for" message below for an empty path
190
+ continue
191
+ }
192
+ logger .Infof ("Looking for %s in: %s" , configFileName , path )
193
+ if _ , err := os .Stat (filepath .Join (path , configFileName )); err != nil {
194
+ // The YAML file does not exist in this component of the path
176
195
continue
177
196
}
178
- cfgPath = genesisPath
197
+ cfgPath = path
198
+ logger .Infof ("Found %s there" , configFileName )
179
199
}
180
200
181
201
if cfgPath == "" {
182
- logger .Fatalf ("Could not find configtx.yaml in paths of %s. Try setting ORDERER_CFG_PATH, PEER_CFG_PATH, or GOPATH correctly" , searchPath )
202
+ logger .Fatalf ("Could not find %s in paths of %s." +
203
+ "Try setting ORDERER_CFG_PATH, PEER_CFG_PATH, or GOPATH correctly." ,
204
+ configFileName , searchPath )
183
205
}
184
- config .AddConfigPath (cfgPath ) // Path to look for the config file in
185
206
186
- // for environment variables
207
+ // Path to look for the config file in
208
+ config .AddConfigPath (cfgPath )
209
+
210
+ // For environment variables
187
211
config .SetEnvPrefix (Prefix )
188
212
config .AutomaticEnv ()
189
213
// This replacer allows substitution within the particular profile without having to fully qualify the name
@@ -192,14 +216,13 @@ func Load(profile string) *Profile {
192
216
193
217
err := config .ReadInConfig ()
194
218
if err != nil {
195
- panic ( fmt . Errorf ("Error reading %s plugin config from %s: %s" , Prefix , cfgPath , err ) )
219
+ logger . Panicf ("Error reading configuration from %s in %s: %s" , configFileName , cfgPath , err )
196
220
}
197
221
198
222
var uconf TopLevel
199
-
200
223
err = viperutil .EnhancedExactUnmarshal (config , & uconf )
201
224
if err != nil {
202
- panic ( fmt . Errorf ("Error unmarshaling into structure : %s" , err ) )
225
+ logger . Panicf ("Error unmarshaling config into struct : %s" , err )
203
226
}
204
227
205
228
result , ok := uconf .Profiles [profile ]
0 commit comments