Skip to content

Conversation

@kallewoof
Copy link
Contributor

@kallewoof kallewoof commented May 17, 2018

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

@kallewoof kallewoof changed the title uint256: Remove unnecessary crypto/common.h use (alternative) uint256: Remove unnecessary crypto/common.h dependency (alternative) May 17, 2018
@kallewoof kallewoof changed the title uint256: Remove unnecessary crypto/common.h dependency (alternative) uint256: Remove unnecessary crypto/common.h dependency May 17, 2018
@Empact
Copy link
Contributor

Empact commented May 17, 2018

All the GetCheapHash calls are relative to CHashWriter and BlockHasher, how about putting it higher up?

I'm not crazy about the template approach because it's overly general and doesn't guarantee that there are 64 bits there to read.

@kallewoof
Copy link
Contributor Author

I'm not crazy about the template approach because it's overly general and doesn't guarantee that there are 64 bits there to read.

Yeah, but a uint256 does not guarantee it is random, either, so you still have to use this cautiously, even before this patch.

Putting it in CHashWriter may be a better idea, for sure. I'll try that and see what it looks like.

@kallewoof kallewoof force-pushed the uint256-no-crypto-alt branch from 1dbe85d to a02e3e6 Compare May 17, 2018 06:35
@kallewoof
Copy link
Contributor Author

kallewoof commented May 17, 2018

@Empact Changed to your suggested approach. No more template, and code looks cleaner. Only gotcha here is people may be tempted to GetHash().GetCheapHash() which will do double-double-SHA256, instead of double-SHA256. Considering the limited use, I think that gotcha is acceptable.

@Empact
Copy link
Contributor

Empact commented May 17, 2018

Nice, looks much better IMO.

src/addrman.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary include.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@kallewoof kallewoof force-pushed the uint256-no-crypto-alt branch from a02e3e6 to 015e0f7 Compare May 17, 2018 06:47
@Empact
Copy link
Contributor

Empact commented May 17, 2018

utACK 015e0f7

@Empact
Copy link
Contributor

Empact commented May 17, 2018

I'd close #13242 in favor of this - as this offers endianness consistency, test stability, and better code organization.

@kallewoof
Copy link
Contributor Author

Yeah, it got too big for the desired effect. I do want to get rid of the unnecessary endianness consistency, though, but I think rewriting those tests to be a bit more useful is a necessary middle-step.

@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 66 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 7, 2018

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #14624 (Some simple improvements to the RNG code by sipa)
  • #13462 (Simplify common case of CHashWriter and drop SerializeHash by Empact)

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.

@kallewoof kallewoof force-pushed the uint256-no-crypto-alt branch from 015e0f7 to 361ecbf Compare September 10, 2018 01:05
@sipa
Copy link
Member

sipa commented Sep 10, 2018

utACK 361ecbf3e9ffe83800e845426b6cc835267c1932

1 similar comment
@maflcko
Copy link
Member

maflcko commented Sep 10, 2018

utACK 361ecbf3e9ffe83800e845426b6cc835267c1932

src/validation.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could benefit from a comment referencing GetCheapHash to explain the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. Got 3 utACKs so will fix this if another rebase becomes necessary or other changes are suggested.

Copy link
Member

Choose a reason for hiding this comment

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

Could add a commit with "doc: bla..." on top of the branch (not touching the existing commits)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done!

@Empact
Copy link
Contributor

Empact commented Sep 10, 2018

re-utACK 361ecbf

src/hash.h Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this comment is still appropriate. As it samples the output, which went through a hash function, this requirement about the distribution of the input of the hash writer no longer holds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I also wonder about the 'cheap' part here, as it's actually just taking the prefix of the real hash, but keeping for now.

@kallewoof kallewoof force-pushed the uint256-no-crypto-alt branch from bf27187 to 93baaf9 Compare September 14, 2018 02:44
@ken2812221
Copy link
Contributor

re-utACK 93baaf9

@maflcko
Copy link
Member

maflcko commented Sep 17, 2018

re-utACK 93baaf9c3e

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.

utACK 93baaf9, sorry the nit 🏃

src/validation.h Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, sort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damn. Fixed.

@kallewoof kallewoof force-pushed the uint256-no-crypto-alt branch from 93baaf9 to bf2e010 Compare September 18, 2018 05:27
@promag
Copy link
Contributor

promag commented Sep 18, 2018

utACK bf2e010.

@maflcko
Copy link
Member

maflcko commented Nov 7, 2018

utACK bf2e010

@Empact
Copy link
Contributor

Empact commented Nov 7, 2018

re-utACK bf2e010

@laanwj laanwj merged commit bf2e010 into bitcoin:master Nov 30, 2018
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
@kallewoof kallewoof deleted the uint256-no-crypto-alt branch October 17, 2019 08:36
ptschip pushed a commit to ptschip/BitcoinUnlimited that referenced this pull request Oct 22, 2019
Summary:
bf2e01097 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

Backport of Core PR13258
bitcoin/bitcoin#13258

Test Plan:
  make check

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4277
jonspock pushed a commit to jonspock/devault that referenced this pull request Dec 27, 2019
Summary:
bf2e01097 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

Backport of Core PR13258
bitcoin/bitcoin#13258

Test Plan:
  make check

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4277
jonspock pushed a commit to devaultcrypto/devault that referenced this pull request Dec 29, 2019
Summary:
bf2e01097 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

Backport of Core PR13258
bitcoin/bitcoin#13258

Test Plan:
  make check

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4277
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.

9 participants