Remove STOP message; txgen doesn't send it anymore

pull/854/head
Eugene Kim 6 years ago
parent 7d26462b1b
commit 32040c0fe6
  1. 18
      api/proto/node/node.go
  2. 8
      api/proto/node/node_test.go
  3. 8
      cmd/harmony/main.go
  4. 5
      node/node.go
  5. 30
      node/node_handler.go
  6. 10
      test/deploy.sh
  7. 2
      test/deploy_newnode.sh

@ -24,7 +24,7 @@ const (
Transaction MessageType = iota Transaction MessageType = iota
Block Block
Client Client
Control _ // used to be Control
PING // node send ip/pki to register with leader PING // node send ip/pki to register with leader
PONG // node broadcast pubK PONG // node broadcast pubK
ShardState ShardState
@ -99,14 +99,6 @@ const (
Sync BlockMessageType = iota Sync BlockMessageType = iota
) )
// ControlMessageType is the type of messages used for Node/Control
type ControlMessageType int
// ControlMessageType
const (
STOP ControlMessageType = iota
)
// SerializeBlockchainSyncMessage serializes BlockchainSyncMessage. // SerializeBlockchainSyncMessage serializes BlockchainSyncMessage.
func SerializeBlockchainSyncMessage(blockchainSyncMessage *BlockchainSyncMessage) []byte { func SerializeBlockchainSyncMessage(blockchainSyncMessage *BlockchainSyncMessage) []byte {
var result bytes.Buffer var result bytes.Buffer
@ -155,14 +147,6 @@ func ConstructRequestTransactionsMessage(transactionIds [][]byte) []byte {
return byteBuffer.Bytes() return byteBuffer.Bytes()
} }
// ConstructStopMessage constructs STOP message for node to stop
func ConstructStopMessage() []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.Node)})
byteBuffer.WriteByte(byte(Control))
byteBuffer.WriteByte(byte(STOP))
return byteBuffer.Bytes()
}
// ConstructBlocksSyncMessage constructs blocks sync message to send blocks to other nodes // ConstructBlocksSyncMessage constructs blocks sync message to send blocks to other nodes
func ConstructBlocksSyncMessage(blocks []*types.Block) []byte { func ConstructBlocksSyncMessage(blocks []*types.Block) []byte {
byteBuffer := bytes.NewBuffer([]byte{byte(proto.Node)}) byteBuffer := bytes.NewBuffer([]byte{byte(proto.Node)})

@ -66,14 +66,6 @@ func TestConstructRequestTransactionsMessage(t *testing.T) {
} }
} }
func TestConstructStopMessage(t *testing.T) {
buf := ConstructStopMessage()
if len(buf) == 0 {
t.Error("Failed to contruct STOP message")
}
}
func TestConstructBlocksSyncMessage(t *testing.T) { func TestConstructBlocksSyncMessage(t *testing.T) {
db := ethdb.NewMemDatabase() db := ethdb.NewMemDatabase()

@ -94,10 +94,6 @@ 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() {
@ -231,10 +227,6 @@ 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,11 +179,6 @@ 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

@ -19,10 +19,10 @@ import (
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
pb "github.com/golang/protobuf/proto" pb "github.com/golang/protobuf/proto"
"github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/api/proto" "github.com/harmony-one/harmony/api/proto"
proto_discovery "github.com/harmony-one/harmony/api/proto/discovery" proto_discovery "github.com/harmony-one/harmony/api/proto/discovery"
"github.com/harmony-one/harmony/api/proto/message" "github.com/harmony-one/harmony/api/proto/message"
@ -172,34 +172,6 @@ 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 && node.ProcessStopMessage {
utils.GetLogInstance().Debug("Stopping Node", "numBlocks", node.blockchain.CurrentBlock().NumberU64(), "numTxsProcessed", node.countNumTransactionsInBlockchain())
var avgBlockSizeInBytes common.StorageSize
txCount := 0
blockCount := 0
avgTxSize := 0
for block := node.blockchain.CurrentBlock(); block != nil; block = node.blockchain.GetBlockByHash(block.Header().ParentHash) {
avgBlockSizeInBytes += block.Size()
txCount += len(block.Transactions())
bytes, _ := rlp.EncodeToBytes(block.Transactions())
avgTxSize += len(bytes)
blockCount++
}
if blockCount != 0 && txCount != 0 {
avgBlockSizeInBytes = avgBlockSizeInBytes / common.StorageSize(blockCount)
avgTxSize = avgTxSize / txCount
}
utils.GetLogInstance().Debug("Blockchain Report", "totalNumBlocks", blockCount, "avgBlockSizeInCurrentEpoch", avgBlockSizeInBytes, "totalNumTxs", txCount, "avgTxSzieInCurrentEpoch", avgTxSize)
os.Exit(0)
}
case proto_node.PING: case proto_node.PING:
node.pingMessageHandler(msgPayload, sender) node.pingMessageHandler(msgPayload, sender)
case proto_node.PONG: case proto_node.PONG:

@ -141,24 +141,24 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line IFS=' ' read ip port mode shardID <<< $line
if [ "$mode" == "leader" ]; then if [ "$mode" == "leader" ]; then
echo "launching leader ..." echo "launching leader ..."
$DRYRUN $ROOT/bin/harmony -enable_stop -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key -is_leader 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key -is_leader 2>&1 | tee -a $LOG_FILE &
fi fi
if [ "$mode" == "leader_archival" ]; then if [ "$mode" == "leader_archival" ]; then
echo "launching leader ..." echo "launching leader ..."
$DRYRUN $ROOT/bin/harmony -enable_stop -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 -key /tmp/$ip-$port.key -is_leader -is_archival 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 -key /tmp/$ip-$port.key -is_leader -is_archival 2>&1 | tee -a $LOG_FILE &
fi fi
if [ "$mode" == "validator" ]; then if [ "$mode" == "validator" ]; then
echo "launching validator ..." echo "launching validator ..."
$DRYRUN $ROOT/bin/harmony -enable_stop -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE &
fi fi
if [ "$mode" == "archival" ]; then if [ "$mode" == "archival" ]; then
echo "launching archival node ... wait" echo "launching archival node ... wait"
$DRYRUN $ROOT/bin/harmony -enable_stop -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 -key /tmp/$ip-$port.key -is_archival 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 -key /tmp/$ip-$port.key -is_archival 2>&1 | tee -a $LOG_FILE &
fi fi
if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then
(( NUM_NN += 30 )) (( NUM_NN += 30 ))
echo "launching new node ..." echo "launching new node ..."
(sleep $NUM_NN; $DRYRUN $ROOT/bin/harmony -enable_stop -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE ) & (sleep $NUM_NN; $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -account_index $i -min_peers $MIN $HMY_OPT2 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE ) &
fi fi
i=$((i+1)) i=$((i+1))
done < $config done < $config

@ -128,6 +128,6 @@ HMY_OPT2="-bootnodes ${bn_ma}"
for i in 0{1..5} # {10..99} for i in 0{1..5} # {10..99}
do do
echo "launching new node $i ..." echo "launching new node $i ..."
($DRYRUN $ROOT/bin/harmony -enable_stop -ip 127.0.0.1 -port 91$i -log_folder $log_folder -is_newnode $DB -account_index $i -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/127.0.0.1-91$i.key 2>&1 | tee -a $LOG_FILE ) & ($DRYRUN $ROOT/bin/harmony -ip 127.0.0.1 -port 91$i -log_folder $log_folder -is_newnode $DB -account_index $i -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/127.0.0.1-91$i.key 2>&1 | tee -a $LOG_FILE ) &
sleep 5 sleep 5
done done

Loading…
Cancel
Save