Skip to content

Commit

Permalink
[FAB-1748] Refactor provisional bootstrapper
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1748

The old provisional bootstrapper was becoming increasingly convoluted
for doing very little, this changeset deletes must/most of that code in
favor of a much simpler approach.

Change-Id: I4d9a659856eb150852fabe7c498e0818e81bdca0
Signed-off-by: Jason Yellick <[email protected]>
  • Loading branch information
Jason Yellick committed Jan 19, 2017
1 parent c7e3168 commit 8c6fe20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 150 deletions.
61 changes: 0 additions & 61 deletions orderer/common/bootstrap/provisional/item.go

This file was deleted.

83 changes: 35 additions & 48 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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)

Expand All @@ -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)
}
41 changes: 0 additions & 41 deletions orderer/common/bootstrap/provisional/templates.go

This file was deleted.

0 comments on commit 8c6fe20

Please sign in to comment.