Bitcoin Core 32.99.0
P2P Digital Currency
Loading...
Searching...
No Matches
denialofservice_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5// Unit tests for denial-of-service detection/prevention code
6
7#include <banman.h>
8#include <chainparams.h>
9#include <common/args.h>
10#include <key.h>
11#include <net.h>
12#include <net_processing.h>
14#include <pubkey.h>
15#include <script/sign.h>
17#include <script/solver.h>
18#include <serialize.h>
19#include <test/util/net.h>
20#include <test/util/random.h>
22#include <test/util/time.h>
23#include <util/string.h>
24#include <util/time.h>
25#include <validation.h>
26
27#include <array>
28#include <cstdint>
29
30#include <boost/test/unit_test.hpp>
31
33{
34 struct in_addr s;
35 s.s_addr = i;
36 return CService(CNetAddr(s), Params().GetDefaultPort());
37}
38
40
41// Test eviction of an outbound peer whose chain never advances
42// Mock a node connection, and use mocktime to simulate a peer
43// which never sends any headers messages. PeerLogic should
44// decide to evict that outbound peer, after the appropriate timeouts.
45// Note that we protect 4 outbound nodes from being subject to
46// this logic; this test takes advantage of that protection only
47// being applied to nodes which send headers with sufficient
48// work.
50{
52
53 ConnmanTestMsg& connman = static_cast<ConnmanTestMsg&>(*m_node.connman);
54 // Disable inactivity checks for this test to avoid interference
55 connman.SetPeerConnectTimeout(99999s);
56 PeerManager& peerman = *m_node.peerman;
57
58 // Mock an outbound peer
59 CAddress addr1(ip(0xa0b0c001), NODE_NONE);
60 NodeId id{0};
61 CNode dummyNode1{id++,
62 /*sock=*/nullptr,
63 addr1,
64 /*nKeyedNetGroupIn=*/0,
65 /*nLocalHostNonceIn=*/0,
66 CAddress(),
67 /*addrNameIn=*/"",
69 /*inbound_onion=*/false,
70 /*network_key=*/0};
71
72 connman.Handshake(
73 /*node=*/dummyNode1,
74 /*successfully_connected=*/true,
75 /*remote_services=*/ServiceFlags(NODE_NETWORK | NODE_WITNESS),
76 /*local_services=*/ServiceFlags(NODE_NETWORK | NODE_WITNESS),
77 /*version=*/PROTOCOL_VERSION,
78 /*relay_txs=*/true);
79
80 // This test requires that we have a chain with non-zero work.
81 {
83 BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr);
84 BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0);
85 }
86
87 // Test starts here
88 BOOST_CHECK(peerman.SendMessages(dummyNode1)); // should result in getheaders
89
90 {
91 LOCK(dummyNode1.cs_vSend);
92 const auto& [to_send, _more, _msg_type] = dummyNode1.m_transport->GetBytesToSend(false);
93 BOOST_CHECK(!to_send.empty());
94 }
96
98 clock += 21min;
99
100 BOOST_CHECK(peerman.SendMessages(dummyNode1)); // should result in getheaders
101 {
102 LOCK(dummyNode1.cs_vSend);
103 const auto& [to_send, _more, _msg_type] = dummyNode1.m_transport->GetBytesToSend(false);
104 BOOST_CHECK(!to_send.empty());
105 }
106
107 clock += 3min;
108 BOOST_CHECK(peerman.SendMessages(dummyNode1)); // should result in disconnect
109 BOOST_CHECK(dummyNode1.fDisconnect == true);
110
111 peerman.FinalizeNode(dummyNode1);
112}
113
116{
117 CAddress addr;
118
119 if (onion_peer) {
122 }
123
124 while (!addr.IsRoutable()) {
125 addr = CAddress(ip(m_rng.randbits(32)), NODE_NONE);
126 }
127
128 vNodes.emplace_back(new CNode{id++,
129 /*sock=*/nullptr,
130 addr,
131 /*nKeyedNetGroupIn=*/0,
132 /*nLocalHostNonceIn=*/0,
133 CAddress(),
134 /*addrNameIn=*/"",
135 connType,
136 /*inbound_onion=*/false,
137 /*network_key=*/0});
138 CNode &node = *vNodes.back();
139 node.SetCommonVersion(PROTOCOL_VERSION);
140
142 node.fSuccessfullyConnected = true;
143
144 connman.AddTestNode(node);
145}
146}; // struct OutboundTest
147
149{
150 NodeId id{0};
151 auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
153
155 CConnman::Options options;
157
158 const auto time_init{Now<NodeSeconds>()};
160 const auto delta{3 * std::chrono::seconds{m_node.chainman->GetConsensus().nPowTargetSpacing} + 1s};
161 connman->Init(options);
162 std::vector<CNode *> vNodes;
163
164 // Mock some outbound peers
165 for (int i = 0; i < max_outbound_full_relay; ++i) {
166 AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
167 }
168
169 peerLogic->CheckForStaleTipAndEvictPeers();
170
171 // No nodes should be marked for disconnection while we have no extra peers
172 for (const CNode *node : vNodes) {
173 BOOST_CHECK(node->fDisconnect == false);
174 }
175
176 clock += delta;
177
178 // Now tip should definitely be stale, and we should look for an extra
179 // outbound peer
180 peerLogic->CheckForStaleTipAndEvictPeers();
181 BOOST_CHECK(connman->GetTryNewOutboundPeer());
182
183 // Still no peers should be marked for disconnection
184 for (const CNode *node : vNodes) {
185 BOOST_CHECK(node->fDisconnect == false);
186 }
187
188 // If we add one more peer, something should get marked for eviction
189 // on the next check (since we're mocking the time to be in the future, the
190 // required time connected check should be satisfied).
192 AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
193 clock += delta;
194
195 peerLogic->CheckForStaleTipAndEvictPeers();
196 for (int i = 0; i < max_outbound_full_relay; ++i) {
197 BOOST_CHECK(vNodes[i]->fDisconnect == false);
198 }
199 // Last added node should get marked for eviction
200 BOOST_CHECK(vNodes.back()->fDisconnect == true);
201
202 vNodes.back()->fDisconnect = false;
203
204 // Update the last announced block time for the last
205 // peer, and check that the next newest node gets evicted.
206 peerLogic->UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), NodeClock::now());
207
208 peerLogic->CheckForStaleTipAndEvictPeers();
209 for (int i = 0; i < max_outbound_full_relay - 1; ++i) {
210 BOOST_CHECK(vNodes[i]->fDisconnect == false);
211 }
212 BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true);
213 BOOST_CHECK(vNodes.back()->fDisconnect == false);
214
215 vNodes[max_outbound_full_relay - 1]->fDisconnect = false;
216
217 // Add an onion peer, that will be protected because it is the only one for
218 // its network, so another peer gets disconnected instead.
220 AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY, /*onion_peer=*/true);
221 clock += delta;
222 peerLogic->CheckForStaleTipAndEvictPeers();
223
224 for (int i = 0; i < max_outbound_full_relay - 2; ++i) {
225 BOOST_CHECK(vNodes[i]->fDisconnect == false);
226 }
227 BOOST_CHECK(vNodes[max_outbound_full_relay - 2]->fDisconnect == false);
228 BOOST_CHECK(vNodes[max_outbound_full_relay - 1]->fDisconnect == true);
229 BOOST_CHECK(vNodes[max_outbound_full_relay]->fDisconnect == false);
230
231 // Add a second onion peer which won't be protected
233 AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY, /*onion_peer=*/true);
234 clock += delta;
235 peerLogic->CheckForStaleTipAndEvictPeers();
236
237 BOOST_CHECK(vNodes.back()->fDisconnect == true);
238
239 for (const CNode *node : vNodes) {
240 peerLogic->FinalizeNode(*node);
241 }
242
243 connman->ClearTestNodes();
244}
245
247{
248 NodeId id{0};
250 auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
252
254 constexpr auto MINIMUM_CONNECT_TIME{30s};
255 CConnman::Options options;
257
258 connman->Init(options);
259 std::vector<CNode*> vNodes;
260
261 // Add block-relay-only peers up to the limit
262 for (int i = 0; i < max_outbound_block_relay; ++i) {
263 AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::BLOCK_RELAY);
264 }
265 peerLogic->CheckForStaleTipAndEvictPeers();
266
267 for (int i = 0; i < max_outbound_block_relay; ++i) {
268 BOOST_CHECK(vNodes[i]->fDisconnect == false);
269 }
270
271 // Add an extra block-relay-only peer breaking the limit (mocks logic in ThreadOpenConnections)
272 AddRandomOutboundPeer(id, vNodes, *peerLogic, *connman, ConnectionType::BLOCK_RELAY);
273 peerLogic->CheckForStaleTipAndEvictPeers();
274
275 // The extra peer should only get marked for eviction after MINIMUM_CONNECT_TIME
276 for (int i = 0; i < max_outbound_block_relay; ++i) {
277 BOOST_CHECK(vNodes[i]->fDisconnect == false);
278 }
279 BOOST_CHECK(vNodes.back()->fDisconnect == false);
280
282 peerLogic->CheckForStaleTipAndEvictPeers();
283 for (int i = 0; i < max_outbound_block_relay; ++i) {
284 BOOST_CHECK(vNodes[i]->fDisconnect == false);
285 }
286 BOOST_CHECK(vNodes.back()->fDisconnect == true);
287
288 // Update the last block time for the extra peer,
289 // and check that the next youngest peer gets evicted.
290 vNodes.back()->fDisconnect = false;
291 vNodes.back()->m_last_block_time = GetTime<std::chrono::seconds>();
292
293 peerLogic->CheckForStaleTipAndEvictPeers();
294 for (int i = 0; i < max_outbound_block_relay - 1; ++i) {
295 BOOST_CHECK(vNodes[i]->fDisconnect == false);
296 }
297 BOOST_CHECK(vNodes[max_outbound_block_relay - 1]->fDisconnect == true);
298 BOOST_CHECK(vNodes.back()->fDisconnect == false);
299
300 for (const CNode* node : vNodes) {
301 peerLogic->FinalizeNode(*node);
302 }
303 connman->ClearTestNodes();
304}
305
307{
309
310 auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
311 auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
312 auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
313
316 tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
318
319 const std::array<CAddress, 3> addr{CAddress{ip(0xa0b0c001), NODE_NONE},
320 CAddress{ip(0xa0b0c002), NODE_NONE},
322
323 const CNetAddr other_addr{ip(0xa0b0ff01)}; // Not any of addr[].
324
325 std::array<CNode*, 5> nodes;
326
327 banman->ClearBanned();
328 NodeId id{0};
329 nodes[0] = new CNode{id++,
330 /*sock=*/nullptr,
331 addr[0],
332 /*nKeyedNetGroupIn=*/0,
333 /*nLocalHostNonceIn=*/0,
334 CAddress(),
335 /*addrNameIn=*/"",
337 /*inbound_onion=*/false,
338 /*network_key=*/1};
339 nodes[0]->SetCommonVersion(PROTOCOL_VERSION);
340 peerLogic->InitializeNode(*nodes[0], NODE_NETWORK);
341 nodes[0]->fSuccessfullyConnected = true;
342 connman->AddTestNode(*nodes[0]);
343 peerLogic->UnitTestMisbehaving(nodes[0]->GetId()); // Should be discouraged
344 BOOST_CHECK(peerLogic->SendMessages(*nodes[0]));
345
346 BOOST_CHECK(banman->IsDiscouraged(addr[0]));
347 BOOST_CHECK(nodes[0]->fDisconnect);
348 BOOST_CHECK(!banman->IsDiscouraged(other_addr)); // Different address, not discouraged
349
350 nodes[1] = new CNode{id++,
351 /*sock=*/nullptr,
352 addr[1],
353 /*nKeyedNetGroupIn=*/1,
354 /*nLocalHostNonceIn=*/1,
355 CAddress(),
356 /*addrNameIn=*/"",
358 /*inbound_onion=*/false,
359 /*network_key=*/1};
360 nodes[1]->SetCommonVersion(PROTOCOL_VERSION);
361 peerLogic->InitializeNode(*nodes[1], NODE_NETWORK);
362 nodes[1]->fSuccessfullyConnected = true;
363 connman->AddTestNode(*nodes[1]);
364 BOOST_CHECK(peerLogic->SendMessages(*nodes[1]));
365 // [0] is still discouraged/disconnected.
366 BOOST_CHECK(banman->IsDiscouraged(addr[0]));
367 BOOST_CHECK(nodes[0]->fDisconnect);
368 // [1] is not discouraged/disconnected yet.
369 BOOST_CHECK(!banman->IsDiscouraged(addr[1]));
370 BOOST_CHECK(!nodes[1]->fDisconnect);
371 peerLogic->UnitTestMisbehaving(nodes[1]->GetId());
372 BOOST_CHECK(peerLogic->SendMessages(*nodes[1]));
373 // Expect both [0] and [1] to be discouraged/disconnected now.
374 BOOST_CHECK(banman->IsDiscouraged(addr[0]));
375 BOOST_CHECK(nodes[0]->fDisconnect);
376 BOOST_CHECK(banman->IsDiscouraged(addr[1]));
377 BOOST_CHECK(nodes[1]->fDisconnect);
378
379 // Make sure non-IP peers are discouraged and disconnected properly.
380
381 nodes[2] = new CNode{id++,
382 /*sock=*/nullptr,
383 addr[2],
384 /*nKeyedNetGroupIn=*/1,
385 /*nLocalHostNonceIn=*/1,
386 CAddress(),
387 /*addrNameIn=*/"",
389 /*inbound_onion=*/false,
390 /*network_key=*/2};
391 nodes[2]->SetCommonVersion(PROTOCOL_VERSION);
392 peerLogic->InitializeNode(*nodes[2], NODE_NETWORK);
393 nodes[2]->fSuccessfullyConnected = true;
394 connman->AddTestNode(*nodes[2]);
395
396 nodes[3] = new CNode{/*id=*/id++,
397 /*sock=*/nullptr,
398 /*addrIn=*/addr[2],
399 /*nKeyedNetGroupIn=*/0,
400 /*nLocalHostNonceIn=*/0,
401 /*addrBindIn=*/CAddress{},
402 /*addrNameIn=*/"",
403 /*conn_type_in=*/ConnectionType::PRIVATE_BROADCAST,
404 /*inbound_onion=*/false,
405 /*network_key=*/0};
406 peerLogic->InitializeNode(*nodes[3], NODE_NETWORK);
407 connman->AddTestNode(*nodes[3]);
408
409 peerLogic->UnitTestMisbehaving(nodes[2]->GetId());
410 BOOST_CHECK(peerLogic->SendMessages(*nodes[2]));
411 BOOST_CHECK(banman->IsDiscouraged(addr[0]));
412 BOOST_CHECK(banman->IsDiscouraged(addr[1]));
413 BOOST_CHECK(banman->IsDiscouraged(addr[2]));
414 BOOST_CHECK(nodes[0]->fDisconnect);
415 BOOST_CHECK(nodes[1]->fDisconnect);
416 BOOST_CHECK(nodes[2]->fDisconnect);
417 BOOST_CHECK(!nodes[3]->fDisconnect);
418
419 nodes[4] = new CNode{/*id=*/id++,
420 /*sock=*/nullptr,
422 /*nKeyedNetGroupIn=*/0,
423 /*nLocalHostNonceIn=*/0,
424 /*addrBindIn=*/CAddress{},
425 /*addrNameIn=*/"",
426 /*conn_type_in=*/ConnectionType::PRIVATE_BROADCAST,
427 /*inbound_onion=*/false,
428 /*network_key=*/0};
429 peerLogic->InitializeNode(*nodes[4], NODE_NETWORK);
430 connman->AddTestNode(*nodes[4]);
431
432 peerLogic->UnitTestMisbehaving(nodes[4]->GetId());
433 BOOST_CHECK(peerLogic->SendMessages(*nodes[4]));
434 BOOST_CHECK(nodes[4]->fDisconnect);
435 BOOST_CHECK(!banman->IsDiscouraged(other_addr));
436
437 for (CNode* node : nodes) {
438 peerLogic->FinalizeNode(*node);
439 }
440 connman->ClearTestNodes();
441}
442
444{
446
447 auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
448 auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
449 auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
450
451 banman->ClearBanned();
452 const FakeNodeClock clock{}; // keep mocktime constant
453
454 CAddress addr(ip(0xa0b0c001), NODE_NONE);
455 NodeId id{0};
456 CNode dummyNode{id++,
457 /*sock=*/nullptr,
458 addr,
459 /*nKeyedNetGroupIn=*/4,
460 /*nLocalHostNonceIn=*/4,
461 CAddress(),
462 /*addrNameIn=*/"",
464 /*inbound_onion=*/false,
465 /*network_key=*/1};
466 dummyNode.SetCommonVersion(PROTOCOL_VERSION);
467 peerLogic->InitializeNode(dummyNode, NODE_NETWORK);
468 dummyNode.fSuccessfullyConnected = true;
469
470 peerLogic->UnitTestMisbehaving(dummyNode.GetId());
471 BOOST_CHECK(peerLogic->SendMessages(dummyNode));
472 BOOST_CHECK(banman->IsDiscouraged(addr));
473
474 peerLogic->FinalizeNode(dummyNode);
475}
476
477// Reconsidering orphans must be interruptible: at most one orphan is accepted
478// or rejected per ProcessMessages() call.
479// See https://bitcoincore.org/en/2024/07/03/disclose-orphan-dos.
481{
483
484 ConnmanTestMsg& connman = static_cast<ConnmanTestMsg&>(*m_node.connman);
485 PeerManager& peerman = *m_node.peerman;
486 const CTxMemPool& mempool = *m_node.mempool;
487
488 CNode peer{/*id=*/0,
489 /*sock=*/nullptr,
490 CAddress(ip(0xa0b0c001), NODE_NONE),
491 /*nKeyedNetGroupIn=*/0,
492 /*nLocalHostNonceIn=*/0,
493 CAddress(),
494 /*addrNameIn=*/"",
496 /*inbound_onion=*/false,
497 /*network_key=*/0};
498 connman.Handshake(
499 /*node=*/peer,
500 /*successfully_connected=*/true,
501 /*remote_services=*/ServiceFlags(NODE_NETWORK | NODE_WITNESS),
502 /*local_services=*/ServiceFlags(NODE_NETWORK | NODE_WITNESS),
503 /*version=*/PROTOCOL_VERSION,
504 /*relay_txs=*/true);
505
506 const CScript script{GetScriptForRawPubKey(coinbaseKey.GetPubKey())};
507 const int num_children{6};
508 const auto parent{MakeTransactionRef(CreateValidMempoolTransaction(
509 {m_coinbase_txns[0]}, {COutPoint{m_coinbase_txns[0]->GetHash(), 0}}, /*input_height=*/1, {coinbaseKey},
510 std::vector<CTxOut>(num_children, CTxOut{5 * COIN, script}), /*submit=*/false))};
511
513 connman.FlushSendBuffer(peer); // Drop messages we sent, the transport is shared with the fake peer.
515 peer.fPauseSend = false;
516 return connman.ProcessMessagesOnce(peer);
517 }};
518
519 // Children arrive first and become orphans. Half of them pay no fee and will be rejected.
520 for (int i{0}; i < num_children; ++i) {
521 const CAmount output_value{i % 2 ? 5 * COIN : 4 * COIN};
522 send_tx(MakeTransactionRef(CreateValidMempoolTransaction(parent, i, /*input_height=*/101, coinbaseKey, script, output_value, /*submit=*/false)));
523 }
525 BOOST_CHECK_EQUAL(mempool.size(), 0U);
526
527 // Accepting the parent schedules all children for reconsideration.
528 BOOST_CHECK(send_tx(parent));
530 BOOST_CHECK_EQUAL(mempool.size(), 1U);
531
532 // Each call accepts or rejects exactly one orphan, whether it is valid or not.
533 for (int i{1}; i <= num_children; ++i) {
534 BOOST_CHECK(connman.ProcessMessagesOnce(peer));
536 }
537 BOOST_CHECK_EQUAL(mempool.size(), 1U + num_children / 2);
538 BOOST_CHECK(!connman.ProcessMessagesOnce(peer));
539
540 peerman.FinalizeNode(peer);
541}
542
int64_t CAmount
Amount in satoshis (Can be negative)
Definition amount.h:12
constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition amount.h:15
constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME
Definition banman.h:19
node::NodeContext m_node
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
Definition protocol.h:387
uint16_t GetDefaultPort() const
Definition chainparams.h:91
Network address.
Definition netaddress.h:113
bool IsRoutable() const
bool SetSpecial(std::string_view addr)
Parse a Tor or I2P address and set this object to it.
Information about a peer.
Definition net.h:686
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition transaction.h:30
Serialized script, used inside transaction inputs and outputs.
Definition script.h:406
A combination of a network address (CNetAddr) and a (TCP) port.
Definition netaddress.h:531
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition txmempool.h:188
unsigned long size() const
Definition txmempool.h:496
An output of a transaction.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Definition time.h:54
void set(NodeSeconds t)
Set mocktime.
Definition time.h:71
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
Definition net.h:1047
virtual void FinalizeNode(const CNode &node)=0
Handle removal of a peer (clear state)
virtual bool SendMessages(CNode &node) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex)=0
Send queued protocol messages to a given node.
virtual std::vector< node::TxOrphanage::OrphanInfo > GetOrphanTransactions()=0
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
std::vector< B > randbytes(size_t len) noexcept
Generate random bytes.
Definition random.h:297
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Definition random.h:204
ConnectionType
Different types of connections to a peer.
@ PRIVATE_BROADCAST
Private broadcast connections are short-lived and only opened to privacy networks (Tor,...
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ INBOUND
Inbound connections are those initiated by a peer.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition cs_main.cpp:8
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(stale_tip_peer_management, OutboundTest)
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
static CService ip(uint32_t i)
static const std::string addr1
Definition key_tests.cpp:31
CSerializedNetMsg Make(std::string msg_type, Args &&... args)
constexpr const char * TX
The tx message transmits a single transaction.
Definition protocol.h:117
constexpr unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition net.h:82
int64_t NodeId
Definition net.h:108
constexpr int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition net.h:74
constexpr int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition net.h:70
static constexpr auto MINIMUM_CONNECT_TIME
Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict.
std::string OnionToString(std::span< const uint8_t > addr)
constexpr size_t ADDR_TORV3_SIZE
Size of TORv3 address (in bytes).
Definition netaddress.h:93
#define BOOST_CHECK_EQUAL(v1, v2)
Definition object.cpp:17
#define BOOST_CHECK(expr)
Definition object.cpp:16
constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
ServiceFlags
nServices flags
Definition protocol.h:321
@ NODE_NONE
Definition protocol.h:324
@ NODE_WITNESS
Definition protocol.h:332
@ NODE_NETWORK
Definition protocol.h:327
constexpr int PROTOCOL_VERSION
network protocol versioning
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Definition solver.cpp:213
FastRandomContext m_rng
int m_max_automatic_connections
Definition net.h:1094
bool ReceiveMsgFrom(CNode &node, CSerializedNetMsg &&ser_msg) const
Definition net.cpp:111
void AddTestNode(CNode &node)
Definition net.h:62
void Handshake(CNode &node, bool successfully_connected, ServiceFlags remote_services, ServiceFlags local_services, int32_t version, bool relay_txs) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface bool ProcessMessagesOnce(CNode &node) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface
Definition net.h:105
void FlushSendBuffer(CNode &node) const
Definition net.cpp:99
void SetPeerConnectTimeout(std::chrono::seconds timeout)
Definition net.h:46
static time_point now() noexcept
Return current system time or mocked time, if set.
Definition time.cpp:38
void AddRandomOutboundPeer(NodeId &id, std::vector< CNode * > &vNodes, PeerManager &peerLogic, ConnmanTestMsg &connman, ConnectionType connType, bool onion_peer=false)
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Testing setup that configures a complete environment.
std::unique_ptr< CConnman > connman
Definition context.h:68
std::unique_ptr< CTxMemPool > mempool
Definition context.h:69
std::unique_ptr< AddrMan > addrman
Definition context.h:67
std::unique_ptr< ChainstateManager > chainman
Definition context.h:74
std::unique_ptr< node::Warnings > warnings
Manages all the node warnings.
Definition context.h:92
std::unique_ptr< PeerManager > peerman
Definition context.h:72
std::unique_ptr< const NetGroupManager > netgroupman
Definition context.h:70
#define LOCK(cs)
Definition sync.h:268
#define EXCLUSIVE_LOCKS_REQUIRED(...)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:82
FakeNodeClock clock