Skip to content

Conversation

@kallewoof
Copy link
Contributor

@kallewoof kallewoof commented May 16, 2018

Alternative approach: #13258.

There is no reason for uint256::GetCheapHash() to support multi-platform endian-ness, since the cheap hash is never used outside of the internal system (it is used in CAddrInfo bucket stuff, and that's it). We can remove an entire #include and probably some overhead as well. This will remove a number of chained dependencies from uint256 (crypto/common.h, compat/endian.h, and compat/byteswap.h).

Edit: due to the dependency on little endian in the tests for the address manager, #7078 switched to the ReadLE64() function. This test reverts that decision and updates the tests instead to work with big and little endian. These tests need to be rethought, possibly removed, as they test basically nothing right now*, but in the meantime, this will address the test errors for big endian.

(* they test that after adding a, b, and c to a bucket, adding d will cause a collision, but adding e will not...)

@Empact
Copy link
Contributor

Empact commented May 16, 2018

For reference, added in #7078, 0.12.0

@kallewoof
Copy link
Contributor Author

@Empact Thanks! Wow, this was added because of false positive test failures? I don't know if I can agree with that decision. Hard to test a fix though (no PPC/MIPS here).

@sipa
Copy link
Member

sipa commented May 16, 2018

NACK, this is invalid C++. You cannot take a pointer to an object of type A and then dereference it as a pointer of type B, unless the types are compatible, or B is a char type.

This will likely work on little-endian systems, but will produce different results on big-endian ones. And regardless of architecture, this is undefined behaviour.

FWIW, on x86 ReadLE64 is compiled to a simple load from memory.

@kallewoof kallewoof force-pushed the uint256-no-crypto branch from caa75a7 to ea1d189 Compare May 16, 2018 01:14
@kallewoof
Copy link
Contributor Author

@sipa ea1d189

@kallewoof
Copy link
Contributor Author

OK, I tried switching to ReadBE64 from ReadLE64 and the addrman tests are failing all over the place. If this hash is a hash, that makes no sense whatsoever.

kallewoof added 2 commits May 16, 2018 13:58
The address manager tests currently depend on little endianness because they are written with assumptions about collisions occurring at specific
points. This should be revisited, and these tests should potentially be removed as they serve little purpose now.
For now, this commit adds support for big endian assumptions and determines the endianness of the system, basing assumptions on that.
@kallewoof kallewoof force-pushed the uint256-no-crypto branch from ea1d189 to 656ddec Compare May 16, 2018 04:58
@kallewoof
Copy link
Contributor Author

I updated the tests to work on big endian. I also addressed @sipa's point about not dereferencing different type.

@kallewoof
Copy link
Contributor Author

There is an alternative approach to this in #13258.

@kallewoof kallewoof closed this May 17, 2018
@kallewoof kallewoof deleted the uint256-no-crypto branch July 3, 2018 08:44
laanwj added a commit that referenced this pull request Nov 30, 2018
bf2e010 uint256: Remove unnecessary crypto/common.h use (Karl-Johan Alm)

Pull request description:

  This is an alternative to #13242 which keeps the `ReadLE64` part, but moves the `crypto/common.h` dependency into `crypto/common.h` as a function outside of `uint256`.

  **Reason:** this change will remove dependencies for `uint256` to `crypto/common.h`, `compat/endian.h`, and `compat/byteswap.h`.

  This PR removes the need to update tests to be endian-aware/-independent, but keeps the (arguably dubious) `ReadLE64` part (which was only introduced to fix the tests, not for any functionality).

Tree-SHA512: 78b35123cdb185b3b3ec59aba5ca8a5db72624d147f2d6a5484ffa5ce626a72f782a01dc6893fc8f5619b03e2eae7b5a03b0df5d43460f3bda428e719e188aec
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Oct 21, 2021
…ndency

bf2e010 uint256: Remove unnecessary crypto/common.h use (Karl-Johan Alm)

Pull request description:

  This is an alternative to bitcoin#13242 which keeps the `ReadLE64` part, but moves the `crypto/common.h` dependency into `crypto/common.h` as a function outside of `uint256`.

  **Reason:** this change will remove dependencies for `uint256` to `crypto/common.h`, `compat/endian.h`, and `compat/byteswap.h`.

  This PR removes the need to update tests to be endian-aware/-independent, but keeps the (arguably dubious) `ReadLE64` part (which was only introduced to fix the tests, not for any functionality).

Tree-SHA512: 78b35123cdb185b3b3ec59aba5ca8a5db72624d147f2d6a5484ffa5ce626a72f782a01dc6893fc8f5619b03e2eae7b5a03b0df5d43460f3bda428e719e188aec
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Nov 18, 2021
…ndency

bf2e010 uint256: Remove unnecessary crypto/common.h use (Karl-Johan Alm)

Pull request description:

  This is an alternative to bitcoin#13242 which keeps the `ReadLE64` part, but moves the `crypto/common.h` dependency into `crypto/common.h` as a function outside of `uint256`.

  **Reason:** this change will remove dependencies for `uint256` to `crypto/common.h`, `compat/endian.h`, and `compat/byteswap.h`.

  This PR removes the need to update tests to be endian-aware/-independent, but keeps the (arguably dubious) `ReadLE64` part (which was only introduced to fix the tests, not for any functionality).

Tree-SHA512: 78b35123cdb185b3b3ec59aba5ca8a5db72624d147f2d6a5484ffa5ce626a72f782a01dc6893fc8f5619b03e2eae7b5a03b0df5d43460f3bda428e719e188aec
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
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.

4 participants