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.
pull/854/head
Eugene Kim 6 years ago
parent 8ae9307632
commit 4bb5efe802
  1. 8
      cmd/harmony/main.go
  2. 5
      node/node.go
  3. 2
      node/node_handler.go

@ -94,6 +94,10 @@ var (
shardID = flag.Int("shard_id", -1, "the shard ID of this node") shardID = flag.Int("shard_id", -1, "the shard ID of this node")
// logConn logs incoming/outgoing connections // logConn logs incoming/outgoing connections
logConn = flag.Bool("log_conn", false, "log 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() { func initSetup() {
@ -227,6 +231,10 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen
currentNode := node.New(nodeConfig.Host, currentConsensus, nodeConfig.MainDB, *isArchival) currentNode := node.New(nodeConfig.Host, currentConsensus, nodeConfig.MainDB, *isArchival)
currentNode.NodeConfig.SetRole(nodeconfig.NewNode) currentNode.NodeConfig.SetRole(nodeconfig.NewNode)
currentNode.AccountKey = nodeConfig.StakingPriKey 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", utils.GetLogInstance().Info("node account set",
"address", crypto.PubkeyToAddress(currentNode.AccountKey.PublicKey)) "address", crypto.PubkeyToAddress(currentNode.AccountKey.PublicKey))

@ -179,6 +179,11 @@ type Node struct {
// Used to call smart contract locally // Used to call smart contract locally
ContractCaller *contracts.ContractCaller 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 // Blockchain returns the blockchain from node

@ -175,7 +175,7 @@ func (node *Node) messageHandler(content []byte, sender string) {
case proto_node.Control: case proto_node.Control:
utils.GetLogInstance().Info("NET: received message: Node/Control") utils.GetLogInstance().Info("NET: received message: Node/Control")
controlType := msgPayload[0] 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()) utils.GetLogInstance().Debug("Stopping Node", "numBlocks", node.blockchain.CurrentBlock().NumberU64(), "numTxsProcessed", node.countNumTransactionsInBlockchain())
var avgBlockSizeInBytes common.StorageSize var avgBlockSizeInBytes common.StorageSize

Loading…
Cancel
Save