diff --git a/orderer/common/bootstrap/provisional/provisional.go b/orderer/common/bootstrap/provisional/provisional.go index 2740c892dab..61ac3972251 100644 --- a/orderer/common/bootstrap/provisional/provisional.go +++ b/orderer/common/bootstrap/provisional/provisional.go @@ -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, @@ -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)) } } diff --git a/orderer/common/bootstrap/provisional/provisional_test.go b/orderer/common/bootstrap/provisional/provisional_test.go index 97dd42ca00c..65b34903ff3 100644 --- a/orderer/common/bootstrap/provisional/provisional_test.go +++ b/orderer/common/bootstrap/provisional/provisional_test.go @@ -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} } @@ -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) } } } diff --git a/orderer/kafka/config_test.go b/orderer/kafka/config_test.go index e1ea13f22e2..5c25148f444 100644 --- a/orderer/kafka/config_test.go +++ b/orderer/kafka/config_test.go @@ -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"}, @@ -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) { diff --git a/orderer/localconfig/config.go b/orderer/localconfig/config.go index 8b4f47d6435..d6f829f9909 100644 --- a/orderer/localconfig/config.go +++ b/orderer/localconfig/config.go @@ -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 @@ -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", @@ -137,6 +137,13 @@ 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() { @@ -144,18 +151,9 @@ func (c *TopLevel) completeInitialization() { 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 @@ -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. diff --git a/orderer/multichain/manager_test.go b/orderer/multichain/manager_test.go index 5044702fa2e..277c951fbfc 100644 --- a/orderer/multichain/manager_test.go +++ b/orderer/multichain/manager_test.go @@ -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) @@ -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) } @@ -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) } @@ -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) @@ -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) } @@ -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) @@ -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) } @@ -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) } diff --git a/orderer/orderer.yaml b/orderer/orderer.yaml index 65ba093513a..3434f4167d6 100644 --- a/orderer/orderer.yaml +++ b/orderer/orderer.yaml @@ -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 @@ -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" @@ -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 @@ -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 + diff --git a/orderer/sample_clients/broadcast_config/client.go b/orderer/sample_clients/broadcast_config/client.go index 84437a7263d..d8173816e28 100644 --- a/orderer/sample_clients/broadcast_config/client.go +++ b/orderer/sample_clients/broadcast_config/client.go @@ -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() diff --git a/orderer/sample_clients/broadcast_config/newchain.go b/orderer/sample_clients/broadcast_config/newchain.go index 1426b9abe8b..8f2d57761b5 100644 --- a/orderer/sample_clients/broadcast_config/newchain.go +++ b/orderer/sample_clients/broadcast_config/newchain.go @@ -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) diff --git a/orderer/sbft/backend/backend_test.go b/orderer/sbft/backend/backend_test.go index 3accd9951ee..9eb74d649ab 100644 --- a/orderer/sbft/backend/backend_test.go +++ b/orderer/sbft/backend/backend_test.go @@ -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) diff --git a/orderer/sbft/main/main.go b/orderer/sbft/main/main.go index 914d4cede09..22455f28d08 100644 --- a/orderer/sbft/main/main.go +++ b/orderer/sbft/main/main.go @@ -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)