Merge pull request #854 from harmony-ek/disable_stop_message_by_default

Remove STOP message
pull/857/head
Eugene Kim 6 years ago committed by GitHub
commit 972ea71b17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      api/proto/node/node.go
  2. 8
      api/proto/node/node_test.go
  3. 30
      node/node_handler.go

@ -24,7 +24,7 @@ const (
Transaction MessageType = iota
Block
Client
Control
_ // used to be Control
PING // node send ip/pki to register with leader
PONG // node broadcast pubK
ShardState
@ -99,14 +99,6 @@ const (
Sync BlockMessageType = iota
)
// ControlMessageType is the type of messages used for Node/Control
type ControlMessageType int
// ControlMessageType
const (
STOP ControlMessageType = iota
)
// SerializeBlockchainSyncMessage serializes BlockchainSyncMessage.
func SerializeBlockchainSyncMessage(blockchainSyncMessage *BlockchainSyncMessage) []byte {
var result bytes.Buffer
@ -155,14 +147,6 @@ func ConstructRequestTransactionsMessage(transactionIds [][]byte) []byte {
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
func ConstructBlocksSyncMessage(blocks []*types.Block) []byte {
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) {
db := ethdb.NewMemDatabase()

@ -19,10 +19,10 @@ import (
"github.com/harmony-one/harmony/core"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
pb "github.com/golang/protobuf/proto"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/api/proto"
proto_discovery "github.com/harmony-one/harmony/api/proto/discovery"
"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 {
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:
node.pingMessageHandler(msgPayload, sender)
case proto_node.PONG:

Loading…
Cancel
Save