1

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.

enter image description here

1 Answer 1

2

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

Transaction Relay and trickling in Bitcoin

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.