I noticed my peer-observer nodes spending a lot of time in b-msghand thread today on 2026-02-17 starting around 1:30 am UTC. Note that the screenshots are UTC+1.
Looking on a different node at the broadcast at around 17:20 UTC shows that we spend about 20% of our time in CompareMiningScoreWithTopology() (i.e. the new name of CompareDepthAndScore).
Sorting before sending ensures that youâre not leaking info about the order in which you received the txs by the order in which you announce them.
I think have a global queue for rate limiting outbound announcements is the solution here, fwiw. Hereâs a gist:
Iâve been running that code with a very low rate limit for inbounds (4tx/s instead of the 14tx/s target from core) to ensure it behaves well when backlogs occur, and it seems to.
And here is the rate at which my local spy-node-like peer received WTx invs.
Normally, one would expect the rate at which we send INVs to remain fairly constant since weâre on a fixed timer. However, it seems like for some nodes it actually slowed INV-sending down by about 50% while for others it (at least briefly) speed up. My theory for slowing down is: the node is overloaded to a point where it canât send out INVs at a normal rate.
Sure. I think I wasnât clear in my description: Donât keep a set (as we do currently), but keep a (sorted) queue. When inserting a to-be-announced transaction, put it in the right place in the queue. This avoids having to re-sort the whole set every 5s (or 2s for outbounds) for each peer. The queue is already sorted, so we can just pick the top 70 + x transactions to INV. Then, do some clean up removing evicted/confirmed transactions by iterating the queue once.
Maybe thatâs similar to you gloabl queue. Iâll have a look.
As far as data structures go, a sorted queue is best stored as a set anyway; problem is that with cluster mempool the sort order doesnât stay consistent as txs are added â a cpfp tx can bump the ordering of the pre-existing parent, eg. That breaks set invariants, so risks UB if using std::set, and I couldnât see a simpler way of dealing with it properly without just doing a re-sort.