|
|
@ -28,6 +28,13 @@ func (consensus *Consensus) WaitForNewBlock(blockChannel chan blockchain.Block) |
|
|
|
consensus.Log.Debug("Waiting for block", "consensus", consensus) |
|
|
|
consensus.Log.Debug("Waiting for block", "consensus", consensus) |
|
|
|
for { // keep waiting for new blocks
|
|
|
|
for { // keep waiting for new blocks
|
|
|
|
newBlock := <-blockChannel |
|
|
|
newBlock := <-blockChannel |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !consensus.HasEnoughValidators() { |
|
|
|
|
|
|
|
consensus.Log.Debug("Not enough validators", "# Validators", len(consensus.validators)) |
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: think about potential race condition
|
|
|
|
// TODO: think about potential race condition
|
|
|
|
startTime = time.Now() |
|
|
|
startTime = time.Now() |
|
|
|
consensus.Log.Debug("STARTING CONSENSUS", "consensus", consensus, "startTime", startTime) |
|
|
|
consensus.Log.Debug("STARTING CONSENSUS", "consensus", consensus, "startTime", startTime) |
|
|
@ -452,3 +459,10 @@ func (consensus *Consensus) reportMetrics(block blockchain.Block) { |
|
|
|
} |
|
|
|
} |
|
|
|
profiler.LogMetrics(metrics) |
|
|
|
profiler.LogMetrics(metrics) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (consensus *Consensus) HasEnoughValidators() bool { |
|
|
|
|
|
|
|
if len(consensus.validators) < consensus.MinPeers { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|