Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jan 4, 2022

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 #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.

@maflcko maflcko changed the title refactor: Remove pointless and confusing shift in RelayAddress Remove pointless and confusing shift in RelayAddress Jan 4, 2022
@maflcko maflcko added the P2P label Jan 4, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 5, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23542 (net: open p2p connections to nodes that listen on non-default ports by vasild)
  • #18642 (Use std::chrono for the time to rotate destination of addr messages + tests by naumenkogs)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK fa9f455.

@laanwj
Copy link
Member

laanwj commented Jan 5, 2022

Code review ACK fa9f455
Agree with the reasoning that shifting (essentially moving the zeroes) is pointless statistically when using a "real" hash algorithm like siphash.

@sipa
Copy link
Member

sipa commented Jan 5, 2022

utACK fa9f455

@fanquake fanquake merged commit 17fdbef into bitcoin:master Jan 5, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 6, 2022
…ress

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#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
@maflcko maflcko deleted the 2112-noShiftAdd branch January 6, 2022 12:32
@bitcoin bitcoin locked and limited conversation to collaborators Jan 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants