-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-2339] Add simple tool write out genesis block
https://jira.hyperledger.org/browse/FAB-2339 In order to simulate real deployment scenarios, it's necessary to have the genesis block generated ahead of time and loaded via a file. This has been done only via bdd thusfar. This CR adds a simple tool which dumps the genesis block created by the configtx provisional genesis package to the filesystem. There is a doc file under docs/configtxgen.md which describes the usage. Change-Id: I42171afdce4bb47d63806805a88aa3b93759023d Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Feb 19, 2017
1 parent
4887bf4
commit 6be8f63
Showing
6 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
Copyright IBM Corp. 2017 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 main | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
|
||
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" | ||
"github.com/hyperledger/fabric/common/configtx/tool/provisional" | ||
"github.com/hyperledger/fabric/protos/utils" | ||
|
||
logging "github.com/op/go-logging" | ||
) | ||
|
||
const ( | ||
DefaultGenesisFileLocation = "genesis.block" | ||
) | ||
|
||
var logger = logging.MustGetLogger("common/configtx/tool") | ||
|
||
func main() { | ||
var writePath, profile string | ||
|
||
dryRun := flag.Bool("dryRun", false, "Whether to only generate but not write the genesis block file.") | ||
flag.StringVar(&writePath, "path", DefaultGenesisFileLocation, "The path to write the genesis block to.") | ||
flag.StringVar(&profile, "profile", genesisconfig.SampleInsecureProfile, "The profile from configtx.yaml to use for generation.") | ||
flag.Parse() | ||
|
||
logging.SetLevel(logging.INFO, "") | ||
|
||
logger.Info("Loading configuration") | ||
config := genesisconfig.Load(profile) | ||
|
||
logger.Info("Generating genesis block") | ||
genesisBlock := provisional.New(config).GenesisBlock() | ||
|
||
if !*dryRun { | ||
logger.Info("Writing genesis block") | ||
ioutil.WriteFile(writePath, utils.MarshalOrPanic(genesisBlock), 0644) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Configuring using the configtxgen tool | ||
|
||
This document describe the usage for the `configtxgen` utility for manipulating fabric channel configuration. | ||
|
||
For now, the tool is primarily focused on generating the genesis block for bootstrapping the orderer, but it is intended to be enhanced in the future for generating new channel configurations as well as reconfiguring existing channels. | ||
|
||
## Building the tool | ||
|
||
Building the tool is as simple as `make configtxgen`. This will create a `configtxgen` binary at `build/bin/configtxgen` which is included in the Vagrant development environment path by default. | ||
|
||
## Configuration Profiles | ||
|
||
The configuration parameters supplied to the `configtxgen` tool are primarily provided by the `configtx.yaml` file. This file is located at `fabric/common/configtx/tool/configtx.yaml` in the fabric.git repository. | ||
|
||
This configuration file is split primarily into three pieces. | ||
|
||
1. The `Profiles` section. By default, this section includes some sample configurations which can be used for development or testing scenarios, and refer to crypto material present in the fabric.git tree. These profiles can make a good starting point for construction a real deployment profile. The `configtxgen` tool allows you to specify the profile it is operating under by passing the `-profile` flag. Profiles may explicitly declare all configuration, but usually inherit configuration from the defaults in (3) below. | ||
2. The `Organizations` section. By default, this section includes a single reference to the sampleconfig MSP definition. For production deployments, the sample organization should be removed, and the MSP definitions of the network members should be referenced and defined instead. Each element in the `Organizations` section should be tagged with an anchor label such as `&orgName` which will allow the definition to be referenced in the `Profiles` sections. | ||
3. The default sections. There are default sections for `Orderer` and `Application` configuration, these include attributes like `BatchTimeout` and are generally used as the base inherited values for the profiles. | ||
|
||
This configuration file may be edited, or, individual properties may be overridden by setting environment variables, such as `CONFIGTX_ORDERER_ORDERERTYPE=kafka`. Note that the `Profiles` element and profile name do not need to be specified. | ||
|
||
## Bootstrapping the orderer | ||
After creating a configuration profile as desired, simply invoke | ||
``` | ||
configtxgen -profile <profile_name> | ||
``` | ||
This will produce a `genesis.block` file in the current directory. You may optionally specify another filename by passing in the `-path` parameter, or, you may skip the writing of the file by passing the `dryRun` parameter if you simply wish to test parsing of the file. | ||
|
||
Then, to utilize this genesis block, before starting the orderer, simply specify `ORDERER_GENERAL_GENESISMETHOD=file` and `ORDERER_GENERAL_GENESISFILE=$PWD/genesis.block` or modify the `orderer.yaml` file to encode these values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters