Bitcoin Core  22.99.0
P2P Digital Currency
denialofservice_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2021 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 <arith_uint256.h>
8 #include <banman.h>
9 #include <chainparams.h>
10 #include <net.h>
11 #include <net_processing.h>
12 #include <pubkey.h>
13 #include <script/sign.h>
14 #include <script/signingprovider.h>
15 #include <script/standard.h>
16 #include <serialize.h>
17 #include <test/util/net.h>
18 #include <test/util/setup_common.h>
19 #include <txorphanage.h>
20 #include <util/string.h>
21 #include <util/system.h>
22 #include <util/time.h>
23 #include <validation.h>
24 
25 #include <array>
26 #include <stdint.h>
27 
28 #include <boost/test/unit_test.hpp>
29 
30 static CService ip(uint32_t i)
31 {
32  struct in_addr s;
33  s.s_addr = i;
34  return CService(CNetAddr(s), Params().GetDefaultPort());
35 }
36 
37 static NodeId id = 0;
38 
39 void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds);
40 
41 BOOST_FIXTURE_TEST_SUITE(denialofservice_tests, TestingSetup)
42 
43 // Test eviction of an outbound peer whose chain never advances
44 // Mock a node connection, and use mocktime to simulate a peer
45 // which never sends any headers messages. PeerLogic should
46 // decide to evict that outbound peer, after the appropriate timeouts.
47 // Note that we protect 4 outbound nodes from being subject to
48 // this logic; this test takes advantage of that protection only
49 // being applied to nodes which send headers with sufficient
50 // work.
51 BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
52 {
53  const CChainParams& chainparams = Params();
54  auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
55  // Disable inactivity checks for this test to avoid interference
56  static_cast<ConnmanTestMsg*>(connman.get())->SetPeerConnectTimeout(99999s);
57  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
58  *m_node.chainman, *m_node.mempool, false);
59 
60  // Mock an outbound peer
61  CAddress addr1(ip(0xa0b0c001), NODE_NONE);
62  CNode dummyNode1{id++,
64  /*sock=*/nullptr,
65  addr1,
66  /*nKeyedNetGroupIn=*/0,
67  /*nLocalHostNonceIn=*/0,
68  CAddress(),
69  /*addrNameIn=*/"",
71  /*inbound_onion=*/false};
72  dummyNode1.SetCommonVersion(PROTOCOL_VERSION);
73 
74  peerLogic->InitializeNode(&dummyNode1);
75  dummyNode1.fSuccessfullyConnected = true;
76 
77  // This test requires that we have a chain with non-zero work.
78  {
79  LOCK(cs_main);
80  BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr);
81  BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0);
82  }
83 
84  // Test starts here
85  {
86  LOCK(dummyNode1.cs_sendProcessing);
87  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
88  }
89  {
90  LOCK(dummyNode1.cs_vSend);
91  BOOST_CHECK(dummyNode1.vSendMsg.size() > 0);
92  dummyNode1.vSendMsg.clear();
93  }
94 
95  int64_t nStartTime = GetTime();
96  // Wait 21 minutes
97  SetMockTime(nStartTime+21*60);
98  {
99  LOCK(dummyNode1.cs_sendProcessing);
100  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders
101  }
102  {
103  LOCK(dummyNode1.cs_vSend);
104  BOOST_CHECK(dummyNode1.vSendMsg.size() > 0);
105  }
106  // Wait 3 more minutes
107  SetMockTime(nStartTime+24*60);
108  {
109  LOCK(dummyNode1.cs_sendProcessing);
110  BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in disconnect
111  }
112  BOOST_CHECK(dummyNode1.fDisconnect == true);
113 
114  peerLogic->FinalizeNode(dummyNode1);
115 }
116 
117 static void AddRandomOutboundPeer(std::vector<CNode*>& vNodes, PeerManager& peerLogic, ConnmanTestMsg& connman, ConnectionType connType)
118 {
120  vNodes.emplace_back(new CNode{id++,
122  /*sock=*/nullptr,
123  addr,
124  /*nKeyedNetGroupIn=*/0,
125  /*nLocalHostNonceIn=*/0,
126  CAddress(),
127  /*addrNameIn=*/"",
128  connType,
129  /*inbound_onion=*/false});
130  CNode &node = *vNodes.back();
131  node.SetCommonVersion(PROTOCOL_VERSION);
132 
133  peerLogic.InitializeNode(&node);
134  node.fSuccessfullyConnected = true;
135 
136  connman.AddTestNode(node);
137 }
138 
139 BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
140 {
141  const CChainParams& chainparams = Params();
142  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
143  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
144  *m_node.chainman, *m_node.mempool, false);
145 
146  constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
147  CConnman::Options options;
149  options.m_max_outbound_full_relay = max_outbound_full_relay;
151 
152  const auto time_init{GetTime<std::chrono::seconds>()};
153  SetMockTime(time_init);
154  const auto time_later{time_init + 3 * std::chrono::seconds{chainparams.GetConsensus().nPowTargetSpacing} + 1s};
155  connman->Init(options);
156  std::vector<CNode *> vNodes;
157 
158  // Mock some outbound peers
159  for (int i = 0; i < max_outbound_full_relay; ++i) {
160  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
161  }
162 
163  peerLogic->CheckForStaleTipAndEvictPeers();
164 
165  // No nodes should be marked for disconnection while we have no extra peers
166  for (const CNode *node : vNodes) {
167  BOOST_CHECK(node->fDisconnect == false);
168  }
169 
170  SetMockTime(time_later);
171 
172  // Now tip should definitely be stale, and we should look for an extra
173  // outbound peer
174  peerLogic->CheckForStaleTipAndEvictPeers();
175  BOOST_CHECK(connman->GetTryNewOutboundPeer());
176 
177  // Still no peers should be marked for disconnection
178  for (const CNode *node : vNodes) {
179  BOOST_CHECK(node->fDisconnect == false);
180  }
181 
182  // If we add one more peer, something should get marked for eviction
183  // on the next check (since we're mocking the time to be in the future, the
184  // required time connected check should be satisfied).
185  SetMockTime(time_init);
186  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::OUTBOUND_FULL_RELAY);
187  SetMockTime(time_later);
188 
189  peerLogic->CheckForStaleTipAndEvictPeers();
190  for (int i = 0; i < max_outbound_full_relay; ++i) {
191  BOOST_CHECK(vNodes[i]->fDisconnect == false);
192  }
193  // Last added node should get marked for eviction
194  BOOST_CHECK(vNodes.back()->fDisconnect == true);
195 
196  vNodes.back()->fDisconnect = false;
197 
198  // Update the last announced block time for the last
199  // peer, and check that the next newest node gets evicted.
200  UpdateLastBlockAnnounceTime(vNodes.back()->GetId(), GetTime());
201 
202  peerLogic->CheckForStaleTipAndEvictPeers();
203  for (int i = 0; i < max_outbound_full_relay - 1; ++i) {
204  BOOST_CHECK(vNodes[i]->fDisconnect == false);
205  }
206  BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect == true);
207  BOOST_CHECK(vNodes.back()->fDisconnect == false);
208 
209  for (const CNode *node : vNodes) {
210  peerLogic->FinalizeNode(*node);
211  }
212 
213  connman->ClearTestNodes();
214 }
215 
216 BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
217 {
218  const CChainParams& chainparams = Params();
219  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
220  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr,
221  *m_node.chainman, *m_node.mempool, false);
222 
223  constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
224  constexpr int64_t MINIMUM_CONNECT_TIME{30};
225  CConnman::Options options;
228  options.m_max_outbound_block_relay = max_outbound_block_relay;
229 
230  connman->Init(options);
231  std::vector<CNode*> vNodes;
232 
233  // Add block-relay-only peers up to the limit
234  for (int i = 0; i < max_outbound_block_relay; ++i) {
235  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::BLOCK_RELAY);
236  }
237  peerLogic->CheckForStaleTipAndEvictPeers();
238 
239  for (int i = 0; i < max_outbound_block_relay; ++i) {
240  BOOST_CHECK(vNodes[i]->fDisconnect == false);
241  }
242 
243  // Add an extra block-relay-only peer breaking the limit (mocks logic in ThreadOpenConnections)
244  AddRandomOutboundPeer(vNodes, *peerLogic, *connman, ConnectionType::BLOCK_RELAY);
245  peerLogic->CheckForStaleTipAndEvictPeers();
246 
247  // The extra peer should only get marked for eviction after MINIMUM_CONNECT_TIME
248  for (int i = 0; i < max_outbound_block_relay; ++i) {
249  BOOST_CHECK(vNodes[i]->fDisconnect == false);
250  }
251  BOOST_CHECK(vNodes.back()->fDisconnect == false);
252 
254  peerLogic->CheckForStaleTipAndEvictPeers();
255  for (int i = 0; i < max_outbound_block_relay; ++i) {
256  BOOST_CHECK(vNodes[i]->fDisconnect == false);
257  }
258  BOOST_CHECK(vNodes.back()->fDisconnect == true);
259 
260  // Update the last block time for the extra peer,
261  // and check that the next youngest peer gets evicted.
262  vNodes.back()->fDisconnect = false;
263  vNodes.back()->m_last_block_time = GetTime<std::chrono::seconds>();
264 
265  peerLogic->CheckForStaleTipAndEvictPeers();
266  for (int i = 0; i < max_outbound_block_relay - 1; ++i) {
267  BOOST_CHECK(vNodes[i]->fDisconnect == false);
268  }
269  BOOST_CHECK(vNodes[max_outbound_block_relay - 1]->fDisconnect == true);
270  BOOST_CHECK(vNodes.back()->fDisconnect == false);
271 
272  for (const CNode* node : vNodes) {
273  peerLogic->FinalizeNode(*node);
274  }
275  connman->ClearTestNodes();
276 }
277 
278 BOOST_AUTO_TEST_CASE(peer_discouragement)
279 {
280  const CChainParams& chainparams = Params();
281  auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
282  auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman);
283  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
284  *m_node.chainman, *m_node.mempool, false);
285 
286  CNetAddr tor_netaddr;
287  BOOST_REQUIRE(
288  tor_netaddr.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
289  const CService tor_service{tor_netaddr, Params().GetDefaultPort()};
290 
291  const std::array<CAddress, 3> addr{CAddress{ip(0xa0b0c001), NODE_NONE},
292  CAddress{ip(0xa0b0c002), NODE_NONE},
293  CAddress{tor_service, NODE_NONE}};
294 
295  const CNetAddr other_addr{ip(0xa0b0ff01)}; // Not any of addr[].
296 
297  std::array<CNode*, 3> nodes;
298 
299  banman->ClearBanned();
300  nodes[0] = new CNode{id++,
301  NODE_NETWORK,
302  /*sock=*/nullptr,
303  addr[0],
304  /*nKeyedNetGroupIn=*/0,
305  /*nLocalHostNonceIn=*/0,
306  CAddress(),
307  /*addrNameIn=*/"",
309  /*inbound_onion=*/false};
310  nodes[0]->SetCommonVersion(PROTOCOL_VERSION);
311  peerLogic->InitializeNode(nodes[0]);
312  nodes[0]->fSuccessfullyConnected = true;
313  connman->AddTestNode(*nodes[0]);
314  peerLogic->Misbehaving(nodes[0]->GetId(), DISCOURAGEMENT_THRESHOLD, /*message=*/""); // Should be discouraged
315  {
316  LOCK(nodes[0]->cs_sendProcessing);
317  BOOST_CHECK(peerLogic->SendMessages(nodes[0]));
318  }
319  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
320  BOOST_CHECK(nodes[0]->fDisconnect);
321  BOOST_CHECK(!banman->IsDiscouraged(other_addr)); // Different address, not discouraged
322 
323  nodes[1] = new CNode{id++,
324  NODE_NETWORK,
325  /*sock=*/nullptr,
326  addr[1],
327  /*nKeyedNetGroupIn=*/1,
328  /*nLocalHostNonceIn=*/1,
329  CAddress(),
330  /*addrNameIn=*/"",
332  /*inbound_onion=*/false};
333  nodes[1]->SetCommonVersion(PROTOCOL_VERSION);
334  peerLogic->InitializeNode(nodes[1]);
335  nodes[1]->fSuccessfullyConnected = true;
336  connman->AddTestNode(*nodes[1]);
337  peerLogic->Misbehaving(nodes[1]->GetId(), DISCOURAGEMENT_THRESHOLD - 1, /*message=*/"");
338  {
339  LOCK(nodes[1]->cs_sendProcessing);
340  BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
341  }
342  // [0] is still discouraged/disconnected.
343  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
344  BOOST_CHECK(nodes[0]->fDisconnect);
345  // [1] is not discouraged/disconnected yet.
346  BOOST_CHECK(!banman->IsDiscouraged(addr[1]));
347  BOOST_CHECK(!nodes[1]->fDisconnect);
348  peerLogic->Misbehaving(nodes[1]->GetId(), 1, /*message=*/""); // [1] reaches discouragement threshold
349  {
350  LOCK(nodes[1]->cs_sendProcessing);
351  BOOST_CHECK(peerLogic->SendMessages(nodes[1]));
352  }
353  // Expect both [0] and [1] to be discouraged/disconnected now.
354  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
355  BOOST_CHECK(nodes[0]->fDisconnect);
356  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
357  BOOST_CHECK(nodes[1]->fDisconnect);
358 
359  // Make sure non-IP peers are discouraged and disconnected properly.
360 
361  nodes[2] = new CNode{id++,
362  NODE_NETWORK,
363  /*sock=*/nullptr,
364  addr[2],
365  /*nKeyedNetGroupIn=*/1,
366  /*nLocalHostNonceIn=*/1,
367  CAddress(),
368  /*addrNameIn=*/"",
370  /*inbound_onion=*/false};
371  nodes[2]->SetCommonVersion(PROTOCOL_VERSION);
372  peerLogic->InitializeNode(nodes[2]);
373  nodes[2]->fSuccessfullyConnected = true;
374  connman->AddTestNode(*nodes[2]);
375  peerLogic->Misbehaving(nodes[2]->GetId(), DISCOURAGEMENT_THRESHOLD, /*message=*/"");
376  {
377  LOCK(nodes[2]->cs_sendProcessing);
378  BOOST_CHECK(peerLogic->SendMessages(nodes[2]));
379  }
380  BOOST_CHECK(banman->IsDiscouraged(addr[0]));
381  BOOST_CHECK(banman->IsDiscouraged(addr[1]));
382  BOOST_CHECK(banman->IsDiscouraged(addr[2]));
383  BOOST_CHECK(nodes[0]->fDisconnect);
384  BOOST_CHECK(nodes[1]->fDisconnect);
385  BOOST_CHECK(nodes[2]->fDisconnect);
386 
387  for (CNode* node : nodes) {
388  peerLogic->FinalizeNode(*node);
389  }
390  connman->ClearTestNodes();
391 }
392 
394 {
395  const CChainParams& chainparams = Params();
396  auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
397  auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman);
398  auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, banman.get(),
399  *m_node.chainman, *m_node.mempool, false);
400 
401  banman->ClearBanned();
402  int64_t nStartTime = GetTime();
403  SetMockTime(nStartTime); // Overrides future calls to GetTime()
404 
405  CAddress addr(ip(0xa0b0c001), NODE_NONE);
406  CNode dummyNode{id++,
407  NODE_NETWORK,
408  /*sock=*/nullptr,
409  addr,
410  /*nKeyedNetGroupIn=*/4,
411  /*nLocalHostNonceIn=*/4,
412  CAddress(),
413  /*addrNameIn=*/"",
415  /*inbound_onion=*/false};
416  dummyNode.SetCommonVersion(PROTOCOL_VERSION);
417  peerLogic->InitializeNode(&dummyNode);
418  dummyNode.fSuccessfullyConnected = true;
419 
420  peerLogic->Misbehaving(dummyNode.GetId(), DISCOURAGEMENT_THRESHOLD, /*message=*/"");
421  {
422  LOCK(dummyNode.cs_sendProcessing);
423  BOOST_CHECK(peerLogic->SendMessages(&dummyNode));
424  }
425  BOOST_CHECK(banman->IsDiscouraged(addr));
426 
427  peerLogic->FinalizeNode(dummyNode);
428 }
429 
431 {
432 public:
434  {
435  return m_orphans.size();
436  }
437 
439  {
440  std::map<uint256, OrphanTx>::iterator it;
441  it = m_orphans.lower_bound(InsecureRand256());
442  if (it == m_orphans.end())
443  it = m_orphans.begin();
444  return it->second.tx;
445  }
446 };
447 
449 {
450  std::vector<unsigned char> keydata;
451  keydata = g_insecure_rand_ctx.randbytes(32);
452  key.Set(keydata.data(), keydata.data() + keydata.size(), /*fCompressedIn=*/true);
453  assert(key.IsValid());
454 }
455 
456 BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
457 {
458  // This test had non-deterministic coverage due to
459  // randomly selected seeds.
460  // This seed is chosen so that all branches of the function
461  // ecdsa_signature_parse_der_lax are executed during this test.
462  // Specifically branches that run only when an ECDSA
463  // signature's R and S values have leading zeros.
465 
466  TxOrphanageTest orphanage;
467  CKey key;
469  FillableSigningProvider keystore;
470  BOOST_CHECK(keystore.AddKey(key));
471 
473 
474  // 50 orphan transactions:
475  for (int i = 0; i < 50; i++)
476  {
478  tx.vin.resize(1);
479  tx.vin[0].prevout.n = 0;
480  tx.vin[0].prevout.hash = InsecureRand256();
481  tx.vin[0].scriptSig << OP_1;
482  tx.vout.resize(1);
483  tx.vout[0].nValue = 1*CENT;
484  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
485 
486  orphanage.AddTx(MakeTransactionRef(tx), i);
487  }
488 
489  // ... and 50 that depend on other orphans:
490  for (int i = 0; i < 50; i++)
491  {
492  CTransactionRef txPrev = orphanage.RandomOrphan();
493 
495  tx.vin.resize(1);
496  tx.vin[0].prevout.n = 0;
497  tx.vin[0].prevout.hash = txPrev->GetHash();
498  tx.vout.resize(1);
499  tx.vout[0].nValue = 1*CENT;
500  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
501  BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
502 
503  orphanage.AddTx(MakeTransactionRef(tx), i);
504  }
505 
506  // This really-big orphan should be ignored:
507  for (int i = 0; i < 10; i++)
508  {
509  CTransactionRef txPrev = orphanage.RandomOrphan();
510 
512  tx.vout.resize(1);
513  tx.vout[0].nValue = 1*CENT;
514  tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
515  tx.vin.resize(2777);
516  for (unsigned int j = 0; j < tx.vin.size(); j++)
517  {
518  tx.vin[j].prevout.n = j;
519  tx.vin[j].prevout.hash = txPrev->GetHash();
520  }
521  BOOST_CHECK(SignSignature(keystore, *txPrev, tx, 0, SIGHASH_ALL));
522  // Re-use same signature for other inputs
523  // (they don't have to be valid for this test)
524  for (unsigned int j = 1; j < tx.vin.size(); j++)
525  tx.vin[j].scriptSig = tx.vin[0].scriptSig;
526 
527  BOOST_CHECK(!orphanage.AddTx(MakeTransactionRef(tx), i));
528  }
529 
530  // Test EraseOrphansFor:
531  for (NodeId i = 0; i < 3; i++)
532  {
533  size_t sizeBefore = orphanage.CountOrphans();
534  orphanage.EraseForPeer(i);
535  BOOST_CHECK(orphanage.CountOrphans() < sizeBefore);
536  }
537 
538  // Test LimitOrphanTxSize() function:
539  orphanage.LimitOrphans(40);
540  BOOST_CHECK(orphanage.CountOrphans() <= 40);
541  orphanage.LimitOrphans(10);
542  BOOST_CHECK(orphanage.CountOrphans() <= 10);
543  orphanage.LimitOrphans(0);
544  BOOST_CHECK(orphanage.CountOrphans() == 0);
545 }
546 
NodeId
int64_t NodeId
Definition: net.h:88
CService
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:528
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:366
arith_uint256.h
assert
assert(!tx.IsCoinBase())
g_insecure_rand_ctx
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
Definition: setup_common.cpp:58
AddRandomOutboundPeer
static void AddRandomOutboundPeer(std::vector< CNode * > &vNodes, PeerManager &peerLogic, ConnmanTestMsg &connman, ConnectionType connType)
Definition: denialofservice_tests.cpp:117
setup_common.h
MakeNewKeyWithFastRandomContext
static void MakeNewKeyWithFastRandomContext(CKey &key)
Definition: denialofservice_tests.cpp:448
node::NodeContext::addrman
std::unique_ptr< AddrMan > addrman
Definition: context.h:43
FillableSigningProvider
Fillable signing provider that keeps keys in an address->secret map.
Definition: signingprovider.h:90
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:310
string.h
MINIMUM_CONNECT_TIME
static constexpr auto MINIMUM_CONNECT_TIME
Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict.
Definition: net_processing.cpp:73
CNetAddr
Network address.
Definition: netaddress.h:118
arith_uint256
256-bit unsigned big integer.
Definition: arith_uint256.h:250
DEFAULT_MAX_PEER_CONNECTIONS
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
Definition: net.h:72
InsecureRand256
static uint256 InsecureRand256()
Definition: setup_common.h:73
CKey::Set
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
Definition: key.h:73
ConnectionType::OUTBOUND_FULL_RELAY
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
CNode
Information about a peer.
Definition: net.h:394
UpdateLastBlockAnnounceTime
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
Definition: net_processing.cpp:1181
m_node
node::NodeContext m_node
Definition: bitcoin-gui.cpp:36
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
GetTime
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:26
FastRandomContext::randbytes
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
Definition: random.cpp:623
MakeTransactionRef
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:407
TxOrphanageTest
Definition: denialofservice_tests.cpp:430
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
PeerManager::make
static std::unique_ptr< PeerManager > make(const CChainParams &chainparams, CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
Definition: net_processing.cpp:1498
ServiceFlags
ServiceFlags
nServices flags
Definition: protocol.h:271
NODE_NETWORK
@ NODE_NETWORK
Definition: protocol.h:277
pubkey.h
chainparams.h
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:406
TxOrphanage::LimitOrphans
void EraseForBlock(const CBlock &block) LOCKS_EXCLUDED(unsigned int LimitOrphans(unsigned int max_orphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans included in or invalidated by a new block.
Definition: txorphanage.h:44
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
node::NodeContext::mempool
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:45
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
FillableSigningProvider::AddKey
virtual bool AddKey(const CKey &key)
Definition: signingprovider.h:151
FastRandomContext::randbits
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Definition: random.h:184
ConnmanTestMsg
Definition: net.h:19
Consensus::Params::nPowTargetSpacing
int64_t nPowTargetSpacing
Definition: params.h:103
signingprovider.h
OP_1
@ OP_1
Definition: script.h:76
ConnmanTestMsg::AddTestNode
void AddTestNode(CNode &node)
Definition: net.h:27
NetEventsInterface::InitializeNode
virtual void InitializeNode(CNode *pnode)=0
Initialize a peer (setup state, queue any initial messages)
ConnectionType::INBOUND
@ INBOUND
Inbound connections are those initiated by a peer.
MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
Definition: net.h:62
banman.h
CNetAddr::SetSpecial
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Definition: netaddress.cpp:212
SignSignature
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType)
Produce a script signature for a transaction.
Definition: sign.cpp:516
ip
static CService ip(uint32_t i)
Definition: denialofservice_tests.cpp:30
net.h
SetMockTime
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
Definition: time.cpp:101
CENT
static constexpr CAmount CENT
Definition: setup_common.h:78
time.h
CKey::IsValid
bool IsValid() const
Check whether this private key is valid.
Definition: key.h:93
sign.h
standard.h
CConnman::Options::m_max_outbound_block_relay
int m_max_outbound_block_relay
Definition: net.h:759
PeerManager
Definition: net_processing.h:37
TxOrphanageTest::RandomOrphan
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Definition: denialofservice_tests.cpp:438
MAX_FEELER_CONNECTIONS
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
Definition: net.h:68
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:187
addr1
static const std::string addr1
Definition: key_tests.cpp:24
net_processing.h
CConnman::Options
Definition: net.h:754
CConnman::Options::nMaxConnections
int nMaxConnections
Definition: net.h:757
NODE_NONE
@ NODE_NONE
Definition: protocol.h:274
NODE_WITNESS
@ NODE_WITNESS
Definition: protocol.h:284
system.h
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:367
PKHash
Definition: standard.h:79
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
Definition: denialofservice_tests.cpp:51
SIGHASH_ALL
@ SIGHASH_ALL
Definition: interpreter.h:28
CConnman::Options::nMaxFeeler
int nMaxFeeler
Definition: net.h:761
MAX_BLOCK_RELAY_ONLY_CONNECTIONS
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
Definition: net.h:66
CAddress
A CService with information about it as peer.
Definition: protocol.h:358
CKey
An encapsulated private key.
Definition: key.h:26
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
LOCK
#define LOCK(cs)
Definition: sync.h:226
DEFAULT_MISBEHAVING_BANTIME
static constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME
Definition: banman.h:19
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:561
node::NodeContext::chainman
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:48
DISCOURAGEMENT_THRESHOLD
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
Definition: net_processing.h:24
TestingSetup
Testing setup that configures a complete environment.
Definition: setup_common.h:107
TxOrphanageTest::CountOrphans
size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Definition: denialofservice_tests.cpp:433
node
Definition: init.h:22
serialize.h
TxOrphanage::AddTx
bool AddTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add a new orphan transaction.
Definition: txorphanage.cpp:20
ConnectionType::BLOCK_RELAY
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
CConnman::Options::m_max_outbound_full_relay
int m_max_outbound_full_relay
Definition: net.h:758
TxOrphanage
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
Definition: txorphanage.h:21
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:364
TxOrphanage::EraseForPeer
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans announced by a peer (eg, after that peer disconnects)
Definition: txorphanage.cpp:88
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:138
txorphanage.h
ConnectionType
ConnectionType
Different types of connections to a peer.
Definition: net.h:121
g_cs_orphans
RecursiveMutex g_cs_orphans
Guards orphan transactions and extra txs for compact blocks.
Definition: txorphanage.cpp:18
FastRandomContext
Fast randomness source.
Definition: random.h:131
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition: object.cpp:17
ArithToUint256
uint256 ArithToUint256(const arith_uint256 &a)
Definition: arith_uint256.cpp:246
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
CChainParams::GetDefaultPort
uint16_t GetDefaultPort() const
Definition: chainparams.h:84