From d91990518070517d2a2d8b9bb7f047b10022d5e3 Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Thu, 29 Aug 2019 10:17:05 -0700 Subject: [PATCH] [FAB-16477] Use bootstrap file for raft consensus Currently, the genesisfile is used for solo and kafka mode, while in the raft consensus, it can be boostraped from genesis block or the latest config block. This patchset use the bootstrap file for both case, which is more clear. Change-Id: I3e97bc1146211377393fa275c89631f1f1575e21 Signed-off-by: Baohua Yang Signed-off-by: Baohua Yang --- docs/source/kafka.rst | 2 +- docs/source/orderer_deploy.md | 6 +++--- docs/source/raft_configuration.md | 2 +- integration/nwo/fabricconfig/orderer.go | 3 ++- integration/nwo/orderer_template.go | 2 +- orderer/README.md | 2 +- orderer/common/localconfig/config.go | 17 ++++++++++++----- orderer/common/server/etcdraft_test.go | 6 +++--- orderer/common/server/main.go | 2 +- orderer/common/server/main_test.go | 12 ++++++------ sampleconfig/orderer.yaml | 7 +++++++ 11 files changed, 38 insertions(+), 23 deletions(-) diff --git a/docs/source/kafka.rst b/docs/source/kafka.rst index 0922d2fa4d8..85807f57f54 100644 --- a/docs/source/kafka.rst +++ b/docs/source/kafka.rst @@ -131,7 +131,7 @@ Then proceed as follows: of this writing, so there's no need to set it explicitly.) 7. Orderers: **Point each OSN to the genesis block.** Edit - ``General.GenesisFile`` in ``orderer.yaml`` so that it points to the genesis + ``General.BootstrapFile`` in ``orderer.yaml`` so that it points to the genesis block created in Step 5 above. While at it, ensure all other keys in that YAML file are set appropriately. diff --git a/docs/source/orderer_deploy.md b/docs/source/orderer_deploy.md index e912d415b35..b0635451d61 100644 --- a/docs/source/orderer_deploy.md +++ b/docs/source/orderer_deploy.md @@ -48,11 +48,11 @@ to [enable TLS](enable_tls.html). If you set this value to `true`, you will have to specify the locations of the relevant TLS certificates. Note that this is mandatory for Raft nodes. -* `GenesisFile` --- this is the name of the genesis block you will generate for +* `BootstrapFile` --- this is the name of the genesis block you will generate for this ordering service. -* `GenesisMethod` --- the method by which the genesis block is created. For now, -this can only be `file`, in which the file in the `GenesisFile` is specified. +* `GenesisMethod` --- the method by which the bootstrap block is given. For now, +this can only be `file`, in which the file in the `BootstrapFile` is specified. If you are deploying this node as part of a cluster (for example, as part of a cluster of Raft nodes), make note of the `Cluster` and `Consensus` sections. diff --git a/docs/source/raft_configuration.md b/docs/source/raft_configuration.md index de94ccfa3e2..c1a5ab5c311 100644 --- a/docs/source/raft_configuration.md +++ b/docs/source/raft_configuration.md @@ -217,7 +217,7 @@ Adding a new node to a Raft cluster is done by: by checking that the config block that was fetched includes the certificate of (soon to be) added node. 4. **Starting the new Raft node** with the path to the config block in the - `General.GenesisFile` configuration parameter. + `General.BootstrapFile` configuration parameter. 5. **Waiting for the Raft node to replicate the blocks** from existing nodes for all channels its certificates have been added to. After this step has been completed, the node begins servicing the channel. diff --git a/integration/nwo/fabricconfig/orderer.go b/integration/nwo/fabricconfig/orderer.go index da939f7e495..ac1892dbb71 100644 --- a/integration/nwo/fabricconfig/orderer.go +++ b/integration/nwo/fabricconfig/orderer.go @@ -24,7 +24,8 @@ type General struct { Keepalive *OrdererKeepalive `yaml:"Keepalive,omitempty"` GenesisMethod string `yaml:"GenesisMethod,omitempty"` GenesisProfile string `yaml:"GenesisProfile,omitempty"` - GenesisFile string `yaml:"GenesisFile,omitempty"` + GenesisFile string `yaml:"GenesisFile,omitempty"` // will be replaced by the BootstrapFile + BootstrapFile string `yaml:"BootstrapFile,omitempty"` LocalMSPDir string `yaml:"LocalMSPDir,omitempty"` LocalMSPID string `yaml:"LocalMSPID,omitempty"` Profile *OrdererProfile `yaml:"Profile,omitempty"` diff --git a/integration/nwo/orderer_template.go b/integration/nwo/orderer_template.go index 6f288433817..dc60aeea6cb 100644 --- a/integration/nwo/orderer_template.go +++ b/integration/nwo/orderer_template.go @@ -36,7 +36,7 @@ General: ServerInterval: 7200s ServerTimeout: 20s GenesisMethod: file - GenesisFile: {{ .RootDir }}/{{ .SystemChannel.Name }}_block.pb + BootstrapFile: {{ .RootDir }}/{{ .SystemChannel.Name }}_block.pb LocalMSPDir: {{ $w.OrdererLocalMSPDir Orderer }} LocalMSPID: {{ ($w.Organization Orderer.Organization).MSPID }} Profile: diff --git a/orderer/README.md b/orderer/README.md index 27864e3ed23..1b43cfd810b 100644 --- a/orderer/README.md +++ b/orderer/README.md @@ -22,7 +22,7 @@ For details on the configuration structure of channels, refer to the [Channel Co `configtxgen` is a tool that allows for the creation of a genesis block using profiles, or grouped configuration parameters — refer to the [Configuring using the connfigtxgen tool](../docs/source/configtxgen.rst) guide for more. -The location of this block can be set using the `ORDERER_GENERAL_GENESISFILE` environment variable. As is the case with all the configuration paths for Fabric binaries, this location is relative to the path set via the `FABRIC_CFG_PATH` environment variable. +The location of this block can be set using the `ORDERER_GENERAL_BOOTSTRAPFILE` environment variable. As is the case with all the configuration paths for Fabric binaries, this location is relative to the path set via the `FABRIC_CFG_PATH` environment variable. ## Ledger diff --git a/orderer/common/localconfig/config.go b/orderer/common/localconfig/config.go index 41bfb041d38..350f9a188e6 100644 --- a/orderer/common/localconfig/config.go +++ b/orderer/common/localconfig/config.go @@ -46,7 +46,8 @@ type General struct { Keepalive Keepalive ConnectionTimeout time.Duration GenesisMethod string - GenesisFile string + GenesisFile string // For compatibility only, will be replaced by BootstrapFile + BootstrapFile string Profile Profile LocalMSPDir string LocalMSPID string @@ -207,7 +208,7 @@ var Defaults = TopLevel{ ListenAddress: "127.0.0.1", ListenPort: 7050, GenesisMethod: "file", - GenesisFile: "genesisblock", + BootstrapFile: "genesisblock", Profile: Profile{ Enabled: false, Address: "0.0.0.0:6060", @@ -316,7 +317,7 @@ func (c *TopLevel) completeInitialization(configDir string) { c.General.TLS.ClientRootCAs = translateCAs(configDir, c.General.TLS.ClientRootCAs) coreconfig.TranslatePathInPlace(configDir, &c.General.TLS.PrivateKey) coreconfig.TranslatePathInPlace(configDir, &c.General.TLS.Certificate) - coreconfig.TranslatePathInPlace(configDir, &c.General.GenesisFile) + coreconfig.TranslatePathInPlace(configDir, &c.General.BootstrapFile) coreconfig.TranslatePathInPlace(configDir, &c.General.LocalMSPDir) // Translate file ledger location coreconfig.TranslatePathInPlace(configDir, &c.FileLedger.Location) @@ -332,8 +333,14 @@ func (c *TopLevel) completeInitialization(configDir string) { c.General.ListenPort = Defaults.General.ListenPort case c.General.GenesisMethod == "": c.General.GenesisMethod = Defaults.General.GenesisMethod - case c.General.GenesisFile == "": - c.General.GenesisFile = Defaults.General.GenesisFile + case c.General.BootstrapFile == "": + if c.General.GenesisFile != "" { + // This is to keep the compatibility with old config file that uses genesisfile + logger.Warn("General.GenesisFile should be replaced by General.BootstrapFile") + c.General.BootstrapFile = c.General.GenesisFile + } else { + c.General.BootstrapFile = Defaults.General.BootstrapFile + } case c.General.Cluster.RPCTimeout == 0: c.General.Cluster.RPCTimeout = Defaults.General.Cluster.RPCTimeout case c.General.Cluster.DialTimeout == 0: diff --git a/orderer/common/server/etcdraft_test.go b/orderer/common/server/etcdraft_test.go index 0f34e1c2e09..93583ba5e36 100644 --- a/orderer/common/server/etcdraft_test.go +++ b/orderer/common/server/etcdraft_test.go @@ -150,7 +150,7 @@ func testEtcdRaftOSNNoTLSSingleListener(gt *GomegaWithT, tempDir, orderer, fabri "ORDERER_GENERAL_GENESISMETHOD=file", "ORDERER_GENERAL_SYSTEMCHANNEL=system", fmt.Sprintf("ORDERER_FILELEDGER_LOCATION=%s", filepath.Join(tempDir, "ledger")), - fmt.Sprintf("ORDERER_GENERAL_GENESISFILE=%s", genesisBlockPath), + fmt.Sprintf("ORDERER_GENERAL_BOOTSTRAPFILE=%s", genesisBlockPath), fmt.Sprintf("FABRIC_CFG_PATH=%s", filepath.Join(fabricRootDir, "sampleconfig")), } ordererProcess, err := gexec.Start(cmd, nil, nil) @@ -175,7 +175,7 @@ func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, tempDir, orderer, fabricR "ORDERER_GENERAL_TLS_ENABLED=false", "ORDERER_OPERATIONS_TLS_ENABLED=false", fmt.Sprintf("ORDERER_FILELEDGER_LOCATION=%s", filepath.Join(tempDir, "ledger")), - fmt.Sprintf("ORDERER_GENERAL_GENESISFILE=%s", genesisBlockPath), + fmt.Sprintf("ORDERER_GENERAL_BOOTSTRAPFILE=%s", genesisBlockPath), fmt.Sprintf("ORDERER_GENERAL_CLUSTER_LISTENPORT=%d", nextPort()), "ORDERER_GENERAL_CLUSTER_LISTENADDRESS=127.0.0.1", fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")), @@ -210,7 +210,7 @@ func launchOrderer(gt *GomegaWithT, orderer, tempDir, genesisBlockPath, fabricRo "ORDERER_GENERAL_TLS_ENABLED=true", "ORDERER_OPERATIONS_TLS_ENABLED=false", fmt.Sprintf("ORDERER_FILELEDGER_LOCATION=%s", filepath.Join(tempDir, "ledger")), - fmt.Sprintf("ORDERER_GENERAL_GENESISFILE=%s", genesisBlockPath), + fmt.Sprintf("ORDERER_GENERAL_BOOTSTRAPFILE=%s", genesisBlockPath), fmt.Sprintf("ORDERER_GENERAL_CLUSTER_LISTENPORT=%d", nextPort()), "ORDERER_GENERAL_CLUSTER_LISTENADDRESS=127.0.0.1", fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=%s", filepath.Join(cwd, "testdata", "example.com", "tls", "server.crt")), diff --git a/orderer/common/server/main.go b/orderer/common/server/main.go index 43de583a876..1749fa2939b 100644 --- a/orderer/common/server/main.go +++ b/orderer/common/server/main.go @@ -592,7 +592,7 @@ func extractBootstrapBlock(conf *localconfig.TopLevel) *cb.Block { // Select the bootstrapping mechanism switch conf.General.GenesisMethod { case "file": // For now, "file" is the only supported genesis method - bootstrapBlock = file.New(conf.General.GenesisFile).GenesisBlock() + bootstrapBlock = file.New(conf.General.BootstrapFile).GenesisBlock() case "none": // simply honor the configuration value return nil default: diff --git a/orderer/common/server/main_test.go b/orderer/common/server/main_test.go index 243e1672d27..61d0362391d 100644 --- a/orderer/common/server/main_test.go +++ b/orderer/common/server/main_test.go @@ -216,12 +216,12 @@ func TestInitializeBootstrapChannel(t *testing.T) { bootstrapConfig := &localconfig.TopLevel{ General: localconfig.General{ GenesisMethod: "file", - GenesisFile: genesisFile, + BootstrapFile: genesisFile, }, } - genesisBlock := extractBootstrapBlock(bootstrapConfig) - initializeBootstrapChannel(genesisBlock, ledgerFactory) + bootstrapBlock := extractBootstrapBlock(bootstrapConfig) + initializeBootstrapChannel(bootstrapBlock, ledgerFactory) ledger, err := ledgerFactory.GetOrCreate("testchannelid") assert.NoError(t, err) @@ -241,7 +241,7 @@ func TestExtractBootstrapBlock(t *testing.T) { }{ { config: &localconfig.TopLevel{ - General: localconfig.General{GenesisMethod: "file", GenesisFile: genesisFile}, + General: localconfig.General{GenesisMethod: "file", BootstrapFile: genesisFile}, }, block: file.New(genesisFile).GenesisBlock(), }, @@ -470,7 +470,7 @@ func TestUpdateTrustedRoots(t *testing.T) { conf := &localconfig.TopLevel{ General: localconfig.General{ GenesisMethod: "file", - GenesisFile: genesisFile, + BootstrapFile: genesisFile, ListenAddress: "localhost", ListenPort: uint16(port), TLS: localconfig.TLS{ @@ -838,7 +838,7 @@ func genesisConfig(t *testing.T, genesisFile string) *localconfig.TopLevel { return &localconfig.TopLevel{ General: localconfig.General{ GenesisMethod: "file", - GenesisFile: genesisFile, + BootstrapFile: genesisFile, LocalMSPDir: localMSPDir, LocalMSPID: "SampleOrg", BCCSP: &factory.FactoryOpts{ diff --git a/sampleconfig/orderer.yaml b/sampleconfig/orderer.yaml index 4b48c4cfde5..f8e24e6762a 100644 --- a/sampleconfig/orderer.yaml +++ b/sampleconfig/orderer.yaml @@ -77,6 +77,13 @@ General: # The file containing the genesis block to use when initializing the orderer system channel GenesisFile: genesisblock + # Bootstrap file: The file containing the bootstrap block to use when + # initializing the orderer system channel and GenesisMethod is set to + # "file". Ignored if GenesisMethod is set to "provisional". + # The bootstrap file can be the genesis block, and it can also be a config block that expands the + # network to add orderer. + BootstrapFile: genesisblock + # LocalMSPDir is where to find the private crypto material needed by the # orderer. It is set relative here as a default for dev environments but # should be changed to the real location in production.