10000 Simplify hash.h interface using Spans by sipa · Pull Request #19326 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplify hash.h interface using Spans #19326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 3, 2020
Merged

Conversation

sipa
Copy link
Member
@sipa sipa commented Jun 19, 2020

This makes use of the implicit constructions and conversions to Span introduced in #18468 to simplify the hash.h interface:

  • All functions that take a pointer and a length are changed to take a Span instead.
  • The Hash() and Hash160() functions are changed to take in "range" objects instead of begin/end iterators.

@sipa
Copy link
Member Author
sipa commented Jun 19, 2020

@jb55 You may be interested in this.

@DrahtBot
Copy link
Contributor
DrahtBot commented Jun 19, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@jb55
Copy link
Contributor
jb55 commented Jun 19, 2020

yup this will clean up some of my PRs. Concept ACK (I would almost say utACK but I just woke up).

@jonatack
Copy link
Member

Concept ACK. Read the code, built/tested/running bitcoind, need to do more detailed code review stepping through the commits.

@practicalswift
Copy link
Contributor
practicalswift commented Jun 25, 2020

Concept ACK: Span<const unsigned char> as a drop-in replacement for const std::vector<unsigned char>& as parameter type is safe use of Span :)

Copy link
Member
@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK 974381f a useful clear abstraction and nice cleanup. Code review, compared the implementation of as_(writable_)bytes to that shown in https://en.cppreference.com/w/cpp/container/span/as_bytes (if you retouch, s/to_/as_/ in the 45316c2 commit message). Built in various ways, ran tests and benches locally, ran bitcoind without issues for a day.

@sipa sipa force-pushed the 202006_spanhashes branch from 974381f to a4ecf04 Compare June 26, 2020 20:38
@sipa
Copy link
Member Author
sipa commented Jun 26, 2020

Rebased and addressed @jonatack's comment.

@jonatack
Copy link
Member

re-ACK fc7c518

@sipa
Copy link
Member Author
sipa commented Jul 30, 2020

Rebased.

@laanwj
Copy link
Member
laanwj commented Aug 3, 2020

re-ACK 77c5073

Copy link
Member
@jonatack jonatack 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 re-ACK 77c5073 per git range-diff 14ceddd 49fc016 77c5073

@laanwj laanwj merged commit 34eb236 into bitcoin:master Aug 3, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 4, 2020
77c5073 Make Hash[160] consume range-like objects (Pieter Wuille)
02c4cc5 Make CHash256/CHash160 output to Span (Pieter Wuille)
0ef97b1 Make MurmurHash3 consume Spans (Pieter Wuille)
e549bf8 Make CHash256 and CHash160 consume Spans (Pieter Wuille)
2a2182c Make script/standard's BaseHash Span-convertible (Pieter Wuille)
e63dcc3 Add MakeUCharSpan, to help constructing Span<[const] unsigned char> (Pieter Wuille)
5678250 Make uint256 Span-convertible by adding ::data() (Pieter Wuille)
131a2f0 scripted-diff: rename base_blob::data to m_data (Pieter Wuille)

Pull request description:

  This makes use of the implicit constructions and conversions to Span introduced in bitcoin#18468 to simplify the hash.h interface:

  * All functions that take a pointer and a length are changed to take a Span instead.
  * The Hash() and Hash160() functions are changed to take in "range" objects instead of begin/end iterators.

ACKs for top commit:
  laanwj:
    re-ACK 77c5073
  jonatack:
    Code review re-ACK 77c5073 per `git range-diff 14ceddd 49fc016 77c5073`

Tree-SHA512: 9ec929891b1ddcf30eb14b946ee1bf142eca1442b9de0067ad6a3c181e0c7ea0c99c0e291e7f6e7a18bd7bdf78fe94ee3d5de66e167401674caf91e026269771
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
```
This is in preparation for exposing a ::data member function.

-BEGIN VERIFY SCRIPT-
sed -i "s/\([^.]\|other.\)data/\1m_data/g" src/uint256.h src/uint256.cpp
-END VERIFY SCRIPT-
```

Partial backport of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@131a2f0

The comparison fonction differs due to D1527.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9147
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Partial backport (2/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@5678250

Depends on D9147.

Test Plan:
  ninja

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9148
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Partial backport (3/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@e63dcc3

Depends on D9148.

Test Plan:
  ninja

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9149
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Partial backport (4/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@2a2182c

Depends on D9149.

Test Plan:
  ninja

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9150
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Partial backport (5/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@e549bf8

The segwit related parts have been skipped.

Depends on D9150.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9151
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Partial backport (6/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@0ef97b1

Depends on D9151.

Test Plan:
  ninja all check

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9152
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Partial backport (7/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@02c4cc5

Depends on D9152.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9153
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 4, 2021
Summary:
Completes backport (8/8) of core [[bitcoin/bitcoin#19326 | PR19326]]:
bitcoin/bitcoin@77c5073

Depends on D9156.

There is a missing dependency for the `walletdb.cpp` change for which I
left a comment to make the later backport easier.
This diff also contains a few changes which are specific to our repo.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9154
kwvg added a commit to kwvg/dash that referenced this pull request May 19, 2021
kwvg added a commit to kwvg/dash that referenced this pull request May 20, 2021
kwvg added a commit to kwvg/dash that referenced this pull request May 20, 2021
kwvg added a commit to kwvg/dash that referenced this pull request May 20, 2021
kwvg added a commit to kwvg/dash that referenced this pull request May 20, 2021
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jul 21, 2021
a1f3aed util: make EncodeBase64 consume Spans (furszy)
c36754f Add MakeUCharSpan, to help constructing Span<[const] unsigned char> (Pieter Wuille)
1f18199 Make uint256 Span-convertible by adding ::data() (Pieter Wuille)
0067590 Add lifetimebound to attributes for general-purpose usage (Cory Fields)
26eb256 span: add lifetimebound attribute (Cory Fields)
696e91f span: (almost) match std::span's constructor behavior (Cory Fields)
da207d4 doc: Mention Span in developer-notes.md (Pieter Wuille)
138053d doc: Document Span pitfalls (Pieter Wuille)
e2216d7 Add sanity check asserts to span when -DDEBUG (Pieter Wuille)
ebcc978 Add Span constructors for arrays and vectors (Pieter Wuille)
38f105b Make pointer-based Span construction safer (Pieter Wuille)
33d5297 Make Span size type unsigned (Pieter Wuille)
17118e1 Support conversion between Spans of compatible types (Pieter Wuille)
f36042f Span front() and back() methods and SpanPopBack function backport (furszy)
1b2e7c8 Add more methods to Span class (Pieter Wuille)

Pull request description:

  Another decouple from #2411.
  Purely focused on updating the Span sources to be up-to-date with current upstream.

  Following PRs/commits were back ported:

  * bitcoin#13697 (only 29943a9)
  * 2b0fcff (only span changes).
  * bitcoin#18591 (only 0fbde48).
  * bitcoin#18468 (without 2676aea).
  * bitcoin#19367.
  * bitcoin#19387.
  * bitcoin#19326 (only 5678250 and e63dcc3 here).
  * bitcoin#19687 (only e2aa1a5 here, 2bc2071 is inside #2411 and require net related commits that are introduced down the commits line there).

  Extra side note:
  Some of the current serialization compiler warnings in master will be fixed with this, other ones are coming down 2411 commits line as they need other previous PRs.

ACKs for top commit:
  random-zebra:
    Tested ACK a1f3aed

Tree-SHA512: 256bc2064724ea6d4f6fac722fafb4ed3e2b4590cdad61bf1e4a5be25e0632bafcff39235ea6ed7badbef4f79dbb4f866356372a1b3c201af23873884baedfea
@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
0