Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Dec 6, 2022

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 AutoFile and HashVerifier. CAutoFile and CHashVerifier remain in places where it is not yet possible.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 6, 2022

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK stickies-v

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@DrahtBot DrahtBot changed the title refactor: Use AutoFile and HashVerifier (without ser-type and ser-version) where possible refactor: Use AutoFile and HashVerifier (without ser-type and ser-version) where possible Dec 6, 2022
MarcoFalke added 2 commits January 3, 2023 12:54
It is similar to CHashVerifier, but HashVerifier does not need a
serialize type and version
Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

Concept ACK

if (fileout.IsNull()) {
return error("%s: OpenUndoFile failed", __func__);
}

// Write index header
unsigned int nSize = GetSerializeSize(blockundo, fileout.GetVersion());
unsigned int nSize = GetSerializeSize(blockundo, CLIENT_VERSION);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
unsigned int nSize = GetSerializeSize(blockundo, CLIENT_VERSION);
unsigned int nSize{GetSerializeSize(blockundo, CLIENT_VERSION)};

Copy link
Member Author

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.

Copy link
Contributor

@stickies-v stickies-v left a 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;
Copy link
Contributor

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()) {

Copy link
Member Author

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<'

@fanquake fanquake merged commit 0a1d372 into bitcoin:master Jan 30, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 30, 2023
… 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
@stickies-v
Copy link
Contributor

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.

@sipa
Copy link
Member

sipa commented Jan 30, 2023

utACK eeee610

@maflcko maflcko deleted the 2212-ser-type-ver-👬 branch January 31, 2023 11:08
@bitcoin bitcoin locked and limited conversation to collaborators Jan 31, 2024
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.

5 participants