update node.StartServer

pull/119/head
Richard Liu 6 years ago
parent 4076311d19
commit b2b68d0055
  1. 6
      benchmark.go
  2. 83
      client/txgen/main.go
  3. 4
      client/wallet/main.go
  4. 4
      client/wallet_v2/main.go
  5. 9
      node/node.go
  6. 8
      node/node_test.go

@ -141,7 +141,7 @@ func main() {
clientPeer = distributionConfig.GetClientPeer()
}
fmt.Println(peers, leader, selfPeer, clientPeer, *logFolder, *minPeers) //TODO: to be replaced by a logger later: ak, rl
// fmt.Println(peers, leader, selfPeer, clientPeer, *logFolder, *minPeers) //TODO: to be replaced by a logger later: ak, rl
var role string
if leader.IP == *ip && leader.Port == *port {
@ -181,8 +181,6 @@ func main() {
attack.GetInstance().SetLogger(consensus.Log)
// Current node.
currentNode := node.New(consensus, ldb, selfPeer)
// Add self peer.
currentNode.SelfPeer = selfPeer
// Add sync node configuration.
currentNode.SyncNode = *syncNode
// If there is a client configured in the node list.
@ -226,5 +224,5 @@ func main() {
}
go currentNode.SupportSyncing()
currentNode.StartServer(*port)
currentNode.StartServer()
}

@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"github.com/harmony-one/harmony/utils"
"os"
"path"
"runtime"
@ -21,6 +20,7 @@ import (
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
proto_node "github.com/harmony-one/harmony/proto/node"
"github.com/harmony-one/harmony/utils"
)
var (
@ -76,9 +76,9 @@ func main() {
)
log.Root().SetHandler(h)
clientPeer := config.GetClientPeer()
// Nodes containing utxopools to mirror the shards' data in the network
nodes := []*node.Node{}
clientPeer := config.GetClientPeer()
for shardID := range shardIDLeaderMap {
_, pubKey := utils.GenKey(clientPeer.IP, clientPeer.Port)
clientPeer.PubKey = pubKey
@ -89,56 +89,57 @@ func main() {
}
// Client/txgenerator server node setup
if clientPeer == nil {
log.Error("Client Peer is nil!")
}
consensusObj := consensus.New(*clientPeer, "0", nil, p2p.Peer{})
clientNode := node.New(consensusObj, nil, *clientPeer)
if clientPeer != nil {
//p2pv2.InitHost(clientPeer.IP, clientPeer.Port) // TODO: this should be moved into client node.
clientNode.Client = client.NewClient(&shardIDLeaderMap)
// This func is used to update the client's utxopool when new blocks are received from the leaders
updateBlocksFunc := func(blocks []*blockchain.Block) {
log.Debug("Received new block from leader", "len", len(blocks))
for _, block := range blocks {
for _, node := range nodes {
shardID := block.ShardID
accountBlock := new(types.Block)
err := rlp.DecodeBytes(block.AccountBlock, accountBlock)
if err == nil {
shardID = accountBlock.ShardID()
}
if node.Consensus.ShardID == shardID {
log.Debug("Adding block from leader", "shardID", shardID)
// Add it to blockchain
node.AddNewBlock(block)
utxoPoolMutex.Lock()
node.UpdateUtxoAndState(block)
utxoPoolMutex.Unlock()
clientNode.Client = client.NewClient(&shardIDLeaderMap)
// This func is used to update the client's utxopool when new blocks are received from the leaders
updateBlocksFunc := func(blocks []*blockchain.Block) {
log.Debug("Received new block from leader", "len", len(blocks))
for _, block := range blocks {
for _, node := range nodes {
shardID := block.ShardID
accountBlock := new(types.Block)
err := rlp.DecodeBytes(block.AccountBlock, accountBlock)
if err == nil {
shardID = accountBlock.ShardID()
}
if node.Consensus.ShardID == shardID {
log.Debug("Adding block from leader", "shardID", shardID)
// Add it to blockchain
node.AddNewBlock(block)
utxoPoolMutex.Lock()
node.UpdateUtxoAndState(block)
utxoPoolMutex.Unlock()
if err != nil {
log.Error("Failed decoding the block with RLP")
} else {
fmt.Println("RECEIVED NEW BLOCK ", len(accountBlock.Transactions()))
node.AddNewBlockAccount(accountBlock)
node.Worker.UpdateCurrent()
if err != nil {
log.Error("Failed decoding the block with RLP")
} else {
fmt.Println("RECEIVED NEW BLOCK ", len(accountBlock.Transactions()))
node.AddNewBlockAccount(accountBlock)
node.Worker.UpdateCurrent()
if err != nil {
log.Debug("Failed to add new block to worker", "Error", err)
}
log.Debug("Failed to add new block to worker", "Error", err)
}
} else {
continue
}
} else {
continue
}
}
}
clientNode.Client.UpdateBlocks = updateBlocksFunc
// Start the client server to listen to leader's message
go func() {
clientNode.StartServer(clientPeer.Port)
}()
}
clientNode.Client.UpdateBlocks = updateBlocksFunc
// Start the client server to listen to leader's message
go func() {
clientNode.StartServer()
}()
// Transaction generation process
time.Sleep(10 * time.Second) // wait for nodes to be ready
start := time.Now()

@ -93,7 +93,7 @@ func main() {
fmt.Println("Private key imported...")
case "showBalance":
walletNode := CreateWalletServerNode()
go walletNode.StartServer(walletNode.ClientPeer.Port)
go walletNode.StartServer()
shardUtxoMap, err := FetchUtxos(ReadAddresses(), walletNode)
if err != nil {
@ -163,7 +163,7 @@ func main() {
// Start client server
walletNode := CreateWalletServerNode()
go walletNode.StartServer(walletNode.ClientPeer.Port)
go walletNode.StartServer()
shardUtxoMap, err := FetchUtxos([][20]byte{senderAddressBytes}, walletNode)
if err != nil {

@ -93,7 +93,7 @@ func main() {
fmt.Println("Private key imported...")
case "showBalance":
walletNode := CreateWalletServerNode()
go walletNode.StartServer(walletNode.ClientPeer.Port)
go walletNode.StartServer()
shardUtxoMap, err := FetchUtxos(ReadAddresses(), walletNode)
if err != nil {
@ -163,7 +163,7 @@ func main() {
// Start client server
walletNode := CreateWalletServerNode()
go walletNode.StartServer(walletNode.ClientPeer.Port)
go walletNode.StartServer()
shardUtxoMap, err := FetchUtxos([][20]byte{senderAddressBytes}, walletNode)
if err != nil {

@ -152,17 +152,16 @@ func (node *Node) getTransactionsForNewBlockAccount(maxNumTxs int) (types.Transa
}
// StartServer starts a server and process the request by a handler.
func (node *Node) StartServer(port string) {
func (node *Node) StartServer() {
if node.SyncNode {
// Disable this temporarily.
// node.blockchain = syncing.StartBlockSyncing(node.Consensus.GetValidatorPeers())
}
if p2p.Version == 1 {
fmt.Println("going to start server on port:", port)
//node.log.Debug("Starting server", "node", node, "port", port)
node.listenOnPort(port)
node.log.Debug("Starting server", "node", node, "ip", node.SelfPeer.IP, "port", node.SelfPeer.Port)
node.listenOnPort(node.SelfPeer.Port)
} else {
p2pv2.InitHost(node.SelfPeer.IP, port)
p2pv2.InitHost(node.SelfPeer.IP, node.SelfPeer.Port)
p2pv2.BindHandler(node.NodeHandlerV1)
// Hang forever
<-make(chan struct{})

@ -2,18 +2,16 @@ package node
import (
"fmt"
"github.com/harmony-one/harmony/utils"
"os"
"testing"
"time"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/crypto/pki"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/p2p"
proto_node "github.com/harmony-one/harmony/proto/node"
"github.com/harmony-one/harmony/utils"
)
func TestNewNewNode(test *testing.T) {
@ -160,5 +158,5 @@ func TestPingPongHandler(test *testing.T) {
//go sendPingMessage(leader)
go sendPongMessage(leader)
go exitServer()
node.StartServer("8881")
node.StartServer()
}

Loading…
Cancel
Save