Skip to content

Commit 00f4dcd

Browse files
author
MarcoFalke
committed
Merge #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/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
2 parents f3e1768 + fa0f415 commit 00f4dcd

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/net.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@
2424
#include <sync.h>
2525
#include <threadinterrupt.h>
2626
#include <uint256.h>
27+
#include <util/check.h>
2728

2829
#include <atomic>
30+
#include <condition_variable>
2931
#include <cstdint>
3032
#include <deque>
3133
#include <map>
32-
#include <thread>
3334
#include <memory>
34-
#include <condition_variable>
35+
#include <thread>
3536

3637
class CScheduler;
3738
class CNode;
@@ -1131,6 +1132,7 @@ class CNode
11311132

11321133
void SetCommonVersion(int greatest_common_version)
11331134
{
1135+
Assume(m_greatest_common_version == INIT_PROTO_VERSION);
11341136
m_greatest_common_version = greatest_common_version;
11351137
}
11361138
int GetCommonVersion() const

src/test/fuzz/net.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ void test_one_input(const std::vector<uint8_t>& buffer)
4848
fuzzed_data_provider.ConsumeRandomLengthString(32),
4949
fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND_FULL_RELAY, ConnectionType::MANUAL, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH}),
5050
fuzzed_data_provider.ConsumeBool()};
51+
node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
5152
while (fuzzed_data_provider.ConsumeBool()) {
52-
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 11)) {
53+
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 10)) {
5354
case 0: {
5455
node.CloseSocketDisconnect();
5556
break;
@@ -59,10 +60,6 @@ void test_one_input(const std::vector<uint8_t>& buffer)
5960
break;
6061
}
6162
case 2: {
62-
node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
63-
break;
64-
}
65-
case 3: {
6663
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
6764
if (!SanityCheckASMap(asmap)) {
6865
break;
@@ -71,18 +68,18 @@ void test_one_input(const std::vector<uint8_t>& buffer)
7168
node.copyStats(stats, asmap);
7269
break;
7370
}
74-
case 4: {
71+
case 3: {
7572
const CNode* add_ref_node = node.AddRef();
7673
assert(add_ref_node == &node);
7774
break;
7875
}
79-
case 5: {
76+
case 4: {
8077
if (node.GetRefCount() > 0) {
8178
node.Release();
8279
}
8380
break;
8481
}
85-
case 6: {
82+
case 5: {
8683
if (node.m_addr_known == nullptr) {
8784
break;
8885
}
@@ -93,7 +90,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
9390
node.AddAddressKnown(*addr_opt);
9491
break;
9592
}
96-
case 7: {
93+
case 6: {
9794
if (node.m_addr_known == nullptr) {
9895
break;
9996
}
@@ -105,27 +102,27 @@ void test_one_input(const std::vector<uint8_t>& buffer)
105102
node.PushAddress(*addr_opt, fast_random_context);
106103
break;
107104
}
108-
case 8: {
105+
case 7: {
109106
const std::optional<CInv> inv_opt = ConsumeDeserializable<CInv>(fuzzed_data_provider);
110107
if (!inv_opt) {
111108
break;
112109
}
113110
node.AddKnownTx(inv_opt->hash);
114111
break;
115112
}
116-
case 9: {
113+
case 8: {
117114
node.PushTxInventory(ConsumeUInt256(fuzzed_data_provider));
118115
break;
119116
}
120-
case 10: {
117+
case 9: {
121118
const std::optional<CService> service_opt = ConsumeDeserializable<CService>(fuzzed_data_provider);
122119
if (!service_opt) {
123120
break;
124121
}
125122
node.SetAddrLocal(*service_opt);
126123
break;
127124
}
128-
case 11: {
125+
case 10: {
129126
const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);
130127
bool complete;
131128
node.ReceiveMsgBytes(b, complete);

0 commit comments

Comments
 (0)