diff --git a/node/node.go b/node/node.go index 881c5cd99..fd0367511 100644 --- a/node/node.go +++ b/node/node.go @@ -6,29 +6,30 @@ import ( "harmony-benchmark/log" "net" "os" - "sync" "strconv" + "sync" ) var pendingTxMutex = &sync.Mutex{} -// A node represents a program (machine) participating in the network +// Node represents a program (machine) participating in the network +// TODO(minhdoan, rj): consider using BlockChannel *chan blockchain.Block for efficiency. type Node struct { // Consensus object containing all consensus related data (e.g. committee members, signatures, commits) - consensus *consensus.Consensus + consensus *consensus.Consensus // The channel to receive new blocks from Node - BlockChannel chan blockchain.Block + BlockChannel chan blockchain.Block // All the transactions received but not yet processed for consensus - pendingTransactions []*blockchain.Transaction + pendingTransactions []*blockchain.Transaction // The transactions selected into the new block and under consensus process transactionInConsensus []*blockchain.Transaction // The blockchain for the shard where this node belongs - blockchain *blockchain.Blockchain + blockchain *blockchain.Blockchain // The corresponding UTXO pool of the current blockchain - UtxoPool *blockchain.UTXOPool + UtxoPool *blockchain.UTXOPool // Log utility - log log.Logger + log log.Logger } // Add new transactions to the pending transaction list diff --git a/node/node_handler.go b/node/node_handler.go index fd50b34d3..5c423d6de 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -2,27 +2,27 @@ package node import ( "bytes" + "encoding/gob" "harmony-benchmark/blockchain" - "time" - "net" - "harmony-benchmark/p2p" "harmony-benchmark/common" + "harmony-benchmark/p2p" + "net" "os" - "encoding/gob" + "time" ) -// Handler of the leader node. +// NodeHandler handles a new incoming connection. func (node *Node) NodeHandler(conn net.Conn) { defer conn.Close() // Read p2p message payload content, err := p2p.ReadMessageContent(conn) - consensus := node.consensus if err != nil { node.log.Error("Read p2p data failed", "err", err, "node", node) return } + consensus := node.consensus msgCategory, err := common.GetMessageCategory(content) if err != nil { @@ -106,7 +106,7 @@ func (node *Node) transactionMessageHandler(msgPayload []byte) { } } -// Copy the txId byte slice over to 32 byte array so the map can key on it +// getFixedByteTxId copies the txId byte slice over to 32 byte array so the map can key on it func getFixedByteTxId(txId []byte) [32]byte { var id [32]byte for i := range id { @@ -115,6 +115,7 @@ func getFixedByteTxId(txId []byte) [32]byte { return id } +// WaitForConsensusReady ... func (node *Node) WaitForConsensusReady(readySignal chan int) { node.log.Debug("Waiting for consensus ready", "node", node) @@ -153,4 +154,4 @@ func (node *Node) WaitForConsensusReady(readySignal chan int) { // Send the new block to consensus so it can be confirmed. node.BlockChannel <- *newBlock } -} \ No newline at end of file +}