Is is possible to construct a Span
from a reference to a CKey
. However, the same is not possible with std::span
.
Fix that.
Is is possible to construct a Span
from a reference to a CKey
. However, the same is not possible with std::span
.
Fix that.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For detailed information about the code coverage, see the test coverage report.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
ACK | shaavan, willcl-ark |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
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.
Code Review ACK
Commit-1:
Since std::span
requires a mutable pointer to the data for certain operations, this change makes XOnlyPubKey compatible with std::span.
Commit-2:
Since the return type of begin()
and end()
much match the data type of the std::span
of the container, this change makes CKey compatible with std::span
, and allows std::span<std::byte>
construction for it.
Commit-3:
Tests that the above changes made CKey
compatible with std::span
.
I am curious about one thing, though.
If we now have std::span
since C++20, are we thinking of making every container in the codebase std::span
compatible and moving away from needing to use our ### custom Span
class?
If we now have
std::span
since C++20, are we thinking of making every container in the codebasestd::span
compatible and moving away from needing to use our ### customSpan
class?
Yes, I think it makes sense to allow new code to use std::span
directly. Also, I think it makes sense to (longer term) remove Span
(or make it an alias of std::span
) to avoid confusion which to use in new code, and to get the additional compile-time checks from std::span
.
This is needed for consistency, and also to allow std::span construction
from XOnlyPubKey.
I dropped the last commit, to not introduce new std::span
usage for now. To verify the changes in this pull, the commit’s diff can be used. (Fails to compile before, compiles after):
0diff --git a/src/key.cpp b/src/key.cpp
1index 2bd6396298..300c95e35a 100644
2--- a/src/key.cpp
3+++ b/src/key.cpp
4@@ -385,7 +385,7 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
5 return key.Derive(out.key, out.chaincode, _nChild, chaincode);
6 }
7
8-void CExtKey::SetSeed(Span<const std::byte> seed)
9+void CExtKey::SetSeed(std::span<const std::byte> seed)
10 {
11 static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
12 std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
13diff --git a/src/key.h b/src/key.h
14index d6b26f891d..d63ec6c1cc 100644
15--- a/src/key.h
16+++ b/src/key.h
17@@ -12,10 +12,10 @@
18 #include <support/allocators/secure.h>
19 #include <uint256.h>
20
21+#include <span>
22 #include <stdexcept>
23 #include <vector>
24
25-
26 /**
27 * CPrivKey is a serialized private key, with all parameters included
28 * (SIZE bytes)
29@@ -227,7 +227,7 @@ struct CExtKey {
30 void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
31 [[nodiscard]] bool Derive(CExtKey& out, unsigned int nChild) const;
32 CExtPubKey Neuter() const;
33- void SetSeed(Span<const std::byte> seed);
34+ void SetSeed(std::span<const std::byte> seed);
35 };
36
37 /** Initialize the elliptic curve support. May not be called twice without calling ECC_Stop first. */
ReACK fa96d937116682f32613d31a3ae7d6f652e8146d
Changes since my last review
ACK fa96d937116682f32613d31a3ae7d6f652e8146d
A nice simple change to enable using std::span
with CKey
.
The PR description could be updated now that the verification commit has been removed.
maflcko
DrahtBot
shaavan
willcl-ark
Labels
Refactoring