Skip to content

Commit

Permalink
Pool: don't send empty events (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Nov 7, 2021
1 parent 52ef645 commit 138a208
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,12 @@ func (p *TxPool) AddLocalTxs(ctx context.Context, newTransactions TxSlots) ([]Di
p.promoted = append(p.promoted, newTxs.txs[i].IdHash[:]...)
}
}
p.newPendingTxs <- common.Copy(p.promoted)
if p.promoted.Len() > 0 {
select {
case p.newPendingTxs <- common.Copy(p.promoted):
default:
}
}
return reasons, nil
}

Expand Down Expand Up @@ -1210,19 +1215,21 @@ func MainLoop(ctx context.Context, db kv.RwDB, coreDB kv.RoDB, p *TxPool, newTxs
case h := <-newTxs:
t := time.Now()
notifyMiningAboutNewSlots()
if err := db.View(ctx, func(tx kv.Tx) error {
slotsRlp := make([][]byte, 0, h.Len())
for i := 0; i < h.Len(); i++ {
slotRlp, err := p.GetRlp(tx, h.At(i))
if err != nil {
return err
if h.Len() > 0 {
if err := db.View(ctx, func(tx kv.Tx) error {
slotsRlp := make([][]byte, 0, h.Len())
for i := 0; i < h.Len(); i++ {
slotRlp, err := p.GetRlp(tx, h.At(i))
if err != nil {
return err
}
slotsRlp = append(slotsRlp, slotRlp)
}
slotsRlp = append(slotsRlp, slotRlp)
newSlotsStreams.Broadcast(&proto_txpool.OnAddReply{RplTxs: slotsRlp})
return nil
}); err != nil {
log.Error("[txpool] send new slots by grpc", "err", err)
}
newSlotsStreams.Broadcast(&proto_txpool.OnAddReply{RplTxs: slotsRlp})
return nil
}); err != nil {
log.Error("[txpool] send new slots by grpc", "err", err)
}

// first broadcast all local txs to all peers, then non-local to random sqrt(peersAmount) peers
Expand Down

0 comments on commit 138a208

Please sign in to comment.