Skip to content

Commit 17fdbef

Browse files
committed
Merge bitcoin/bitcoin#23970: Remove pointless and confusing shift in RelayAddress
fa9f455 refactor: Remove pointless and confusing shift in RelayAddress (MarcoFalke) Pull request description: The second argument written to the siphash is already quantized to 24 hours, so it seems confusing to quantize the first argument to 32 bits (out of 64 bits). > The shifting is pointless, we should get rid of it. It seems to be a silly evolution of this 2010 Satoshi code: 5cbf753 (where it made sense because everything was XORed together, and the address used the high bits, while the time used the low ones). (Copied from bitcoin/bitcoin#18642 (comment)) (The original code was `uint256 hashRand = hashSalt ^ (((int64)addr.ip)<<32) ^ ((GetTime()+addr.ip)/(24*60*60));`) This also allows to remove a integer sanitizer suppression for the whole file. ACKs for top commit: laanwj: Code review ACK fa9f455 sipa: utACK fa9f455 promag: Code review ACK fa9f455. Tree-SHA512: f5fd107464ccd839d6749aed6914b4935e39ab42906546b3f3810a7339fc4633fef931a1783a287572af5ec64525626fa91d147d8ff52eb076740465bf5cf839
2 parents 801aaac + fa9f455 commit 17fdbef

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/net_processing.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,8 @@ void PeerManagerImpl::RelayAddress(NodeId originator,
17461746
// Relay to a limited number of other nodes
17471747
// Use deterministic randomness to send to the same nodes for 24 hours
17481748
// at a time so the m_addr_knowns of the chosen nodes prevent repeats
1749-
uint64_t hashAddr = addr.GetHash();
1750-
const CSipHasher hasher = m_connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24 * 60 * 60));
1749+
const uint64_t hashAddr{addr.GetHash()};
1750+
const CSipHasher hasher{m_connman.GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr).Write((GetTime() + hashAddr) / (24 * 60 * 60))};
17511751
FastRandomContext insecure_rand;
17521752

17531753
// Relay reachable addresses to 2 peers. Unreachable addresses are relayed randomly to 1 or 2 peers.

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,5 @@ implicit-unsigned-integer-truncation:crypto/
105105
shift-base:arith_uint256.cpp
106106
shift-base:crypto/
107107
shift-base:hash.cpp
108-
shift-base:net_processing.cpp
109108
shift-base:streams.h
110109
shift-base:util/bip32.cpp

0 commit comments

Comments
 (0)