I read that bitcoin uses random delay when relaying transaction to other peers in order to protect privacy. When I read the source code of the newest Bitcoin Core, I found a function called rand_uniform_delay
. When I searched for its usage, I found it only used in random_test.cpp
. I wonder where the code for the random delay in Bitcoin Core can be found.
Add a comment
|
1 Answer
Code used for better privacy when relaying transactions in \src\net_processing.cpp
:
if (auto tx_relay = peer->GetTxRelay(); tx_relay != nullptr) {
LOCK(tx_relay->m_tx_inventory_mutex);
// Check whether periodic sends should happen
bool fSendTrickle = pto->HasPermission(NetPermissionFlags::NoBan);
if (tx_relay->m_next_inv_send_time < current_time) {
fSendTrickle = true;
if (pto->IsInboundConn()) {
tx_relay->m_next_inv_send_time = NextInvToInbounds(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL);
} else {
tx_relay->m_next_inv_send_time = GetExponentialRand(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL);
}
}
This was initially implemented by Pieter Wuille in #7125, later improved in #7840 and #13298
Related