Skip to content

Commit bb0df71

Browse files
committed
[FAB-2937] Fix minor issues in localconfig
1. Remove unnecessary struct 2. Bring it inline with const/init declarations I did in `common/configtx/tool/localconfig` (By the way, the periods in the exported comments is not OCD but actually a guideline: https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences) Change-Id: If2d4394ffafaf1ae3e15fa228b4e40abc0dea47b Signed-off-by: Kostas Christidis <[email protected]>
1 parent 441b308 commit bb0df71

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

common/configtx/tool/localconfig/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (p *Profile) completeInitialization() {
171171
func Load(profile string) *Profile {
172172
config := viper.New()
173173

174-
config.SetConfigName("configtx")
174+
config.SetConfigName(configName)
175175
var cfgPath string
176176

177177
// Candidate paths to look for the config file in, based on GOPATH

orderer/localconfig/config.go

+40-33
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717
package config
1818

1919
import (
20-
"fmt"
2120
"os"
2221
"path/filepath"
2322
"strings"
2423
"time"
2524

25+
"github.com/hyperledger/fabric/common/flogging"
2626
"github.com/hyperledger/fabric/common/viperutil"
2727

2828
"github.com/Shopify/sarama"
@@ -32,16 +32,29 @@ import (
3232
bccsp "github.com/hyperledger/fabric/bccsp/factory"
3333
)
3434

35-
var logger = logging.MustGetLogger("orderer/config")
35+
const (
36+
pkgLogID = "orderer/config"
37+
38+
// Prefix identifies the prefix for the orderer-related ENV vars.
39+
Prefix = "ORDERER"
40+
)
41+
42+
var (
43+
logger *logging.Logger
44+
45+
configName string
46+
configFileName string
47+
)
3648

3749
func init() {
38-
logging.SetLevel(logging.ERROR, "")
39-
}
50+
logger = flogging.MustGetLogger(pkgLogID)
51+
flogging.SetModuleLevel(pkgLogID, "error")
4052

41-
// Prefix is the default config prefix for the orderer
42-
const Prefix string = "ORDERER"
53+
configName = strings.ToLower(Prefix)
54+
configFileName = configName + ".yaml"
55+
}
4356

44-
// General contains config which should be common among all orderer types
57+
// General contains config which should be common among all orderer types.
4558
type General struct {
4659
LedgerType string
4760
ListenAddress string
@@ -57,7 +70,7 @@ type General struct {
5770
BCCSP *bccsp.FactoryOpts
5871
}
5972

60-
//TLS contains config used to configure TLS
73+
// TLS contains config for TLS connections.
6174
type TLS struct {
6275
Enabled bool
6376
PrivateKey string
@@ -68,68 +81,63 @@ type TLS struct {
6881
}
6982

7083
// Genesis is a deprecated structure which was used to put
71-
// values into the genesis block, but this is now handled elsewhere
84+
// values into the genesis block, but this is now handled elsewhere.
7285
// SBFT did not reference these values via the genesis block however
73-
// so it is being left here for backwards compatibility purposes
86+
// so it is being left here for backwards compatibility purposes.
7487
type Genesis struct {
7588
DeprecatedBatchTimeout time.Duration
7689
DeprecatedBatchSize uint32
7790
SbftShared SbftShared
7891
}
7992

80-
// Profile contains configuration for Go pprof profiling
93+
// Profile contains configuration for Go pprof profiling.
8194
type Profile struct {
8295
Enabled bool
8396
Address string
8497
}
8598

86-
// RAMLedger contains config for the RAM ledger
99+
// RAMLedger contains configuration for the RAM ledger.
87100
type RAMLedger struct {
88101
HistorySize uint
89102
}
90103

91-
// FileLedger contains config for the File ledger
104+
// FileLedger contains configuration for the file-based ledger.
92105
type FileLedger struct {
93106
Location string
94107
Prefix string
95108
}
96109

97-
// Kafka contains config for the Kafka orderer
110+
// Kafka contains configuration for the Kafka-based orderer.
98111
type Kafka struct {
99112
Retry Retry
100113
Verbose bool
101-
Version sarama.KafkaVersion
114+
Version sarama.KafkaVersion // TODO Move this to global config
102115
TLS TLS
103116
}
104117

105-
// SbftLocal contains config for the SBFT peer/replica
118+
// SbftLocal contains configuration for the SBFT peer/replica.
106119
type SbftLocal struct {
107120
PeerCommAddr string
108121
CertFile string
109122
KeyFile string
110123
DataDir string
111124
}
112125

113-
// SbftShared contains config for the SBFT network
126+
// SbftShared contains config for the SBFT network.
114127
type SbftShared struct {
115128
N uint64
116129
F uint64
117130
RequestTimeoutNsec uint64
118131
Peers map[string]string // Address to Cert mapping
119132
}
120133

121-
// Retry contains config for the reconnection attempts to the Kafka brokers
134+
// Retry contains config for the reconnection attempts to the Kafka brokers.
122135
type Retry struct {
123136
Period time.Duration
124137
Stop time.Duration
125138
}
126139

127-
type RuntimeAndGenesis struct {
128-
runtime *TopLevel
129-
genesis *Genesis
130-
}
131-
132-
// TopLevel directly corresponds to the orderer config yaml
140+
// TopLevel directly corresponds to the orderer config YAML.
133141
// Note, for non 1-1 mappings, you may append
134142
// something like `mapstructure:"weirdFoRMat"` to
135143
// modify the default mapping, see the "Unmarshal"
@@ -257,22 +265,23 @@ func (c *TopLevel) completeInitialization() {
257265
func Load() *TopLevel {
258266
config := viper.New()
259267

260-
config.SetConfigName("orderer")
268+
config.SetConfigName(configName)
269+
261270
cfgPath := os.Getenv("ORDERER_CFG_PATH")
262271
if cfgPath == "" {
263-
logger.Infof("No orderer cfg path set, assuming development environment, deriving from go path")
272+
logger.Infof("No ORDERER_CFG_PATH set, assuming development environment, deriving from Go path.")
264273
// Path to look for the config file in based on GOPATH
265274
gopath := os.Getenv("GOPATH")
266275
for _, p := range filepath.SplitList(gopath) {
267276
ordererPath := filepath.Join(p, "src/github.com/hyperledger/fabric/orderer/")
268-
if _, err := os.Stat(filepath.Join(ordererPath, "orderer.yaml")); err != nil {
269-
// The yaml file does not exist in this component of the go src
277+
if _, err := os.Stat(filepath.Join(ordererPath, configFileName)); err != nil {
278+
// The YAML file does not exist in this component of the go src
270279
continue
271280
}
272281
cfgPath = ordererPath
273282
}
274283
if cfgPath == "" {
275-
logger.Fatalf("Could not find orderer.yaml, try setting ORDERER_CFG_PATH or GOPATH correctly")
284+
logger.Fatalf("Could not find %s, try setting ORDERER_CFG_PATH or GOPATH correctly.", configFileName)
276285
}
277286
logger.Infof("Setting ORDERER_CFG_PATH to: %s", cfgPath)
278287
os.Setenv("ORDERER_CFG_PATH", cfgPath)
@@ -287,16 +296,14 @@ func Load() *TopLevel {
287296

288297
err := config.ReadInConfig()
289298
if err != nil {
290-
panic(fmt.Errorf("Error reading %s plugin config: %s", Prefix, err))
299+
logger.Panicf("Error reading configuration from %s in %s: %s", configFileName, cfgPath, err)
291300
}
292301

293302
var uconf TopLevel
294-
295303
err = viperutil.EnhancedExactUnmarshal(config, &uconf)
296304
if err != nil {
297-
panic(fmt.Errorf("Error unmarshaling into structure: %s", err))
305+
logger.Panicf("Error unmarshaling config into struct: %s", err)
298306
}
299-
300307
uconf.completeInitialization()
301308

302309
return &uconf

protos/common/common.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ enum HeaderType {
4848
// This enum enlists indexes of the block metadata array
4949
enum BlockMetadataIndex {
5050
SIGNATURES = 0; // Block metadata array position for block signatures
51-
LAST_CONFIG = 1; // Block metadata array poistion to store last configuration block sequence number
52-
TRANSACTIONS_FILTER = 2; // Block metadata array poistion to store serialized bit array filter of invalid transactions
51+
LAST_CONFIG = 1; // Block metadata array position to store last configuration block sequence number
52+
TRANSACTIONS_FILTER = 2; // Block metadata array position to store serialized bit array filter of invalid transactions
5353
ORDERER = 3; // Block metadata array position to store operational metadata for orderers
5454
// e.g. For Kafka, this is where we store the last offset written to the local ledger.
5555
}

0 commit comments

Comments
 (0)