8#include <chainparams.h>
25#include <validation.h>
30#include <boost/test/unit_test.hpp>
142 node.fSuccessfullyConnected =
true;
160 const auto delta{3 * std::chrono::seconds{
m_node.
chainman->GetConsensus().nPowTargetSpacing} + 1s};
161 connman->Init(options);
162 std::vector<CNode *>
vNodes;
169 peerLogic->CheckForStaleTipAndEvictPeers();
180 peerLogic->CheckForStaleTipAndEvictPeers();
195 peerLogic->CheckForStaleTipAndEvictPeers();
202 vNodes.back()->fDisconnect =
false;
208 peerLogic->CheckForStaleTipAndEvictPeers();
222 peerLogic->CheckForStaleTipAndEvictPeers();
235 peerLogic->CheckForStaleTipAndEvictPeers();
243 connman->ClearTestNodes();
258 connman->Init(options);
259 std::vector<CNode*>
vNodes;
265 peerLogic->CheckForStaleTipAndEvictPeers();
273 peerLogic->CheckForStaleTipAndEvictPeers();
282 peerLogic->CheckForStaleTipAndEvictPeers();
290 vNodes.back()->fDisconnect =
false;
293 peerLogic->CheckForStaleTipAndEvictPeers();
303 connman->ClearTestNodes();
316 tor_netaddr.SetSpecial(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
325 std::array<CNode*, 5>
nodes;
327 banman->ClearBanned();
341 nodes[0]->fSuccessfullyConnected =
true;
342 connman->AddTestNode(*
nodes[0]);
362 nodes[1]->fSuccessfullyConnected =
true;
363 connman->AddTestNode(*
nodes[1]);
393 nodes[2]->fSuccessfullyConnected =
true;
394 connman->AddTestNode(*
nodes[2]);
407 connman->AddTestNode(*
nodes[3]);
430 connman->AddTestNode(*
nodes[4]);
440 connman->ClearTestNodes();
451 banman->ClearBanned();
509 {m_coinbase_txns[0]}, {
COutPoint{m_coinbase_txns[0]->GetHash(), 0}}, 1, {coinbaseKey},
515 peer.fPauseSend =
false;
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount COIN
The amount of satoshis in one BTC.
constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
uint16_t GetDefaultPort() const
bool SetSpecial(std::string_view addr)
Parse a Tor or I2P address and set this object to it.
Information about a peer.
An outpoint - a combination of a transaction hash and an index n into its vout.
Serialized script, used inside transaction inputs and outputs.
A combination of a network address (CNetAddr) and a (TCP) port.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
unsigned long size() const
An output of a transaction.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
void set(NodeSeconds t)
Set mocktime.
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
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.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
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.
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
CSerializedNetMsg Make(std::string msg_type, Args &&... args)
constexpr const char * TX
The tx message transmits a single transaction.
constexpr unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
constexpr int MAX_BLOCK_RELAY_ONLY_CONNECTIONS
Maximum number of block-relay-only outgoing connections.
constexpr int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
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).
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
ServiceFlags
nServices flags
constexpr int PROTOCOL_VERSION
network protocol versioning
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
int m_max_automatic_connections
bool ReceiveMsgFrom(CNode &node, CSerializedNetMsg &&ser_msg) const
void AddTestNode(CNode &node)
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
void FlushSendBuffer(CNode &node) const
void SetPeerConnectTimeout(std::chrono::seconds timeout)
static time_point now() noexcept
Return current system time or mocked time, if set.
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
std::unique_ptr< CTxMemPool > mempool
std::unique_ptr< AddrMan > addrman
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< node::Warnings > warnings
Manages all the node warnings.
std::unique_ptr< PeerManager > peerman
std::unique_ptr< const NetGroupManager > netgroupman
#define EXCLUSIVE_LOCKS_REQUIRED(...)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.