From 1463bc0be6ed948f718b1bcf560c3e932b065565 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 6 Jan 2021 13:28:05 -0500 Subject: [PATCH] blockchain v0: reactor updates --- blockchain/v0/pool.go | 1 + blockchain/v0/reactor.go | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/blockchain/v0/pool.go b/blockchain/v0/pool.go index 7541c06f9..fa4d28954 100644 --- a/blockchain/v0/pool.go +++ b/blockchain/v0/pool.go @@ -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) diff --git a/blockchain/v0/reactor.go b/blockchain/v0/reactor.go index 3c4c16355..bf6109fcc 100644 --- a/blockchain/v0/reactor.go +++ b/blockchain/v0/reactor.go @@ -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