Skip to content

Commit

Permalink
Merge bitcoin#19728: Increase the ip address relay branching factor f…
Browse files Browse the repository at this point in the history
…or unreachable networks

86d4cf4 Increase the ip address relay branching factor for unreachable networks (Pieter Wuille)

Pull request description:

  Onion addresses propagate very badly among the IPv4/IPv6 network, resulting
  in difficulty for those to find each other.

  The branching factor 1 is probably so low that propagations die out before
  they reach another onion peer. Increase it to 1.5 on average.

ACKs for top commit:
  practicalswift:
    ACK 86d4cf4 -- patch looks correct
  naumenkogs:
    ACK 86d4cf4
  jonatack:
    ACK 86d4cf4. Code review, built and running with some sanity check logging. `RelayAddress()` is called by `ProcessMessage() ADDR` msg handling, from within the loop while processing each new address to relay it to a limited number of other nodes. According to git blame, the line setting `nRelayNodes` hasn't been touched since 2016 in e736772 *Move network-msg-processing code out of main to its own file*, which moved the line but otherwise did not change it. Running a mixed clearnet/onion node with this patch and the logging below, I'm only seeing values of `fReachable 1, nRelayNodes 2`. IIUC, I need to use the settings in `init.cpp` that call `SetReachable(*, false)`. *Edit:* with `onlynet=onion` am now seeing entries of `fReachable 0` with `nRelayNodes` values of 1 and 2.
  vasild:
    ACK 86d4cf4

Tree-SHA512: 22391e16d60bcfdec9a9336728da39d68a24a183b3d1b0e8fbc038d265ca6ddf71d16db018f3678745fd9f3e9281049e42197fa0a29124833c50a9170ed6f793
  • Loading branch information
laanwj authored and PastaPastaPasta committed Jun 28, 2021
1 parent 662c083 commit 86eeae3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,6 @@ bool static AlreadyHave(const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)

static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connman)
{
unsigned int nRelayNodes = fReachable ? 2 : 1; // limited relaying of addresses outside our network(s)

// Relay to a limited number of other nodes
// Use deterministic randomness to send to the same nodes for 24 hours
Expand All @@ -1409,6 +1408,9 @@ static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connma
const CSipHasher hasher = connman->GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24*60*60));
FastRandomContext insecure_rand;

// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.
unsigned int nRelayNodes = (fReachable || (hasher.Finalize() & 1)) ? 2 : 1;

std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}};
assert(nRelayNodes <= best.size());

Expand Down

0 comments on commit 86eeae3

Please sign in to comment.