diff --git a/orderer/common/bootstrap/provisional/item.go b/orderer/common/bootstrap/provisional/item.go deleted file mode 100644 index 4e4c594416b..00000000000 --- a/orderer/common/bootstrap/provisional/item.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright IBM Corp. 2016 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package provisional - -import ( - "github.com/hyperledger/fabric/common/cauthdsl" - "github.com/hyperledger/fabric/common/configtx" - "github.com/hyperledger/fabric/orderer/common/sharedconfig" - cb "github.com/hyperledger/fabric/protos/common" -) - -func (cbs *commonBootstrapper) templateConsensusType() *cb.ConfigurationItem { - return sharedconfig.TemplateConsensusType(cbs.consensusType) -} - -func (cbs *commonBootstrapper) templateBatchSize() *cb.ConfigurationItem { - return sharedconfig.TemplateBatchSize(cbs.batchSize) -} - -func (cbs *commonBootstrapper) templateBatchTimeout() *cb.ConfigurationItem { - return sharedconfig.TemplateBatchTimeout(cbs.batchTimeout) -} - -func (cbs *commonBootstrapper) templateChainCreationPolicyNames() *cb.ConfigurationItem { - return sharedconfig.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames) -} - -func (cbs *commonBootstrapper) templateAcceptAllPolicy() *cb.ConfigurationItem { - return cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy) -} - -func (cbs *commonBootstrapper) templateIngressPolicyNames() *cb.ConfigurationItem { - return sharedconfig.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}) -} - -func (cbs *commonBootstrapper) templateEgressPolicyNames() *cb.ConfigurationItem { - return sharedconfig.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}) -} - -func (cbs *commonBootstrapper) templateRejectAllPolicy() *cb.ConfigurationItem { - // Lock down the new configuration item policy to prevent any new configuration items from being created - return cauthdsl.TemplatePolicy(configtx.NewConfigurationItemPolicyKey, cauthdsl.RejectAllPolicy) -} - -func (kbs *kafkaBootstrapper) templateKafkaBrokers() *cb.ConfigurationItem { - return sharedconfig.TemplateKafkaBrokers(kbs.kafkaBrokers) -} diff --git a/orderer/common/bootstrap/provisional/provisional.go b/orderer/common/bootstrap/provisional/provisional.go index 0e341337c66..f87514d5768 100644 --- a/orderer/common/bootstrap/provisional/provisional.go +++ b/orderer/common/bootstrap/provisional/provisional.go @@ -19,9 +19,11 @@ package provisional import ( "fmt" + "github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric/common/configtx" "github.com/hyperledger/fabric/common/genesis" "github.com/hyperledger/fabric/orderer/common/bootstrap" + "github.com/hyperledger/fabric/orderer/common/sharedconfig" "github.com/hyperledger/fabric/orderer/localconfig" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" @@ -36,8 +38,6 @@ type Generator interface { } const ( - msgVersion = int32(1) - // ConsensusTypeSolo identifies the solo consensus implementation. ConsensusTypeSolo = "solo" // ConsensusTypeKafka identifies the Kafka-based consensus implementation. @@ -53,64 +53,61 @@ const ( // AcceptAllPolicyKey is the key of the AcceptAllPolicy. AcceptAllPolicyKey = "AcceptAllPolicy" - - // These values are fixed for the genesis block. - lastModified = 0 - epoch = 0 ) // DefaultChainCreationPolicyNames is the default value of ChainCreatorsKey. var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey} -type commonBootstrapper struct { - chainID string - consensusType string - batchSize *ab.BatchSize - batchTimeout string -} - -type soloBootstrapper struct { - commonBootstrapper -} - -type kafkaBootstrapper struct { - commonBootstrapper - kafkaBrokers []string +type bootstrapper struct { + minimalItems []*cb.ConfigurationItem + systemChainItems []*cb.ConfigurationItem } // New returns a new provisional bootstrap helper. func New(conf *config.TopLevel) Generator { - cbs := &commonBootstrapper{ - chainID: TestChainID, - consensusType: conf.Genesis.OrdererType, - batchSize: &ab.BatchSize{ - MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount, - AbsoluteMaxBytes: conf.Genesis.BatchSize.AbsoluteMaxBytes, - PreferredMaxBytes: conf.Genesis.BatchSize.PreferredMaxBytes, + bs := &bootstrapper{ + minimalItems: []*cb.ConfigurationItem{ + // Orderer Config Types + sharedconfig.TemplateConsensusType(conf.Genesis.OrdererType), + sharedconfig.TemplateBatchSize(&ab.BatchSize{ + MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount, + AbsoluteMaxBytes: conf.Genesis.BatchSize.AbsoluteMaxBytes, + PreferredMaxBytes: conf.Genesis.BatchSize.PreferredMaxBytes, + }), + sharedconfig.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()), + sharedconfig.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}), + sharedconfig.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}), + + // Policies + cauthdsl.TemplatePolicy(configtx.NewConfigurationItemPolicyKey, cauthdsl.RejectAllPolicy), + cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy), + }, + + systemChainItems: []*cb.ConfigurationItem{ + sharedconfig.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames), }, - batchTimeout: conf.Genesis.BatchTimeout.String(), } switch conf.Genesis.OrdererType { case ConsensusTypeSolo, ConsensusTypeSbft: - return &soloBootstrapper{ - commonBootstrapper: *cbs, - } case ConsensusTypeKafka: - return &kafkaBootstrapper{ - commonBootstrapper: *cbs, - kafkaBrokers: conf.Kafka.Brokers, - } + bs.minimalItems = append(bs.minimalItems, sharedconfig.TemplateKafkaBrokers(conf.Kafka.Brokers)) default: panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Genesis.OrdererType)) } + + return bs +} + +func (bs *bootstrapper) TemplateItems() []*cb.ConfigurationItem { + return bs.minimalItems } -func (cbs *commonBootstrapper) genesisBlock(minimalTemplateItems func() []*cb.ConfigurationItem) *cb.Block { +func (bs *bootstrapper) GenesisBlock() *cb.Block { block, err := genesis.NewFactoryImpl( configtx.NewCompositeTemplate( - configtx.NewSimpleTemplate(minimalTemplateItems()...), - configtx.NewSimpleTemplate(cbs.makeOrdererSystemChainConfig()...), + configtx.NewSimpleTemplate(bs.minimalItems...), + configtx.NewSimpleTemplate(bs.systemChainItems...), ), ).Block(TestChainID) @@ -119,13 +116,3 @@ func (cbs *commonBootstrapper) genesisBlock(minimalTemplateItems func() []*cb.Co } return block } - -// GenesisBlock returns the genesis block to be used for bootstrapping. -func (cbs *commonBootstrapper) GenesisBlock() *cb.Block { - return cbs.genesisBlock(cbs.TemplateItems) -} - -// GenesisBlock returns the genesis block to be used for bootstrapping. -func (kbs *kafkaBootstrapper) GenesisBlock() *cb.Block { - return kbs.genesisBlock(kbs.TemplateItems) -} diff --git a/orderer/common/bootstrap/provisional/templates.go b/orderer/common/bootstrap/provisional/templates.go deleted file mode 100644 index df4f3e0b90c..00000000000 --- a/orderer/common/bootstrap/provisional/templates.go +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright IBM Corp. 2016 All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package provisional - -import ( - cb "github.com/hyperledger/fabric/protos/common" -) - -func (cbs *commonBootstrapper) makeOrdererSystemChainConfig() []*cb.ConfigurationItem { - return []*cb.ConfigurationItem{cbs.templateChainCreationPolicyNames()} -} - -func (cbs *commonBootstrapper) TemplateItems() []*cb.ConfigurationItem { - return []*cb.ConfigurationItem{ - cbs.templateConsensusType(), - cbs.templateBatchSize(), - cbs.templateBatchTimeout(), - cbs.templateAcceptAllPolicy(), - cbs.templateIngressPolicyNames(), - cbs.templateEgressPolicyNames(), - cbs.templateRejectAllPolicy(), - } -} - -func (kbs *kafkaBootstrapper) TemplateItems() []*cb.ConfigurationItem { - return append(kbs.commonBootstrapper.TemplateItems(), kbs.templateKafkaBrokers()) -}