Skip to content

Commit

Permalink
Merge "[FAB-1612] Genesis config vars to genesis section"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Jan 13, 2017
2 parents c3f26d8 + 86213ca commit 5c802bd
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 64 deletions.
10 changes: 5 additions & 5 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ type kafkaBootstrapper struct {
func New(conf *config.TopLevel) bootstrap.Helper {
cbs := &commonBootstrapper{
chainID: TestChainID,
consensusType: conf.General.OrdererType,
consensusType: conf.Genesis.OrdererType,
batchSize: &ab.BatchSize{
MaxMessageCount: conf.General.BatchSize.MaxMessageCount,
MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount,
},
batchTimeout: conf.General.BatchTimeout.String(),
batchTimeout: conf.Genesis.BatchTimeout.String(),
}

switch conf.General.OrdererType {
switch conf.Genesis.OrdererType {
case ConsensusTypeSolo, ConsensusTypeSbft:
return &soloBootstrapper{
commonBootstrapper: *cbs,
Expand All @@ -91,7 +91,7 @@ func New(conf *config.TopLevel) bootstrap.Helper {
kafkaBrokers: conf.Kafka.Brokers,
}
default:
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.General.OrdererType))
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Genesis.OrdererType))
}
}

Expand Down
6 changes: 3 additions & 3 deletions orderer/common/bootstrap/provisional/provisional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var testCases []*config.TopLevel
func init() {
confSolo = config.Load()
confKafka = config.Load()
confKafka.General.OrdererType = ConsensusTypeKafka
confKafka.Genesis.OrdererType = ConsensusTypeKafka
testCases = []*config.TopLevel{confSolo, confKafka}
}

Expand All @@ -40,10 +40,10 @@ func TestGenesisBlockHeader(t *testing.T) {
for _, tc := range testCases {
genesisBlock := New(tc).GenesisBlock()
if genesisBlock.Header.Number != expectedHeaderNumber {
t.Fatalf("Case %s: Expected header number %d, got %d", tc.General.OrdererType, expectedHeaderNumber, genesisBlock.Header.Number)
t.Fatalf("Case %s: Expected header number %d, got %d", tc.Genesis.OrdererType, expectedHeaderNumber, genesisBlock.Header.Number)
}
if !bytes.Equal(genesisBlock.Header.PreviousHash, nil) {
t.Fatalf("Case %s: Expected header previousHash to be nil, got %x", tc.General.OrdererType, genesisBlock.Header.PreviousHash)
t.Fatalf("Case %s: Expected header previousHash to be nil, got %x", tc.Genesis.OrdererType, genesisBlock.Header.PreviousHash)
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions orderer/kafka/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,12 @@ var (

var testConf = &config.TopLevel{
General: config.General{
OrdererType: "kafka",
LedgerType: "ram",
BatchTimeout: 500 * time.Millisecond,
QueueSize: 100,
MaxWindowSize: 100,
ListenAddress: "127.0.0.1",
ListenPort: 7050,
GenesisMethod: "provisional",
BatchSize: config.BatchSize{
MaxMessageCount: 100,
},
},
Kafka: config.Kafka{
Brokers: []string{"127.0.0.1:9092"},
Expand All @@ -60,6 +55,13 @@ var testConf = &config.TopLevel{
Verbose: false,
Version: sarama.V0_9_0_1,
},
Genesis: config.Genesis{
OrdererType: "kafka",
BatchTimeout: 500 * time.Millisecond,
BatchSize: config.BatchSize{
MaxMessageCount: 100,
},
},
}

func testClose(t *testing.T, x Closeable) {
Expand Down
43 changes: 25 additions & 18 deletions orderer/localconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@ const Prefix string = "ORDERER"

// General contains config which should be common among all orderer types
type General struct {
OrdererType string
LedgerType string
BatchTimeout time.Duration
QueueSize uint32
MaxWindowSize uint32
ListenAddress string
ListenPort uint16
GenesisMethod string
BatchSize BatchSize
GenesisFile string
Profile Profile
LogLevel string
}

// Genesis contains config which is used by the provisional bootstrapper
type Genesis struct {
OrdererType string
BatchTimeout time.Duration
BatchSize BatchSize
}

// BatchSize contains configuration affecting the size of batches
type BatchSize struct {
MaxMessageCount uint32
Expand Down Expand Up @@ -99,22 +103,18 @@ type TopLevel struct {
RAMLedger RAMLedger
FileLedger FileLedger
Kafka Kafka
Genesis Genesis
}

var defaults = TopLevel{
General: General{
OrdererType: "solo",
LedgerType: "ram",
BatchTimeout: 10 * time.Second,
QueueSize: 1000,
MaxWindowSize: 1000,
ListenAddress: "127.0.0.1",
ListenPort: 7050,
GenesisMethod: "provisional",
BatchSize: BatchSize{
MaxMessageCount: 10,
},
GenesisFile: "./genesisblock",
GenesisFile: "./genesisblock",
Profile: Profile{
Enabled: false,
Address: "0.0.0.0:6060",
Expand All @@ -137,25 +137,23 @@ var defaults = TopLevel{
Verbose: false,
Version: sarama.V0_9_0_1,
},
Genesis: Genesis{
OrdererType: "solo",
BatchTimeout: 10 * time.Second,
BatchSize: BatchSize{
MaxMessageCount: 10,
},
},
}

func (c *TopLevel) completeInitialization() {
defer logger.Infof("Validated configuration to: %+v", c)

for {
switch {
case c.General.OrdererType == "":
logger.Infof("General.OrdererType unset, setting to %s", defaults.General.OrdererType)
c.General.OrdererType = defaults.General.OrdererType
case c.General.LedgerType == "":
logger.Infof("General.LedgerType unset, setting to %s", defaults.General.LedgerType)
c.General.LedgerType = defaults.General.LedgerType
case c.General.BatchTimeout == 0:
logger.Infof("General.BatchTimeout unset, setting to %s", defaults.General.BatchTimeout)
c.General.BatchTimeout = defaults.General.BatchTimeout
case c.General.BatchSize.MaxMessageCount == 0:
logger.Infof("General.BatchSize.MaxMessageCount unset, setting to %s", defaults.General.BatchSize.MaxMessageCount)
c.General.BatchSize.MaxMessageCount = defaults.General.BatchSize.MaxMessageCount
case c.General.QueueSize == 0:
logger.Infof("General.QueueSize unset, setting to %s", defaults.General.QueueSize)
c.General.QueueSize = defaults.General.QueueSize
Expand Down Expand Up @@ -190,6 +188,15 @@ func (c *TopLevel) completeInitialization() {
case c.Kafka.Retry.Stop == 0*time.Second:
logger.Infof("Kafka.Retry.Stop unset, setting to %v", defaults.Kafka.Retry.Stop)
c.Kafka.Retry.Stop = defaults.Kafka.Retry.Stop
case c.Genesis.OrdererType == "":
logger.Infof("Genesis.OrdererType unset, setting to %s", defaults.Genesis.OrdererType)
c.Genesis.OrdererType = defaults.Genesis.OrdererType
case c.Genesis.BatchTimeout == 0:
logger.Infof("Genesis.BatchTimeout unset, setting to %s", defaults.Genesis.BatchTimeout)
c.Genesis.BatchTimeout = defaults.Genesis.BatchTimeout
case c.Genesis.BatchSize.MaxMessageCount == 0:
logger.Infof("Genesis.BatchSize.MaxMessageCount unset, setting to %s", defaults.Genesis.BatchSize.MaxMessageCount)
c.Genesis.BatchSize.MaxMessageCount = defaults.Genesis.BatchSize.MaxMessageCount
default:
// A bit hacky, but its type makes it impossible to test for a nil value.
// This may be overwritten by the Kafka orderer upon instantiation.
Expand Down
22 changes: 11 additions & 11 deletions orderer/multichain/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestManagerImpl(t *testing.T) {
lf, rl := NewRAMLedgerAndFactory(10)

consenters := make(map[string]Consenter)
consenters[conf.General.OrdererType] = &mockConsenter{}
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

manager := NewManagerImpl(lf, consenters)

Expand All @@ -119,8 +119,8 @@ func TestManagerImpl(t *testing.T) {
t.Fatalf("Should have gotten chain which was initialized by ramledger")
}

messages := make([]*cb.Envelope, conf.General.BatchSize.MaxMessageCount)
for i := 0; i < int(conf.General.BatchSize.MaxMessageCount); i++ {
messages := make([]*cb.Envelope, conf.Genesis.BatchSize.MaxMessageCount)
for i := 0; i < int(conf.Genesis.BatchSize.MaxMessageCount); i++ {
messages[i] = makeNormalTx(provisional.TestChainID, i)
}

Expand All @@ -135,7 +135,7 @@ func TestManagerImpl(t *testing.T) {
if status != cb.Status_SUCCESS {
t.Fatalf("Could not retrieve block")
}
for i := 0; i < int(conf.General.BatchSize.MaxMessageCount); i++ {
for i := 0; i < int(conf.Genesis.BatchSize.MaxMessageCount); i++ {
if !reflect.DeepEqual(utils.ExtractEnvelopeOrPanic(block, i), messages[i]) {
t.Errorf("Block contents wrong at index %d", i)
}
Expand All @@ -150,7 +150,7 @@ func TestSignatureFilter(t *testing.T) {
lf, rl := NewRAMLedgerAndFactory(10)

consenters := make(map[string]Consenter)
consenters[conf.General.OrdererType] = &mockConsenter{}
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

manager := NewManagerImpl(lf, consenters)

Expand All @@ -160,8 +160,8 @@ func TestSignatureFilter(t *testing.T) {
t.Fatalf("Should have gotten chain which was initialized by ramledger")
}

messages := make([]*cb.Envelope, conf.General.BatchSize.MaxMessageCount)
for i := 0; i < int(conf.General.BatchSize.MaxMessageCount); i++ {
messages := make([]*cb.Envelope, conf.Genesis.BatchSize.MaxMessageCount)
for i := 0; i < int(conf.Genesis.BatchSize.MaxMessageCount); i++ {
messages[i] = makeSignaturelessTx(provisional.TestChainID, i)
}

Expand All @@ -188,7 +188,7 @@ func TestNewChain(t *testing.T) {
lf, rl := NewRAMLedgerAndFactory(10)

consenters := make(map[string]Consenter)
consenters[conf.General.OrdererType] = &mockConsenter{}
consenters[conf.Genesis.OrdererType] = &mockConsenter{}

manager := NewManagerImpl(lf, consenters)

Expand Down Expand Up @@ -229,8 +229,8 @@ func TestNewChain(t *testing.T) {
t.Fatalf("Should have gotten new chain which was created")
}

messages := make([]*cb.Envelope, conf.General.BatchSize.MaxMessageCount)
for i := 0; i < int(conf.General.BatchSize.MaxMessageCount); i++ {
messages := make([]*cb.Envelope, conf.Genesis.BatchSize.MaxMessageCount)
for i := 0; i < int(conf.Genesis.BatchSize.MaxMessageCount); i++ {
messages[i] = makeNormalTx(newChainID, i)
}

Expand Down Expand Up @@ -262,7 +262,7 @@ func TestNewChain(t *testing.T) {
if status != cb.Status_SUCCESS {
t.Fatalf("Could not retrieve block on new chain")
}
for i := 0; i < int(conf.General.BatchSize.MaxMessageCount); i++ {
for i := 0; i < int(conf.Genesis.BatchSize.MaxMessageCount); i++ {
if !reflect.DeepEqual(utils.ExtractEnvelopeOrPanic(block, i), messages[i]) {
t.Errorf("Block contents wrong at index %d in new chain", i)
}
Expand Down
47 changes: 29 additions & 18 deletions orderer/orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,10 @@
################################################################################
General:

# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo

# Ledger Type: The ledger type to provide to the orderer (if needed)
# Available types are "ram", "file".
LedgerType: ram

# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 10s

# Batch Size: Controls the number of messages batched into a block
BatchSize:

# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10

# Queue Size: The maximum number of messages to allow pending from a gRPC
# client.
QueueSize: 10
Expand All @@ -45,6 +32,8 @@ General:
LogLevel: info

# Genesis method: The method by which to retrieve/generate the genesis block. Available values are "provisional", "file"
# Provisional utilizes the parameters in the Genesis section to dynamically generate a new genesis block
# File uses the fil provided by GenesisFile as the genesis block
GenesisMethod: provisional

# Genesis file: The file containing the genesis block. Used by the orderer when GenesisMethod is set to "file"
Expand Down Expand Up @@ -96,11 +85,6 @@ FileLedger:
################################################################################
Kafka:

# Brokers: A list of Kafka brokers to which the orderer connects
# NOTE: Use IP:port notation
Brokers:
- 127.0.0.1:9092

# Retry: What to do if none of the Kafka brokers are available
Retry:
# The producer should attempt to reconnect every <Period>
Expand All @@ -111,3 +95,30 @@ Kafka:
# Verbose: Turn on logging for sarama, the client library that we use to
# interact with the Kafka cluster
Verbose: false

# Brokers: A list of Kafka brokers to which the orderer connects
# NOTE: Use IP:port notation
Brokers:
- 127.0.0.1:9092
################################################################################
#
# SECTION: Genesis
#
# - This section applies to the configuration for the provisional bootstrapper
#
################################################################################
Genesis:

# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo

# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 10s

# Batch Size: Controls the number of messages batched into a block
BatchSize:

# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10

2 changes: 1 addition & 1 deletion orderer/sample_clients/broadcast_config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {

flag.StringVar(&srv, "server", fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort), "The RPC server to connect to.")
flag.StringVar(&cmd.name, "cmd", "newChain", "The action that this client is requesting via the config transaction.")
flag.StringVar(&cmd.args.consensusType, "consensusType", conf.General.OrdererType, "In case of a newChain command, the type of consensus the ordering service is running on.")
flag.StringVar(&cmd.args.consensusType, "consensusType", conf.Genesis.OrdererType, "In case of a newChain command, the type of consensus the ordering service is running on.")
flag.StringVar(&cmd.args.creationPolicy, "creationPolicy", "AcceptAllPolicy", "In case of a newChain command, the chain creation policy this request should be validated against.")
flag.StringVar(&cmd.args.chainID, "chainID", "NewChainID", "In case of a newChain command, the chain ID to create.")
flag.Parse()
Expand Down
2 changes: 1 addition & 1 deletion orderer/sample_clients/broadcast_config/newchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func newChainRequest(consensusType, creationPolicy, newChainID string) *cb.Envelope {
conf.General.OrdererType = consensusType
conf.Genesis.OrdererType = consensusType
genesisBlock := provisional.New(conf).GenesisBlock()
oldGenesisTx := utils.ExtractEnvelopeOrPanic(genesisBlock, 0)
oldGenesisTxPayload := utils.ExtractPayloadOrPanic(oldGenesisTx)
Expand Down
2 changes: 1 addition & 1 deletion orderer/sbft/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestSignAndVerifyEcdsa(t *testing.T) {

func TestLedgerReadWrite(t *testing.T) {
localConf := localconfig.Load()
localConf.General.OrdererType = provisional.ConsensusTypeSbft
localConf.Genesis.OrdererType = provisional.ConsensusTypeSbft
genesis := provisional.New(localConf).GenesisBlock()
rlf := ramledger.New(10)
rl, _ := rlf.GetOrCreate(provisional.TestChainID)
Expand Down
2 changes: 1 addition & 1 deletion orderer/sbft/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func serve(c flags) {
}

localConf := localconfig.Load()
localConf.General.OrdererType = provisional.ConsensusTypeSbft
localConf.Genesis.OrdererType = provisional.ConsensusTypeSbft
genesisBlock := provisional.New(localConf).GenesisBlock()

flf := fileledger.New(c.dataDir)
Expand Down

0 comments on commit 5c802bd

Please sign in to comment.