Found during testing: The recently introduced GetNetworkForMagic() doesn't handle Testnet4 yet.
chainparams: Handle Testnet4 in GetNetworkForMagic #30625
pull fjahr wants to merge 1 commits into bitcoin:master from fjahr:2024-08-testnet4-missing-check changing 1 files +3 −0-
fjahr commented at 8:23 PM on August 10, 2024: contributor
-
chainparams: Handle Testnet4 in GetNetworkForMagic b0ec8716bf
-
DrahtBot commented at 8:23 PM on August 10, 2024: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
Code Coverage
For detailed information about the code coverage, see the test coverage report.
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline for information on the review process.
Type Reviewers ACK tdb3, maflcko, theStack, willcl-ark If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
- tdb3 approved
-
tdb3 commented at 9:39 PM on August 10, 2024: contributor
cr ACK b0ec8716bf27335686471e0ae4c6a34f9a08f33c
-
in src/kernel/chainparams.cpp:696 in b0ec8716bf
691 | 692 | if (std::equal(message.begin(), message.end(), mainnet_msg.data())) { 693 | return ChainType::MAIN; 694 | } else if (std::equal(message.begin(), message.end(), testnet_msg.data())) { 695 | return ChainType::TESTNET; 696 | + } else if (std::equal(message.begin(), message.end(), testnet4_msg.data())) {
maflcko commented at 10:09 AM on August 11, 2024:style-nit: I know you copied this from the surrounding code, but creating a copy is not needed to compare two const references, and if the size of the second range in
std::equalis different, the result is either wrong or undefined behavior (UB/uninitialized read). See also the notes section (https://en.cppreference.com/w/cpp/algorithm/equal#Notes), which says "... When comparing entire containers for equality, operator== for the corresponding container are usually preferred".So that'd be:
diff --git a/src/kernel/chainparams.cpp b/src/kernel/chainparams.cpp index d0de3a4eab..c8522aa314 100644 --- a/src/kernel/chainparams.cpp +++ b/src/kernel/chainparams.cpp @@ -688,7 +688,7 @@ std::optional<ChainType> GetNetworkForMagic(const MessageStartChars& message) const auto regtest_msg = CChainParams::RegTest({})->MessageStart(); const auto signet_msg = CChainParams::SigNet({})->MessageStart(); - if (std::equal(message.begin(), message.end(), mainnet_msg.data())) { + if (message == CChainParams::Main()->MessageStart()) { return ChainType::MAIN; } else if (std::equal(message.begin(), message.end(), testnet_msg.data())) { return ChainType::TESTNET;An alternative would be to use
std::ranges::equalhttps://en.cppreference.com/w/cpp/algorithm/ranges/equal or thestd::equaloverload that takes 4 iterators.maflcko approvedmaflcko commented at 10:10 AM on August 11, 2024: memberreview ACK b0ec8716bf27335686471e0ae4c6a34f9a08f33c
Left a style-nit to avoid a copy and to make the code shorter, but only if you re-touch.
theStack approvedtheStack commented at 10:29 PM on August 11, 2024: contributorACK b0ec8716bf27335686471e0ae4c6a34f9a08f33c
willcl-ark approvedwillcl-ark commented at 8:48 AM on August 12, 2024: membercrACK b0ec8716bf27335686471e0ae4c6a34f9a08f33c
Theschorpioen approvedfanquake merged this on Aug 12, 2024fanquake closed this on Aug 12, 2024bitcoin locked this on Aug 12, 2025
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-22 03:13 UTC
More mirrored repositories can be found on mirror.b10c.me