This is a re-attempt of #28765
The new approach differs from the previous in how peers are selected for fanout:
For Erlay-enabled peers, fanout targets are chosen for each transaction individually. Once the fanout target is reached, the transaction is reconciled with the rest of our peers. Whether a peer is selected for fanout depends on factors like peer type (inbound or outbound), how the transaction was received (via fanout or reconciliation), and how many of our peers are already aware of it.
For outbound peers:
If the transaction was received through fanout (or we originated it), we set a fanout rate threshold OUTBOUND_FANOUT_THRESHOLD{4}
. As long as the transaction has been announced to (or received from) fewer than this number of peers, we continue faning out based on the order in which peers’ Poisson timers go off.
If the transaction was received via reconciliation, we simply reconcile it with the rest of our peers.
For inbound peers: We select a subset of inbound peers as fanout targets and send all transactions to them within a set time interval. Once the interval ends, the selection is randomly rotated.
This approach helps scale the transaction fanout rate for outbound peers by approximating how widely a transaction has already been propagated. For inbound peers, we use a random selection strategy to prevent them from easily exploiting our heuristic.
You may notice 398078a8a92725f33ac28107f8fa045e02b2c5bd is not currently being used. It is likely to be dropped and brought back in a follow-up. Currently, we are picking Erlay fanout targets independently of whether we already have other non-erlay peers (which are always fanout). We may want to scale the selection based on non-Erlay connections, but I think that can be addressed on it’s own PR.
Erlay Project Tracking: https://github.com/bitcoin/bitcoin/issues/30249