GetSerializeSize()
, simplifying the code in various places. Also drop GetSerializeSizeMany()
(as just removing the version parameter could result in silent bugs) and remove unnecessary instances of #include <version.h>
.
GetSerializeSize()
, simplifying the code in various places. Also drop GetSerializeSizeMany()
(as just removing the version parameter could result in silent bugs) and remove unnecessary instances of #include <version.h>
.
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.
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.
Playing around locally, I was also able to drop the include in:
0$ git diff --stat
1 src/bitcoin-util.cpp | 1 -
2 src/coins.cpp | 1 -
3 src/core_read.cpp | 1 -
4 src/kernel/coinstats.cpp | 1 -
5 src/rest.cpp | 1 -
6 src/script/bitcoinconsensus.cpp | 1 -
7 src/zmq/zmqpublishnotifier.cpp | 1 -
(I didn’t mess with the tests, maybe could drop some there too).
Also worth pointing out: libbitcoinkernel now only requires version.h
for signet.cpp
, which I assume will go away in one of these follow-ups.
Edit: Not that the header dependency matters at all for libbitcoinkernel. It’s just indicative imo that we’re moving the right direction if it ends up un-tethered.
Protocol version is no longer needed to work out the serialized size
of objects so drop that information from CSizeComputer and rename the
class to SizeComputer.
Rebased after #28438 was merged.
Is this next after #28438? Or something else first?
Either this or #28451 seem good to go; I think they conflict due to the “Convert some CDataStream..” commit here though; shouldn’t be a hard rebase in either case though, I think.
Playing around locally, I was also able to drop the include in:
Taken.
Also worth pointing out: libbitcoinkernel now only requires
version.h
forsignet.cpp
, which I assume will go away in one of these follow-ups.
That just needs SpanReader
and CVectorWriter
to be updated to not need a version.
449@@ -450,7 +450,7 @@ inline unsigned int GetSizeOfVarInt(I n)
450 }
451
452 template<typename I>
453-inline void WriteVarInt(CSizeComputer& os, I n);
454+inline void WriteVarInt(SizeComputer& os, I n);
inline
is implied by template
and can be removed.
1087 size_t nSize{0};
1088
1089- const int nVersion;
1090 public:
1091- explicit CSizeComputer(int nVersionIn) : nVersion(nVersionIn) {}
1092+ SizeComputer() {}
explicit
? Shouldn’t matter in this context, but when in doubt, I’d prefer to keep it, unless there is a reason to remove it?
explicit
is good for constructors that take a single argument to prevent accidental conversion, but seems useless for constructors that don’t take an argument. (The real question is why leave a constructor there at all?)
1097@@ -1099,7 +1098,7 @@ class CSizeComputer
1098 }
1099
1100 template<typename T>
1101- CSizeComputer& operator<<(const T& obj)
1102+ SizeComputer& operator<<(const T& obj)
1103 {
1104 ::Serialize(*this, obj);
1105 return (*this);
()
, which achieve nothing in this context.
1111- int GetVersion() const { return nVersion; }
1112 };
1113
1114 template<typename I>
1115-inline void WriteVarInt(CSizeComputer &s, I n)
1116+inline void WriteVarInt(SizeComputer &s, I n)
inline
)
Some nits in the first commit. Otherwise:
ACK 83986f464c59a6517f790a960a72574e167f3f72 📒
Signature:
0untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
1RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
2trusted comment: ACK 83986f464c59a6517f790a960a72574e167f3f72 📒
3u/O7R7516VMRG5DuyOAXpyIHkMFCYUDfQH4PmkXGtkYoDV483ta0wAcinIAZ/Fijsk9h85VNKL9CG4+pCBLwAA==
88@@ -89,7 +89,9 @@ struct PSBTProprietary
89 template<typename Stream, typename... X>
90 void SerializeToVector(Stream& s, const X&... args)
91 {
92- WriteCompactSize(s, GetSerializeSizeMany(s.GetVersion(), args...));
93+ SizeComputer sizecomp;
94+ SerializeMany(sizecomp, args...);
95+ WriteCompactSize(s, sizecomp.size());
96 SerializeMany(s, args...);
Unrelated to this PR, but I think we could make this much more efficient by adding a serializer override that keeps a running tally of serialized size? That way size is calculated as a side-effect of the actual serialization and prepended to the stream, rather than running all the way through twice.
No idea if this path is hot enough to bother messing with that.
ACK 83986f464c59a6517f790a960a72574e167f3f72.
I started working on a patch to remove clientversion.h
where it’s no longer necessary after these changes, but it’s just more work than it’s worth for this.
Can we just agree to do a (client)version.h include cleanup at some point when the dust has settled on all this? :)
ajtowns
DrahtBot
theuni
maflcko
Labels
Refactoring