Skip to content

Commit 1e022cf

Browse files
author
Jason Yellick
committedFeb 20, 2017
[FAB-2377] configtxgen channel create configtx out
https://jira.hyperledger.org/browse/FAB-2377 This update modifies the CLI to output a configtx capable of creating a channel. Change-Id: I7e3ef12030f39d1ae09913b0f4a532d3a7466991 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 1405e27 commit 1e022cf

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed
 

‎common/configtx/tool/configtxgen/main.go

+32-12
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,57 @@ import (
2020
"flag"
2121
"io/ioutil"
2222

23+
"github.com/hyperledger/fabric/common/configtx"
2324
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2425
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
26+
"github.com/hyperledger/fabric/msp"
2527
"github.com/hyperledger/fabric/protos/utils"
2628

2729
logging "github.com/op/go-logging"
2830
)
2931

30-
const (
31-
DefaultGenesisFileLocation = "genesis.block"
32-
)
33-
3432
var logger = logging.MustGetLogger("common/configtx/tool")
3533

3634
func main() {
37-
var writePath, profile string
35+
var outputBlock, outputChannelCreateTx, profile, channelID string
3836

39-
dryRun := flag.Bool("dryRun", false, "Whether to only generate but not write the genesis block file.")
40-
flag.StringVar(&writePath, "path", DefaultGenesisFileLocation, "The path to write the genesis block to.")
37+
flag.StringVar(&outputBlock, "outputBlock", "", "The path to write the genesis block to (if set)")
38+
flag.StringVar(&channelID, "channelID", provisional.TestChainID, "The channel ID to use in the configtx")
39+
flag.StringVar(&outputChannelCreateTx, "outputCreateChannelTx", "", "The path to write a channel creation configtx to (if set)")
4140
flag.StringVar(&profile, "profile", genesisconfig.SampleInsecureProfile, "The profile from configtx.yaml to use for generation.")
4241
flag.Parse()
4342

4443
logging.SetLevel(logging.INFO, "")
4544

4645
logger.Info("Loading configuration")
4746
config := genesisconfig.Load(profile)
47+
pgen := provisional.New(config)
4848

49-
logger.Info("Generating genesis block")
50-
genesisBlock := provisional.New(config).GenesisBlock()
51-
52-
if !*dryRun {
49+
if outputBlock != "" {
50+
logger.Info("Generating genesis block")
51+
genesisBlock := pgen.GenesisBlock()
5352
logger.Info("Writing genesis block")
54-
ioutil.WriteFile(writePath, utils.MarshalOrPanic(genesisBlock), 0644)
53+
err := ioutil.WriteFile(outputBlock, utils.MarshalOrPanic(genesisBlock), 0644)
54+
if err != nil {
55+
logger.Errorf("Error writing genesis block: %s", err)
56+
}
57+
}
58+
59+
if outputChannelCreateTx != "" {
60+
logger.Info("Generating new channel configtx")
61+
// TODO, use actual MSP eventually
62+
signer, err := msp.NewNoopMsp().GetDefaultSigningIdentity()
63+
if err != nil {
64+
logger.Fatalf("Error getting signing identity: %s", err)
65+
}
66+
configtx, err := configtx.MakeChainCreationTransaction(provisional.AcceptAllPolicyKey, channelID, signer, pgen.ChannelTemplate())
67+
if err != nil {
68+
logger.Fatalf("Error generating configtx: %s", err)
69+
}
70+
logger.Info("Writing new channel tx")
71+
err = ioutil.WriteFile(outputChannelCreateTx, utils.MarshalOrPanic(configtx), 0644)
72+
if err != nil {
73+
logger.Errorf("Error writing channel create tx: %s", err)
74+
}
5575
}
5676
}

‎common/configtx/tool/provisional/provisional.go

+15
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ func (bs *bootstrapper) ChannelTemplate() configtx.Template {
163163
)
164164
}
165165

166+
// XXX deprecate and remove
166167
func (bs *bootstrapper) GenesisBlock() *cb.Block {
167168
block, err := genesis.NewFactoryImpl(
168169
configtx.NewCompositeTemplate(
@@ -176,3 +177,17 @@ func (bs *bootstrapper) GenesisBlock() *cb.Block {
176177
}
177178
return block
178179
}
180+
181+
func (bs *bootstrapper) GenesisBlockForChannel(channelID string) *cb.Block {
182+
block, err := genesis.NewFactoryImpl(
183+
configtx.NewCompositeTemplate(
184+
configtx.NewSimpleTemplate(bs.ordererSystemChannelGroups...),
185+
bs.ChannelTemplate(),
186+
),
187+
).Block(channelID)
188+
189+
if err != nil {
190+
panic(err)
191+
}
192+
return block
193+
}

‎docs/configtxgen.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,18 @@ This configuration file may be edited, or, individual properties may be overridd
2323
## Bootstrapping the orderer
2424
After creating a configuration profile as desired, simply invoke
2525
```
26-
configtxgen -profile &lt;profile_name&gt;
26+
configtxgen -profile &lt;profile_name&gt; -outputBlock &lt;genesis.blockname&gt;
2727
```
28-
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.
28+
This will produce a `genesis.block` file in the current directory. If you wish to skip writing the file simply do not pass `outputBlock`
2929

3030
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.
31+
32+
## Creating a channel
33+
34+
The tool can also output a channel creation tx by executing
35+
36+
```
37+
configtxgen -profile &lt;profile_name&gt; -outputCreateChannelTx &lt;output.txname&gt;
38+
```
39+
40+
This will output a marshaled `Envelope` message which may be sent to broadcast to create a channel.

0 commit comments

Comments
 (0)
Please sign in to comment.