-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
kernel: Remove protocol.h/netaddress.h/compat.h from kernel headers #28423
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. ConflictsReviewers, 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. |
8e2f988
to
9861c7a
Compare
8556f1f
to
d4cc87f
Compare
Very nice. Concept ACK. |
d4cc87f
to
5bebabd
Compare
Updated d4cc87f -> 978baaf (rmNetKernel_0 -> rmNetKernel_1, compare) |
5bebabd
to
978baaf
Compare
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 978baaf
I didn't mind the additional messageheader.h split before, but without it this way is fine too.
The GetDefaultPort()
's are awkward in their new home, but I don't have a better suggestion.
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 978baaf
978baaf
to
197de6a
Compare
Updated 978baaf -> 197de6a (rmNetKernel_1 -> rmNetKernel_2, compare) |
ACK 197de6a |
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 197de6a.
I would've preferred to see the Params change in CConnman
split into a separate commit, as the implications of that aren't 100% clear to me (Mostly: can we trickle m_params
down anywhere else now?).
But it looks correct and is an improvement on top of the original PR.
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.
lgtm, left a nit
@@ -6,8 +6,6 @@ | |||
#ifndef BITCOIN_UTIL_TIME_H | |||
#define BITCOIN_UTIL_TIME_H | |||
|
|||
#include <compat/compat.h> |
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.
According to iwyu:
util/time.h should add these lines:
#include <sys/time.h> // for timeval
#include <ctime> // for time_t
Seems the only reason this compiles is because those are exported from chrono
, which seems fragile to rely on, no?
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.
Ah yes, nice catch. MillisToTimeval()
is the problem here. Ideally that should be moved away as timeval
isn't api safe.
Edit: Not the highest prio though, as it's a struct and the forward-declare is fine.
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.
Ah nvm. std::time_t
is part of the public interface of chrono
, so the include isn't needed. And the timeval
type is fwd-declared, so this seems like a bug in iwyu.
ba37340
to
4ce0ead
Compare
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.
re-ACK 4ce0ead
@@ -203,6 +203,7 @@ template<typename Stream> inline void Serialize(Stream& s, int64_t a ) { ser_wri | |||
template<typename Stream> inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); } | |||
template<typename Stream, int N> inline void Serialize(Stream& s, const char (&a)[N]) { s.write(MakeByteSpan(a)); } | |||
template<typename Stream, int N> inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(MakeByteSpan(a)); } | |||
template <typename Stream, typename B, std::size_t N> void Serialize(Stream& s, const std::array<B, N>& a) { (void)/* force byte-type */UCharCast(a.data()); s.write(MakeByteSpan(a)); } |
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: ser, that's a long line
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.
Seemed awkward to format this line, but leave the others. I think I'll leave this as is.
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.
Might be clearer as { s.write(AsBytes(UCharSpanCast(Span(a)))); }
? I think that has all the same restrictions as you get with the dummy UCharCast
.
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.
Sure, as long as you keep the comment. Otherwise I fear that someone will remove the UChar(Span)Cast
because "it isn't needed" and "everything still compiles".
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.
Yeah. Might be another place where C++20 concepts would be good -- concept BytesLike = requires (B& b) { UCharCast(b) }
and template<typename Stream, BytesLike B, ..>
or so.
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.
Yes, should be possible, see #27927 (comment), but IIRC it also changes the compiler error message
4ce0ead
to
d4170ca
Compare
Updated 4ce0ead -> d4170ca (rmNetKernel_3 -> rmNetKernel_4, compare)
|
This is already possible for C-style arrays, so allow it for C++11 std::array as well.
The protocol.h file contains many non-consensus related definitions and should thus not be part of the libbitcoinkernel. This commit makes protocol.h no longer a required include for users of the libbitcoinkernel. This commit is part of the libbitcoinkernel project, namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel. Co-Authored-By: Cory Fields <cory-nospam-@coryfields.com>
This is done in preparation to the next commit, but has the nice effect of removing one further data structure relying on the global `Params()`.
Move functions requiring the netaddress.h include out of libbitcoinkernel source files. The netaddress.h file contains many non-consensus related definitions and should thus not be part of the libbitcoinkernel. This commit makes netaddress.h no longer a required include for users of the libbitcoinkernel. This commit is part of the libbitcoinkernel project, namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel.
This commit makes compat.h no longer a required include for users of the libbitcoinkernel. Including compat.h imports a bunch of platform-specific definitions. This commit is part of the libbitcoinkernel project, namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel.
d4170ca
to
d506765
Compare
Rebased d4170ca -> d506765 (rmNetKernel_4 -> rmNetKernel_5, compare)
|
re-ACK d506765 |
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 d506765.
@@ -301,6 +302,7 @@ template<typename Stream> inline void Unserialize(Stream& s, int64_t& a ) { a = | |||
template<typename Stream> inline void Unserialize(Stream& s, uint64_t& a) { a = ser_readdata64(s); } | |||
template<typename Stream, int N> inline void Unserialize(Stream& s, char (&a)[N]) { s.read(MakeWritableByteSpan(a)); } | |||
template<typename Stream, int N> inline void Unserialize(Stream& s, unsigned char (&a)[N]) { s.read(MakeWritableByteSpan(a)); } | |||
template <typename Stream, typename B, std::size_t N> void Unserialize(Stream& s, std::array<B, N>& a) { (void)/* force byte-type */UCharCast(a.data()); s.read(MakeWritableByteSpan(a)); } |
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.
Add std::array
objects to serialize_tests.cpp
?
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.
Would this be enough for you? Can otherwise do it in a follow-up.
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
index 2f2bb6698c..28d276076e 100644
--- a/src/test/serialize_tests.cpp
+++ b/src/test/serialize_tests.cpp
@@ -87,2 +87,4 @@ BOOST_AUTO_TEST_CASE(sizes)
BOOST_CHECK_EQUAL(GetSerializeSize(bool(0), 0), 1U);
+ BOOST_CHECK_EQUAL(GetSerializeSize(std::array<uint8_t, 1>{0}, 0), 1U);
+ BOOST_CHECK_EQUAL(GetSerializeSize(std::array<uint8_t, 2>{0, 0}, 0), 2U);
}
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.
Sorry, I had to be clear in my initial comment that it was a suggestion for a follow-up.
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.
utACK d506765
@@ -203,6 +203,7 @@ template<typename Stream> inline void Serialize(Stream& s, int64_t a ) { ser_wri | |||
template<typename Stream> inline void Serialize(Stream& s, uint64_t a) { ser_writedata64(s, a); } | |||
template<typename Stream, int N> inline void Serialize(Stream& s, const char (&a)[N]) { s.write(MakeByteSpan(a)); } | |||
template<typename Stream, int N> inline void Serialize(Stream& s, const unsigned char (&a)[N]) { s.write(MakeByteSpan(a)); } | |||
template <typename Stream, typename B, std::size_t N> void Serialize(Stream& s, const std::array<B, N>& a) { (void)/* force byte-type */UCharCast(a.data()); s.write(MakeByteSpan(a)); } |
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.
Might be clearer as { s.write(AsBytes(UCharSpanCast(Span(a)))); }
? I think that has all the same restrictions as you get with the dummy UCharCast
.
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.
left some style nits, better to be left as-is for a follow-up
lgtm ACK d506765 🍛
Show signature
Signature:
untrusted 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}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: lgtm ACK d5067651991f3e6daf456ba13c7036ddc4545352 🍛
lStXnLnO5f5mgzKS9vTXRcRE1E6bMezm8Whu8+/ejq9XWm3C/d0zha2XRO2Zh+Qup7wt0W56hpPWA2AteHA/CQ==
@@ -730,7 +730,7 @@ V1Transport::V1Transport(const NodeId node_id, int nTypeIn, int nVersionIn) noex | |||
m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), vRecv(nTypeIn, nVersionIn) | |||
{ | |||
assert(std::size(Params().MessageStart()) == std::size(m_magic_bytes)); | |||
std::copy(std::begin(Params().MessageStart()), std::end(Params().MessageStart()), m_magic_bytes); | |||
m_magic_bytes = Params().MessageStart(); |
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 in 9be330b: Not sure if it compiles, but could use an constructor initializer for this?
@@ -92,7 +92,7 @@ const static std::vector<std::string> g_all_net_message_types{ | |||
|
|||
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn) | |||
{ | |||
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); | |||
pchMessageStart = pchMessageStartIn; |
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.
same?
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.
This would allow to make it const
, I guess. Which makes sense to do, because it is public
. But that seems unrelated and better put into a follow-up.
src/kernel/chainparams.h
Outdated
#include <consensus/params.h> | ||
#include <kernel/messagestartchars.h> |
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.
iwyu nit in 534b314: Can probably export those two and chaintype.h ?
This would allow dropping the include from stuff like blockstorage.cpp and validation.cpp again, because that already includes chainparams.
Going to merge this shortly. The 324 integration PR will have to be rebased, but it looks like that will be pushed to again in any case (to address comments). The comments left here can be addressed in a followup PR. |
Added the following comments to the kernel project tracking issue TODOs: |
…from kernel headers d506765 [refactor] Remove compat.h from kernel headers (TheCharlatan) 36193af [refactor] Remove netaddress.h from kernel headers (TheCharlatan) 2b08c55 [refactor] Add CChainParams member to CConnman (TheCharlatan) f0d1d8b [refactor] Add missing includes for next commit (TheCharlatan) 534b314 kernel: Move MessageStartChars to its own file (TheCharlatan) 9be330b [refactor] Define MessageStartChars as std::array (TheCharlatan) 37e2b01 [refactor] Allow std::array<std::byte, N> in serialize.h (MarcoFalke) Pull request description: This removes the non-consensus critical `protocol.h` and `netaddress.h` headers from the kernel headers. With this patch, they are no longer required to include in order to use the libbitcoinkernel library. This also allows for the removal of the `compat.h` header from the kernel headers. As an added future benefit it also reduces the number of of kernel headers that include the platform specific `bitcoin-config.h`. For those interested, the currently required kernel headers can be inspected visually with the [sourcetrail](https://github.com/CoatiSoftware/Sourcetrail) tool by looking at the required includes of `bitcoin-chainstate.cpp`. --- This is part of the [libbitcoinkernel project](bitcoin#27587), namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel. ACKs for top commit: stickies-v: re-ACK d506765 hebasto: ACK d506765. ajtowns: utACK d506765 MarcoFalke: lgtm ACK d506765 🍛 Tree-SHA512: 6f90ea510a302c2927e84d16900e89997c39b8ff3ce9d4effeb8a134bd29cc52bd9e81e51aaa11f7496bad00025b78a58b88c5a9e0bb3f4ebbe9a76309215fb7
1e5b861 test: Add test for array serialization (TheCharlatan) d49d198 refactor: Initialize magic bytes in constructor initializer (TheCharlatan) Pull request description: This is a followup-PR for #28423 * Initialize magic bytes in constructor * Add a small unit test for serializing arrays. ACKs for top commit: sipa: utACK 1e5b861 maflcko: lgtm ACK 1e5b861 Tree-SHA512: 0f58d2332dc501ca9fd419f40ed4f977c83dce0169e9a0eee1ffc9f8daa2d2ef7e7df18205ba076f55d90ae6c4a20d2b51ab303150d38470a962bcc58a66f6e7
This removes the non-consensus critical
protocol.h
andnetaddress.h
headers from the kernel headers. With this patch, they are no longer required to include in order to use the libbitcoinkernel library. This also allows for the removal of thecompat.h
header from the kernel headers.As an added future benefit it also reduces the number of of kernel headers that include the platform specific
bitcoin-config.h
.For those interested, the currently required kernel headers can be inspected visually with the sourcetrail tool by looking at the required includes of
bitcoin-chainstate.cpp
.This is part of the libbitcoinkernel project, namely its stage 1 step 3: Decouple most non-consensus headers from libbitcoinkernel.