diff --git a/internal/consensus/reactor.go b/internal/consensus/reactor.go index d9006f2e0..ca5eeca9b 100644 --- a/internal/consensus/reactor.go +++ b/internal/consensus/reactor.go @@ -544,6 +544,8 @@ func (r *Reactor) gossipDataForCatchup(rs *cstypes.RoundState, prs *cstypes.Peer func (r *Reactor) gossipDataRoutine(ps *PeerState) { logger := r.Logger.With("peer", ps.peerID) + timer := time.NewTimer(r.state.config.PeerGossipSleepDuration) + defer timer.Stop() OUTER_LOOP: for { @@ -551,6 +553,8 @@ OUTER_LOOP: return } + timer.Reset(r.state.config.PeerGossipSleepDuration) + select { case <-r.closeCh: return @@ -558,8 +562,7 @@ OUTER_LOOP: // The peer is marked for removal via a PeerUpdate as the doneCh was // explicitly closed to signal we should exit. return - - default: + case <-timer.C: } rs := r.getRoundState() @@ -605,7 +608,6 @@ OUTER_LOOP: "blockstoreBase", blockStoreBase, "blockstoreHeight", r.state.blockStore.Height(), ) - time.Sleep(r.state.config.PeerGossipSleepDuration) } else { ps.InitProposalBlockParts(blockMeta.BlockID.PartSetHeader) } @@ -621,7 +623,6 @@ OUTER_LOOP: // if height and round don't match, sleep if (rs.Height != prs.Height) || (rs.Round != prs.Round) { - time.Sleep(r.state.config.PeerGossipSleepDuration) continue OUTER_LOOP } @@ -676,12 +677,8 @@ OUTER_LOOP: }: } } - - continue OUTER_LOOP } - // nothing to do -- sleep - time.Sleep(r.state.config.PeerGossipSleepDuration) continue OUTER_LOOP } }