mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
eth: stabilize peer selection for transaction broadcast
When maxPeers was just above some perfect square, and a few peers dropped for some reason, we changed the peer selection function. When new peers were acquired, we changed again. This patch stabilizes the selection function under normal operating conditions close to saturation. Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
27d4a10185
commit
c022c3f8ab
1 changed files with 7 additions and 4 deletions
|
|
@ -482,10 +482,13 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
|
||||||
annos = make(map[*ethPeer][]common.Hash) // Set peer->hash to announce
|
annos = make(map[*ethPeer][]common.Hash) // Set peer->hash to announce
|
||||||
)
|
)
|
||||||
// Broadcast transactions to a batch of peers not knowing about it
|
// Broadcast transactions to a batch of peers not knowing about it
|
||||||
direct := big.NewInt(int64(math.Sqrt(float64(h.peers.len())))) // Approximate number of peers to broadcast to
|
sqrtPeers := int64(math.Sqrt(float64(h.peers.len()))) // Approximate number of peers to broadcast to
|
||||||
if direct.BitLen() == 0 {
|
|
||||||
direct = big.NewInt(1)
|
// If maxPeers is just above some perfect square, we need to stabilize
|
||||||
}
|
// the number to avoid frequent changes when a few peers drop.
|
||||||
|
maxDirect := int64(math.Sqrt(float64(h.maxPeers)) - 0.5)
|
||||||
|
direct := big.NewInt(max(min(sqrtPeers, maxDirect), 1))
|
||||||
|
|
||||||
total := new(big.Int).Exp(direct, big.NewInt(2), nil) // Stabilise total peer count a bit based on sqrt peers
|
total := new(big.Int).Exp(direct, big.NewInt(2), nil) // Stabilise total peer count a bit based on sqrt peers
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue