-
Notifications
You must be signed in to change notification settings - Fork 38.8k
refactor: Use AutoFile and HashVerifier (without ser-type and ser-version) where possible #26649
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
The head ref may contain hidden characters: "2212-ser-type-ver-\u{1F46C}"
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
It is similar to CHashVerifier, but HashVerifier does not need a serialize type and version
fa55c7e to
eeee610
Compare
stickies-v
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
|
|
||
| // Write index header | ||
| unsigned int nSize = GetSerializeSize(blockundo, fileout.GetVersion()); | ||
| unsigned int nSize = GetSerializeSize(blockundo, CLIENT_VERSION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
| unsigned int nSize = GetSerializeSize(blockundo, CLIENT_VERSION); | |
| unsigned int nSize{GetSerializeSize(blockundo, CLIENT_VERSION)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will do on the next push, if there is one.
stickies-v
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK eeee610
| class HashVerifier : public HashWriter | ||
| { | ||
| private: | ||
| Source& m_source; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this ideally be const? Can be done when making AutoFile::read() const.
git diff
diff --git a/src/hash.h b/src/hash.h
index b2ef29fcd..ef5f03578 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -170,10 +170,10 @@ template <typename Source>
class HashVerifier : public HashWriter
{
private:
- Source& m_source;
+ const Source& m_source;
public:
- explicit HashVerifier(Source& source LIFETIMEBOUND) : m_source{source} {}
+ explicit HashVerifier(const Source& source LIFETIMEBOUND) : m_source{source} {}
void read(Span<std::byte> dst)
{
diff --git a/src/streams.h b/src/streams.h
index 4f2c3ffe7..ff812280f 100644
--- a/src/streams.h
+++ b/src/streams.h
@@ -516,7 +516,7 @@ public:
//
// Stream subset
//
- void read(Span<std::byte> dst)
+ void read(Span<std::byte> dst) const
{
if (!file) throw std::ios_base::failure("AutoFile::read: file handle is nullptr");
if (fread(dst.data(), 1, dst.size(), file) != dst.size()) {There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to do it for all functions in the same commit: git grep 'void read(Span<'
… ser-type and ser-version) where possible eeee610 Use AutoFile and HashVerifier where possible (MarcoFalke) fa96114 Add HashVerifier (MarcoFalke) Pull request description: This was done in the context of bitcoin#25284 , but I think it also makes sense standalone. The basic idea is that serialization type should not be initialized when it is not needed. Same for the serialization version. So do this here for `AutoFile` and `HashVerifier`. `CAutoFile` and `CHashVerifier` remain in places where it is not yet possible. ACKs for top commit: stickies-v: ACK eeee610 Tree-SHA512: 93786778c309ecfdc1ed43552d24ff9d966954d69a47f66faaa6de24daacd25c651f3f62bde5abbb362700298fb3c04ffbd3207a0dd13d0bd8bff7fd6d07dcf8
|
Obviously not against getting this merged, but I think I'd have been more comfortable with another ACK? Perhaps someone can have a look here post-merge? Not a huge overhaul, but also not as trivial as a docs change. |
|
utACK eeee610 |
This was done in the context of #25284 , but I think it also makes sense standalone.
The basic idea is that serialization type should not be initialized when it is not needed. Same for the serialization version.
So do this here for
AutoFileandHashVerifier.CAutoFileandCHashVerifierremain in places where it is not yet possible.