Skip to content

Commit

Permalink
[FAB-2155] Split orderer config local and genesis
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2155

The orderer is currently capable of generating its genesis material
based on configuration.  This function is needed in the common
components in order to deprecate the static templating that exists
today.

Change-Id: Ida60c158eabce3491b25350ee50d5863b5934820
Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Feb 12, 2017
1 parent f5ab160 commit 40cfff3
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 117 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ build/image/peer/payload: build/docker/bin/peer \
build/genesis-sampleconfig.tar.bz2
build/image/orderer/payload: build/docker/bin/orderer \
build/msp-sampleconfig.tar.bz2 \
orderer/orderer.yaml
orderer/orderer.yaml \
orderer/genesis.yaml
build/image/testenv/payload: build/gotools.tar.bz2 \
build/docker/bin/orderer \
orderer/orderer.yaml \
orderer/genesis.yaml \
build/docker/bin/peer \
peer/core.yaml \
build/msp-sampleconfig.tar.bz2 \
Expand Down
1 change: 1 addition & 0 deletions images/orderer/Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ RUN mkdir -p /var/hyperledger/production /etc/hyperledger/fabric/orderer
COPY payload/orderer /usr/local/bin
ADD payload/msp-sampleconfig.tar.bz2 $ORDERER_CFG_PATH/../
COPY payload/orderer.yaml $ORDERER_CFG_PATH/
COPY payload/genesis.yaml $ORDERER_CFG_PATH/
EXPOSE 7050
CMD orderer
1 change: 1 addition & 0 deletions images/testenv/Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ADD payload/gotools.tar.bz2 /usr/local/bin/

# fabric configuration files
COPY payload/orderer.yaml $ORDERER_CFG_PATH
COPY payload/genesis.yaml $ORDERER_CFG_PATH
COPY payload/core.yaml $PEER_CFG_PATH
ADD payload/msp-sampleconfig.tar.bz2 $PEER_CFG_PATH

Expand Down
20 changes: 10 additions & 10 deletions orderer/common/bootstrap/provisional/provisional.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ type bootstrapper struct {
}

// New returns a new provisional bootstrap helper.
func New(conf *config.TopLevel) Generator {
func New(conf *config.GenesisTopLevel) Generator {
bs := &bootstrapper{
minimalGroups: []*cb.ConfigGroup{
// Chain Config Types
configtxchannel.DefaultHashingAlgorithm(),
configtxchannel.DefaultBlockDataHashingStructure(),
configtxchannel.TemplateOrdererAddresses([]string{fmt.Sprintf("%s:%d", conf.General.ListenAddress, conf.General.ListenPort)}),
configtxchannel.TemplateOrdererAddresses(conf.Orderer.Addresses),

// Orderer Config Types
configtxorderer.TemplateConsensusType(conf.Genesis.OrdererType),
configtxorderer.TemplateConsensusType(conf.Orderer.OrdererType),
configtxorderer.TemplateBatchSize(&ab.BatchSize{
MaxMessageCount: conf.Genesis.BatchSize.MaxMessageCount,
AbsoluteMaxBytes: conf.Genesis.BatchSize.AbsoluteMaxBytes,
PreferredMaxBytes: conf.Genesis.BatchSize.PreferredMaxBytes,
MaxMessageCount: conf.Orderer.BatchSize.MaxMessageCount,
AbsoluteMaxBytes: conf.Orderer.BatchSize.AbsoluteMaxBytes,
PreferredMaxBytes: conf.Orderer.BatchSize.PreferredMaxBytes,
}),
configtxorderer.TemplateBatchTimeout(conf.Genesis.BatchTimeout.String()),
configtxorderer.TemplateBatchTimeout(conf.Orderer.BatchTimeout.String()),
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),

Expand All @@ -94,12 +94,12 @@ func New(conf *config.TopLevel) Generator {
},
}

switch conf.Genesis.OrdererType {
switch conf.Orderer.OrdererType {
case ConsensusTypeSolo, ConsensusTypeSbft:
case ConsensusTypeKafka:
bs.minimalGroups = append(bs.minimalGroups, configtxorderer.TemplateKafkaBrokers(conf.Kafka.Brokers))
bs.minimalGroups = append(bs.minimalGroups, configtxorderer.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers))
default:
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Genesis.OrdererType))
panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType))
}

return bs
Expand Down
16 changes: 8 additions & 8 deletions orderer/common/bootstrap/provisional/provisional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
cb "github.com/hyperledger/fabric/protos/common"
)

var confSolo, confKafka *config.TopLevel
var testCases []*config.TopLevel
var confSolo, confKafka *config.GenesisTopLevel
var testCases []*config.GenesisTopLevel

func init() {
confSolo = config.Load()
confKafka = config.Load()
confKafka.Genesis.OrdererType = ConsensusTypeKafka
testCases = []*config.TopLevel{confSolo, confKafka}
confSolo = config.LoadGenesis()
confKafka = config.LoadGenesis()
confKafka.Orderer.OrdererType = ConsensusTypeKafka
testCases = []*config.GenesisTopLevel{confSolo, confKafka}
}

func TestGenesisBlockHeader(t *testing.T) {
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.Genesis.OrdererType, expectedHeaderNumber, genesisBlock.Header.Number)
t.Fatalf("Case %s: Expected header number %d, got %d", tc.Orderer.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.Genesis.OrdererType, genesisBlock.Header.PreviousHash)
t.Fatalf("Case %s: Expected header previousHash to be nil, got %x", tc.Orderer.OrdererType, genesisBlock.Header.PreviousHash)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion orderer/common/deliver/deliver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ledgerSize = 10

func init() {
logging.SetLevel(logging.DEBUG, "")
genesisBlock = provisional.New(config.Load()).GenesisBlock()
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
}

type mockD struct {
Expand Down
42 changes: 42 additions & 0 deletions orderer/genesis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
################################################################################
#
# SECTION: Orderer
#
# - This section defines the values to encode into a config transaction or
# genesis block for orderer related parameters
#
################################################################################
Orderer:

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

Addresses:
- 127.0.0.1:7050

# 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

# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 99 MB

# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the preferred
# max bytes will result in a batch larger than preferred max bytes.
PreferredMaxBytes: 512 KB

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

17 changes: 0 additions & 17 deletions orderer/kafka/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ var (
)

var testConf = &config.TopLevel{
General: config.General{
LedgerType: "ram",
QueueSize: 100,
MaxWindowSize: 100,
ListenAddress: "127.0.0.1",
ListenPort: 7050,
GenesisMethod: "provisional",
},
Kafka: config.Kafka{
Brokers: []string{"127.0.0.1:9092"},
Retry: config.Retry{
Expand All @@ -55,15 +47,6 @@ 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,
AbsoluteMaxBytes: 10 * 1024 * 1024,
PreferredMaxBytes: 512 * 1024,
},
},
}

func testClose(t *testing.T, x Closeable) {
Expand Down
2 changes: 1 addition & 1 deletion orderer/ledger/file/fileledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var genesisBlock *cb.Block

func init() {
logging.SetLevel(logging.DEBUG, "")
genesisBlock = provisional.New(config.Load()).GenesisBlock()
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
}

type testEnv struct {
Expand Down
2 changes: 1 addition & 1 deletion orderer/ledger/fileledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
var genesisBlock *cb.Block

func init() {
genesisBlock = provisional.New(config.Load()).GenesisBlock()
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
testables = append(testables, &fileLedgerTestEnv{})
}

Expand Down
2 changes: 1 addition & 1 deletion orderer/ledger/ram/ramledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var genesisBlock *cb.Block

func init() {
logging.SetLevel(logging.DEBUG, "")
genesisBlock = provisional.New(config.Load()).GenesisBlock()
genesisBlock = provisional.New(config.LoadGenesis()).GenesisBlock()
}

func NewTestChain(maxSize int) *ramLedger {
Expand Down
Loading

0 comments on commit 40cfff3

Please sign in to comment.