|
|
@ -34,14 +34,12 @@ type Node struct { |
|
|
|
log log.Logger // Log utility
|
|
|
|
log log.Logger // Log utility
|
|
|
|
pendingTxMutex sync.Mutex |
|
|
|
pendingTxMutex sync.Mutex |
|
|
|
crossTxToReturnMutex sync.Mutex |
|
|
|
crossTxToReturnMutex sync.Mutex |
|
|
|
blockSyncing chan struct{} |
|
|
|
|
|
|
|
doneSyncing chan struct{} |
|
|
|
|
|
|
|
ClientPeer *p2p.Peer // The peer for the benchmark tx generator client, used for leaders to return proof-of-accept
|
|
|
|
ClientPeer *p2p.Peer // The peer for the benchmark tx generator client, used for leaders to return proof-of-accept
|
|
|
|
Client *client.Client // The presence of a client object means this node will also act as a client
|
|
|
|
Client *client.Client // The presence of a client object means this node will also act as a client
|
|
|
|
IsWaiting bool |
|
|
|
IsWaiting bool |
|
|
|
Self p2p.Peer |
|
|
|
Self p2p.Peer |
|
|
|
IDCPeer p2p.Peer |
|
|
|
IDCPeer p2p.Peer |
|
|
|
syncNode bool // TODO(minhdoan): Remove it later.
|
|
|
|
SyncNode bool // TODO(minhdoan): Remove it later.
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add new crossTx and proofs to the list of crossTx that needs to be sent back to client
|
|
|
|
// Add new crossTx and proofs to the list of crossTx that needs to be sent back to client
|
|
|
@ -73,6 +71,9 @@ func (node *Node) getTransactionsForNewBlock(maxNumTxs int) ([]*blockchain.Trans |
|
|
|
|
|
|
|
|
|
|
|
// Start a server and process the request by a handler.
|
|
|
|
// Start a server and process the request by a handler.
|
|
|
|
func (node *Node) StartServer(port string) { |
|
|
|
func (node *Node) StartServer(port string) { |
|
|
|
|
|
|
|
if node.SyncNode { |
|
|
|
|
|
|
|
node.startBlockSyncing() |
|
|
|
|
|
|
|
} |
|
|
|
fmt.Println("Hello in server now") |
|
|
|
fmt.Println("Hello in server now") |
|
|
|
node.log.Debug("Starting server", "node", node, "port", port) |
|
|
|
node.log.Debug("Starting server", "node", node, "port", port) |
|
|
|
|
|
|
|
|
|
|
@ -91,24 +92,17 @@ func (node *Node) listenOnPort(port string) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
conn, err := listen.Accept() |
|
|
|
case <-node.blockSyncing: |
|
|
|
if err != nil { |
|
|
|
// Wait until the syncing part gets finished.
|
|
|
|
node.log.Error("Error listening on port.", "port", port) |
|
|
|
node.startBlockSyncing() |
|
|
|
continue |
|
|
|
<-node.doneSyncing |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
conn, err := listen.Accept() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
node.log.Error("Error listening on port.", "port", port) |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
go node.NodeHandler(conn) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
go node.NodeHandler(conn) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
func (node *Node) startBlockSyncing() { |
|
|
|
func (node *Node) startBlockSyncing() { |
|
|
|
// TODO(minhdoan):
|
|
|
|
|
|
|
|
for { |
|
|
|
for { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -245,10 +239,6 @@ func New(consensus *consensus.Consensus, db *db.LDBDatabase) *Node { |
|
|
|
|
|
|
|
|
|
|
|
// Initialize level db.
|
|
|
|
// Initialize level db.
|
|
|
|
node.db = db |
|
|
|
node.db = db |
|
|
|
|
|
|
|
|
|
|
|
// Initialize channel for syncing.
|
|
|
|
|
|
|
|
node.doneSyncing = make(chan struct{}) |
|
|
|
|
|
|
|
node.blockSyncing = make(chan struct{}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// Logger
|
|
|
|
// Logger
|
|
|
|
node.log = log.New() |
|
|
|
node.log = log.New() |
|
|
|