Skip to content

Commit bb06074

Browse files
jnewberymzumsande
authored andcommitted
scripted-diff: replace PoissonNextSend with GetExponentialRand
This distribution is used for more than just the next inv send, so make the name more generic. Also rename to "exponential" to avoid the confusion that this is a poisson distribution. -BEGIN VERIFY SCRIPT- ren() { sed -i "s/\<$1\>/$2/g" $(git grep -l "$1" ./src) ; } ren PoissonNextSend GetExponentialRand ren "a poisson timer" "an exponential timer" -END VERIFY SCRIPT-
1 parent 03cfa1b commit bb06074

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/net.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,8 +1878,8 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
18781878
auto start = GetTime<std::chrono::microseconds>();
18791879

18801880
// Minimum time before next feeler connection (in microseconds).
1881-
auto next_feeler = PoissonNextSend(start, FEELER_INTERVAL);
1882-
auto next_extra_block_relay = PoissonNextSend(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
1881+
auto next_feeler = GetExponentialRand(start, FEELER_INTERVAL);
1882+
auto next_extra_block_relay = GetExponentialRand(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
18831883
const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
18841884
bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
18851885

@@ -1999,7 +1999,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
19991999
//
20002000
// This is similar to the logic for trying extra outbound (full-relay)
20012001
// peers, except:
2002-
// - we do this all the time on a poisson timer, rather than just when
2002+
// - we do this all the time on an exponential timer, rather than just when
20032003
// our tip is stale
20042004
// - we potentially disconnect our next-youngest block-relay-only peer, if our
20052005
// newest block-relay-only peer delivers a block more recently.
@@ -2008,10 +2008,10 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
20082008
// Because we can promote these connections to block-relay-only
20092009
// connections, they do not get their own ConnectionType enum
20102010
// (similar to how we deal with extra outbound peers).
2011-
next_extra_block_relay = PoissonNextSend(now, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
2011+
next_extra_block_relay = GetExponentialRand(now, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
20122012
conn_type = ConnectionType::BLOCK_RELAY;
20132013
} else if (now > next_feeler) {
2014-
next_feeler = PoissonNextSend(now, FEELER_INTERVAL);
2014+
next_feeler = GetExponentialRand(now, FEELER_INTERVAL);
20152015
conn_type = ConnectionType::FEELER;
20162016
fFeeler = true;
20172017
} else {
@@ -3064,7 +3064,7 @@ std::chrono::microseconds CConnman::PoissonNextSendInbound(std::chrono::microsec
30643064
// If this function were called from multiple threads simultaneously
30653065
// it would possible that both update the next send variable, and return a different result to their caller.
30663066
// This is not possible in practice as only the net processing thread invokes this function.
3067-
m_next_send_inv_to_incoming = PoissonNextSend(now, average_interval);
3067+
m_next_send_inv_to_incoming = GetExponentialRand(now, average_interval);
30683068
}
30693069
return m_next_send_inv_to_incoming;
30703070
}

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4428,13 +4428,13 @@ void PeerManagerImpl::MaybeSendAddr(CNode& node, Peer& peer, std::chrono::micros
44284428
FastRandomContext insecure_rand;
44294429
PushAddress(peer, *local_addr, insecure_rand);
44304430
}
4431-
peer.m_next_local_addr_send = PoissonNextSend(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
4431+
peer.m_next_local_addr_send = GetExponentialRand(current_time, AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL);
44324432
}
44334433

44344434
// We sent an `addr` message to this peer recently. Nothing more to do.
44354435
if (current_time <= peer.m_next_addr_send) return;
44364436

4437-
peer.m_next_addr_send = PoissonNextSend(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
4437+
peer.m_next_addr_send = GetExponentialRand(current_time, AVG_ADDRESS_BROADCAST_INTERVAL);
44384438

44394439
if (!Assume(peer.m_addrs_to_send.size() <= MAX_ADDR_TO_SEND)) {
44404440
// Should be impossible since we always check size before adding to
@@ -4506,7 +4506,7 @@ void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, std::chrono::microseconds c
45064506
m_connman.PushMessage(&pto, CNetMsgMaker(pto.GetCommonVersion()).Make(NetMsgType::FEEFILTER, filterToSend));
45074507
pto.m_tx_relay->lastSentFeeFilter = filterToSend;
45084508
}
4509-
pto.m_tx_relay->m_next_send_feefilter = PoissonNextSend(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL);
4509+
pto.m_tx_relay->m_next_send_feefilter = GetExponentialRand(current_time, AVG_FEEFILTER_BROADCAST_INTERVAL);
45104510
}
45114511
// If the fee filter has changed substantially and it's still more than MAX_FEEFILTER_CHANGE_DELAY
45124512
// until scheduled broadcast, then move the broadcast to within MAX_FEEFILTER_CHANGE_DELAY.
@@ -4788,7 +4788,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47884788
if (pto->IsInboundConn()) {
47894789
pto->m_tx_relay->nNextInvSend = m_connman.PoissonNextSendInbound(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL);
47904790
} else {
4791-
pto->m_tx_relay->nNextInvSend = PoissonNextSend(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL);
4791+
pto->m_tx_relay->nNextInvSend = GetExponentialRand(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL);
47924792
}
47934793
}
47944794

src/random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ void RandomInit()
716716
ReportHardwareRand();
717717
}
718718

719-
std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval)
719+
std::chrono::microseconds GetExponentialRand(std::chrono::microseconds now, std::chrono::seconds average_interval)
720720
{
721721
double unscaled = -std::log1p(GetRand(uint64_t{1} << 48) * -0.0000000000000035527136788 /* -1/2^48 */);
722722
return now + std::chrono::duration_cast<std::chrono::microseconds>(unscaled * average_interval + 0.5us);

src/random.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ constexpr auto GetRandMillis = GetRandomDuration<std::chrono::milliseconds>;
9292
* The probability of an event occuring before time x is 1 - e^-(x/a) where a
9393
* is the average interval between events.
9494
* */
95-
std::chrono::microseconds PoissonNextSend(std::chrono::microseconds now, std::chrono::seconds average_interval);
95+
std::chrono::microseconds GetExponentialRand(std::chrono::microseconds now, std::chrono::seconds average_interval);
9696

9797
int GetRandInt(int nMax) noexcept;
9898
uint256 GetRandHash() noexcept;

0 commit comments

Comments
 (0)