Skip to content

Commit

Permalink
Use switch for interval routine
Browse files Browse the repository at this point in the history
  • Loading branch information
musalbas committed Aug 31, 2023
1 parent d3bf3ed commit 4822a5e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mempool/v1/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ func (memR *Reactor) priorityIntervalRoutine() {
lastRoutine := time.Now()
for {
// Sleep until the next interval.
time.Sleep(mempoolPriorityInterval - time.Since(lastRoutine))
lastRoutine = time.Now()

if !memR.IsRunning() {
select {
case <-memR.Quit():
return
case <-time.After(mempoolPriorityInterval - time.Since(lastRoutine)):
lastRoutine = time.Now()
}

// Sort txes by priority.
Expand Down Expand Up @@ -298,6 +298,11 @@ func (memR *Reactor) broadcastPriorityTxRoutine(peer p2p.Peer) {

// Loop through all the high priority txs.
for _, memTx := range memR.sortedTxs {
// Check that tx is still in mempool.
if !memR.mempool.HasTx(memTx.tx) {
continue
}

// Allow for a lag of 1 block.
if peerState.GetHeight() < memTx.height-1 {
time.Sleep(mempool.PeerCatchupSleepIntervalMS * time.Millisecond)
Expand Down

0 comments on commit 4822a5e

Please sign in to comment.