mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-27 18:34:39 +00:00
cleanup, comments
This commit is contained in:
+6
-6
@@ -23,8 +23,8 @@ var (
|
||||
)
|
||||
|
||||
/*
|
||||
Peers self report their heights when a new peer joins the block pool.
|
||||
Starting from pool.height (inclusive), we request blocks
|
||||
Peers self report their heights when we join the block pool.
|
||||
Starting from our latest pool.height, we request blocks
|
||||
in sequence from peers that reported higher heights than ours.
|
||||
Every so often we ask peers what height they're on so we can keep going.
|
||||
|
||||
@@ -94,7 +94,7 @@ RUN_LOOP:
|
||||
if atomic.LoadInt32(&pool.running) == 0 {
|
||||
break RUN_LOOP
|
||||
}
|
||||
_, numPending := pool.GetStatus()
|
||||
_, numPending, _ := pool.GetStatus()
|
||||
if numPending >= maxPendingRequests {
|
||||
// sleep for a bit.
|
||||
time.Sleep(requestIntervalMS * time.Millisecond)
|
||||
@@ -108,11 +108,11 @@ RUN_LOOP:
|
||||
}
|
||||
}
|
||||
|
||||
func (pool *BlockPool) GetStatus() (int, int32) {
|
||||
func (pool *BlockPool) GetStatus() (int, int32, int32) {
|
||||
pool.requestsMtx.Lock() // Lock
|
||||
defer pool.requestsMtx.Unlock()
|
||||
|
||||
return pool.height, pool.numPending
|
||||
return pool.height, pool.numPending, pool.numUnassigned
|
||||
}
|
||||
|
||||
// We need to see the second block's Validation to validate the first block.
|
||||
@@ -378,7 +378,7 @@ func requestRoutine(pool *BlockPool, height int) {
|
||||
return
|
||||
}
|
||||
// or already processed and we've moved past it
|
||||
bpHeight, _ := pool.GetStatus()
|
||||
bpHeight, _, _ := pool.GetStatus()
|
||||
if height < bpHeight {
|
||||
pool.decrPeer(peer.id)
|
||||
return
|
||||
|
||||
@@ -199,19 +199,18 @@ FOR_LOOP:
|
||||
// ask for status updates
|
||||
go bcR.BroadcastStatusRequest()
|
||||
case _ = <-switchToConsensusTicker.C:
|
||||
// not thread safe access for numUnassigned and numPending but should be fine
|
||||
// TODO make threadsafe and use exposed functions
|
||||
height, numUnassigned, numPending := bcR.pool.GetStatus()
|
||||
outbound, inbound, _ := bcR.sw.NumPeers()
|
||||
log.Debug("Consensus ticker", "numUnassigned", bcR.pool.numUnassigned, "numPending", bcR.pool.numPending,
|
||||
log.Debug("Consensus ticker", "numUnassigned", numUnassigned, "numPending", numPending,
|
||||
"total", len(bcR.pool.requests), "outbound", outbound, "inbound", inbound)
|
||||
// NOTE: this condition is very strict right now. may need to weaken
|
||||
// If all `maxPendingRequests` requests are unassigned
|
||||
// and we have some peers (say >= 3), then we're caught up
|
||||
maxPending := bcR.pool.numPending == maxPendingRequests
|
||||
allUnassigned := bcR.pool.numPending == bcR.pool.numUnassigned
|
||||
maxPending := numPending == maxPendingRequests
|
||||
allUnassigned := numPending == numUnassigned
|
||||
enoughPeers := outbound+inbound >= 3
|
||||
if maxPending && allUnassigned && enoughPeers {
|
||||
log.Info("Time to switch to consensus reactor!", "height", bcR.pool.height)
|
||||
log.Info("Time to switch to consensus reactor!", "height", height)
|
||||
bcR.pool.Stop()
|
||||
|
||||
conR := bcR.sw.Reactor("CONSENSUS").(consensusReactor)
|
||||
|
||||
Reference in New Issue
Block a user