Add more logs and avoid validator broadcast when not necessary

pull/73/head
Rongjian Lan 6 years ago
parent 5d162cf398
commit 67b160901b
  1. 2
      client/txgen/main.go
  2. 6
      consensus/consensus_leader.go
  3. 4
      node/node_handler.go
  4. 6
      p2p/peer.go

@ -374,7 +374,7 @@ func main() {
lock.Unlock()
subsetCounter++
time.Sleep(3000 * time.Millisecond)
time.Sleep(10000 * time.Millisecond)
}
// Send a stop message to stop the nodes at the end

@ -30,9 +30,9 @@ func (consensus *Consensus) WaitForNewBlock(blockChannel chan blockchain.Block)
newBlock := <-blockChannel
// TODO: think about potential race condition
startTime = time.Now()
consensus.Log.Info("STARTING CONSENSUS", "consensus", consensus, "startTime", startTime)
consensus.Log.Debug("STARTING CONSENSUS", "consensus", consensus, "startTime", startTime)
for consensus.state == FINISHED {
time.Sleep(500 * time.Millisecond)
// time.Sleep(500 * time.Millisecond)
consensus.startConsensus(&newBlock)
break
}
@ -79,12 +79,14 @@ func (consensus *Consensus) startConsensus(newBlock *blockchain.Block) {
// Copy over block hash and block header data
copy(consensus.blockHash[:], newBlock.Hash[:])
consensus.Log.Debug("Start encoding block")
// prepare message and broadcast to validators
byteBuffer := bytes.NewBuffer([]byte{})
encoder := gob.NewEncoder(byteBuffer)
encoder.Encode(newBlock)
consensus.blockHeader = byteBuffer.Bytes()
consensus.Log.Debug("Stop encoding block")
msgToSend := consensus.constructAnnounceMessage()
p2p.BroadcastMessageFromLeader(consensus.GetValidatorPeers(), msgToSend)
// Set state to ANNOUNCE_DONE

@ -305,15 +305,15 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}) {
for {
// Once we have pending transactions we will try creating a new block
if len(node.pendingTransactions) >= 1 {
node.log.Debug("Start selecting transactions")
selectedTxs, crossShardTxAndProofs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock)
if len(selectedTxs) == 0 {
node.log.Debug("No valid transactions exist", "pendingTx", len(node.pendingTransactions))
} else {
node.log.Debug("Creating new block", "numTxs", len(selectedTxs), "pendingTxs", len(node.pendingTransactions), "currentChainSize", len(node.blockchain.Blocks))
node.log.Debug("Creating new block", "numAllTxs", len(selectedTxs), "numCrossTxs", len(crossShardTxAndProofs), "pendingTxs", len(node.pendingTransactions), "currentChainSize", len(node.blockchain.Blocks))
node.transactionInConsensus = selectedTxs
node.log.Debug("CROSS SHARD TX", "num", len(crossShardTxAndProofs))
node.CrossTxsInConsensus = crossShardTxAndProofs
newBlock = blockchain.NewBlock(selectedTxs, node.blockchain.GetLatestBlock().Hash, node.Consensus.ShardID)
break

@ -77,8 +77,10 @@ func BroadcastMessageFromLeader(peers []Peer, msg []byte) {
// BroadcastMessage sends the message to a list of peers from a validator.
func BroadcastMessageFromValidator(selfPeer Peer, peers []Peer, msg []byte) {
peers = SelectMyPeers(peers, selfPeer.ValidatorID*MAX_BROADCAST+1, (selfPeer.ValidatorID+1)*MAX_BROADCAST)
BroadcastMessage(peers, msg)
log.Info("Done sending from validator")
if len(peers) > 0 {
BroadcastMessage(peers, msg)
log.Info("Done sending from validator")
}
}
// ConstructP2pMessage constructs the p2p message as [messageType, contentSize, content]

Loading…
Cancel
Save