Skip to content

Commit 6abbbe1

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#20138: net: Assume that SetCommonVersion is called at most once per peer
fa0f415 net: Assume that SetCommonVersion is called at most once per peer (MarcoFalke) Pull request description: This restores the check removed in bitcoin#17785 (comment) Instead of using `error`, which was used previously, it uses a newly introduced `Assume()`. `error` had several issues: * It logs unconditionally to the debug log * It doesn't abort the program when the error is hit in tests ACKs for top commit: practicalswift: cr ACK fa0f415: patch looks correct jnewbery: utACK fa0f415 Tree-SHA512: cd7424a9485775e8c7093b725f8f52a90d47485185e79bac80f7810e450d0b3fda608d8805e9239094929f7bad2dca3fe772fb78ae606c2399d15405521e136b
1 parent 5154fa0 commit 6abbbe1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/net.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
#include <uint256.h>
3030
#include <util/system.h>
3131
#include <consensus/params.h>
32+
#include <util/check.h>
3233

3334
#include <atomic>
35+
#include <condition_variable>
3436
#include <cstdint>
3537
#include <deque>
3638
#include <map>
37-
#include <thread>
3839
#include <memory>
39-
#include <condition_variable>
40+
#include <thread>
4041
#include <optional>
4142
#include <queue>
4243

@@ -1417,6 +1418,7 @@ class CNode
14171418

14181419
void SetCommonVersion(int greatest_common_version)
14191420
{
1421+
Assume(m_greatest_common_version == INIT_PROTO_VERSION);
14201422
m_greatest_common_version = greatest_common_version;
14211423
}
14221424
int GetCommonVersion() const

src/test/fuzz/net.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ FUZZ_TARGET_INIT(net, initialize_net)
3131

3232
CNode node{ConsumeNode(fuzzed_data_provider)};
3333
SetMockTime(ConsumeTime(fuzzed_data_provider));
34+
node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
3435
while (fuzzed_data_provider.ConsumeBool()) {
3536
CallOneOf(
3637
fuzzed_data_provider,
@@ -42,9 +43,6 @@ FUZZ_TARGET_INIT(net, initialize_net)
4243
[&] {
4344
node.MaybeSetAddrName(fuzzed_data_provider.ConsumeRandomLengthString(32));
4445
},
45-
[&] {
46-
node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
47-
},
4846
[&] {
4947
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
5048
if (!SanityCheckASMap(asmap)) {

0 commit comments

Comments
 (0)