blockchain v0: reactor updates

This commit is contained in:
Aleksandr Bezobchuk
2021-01-06 13:28:05 -05:00
parent f021c7df4d
commit 1463bc0be6
2 changed files with 7 additions and 5 deletions
+1
View File
@@ -180,6 +180,7 @@ func (pool *BlockPool) IsCaughtUp() bool {
if len(pool.peers) == 0 {
return false
}
// NOTE: we use maxPeerHeight - 1 because to sync block H requires block H+1
// to verify the LastCommit.
return pool.height >= (pool.maxPeerHeight - 1)
+6 -5
View File
@@ -364,6 +364,9 @@ func (r *Reactor) SwitchToFastSync(state sm.State) error {
// do.
//
// NOTE: Don't sleep in the FOR_LOOP or otherwise slow it down!
//
// TODO: Ensure this works nicely with stopping reactor and that no race
// conditions or deadlocks exist.
func (r *Reactor) poolRoutine(stateSynced bool) {
var (
trySyncTicker = time.NewTicker(trySyncIntervalMS * time.Millisecond)
@@ -380,9 +383,6 @@ func (r *Reactor) poolRoutine(stateSynced bool) {
didProcessCh = make(chan struct{}, 1)
)
defer trySyncTicker.Stop()
defer statusUpdateTicker.Stop()
defer switchToConsensusTicker.Stop()
defer trySyncTicker.Stop()
defer statusUpdateTicker.Stop()
@@ -412,7 +412,6 @@ func (r *Reactor) poolRoutine(stateSynced bool) {
}
case <-statusUpdateTicker.C:
// ask for status updates
go func() {
r.blockchainCh.Out() <- p2p.Envelope{
Broadcast: true,
@@ -455,7 +454,9 @@ FOR_LOOP:
r.Logger.Error("failed to stop pool", "err", err)
}
r.consReactor.SwitchToConsensus(state, blocksSynced > 0 || stateSynced)
if r.consReactor != nil {
r.consReactor.SwitchToConsensus(state, blocksSynced > 0 || stateSynced)
}
break FOR_LOOP