Skip to content

Commit

Permalink
handle last tx when closing (if any)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbundalo committed Nov 3, 2024
1 parent 4db3476 commit e1f891d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,31 @@ func (p *TxPool) startGossipBatchers(batchersNum, batchSize int) {
}

func stopGossipBatchers() {
close(gossipCh)
gossipWG.Wait()
}

func (p *TxPool) gossipBatcher(batchSize int) {
defer gossipWG.Done()
batch := make([]*types.Transaction, 0, batchSize)

ticker := time.NewTicker(time.Millisecond * 500)
tickerPeriod := time.Hour * 24 // reduce empty looping when no batching
if batchSize > 1 {
tickerPeriod = time.Millisecond * 500
}

ticker := time.NewTicker(tickerPeriod)
defer ticker.Stop()

for {
select {
case <-p.shutdownCh:
// flush when closing
tx, ok := <-gossipCh
if ok {
batch = append(batch, tx)
}

if len(batch) > 0 {
p.publish(&batch)
}
Expand Down Expand Up @@ -320,7 +331,7 @@ func (p *TxPool) Start() {
p.updatePending(0)

// start gossip batchers
p.startGossipBatchers(1, 2500)
p.startGossipBatchers(1, 10000)

// run the handler for high gauge level pruning
go func() {
Expand Down

0 comments on commit e1f891d

Please sign in to comment.