Skip to content

Commit

Permalink
Minor refactor/log change for orderer startup
Browse files Browse the repository at this point in the history
FAB-18230

Signed-off-by: Will Lahti <[email protected]>
  • Loading branch information
wlahti authored and Brett Logan committed Oct 27, 2020
1 parent 62a8808 commit 2198c09
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 53 deletions.
42 changes: 21 additions & 21 deletions orderer/common/server/etcdraft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ func testEtcdRaftOSNRestart(gt *GomegaWithT, tempDir, configtxgen, orderer, cryp
genesisBlockPath := generateBootstrapBlock(gt, tempDir, configtxgen, "system", "SampleEtcdRaftSystemChannel")

// Launch the OSN
ordererProcess := launchOrderer(gt, orderer, tempDir, tempDir, genesisBlockPath, cryptoPath, "file", "false")
ordererProcess := launchOrderer(gt, orderer, tempDir, tempDir, genesisBlockPath, cryptoPath, "file", "false", "info")
defer func() { gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit()) }()
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("Beginning to serve requests"))
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("becomeLeader"))

// Restart orderer with ORDERER_GENERAL_BOOTSTRAPMETHOD = none
gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit())
ordererProcess = launchOrderer(gt, orderer, tempDir, tempDir, "", cryptoPath, "none", "true")
ordererProcess = launchOrderer(gt, orderer, tempDir, tempDir, "", cryptoPath, "none", "true", "info")
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("Beginning to serve requests"))
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("becomeLeader"))
gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit())
Expand All @@ -150,7 +150,7 @@ func testEtcdRaftOSNJoinSysChan(gt *GomegaWithT, configPath, configtxgen, ordere
defer os.RemoveAll(tempDir)

// Launch the OSN without channels
ordererProcess := launchOrderer(gt, orderer, tempDir, configPath, "", cryptoPath, "none", "true")
ordererProcess := launchOrderer(gt, orderer, tempDir, configPath, "", cryptoPath, "none", "true", "info:orderer.common.server=debug")
defer func() { gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit()) }()
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("Channel Participation API enabled, registrar initializing with file repo"))
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("No join-block was found for the system channel"))
Expand All @@ -168,7 +168,7 @@ func testEtcdRaftOSNJoinSysChan(gt *GomegaWithT, configPath, configtxgen, ordere
gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit())

// Restart, should pick up the join-block and bootstrap with it
ordererProcess = launchOrderer(gt, orderer, tempDir, configPath, "", cryptoPath, "none", "true")
ordererProcess = launchOrderer(gt, orderer, tempDir, configPath, "", cryptoPath, "none", "true", "info")
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("Channel Participation API enabled, registrar initializing with file repo"))
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("Join-block was found for the system channel: system, number: 0"))
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("Beginning to serve requests"))
Expand All @@ -189,7 +189,7 @@ func testEtcdRaftOSNSuccess(gt *GomegaWithT, configPath, configtxgen, orderer, c
genesisBlockPath := generateBootstrapBlock(gt, configPath, configtxgen, "system", "SampleEtcdRaftSystemChannel")

// Launch the OSN
ordererProcess := launchOrderer(gt, orderer, tempDir, configPath, genesisBlockPath, cryptoPath, "file", "false")
ordererProcess := launchOrderer(gt, orderer, tempDir, configPath, genesisBlockPath, cryptoPath, "file", "false", "info")
defer func() { gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit()) }()
// The following configuration parameters are not specified in the orderer.yaml, so let's ensure
// they are really configured autonomously via the localconfig code.
Expand Down Expand Up @@ -227,7 +227,7 @@ func testEtcdRaftOSNFailureInvalidBootstrapBlock(gt *GomegaWithT, configPath, or
gt.Expect(err).NotTo(HaveOccurred())

// Launch the OSN
ordererProcess := launchOrderer(gt, orderer, tempDir, configPath, genesisBlockPath, cryptoPath, "", "false")
ordererProcess := launchOrderer(gt, orderer, tempDir, configPath, genesisBlockPath, cryptoPath, "", "false", "info")
defer func() { gt.Eventually(ordererProcess.Kill(), time.Minute).Should(gexec.Exit()) }()

expectedErr := "Failed validating bootstrap block: the block isn't a system channel block because it lacks ConsortiumsConfig"
Expand Down Expand Up @@ -295,34 +295,34 @@ func testEtcdRaftOSNNoTLSDualListener(gt *GomegaWithT, configPath, orderer strin
gt.Eventually(ordererProcess.Err, time.Minute).Should(gbytes.Say("becomeLeader"))
}

func launchOrderer(gt *GomegaWithT, orderer, tempDir, configPath, genesisBlockPath, cryptoPath, bootstrapMethod, channelParticipationEnabled string) *gexec.Session {
func launchOrderer(gt *GomegaWithT, orderer, tempDir, configPath, genesisBlockPath, cryptoPath, bootstrapMethod, channelParticipationEnabled, logSpec string) *gexec.Session {
ordererTLSPath := filepath.Join(cryptoPath, "ordererOrganizations", "example.com", "orderers", "127.0.0.1.example.com", "tls")
// Launch the orderer process
cmd := exec.Command(orderer)
cmd.Env = []string{
fmt.Sprintf("ORDERER_GENERAL_LISTENPORT=%d", nextPort()),
fmt.Sprintf("ORDERER_GENERAL_BOOTSTRAPMETHOD=%s", bootstrapMethod),
"ORDERER_GENERAL_BOOTSTRAPMETHOD=" + bootstrapMethod,
"ORDERER_GENERAL_SYSTEMCHANNEL=system",
"ORDERER_GENERAL_TLS_CLIENTAUTHREQUIRED=true",
"ORDERER_GENERAL_TLS_ENABLED=true",
"ORDERER_OPERATIONS_TLS_ENABLED=false",
fmt.Sprintf("ORDERER_FILELEDGER_LOCATION=%s", filepath.Join(tempDir, "ledger")),
fmt.Sprintf("ORDERER_GENERAL_BOOTSTRAPFILE=%s", genesisBlockPath),
"ORDERER_FILELEDGER_LOCATION=" + filepath.Join(tempDir, "ledger"),
"ORDERER_GENERAL_BOOTSTRAPFILE=" + 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(ordererTLSPath, "server.crt")),
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=%s", filepath.Join(ordererTLSPath, "server.key")),
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=%s", filepath.Join(ordererTLSPath, "server.crt")),
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=%s", filepath.Join(ordererTLSPath, "server.key")),
"ORDERER_GENERAL_CLUSTER_SERVERCERTIFICATE=" + filepath.Join(ordererTLSPath, "server.crt"),
"ORDERER_GENERAL_CLUSTER_SERVERPRIVATEKEY=" + filepath.Join(ordererTLSPath, "server.key"),
"ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=" + filepath.Join(ordererTLSPath, "server.crt"),
"ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=" + filepath.Join(ordererTLSPath, "server.key"),
fmt.Sprintf("ORDERER_GENERAL_CLUSTER_ROOTCAS=[%s]", filepath.Join(ordererTLSPath, "ca.crt")),
fmt.Sprintf("ORDERER_GENERAL_TLS_ROOTCAS=[%s]", filepath.Join(ordererTLSPath, "ca.crt")),
fmt.Sprintf("ORDERER_GENERAL_TLS_CERTIFICATE=%s", filepath.Join(ordererTLSPath, "server.crt")),
fmt.Sprintf("ORDERER_GENERAL_TLS_PRIVATEKEY=%s", filepath.Join(ordererTLSPath, "server.key")),
fmt.Sprintf("ORDERER_CONSENSUS_WALDIR=%s", filepath.Join(tempDir, "wal")),
fmt.Sprintf("ORDERER_CONSENSUS_SNAPDIR=%s", filepath.Join(tempDir, "snapshot")),
fmt.Sprintf("ORDERER_CHANNELPARTICIPATION_ENABLED=%s", channelParticipationEnabled),
fmt.Sprintf("FABRIC_CFG_PATH=%s", configPath),
"FABRIC_LOGGING_SPEC=info",
"ORDERER_GENERAL_TLS_CERTIFICATE=" + filepath.Join(ordererTLSPath, "server.crt"),
"ORDERER_GENERAL_TLS_PRIVATEKEY=" + filepath.Join(ordererTLSPath, "server.key"),
"ORDERER_CONSENSUS_WALDIR=" + filepath.Join(tempDir, "wal"),
"ORDERER_CONSENSUS_SNAPDIR=" + filepath.Join(tempDir, "snapshot"),
"ORDERER_CHANNELPARTICIPATION_ENABLED=" + channelParticipationEnabled,
"FABRIC_CFG_PATH=" + configPath,
"FABRIC_LOGGING_SPEC=" + logSpec,
}
sess, err := gexec.Start(cmd, nil, nil)
gt.Expect(err).NotTo(HaveOccurred())
Expand Down
67 changes: 36 additions & 31 deletions orderer/common/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,30 @@ func Main() {
}

var bootstrapBlock *cb.Block
if conf.General.BootstrapMethod == "file" {
switch conf.General.BootstrapMethod {
case "file":
if len(lf.ChannelIDs()) > 0 {
logger.Info("Not bootstrapping the system channel because of existing channels")
break
}

bootstrapBlock = file.New(conf.General.BootstrapFile).GenesisBlock()
if err := onboarding.ValidateBootstrapBlock(bootstrapBlock, cryptoProvider); err != nil {
logger.Panicf("Failed validating bootstrap block: %v", err)
}

// Are we bootstrapping with a genesis block (i.e. bootstrap block number = 0)?
// If yes, generate the system channel with a genesis block.
if len(lf.ChannelIDs()) == 0 && bootstrapBlock.Header.Number == 0 {
logger.Info("Bootstrapping the system channel")
initializeBootstrapChannel(bootstrapBlock, lf)
} else if len(lf.ChannelIDs()) > 0 {
logger.Info("Not bootstrapping the system channel because of existing channels")
} else {
if bootstrapBlock.Header.Number > 0 {
logger.Infof("Not bootstrapping the system channel because the bootstrap block number is %d (>0), replication is needed", bootstrapBlock.Header.Number)
break
}
} else if conf.General.BootstrapMethod == "none" {

// bootstrapping with a genesis block (i.e. bootstrap block number = 0)
// generate the system channel with a genesis block.
logger.Info("Bootstrapping the system channel")
initializeBootstrapChannel(bootstrapBlock, lf)
case "none":
bootstrapBlock = initSystemChannelWithJoinBlock(conf, cryptoProvider, lf)
} else {
default:
logger.Panicf("Unknown bootstrap method: %s", conf.General.BootstrapMethod)
}

Expand Down Expand Up @@ -184,19 +189,23 @@ func Main() {
// If we have a separate gRPC server for the cluster,
// we need to update its TLS CA certificate pool.
serversToUpdate = append(serversToUpdate, clusterGRPCServer)
}

// If the orderer has a system channel and is of cluster type, it may have to replicate first.
if clusterBootBlock != nil && isClusterType {
// When we are bootstrapping with a clusterBootBlock with number >0, replication will be performed.
// Only clusters that are equipped with a recent config block (number i.e. >0) can replicate.
// This will replicate all channels if the clusterBootBlock number > system-channel height (i.e. there is a gap in the ledger).
repInitiator = onboarding.NewReplicationInitiator(lf, clusterBootBlock, conf, clusterClientConfig.SecOpts, signer, cryptoProvider)
repInitiator.ReplicateIfNeeded(clusterBootBlock)
// With BootstrapMethod == "none", the bootstrapBlock comes from a join-block. If it exists, we need to remove
// the system channel join-block from the filerepo.
if conf.General.BootstrapMethod == "none" && bootstrapBlock != nil {
discardSystemChannelJoinBlock(conf, bootstrapBlock)
// If the orderer has a system channel and is of cluster type, it may have
// to replicate first.
if clusterBootBlock != nil {
// When we are bootstrapping with a clusterBootBlock with number >0,
// replication will be performed. Only clusters that are equipped with
// a recent config block (number i.e. >0) can replicate. This will
// replicate all channels if the clusterBootBlock number > system-channel
// height (i.e. there is a gap in the ledger).
repInitiator = onboarding.NewReplicationInitiator(lf, clusterBootBlock, conf, clusterClientConfig.SecOpts, signer, cryptoProvider)
repInitiator.ReplicateIfNeeded(clusterBootBlock)
// With BootstrapMethod == "none", the bootstrapBlock comes from a
// join-block. If it exists, we need to remove the system channel
// join-block from the filerepo.
if conf.General.BootstrapMethod == "none" && bootstrapBlock != nil {
discardSystemChannelJoinBlock(conf, bootstrapBlock)
}
}
}

Expand Down Expand Up @@ -334,8 +343,8 @@ func initSystemChannelWithJoinBlock(
}

if bootstrapBlock == nil {
logger.Info("No join-block was found for the system channel")
return bootstrapBlock
logger.Debug("No join-block was found for the system channel")
return nil
}

if bootstrapBlock.Header.Number == 0 {
Expand All @@ -346,10 +355,7 @@ func initSystemChannelWithJoinBlock(
return bootstrapBlock
}

func discardSystemChannelJoinBlock(
config *localconfig.TopLevel,
bootstrapBlock *cb.Block,
) {
func discardSystemChannelJoinBlock(config *localconfig.TopLevel, bootstrapBlock *cb.Block) {
if !config.ChannelParticipation.Enabled {
return
}
Expand Down Expand Up @@ -384,8 +390,7 @@ func reuseListener(conf *localconfig.TopLevel) bool {

// Else, one of the above is defined, so all 4 properties should be defined.
if clusterConf.ListenPort == 0 || clusterConf.ServerCertificate == "" || clusterConf.ListenAddress == "" || clusterConf.ServerPrivateKey == "" {
logger.Panic("Options: General.Cluster.ListenPort, General.Cluster.ListenAddress, General.Cluster.ServerCertificate," +
" General.Cluster.ServerPrivateKey, should be defined altogether.")
logger.Panic("Options: General.Cluster.ListenPort, General.Cluster.ListenAddress, General.Cluster.ServerCertificate, General.Cluster.ServerPrivateKey, should be defined altogether.")
}

return false
Expand Down
2 changes: 1 addition & 1 deletion orderer/consensus/etcdraft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/common/channelconfig"
"sync"
"sync/atomic"
"time"
Expand All @@ -21,6 +20,7 @@ import (
"github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric-protos-go/orderer/etcdraft"
"github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric/common/channelconfig"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/orderer/common/cluster"
"github.com/hyperledger/fabric/orderer/common/types"
Expand Down

0 comments on commit 2198c09

Please sign in to comment.