Skip to content

Commit ea99f5d

Browse files
jnewberymzumsande
authored andcommitted
[net processing] Move PoissonNextSendInbound to PeerManager
1 parent bb06074 commit ea99f5d

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

src/net.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,17 +3058,6 @@ bool CConnman::ForNode(NodeId id, std::function<bool(CNode* pnode)> func)
30583058
return found != nullptr && NodeFullyConnected(found) && func(found);
30593059
}
30603060

3061-
std::chrono::microseconds CConnman::PoissonNextSendInbound(std::chrono::microseconds now, std::chrono::seconds average_interval)
3062-
{
3063-
if (m_next_send_inv_to_incoming.load() < now) {
3064-
// If this function were called from multiple threads simultaneously
3065-
// it would possible that both update the next send variable, and return a different result to their caller.
3066-
// This is not possible in practice as only the net processing thread invokes this function.
3067-
m_next_send_inv_to_incoming = GetExponentialRand(now, average_interval);
3068-
}
3069-
return m_next_send_inv_to_incoming;
3070-
}
3071-
30723061
CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
30733062
{
30743063
return CSipHasher(nSeed0, nSeed1).Write(id);

src/net.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -936,12 +936,6 @@ class CConnman
936936

937937
void WakeMessageHandler();
938938

939-
/** Attempts to obfuscate tx time through exponentially distributed emitting.
940-
Works assuming that a single interval is used.
941-
Variable intervals will result in privacy decrease.
942-
*/
943-
std::chrono::microseconds PoissonNextSendInbound(std::chrono::microseconds now, std::chrono::seconds average_interval);
944-
945939
/** Return true if we should disconnect the peer for failing an inactivity check. */
946940
bool ShouldRunInactivityChecks(const CNode& node, std::chrono::seconds now) const;
947941

@@ -1221,8 +1215,6 @@ class CConnman
12211215
*/
12221216
std::atomic_bool m_start_extra_block_relay_peers{false};
12231217

1224-
std::atomic<std::chrono::microseconds> m_next_send_inv_to_incoming{0us};
1225-
12261218
/**
12271219
* A vector of -bind=<address>:<port>=onion arguments each of which is
12281220
* an address and port that are designated for incoming Tor connections.

src/net_processing.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ class PeerManagerImpl final : public PeerManager
444444
*/
445445
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex);
446446

447+
std::atomic<std::chrono::microseconds> m_next_send_inv_to_incoming{0us};
448+
447449
/** Number of nodes with fSyncStarted. */
448450
int nSyncStarted GUARDED_BY(cs_main) = 0;
449451

@@ -518,6 +520,15 @@ class PeerManagerImpl final : public PeerManager
518520
Mutex m_recent_confirmed_transactions_mutex;
519521
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
520522

523+
/**
524+
* For sending `inv`s to inbound peers, we use a single (exponentially
525+
* distributed) timer for all peers. If we used a separate timer for each
526+
* peer, a spy node could make multiple inbound connections to us to
527+
* accurately determine when we received the transaction (and potentially
528+
* determine the transaction's origin). */
529+
std::chrono::microseconds PoissonNextSendInbound(std::chrono::microseconds now,
530+
std::chrono::seconds average_interval);
531+
521532
/** Have we requested this block from a peer */
522533
bool IsBlockRequested(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
523534

@@ -819,6 +830,18 @@ static void UpdatePreferredDownload(const CNode& node, CNodeState* state) EXCLUS
819830
nPreferredDownload += state->fPreferredDownload;
820831
}
821832

833+
std::chrono::microseconds PeerManagerImpl::PoissonNextSendInbound(std::chrono::microseconds now,
834+
std::chrono::seconds average_interval)
835+
{
836+
if (m_next_send_inv_to_incoming.load() < now) {
837+
// If this function were called from multiple threads simultaneously
838+
// it would possible that both update the next send variable, and return a different result to their caller.
839+
// This is not possible in practice as only the net processing thread invokes this function.
840+
m_next_send_inv_to_incoming = GetExponentialRand(now, average_interval);
841+
}
842+
return m_next_send_inv_to_incoming;
843+
}
844+
822845
bool PeerManagerImpl::IsBlockRequested(const uint256& hash)
823846
{
824847
return mapBlocksInFlight.find(hash) != mapBlocksInFlight.end();
@@ -4786,7 +4809,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47864809
if (pto->m_tx_relay->nNextInvSend < current_time) {
47874810
fSendTrickle = true;
47884811
if (pto->IsInboundConn()) {
4789-
pto->m_tx_relay->nNextInvSend = m_connman.PoissonNextSendInbound(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL);
4812+
pto->m_tx_relay->nNextInvSend = PoissonNextSendInbound(current_time, INBOUND_INVENTORY_BROADCAST_INTERVAL);
47904813
} else {
47914814
pto->m_tx_relay->nNextInvSend = GetExponentialRand(current_time, OUTBOUND_INVENTORY_BROADCAST_INTERVAL);
47924815
}

src/test/fuzz/connman.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
8989
[&] {
9090
(void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
9191
},
92-
[&] {
93-
// Limit now to int32_t to avoid signed integer overflow
94-
(void)connman.PoissonNextSendInbound(
95-
std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int32_t>()},
96-
std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int>()});
97-
},
9892
[&] {
9993
CSerializedNetMsg serialized_net_msg;
10094
serialized_net_msg.m_type = fuzzed_data_provider.ConsumeRandomLengthString(CMessageHeader::COMMAND_SIZE);

0 commit comments

Comments
 (0)