From 4bb5efe802001e17feaa265e045a65867de7d049 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 16 May 2019 16:14:05 -0700 Subject: [PATCH] Enable STOP message only with -enable_stop The STOP message has always been only for testing, and should never be honored on any network except in controlled, short-lived test networks. --- cmd/harmony/main.go | 8 ++++++++ node/node.go | 5 +++++ node/node_handler.go | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index f3280f86e..b4e31af72 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -94,6 +94,10 @@ var ( shardID = flag.Int("shard_id", -1, "the shard ID of this node") // logConn logs incoming/outgoing connections logConn = flag.Bool("log_conn", false, "log incoming/outgoing connections") + // Enable processing of kill (STOP) message. Only for automated testing. + enableStopMessage = flag.Bool("enable_stop", false, + "enable processing of STOP message, e.g. from txgen "+ + "(USE ONLY IN SHORT-LIVED, PRIVATE TEST NETWORKS)") ) func initSetup() { @@ -227,6 +231,10 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen currentNode := node.New(nodeConfig.Host, currentConsensus, nodeConfig.MainDB, *isArchival) currentNode.NodeConfig.SetRole(nodeconfig.NewNode) currentNode.AccountKey = nodeConfig.StakingPriKey + if *enableStopMessage { + utils.GetLogInstance().Warn("enabling STOP message processing for this node") + currentNode.ProcessStopMessage = true + } utils.GetLogInstance().Info("node account set", "address", crypto.PubkeyToAddress(currentNode.AccountKey.PublicKey)) diff --git a/node/node.go b/node/node.go index f6b13e099..50737068b 100644 --- a/node/node.go +++ b/node/node.go @@ -179,6 +179,11 @@ type Node struct { // Used to call smart contract locally ContractCaller *contracts.ContractCaller + + // Enable processing of STOP message. + // When enabled ANYONE can bring down this node. + // Use only for private testing, and definitely never on prod network. + ProcessStopMessage bool } // Blockchain returns the blockchain from node diff --git a/node/node_handler.go b/node/node_handler.go index c17eea491..ea8880e3f 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -175,7 +175,7 @@ func (node *Node) messageHandler(content []byte, sender string) { case proto_node.Control: utils.GetLogInstance().Info("NET: received message: Node/Control") controlType := msgPayload[0] - if proto_node.ControlMessageType(controlType) == proto_node.STOP { + if proto_node.ControlMessageType(controlType) == proto_node.STOP && node.ProcessStopMessage { utils.GetLogInstance().Debug("Stopping Node", "numBlocks", node.blockchain.CurrentBlock().NumberU64(), "numTxsProcessed", node.countNumTransactionsInBlockchain()) var avgBlockSizeInBytes common.StorageSize