23#include <validation.h>
28#include <boost/test/unit_test.hpp>
54 auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *
m_node.
addrman);
56 static_cast<ConnmanTestMsg*
>(connman.get())->SetPeerConnectTimeout(99999);
65 peerLogic->InitializeNode(&dummyNode1);
83 dummyNode1.vSendMsg.clear();
105 peerLogic->FinalizeNode(dummyNode1);
116 node.fSuccessfullyConnected =
true;
124 auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *
m_node.
addrman);
134 connman->Init(options);
135 std::vector<CNode *> vNodes;
138 for (
int i = 0; i < max_outbound_full_relay; ++i) {
142 peerLogic->CheckForStaleTipAndEvictPeers();
153 peerLogic->CheckForStaleTipAndEvictPeers();
166 peerLogic->CheckForStaleTipAndEvictPeers();
167 for (
int i = 0; i < max_outbound_full_relay; ++i) {
173 vNodes.back()->fDisconnect =
false;
179 peerLogic->CheckForStaleTipAndEvictPeers();
180 for (
int i = 0; i < max_outbound_full_relay - 1; ++i) {
183 BOOST_CHECK(vNodes[max_outbound_full_relay-1]->fDisconnect ==
true);
187 peerLogic->FinalizeNode(*
node);
190 connman->ClearTestNodes();
197 auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *
m_node.
addrman);
203 tor_netaddr.
SetSpecial(
"pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
212 std::array<CNode*, 3> nodes;
214 banman->ClearBanned();
219 peerLogic->InitializeNode(nodes[0]);
220 nodes[0]->fSuccessfullyConnected =
true;
221 connman->AddTestNode(*nodes[0]);
224 LOCK(nodes[0]->cs_sendProcessing);
235 peerLogic->InitializeNode(nodes[1]);
236 nodes[1]->fSuccessfullyConnected =
true;
237 connman->AddTestNode(*nodes[1]);
240 LOCK(nodes[1]->cs_sendProcessing);
249 peerLogic->Misbehaving(nodes[1]->GetId(), 1,
"");
251 LOCK(nodes[1]->cs_sendProcessing);
266 peerLogic->InitializeNode(nodes[2]);
267 nodes[2]->fSuccessfullyConnected =
true;
268 connman->AddTestNode(*nodes[2]);
271 LOCK(nodes[2]->cs_sendProcessing);
282 peerLogic->FinalizeNode(*
node);
284 connman->ClearTestNodes();
291 auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *
m_node.
addrman);
295 banman->ClearBanned();
296 int64_t nStartTime =
GetTime();
302 peerLogic->InitializeNode(&dummyNode);
312 peerLogic->FinalizeNode(dummyNode);
320 return m_orphans.size();
325 std::map<uint256, OrphanTx>::iterator it;
327 if (it == m_orphans.end())
328 it = m_orphans.begin();
329 return it->second.tx;
335 std::vector<unsigned char> keydata;
337 key.
Set(keydata.data(), keydata.data() + keydata.size(),
true);
360 for (
int i = 0; i < 50; i++)
364 tx.
vin[0].prevout.n = 0;
375 for (
int i = 0; i < 50; i++)
381 tx.
vin[0].prevout.n = 0;
382 tx.
vin[0].prevout.hash = txPrev->GetHash();
392 for (
int i = 0; i < 10; i++)
401 for (
unsigned int j = 0; j < tx.
vin.size(); j++)
403 tx.
vin[j].prevout.n = j;
404 tx.
vin[j].prevout.hash = txPrev->GetHash();
409 for (
unsigned int j = 1; j < tx.
vin.size(); j++)
410 tx.
vin[j].scriptSig = tx.
vin[0].scriptSig;
416 for (
NodeId i = 0; i < 3; i++)
uint256 ArithToUint256(const arith_uint256 &a)
static constexpr unsigned int DEFAULT_MISBEHAVING_BANTIME
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
const CChainParams & Params()
Return the currently selected parameters.
A CService with information about it as peer.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const Consensus::Params & GetConsensus() const
uint16_t GetDefaultPort() const
An encapsulated private key.
bool IsValid() const
Check whether this private key is valid.
CPubKey GetPubKey() const
Compute the public key from a private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
bool SetSpecial(const std::string &addr)
Parse a Tor or I2P address and set this object to it.
Information about a peer.
RecursiveMutex cs_sendProcessing
void SetCommonVersion(int greatest_common_version)
std::atomic_bool fSuccessfullyConnected
fSuccessfullyConnected is set to true on receiving VERACK from the peer.
std::atomic_bool fDisconnect
A combination of a network address (CNetAddr) and a (TCP) port.
std::vector< unsigned char > randbytes(size_t len)
Generate random bytes.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKey(const CKey &key)
virtual void InitializeNode(CNode *pnode)=0
Initialize a peer (setup state, queue any initial messages)
static std::unique_ptr< PeerManager > make(const CChainParams &chainparams, CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, bool ignore_incoming_txs)
A class to track orphan transactions (failed on TX_MISSING_INPUTS) Since we cannot distinguish orphan...
void EraseForPeer(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Erase all orphans announced by a peer (eg, after that peer disconnects)
bool AddTx(const CTransactionRef &tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
Add a new orphan transaction.
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.
CTransactionRef RandomOrphan() EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
size_t CountOrphans() const EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans)
256-bit unsigned big integer.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction)
static void AddRandomOutboundPeer(std::vector< CNode * > &vNodes, PeerManager &peerLogic, ConnmanTestMsg &connman)
static void MakeNewKeyWithFastRandomContext(CKey &key)
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds)
static CService ip(uint32_t i)
static const std::string addr1
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS
The maximum number of peer connections to maintain.
@ 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.
static const int MAX_FEELER_CONNECTIONS
Maximum number of feeler connections.
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS
Maximum number of automatic outgoing nodes over which we'll relay everything (blocks,...
static const int DISCOURAGEMENT_THRESHOLD
Threshold for marking a node to be discouraged, e.g.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
ServiceFlags
nServices flags
FastRandomContext g_insecure_rand_ctx
This global and the helpers that use it are not thread-safe.
static constexpr CAmount CENT
static uint256 InsecureRand256()
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.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int m_max_outbound_full_relay
A mutable version of CTransaction.
std::vector< CTxOut > vout
void AddTestNode(CNode &node)
int64_t nPowTargetSpacing
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< AddrMan > addrman
std::unique_ptr< CTxMemPool > mempool
Testing setup that configures a complete environment.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
RecursiveMutex g_cs_orphans
Guards orphan transactions and extra txs for compact blocks.
static const int PROTOCOL_VERSION
network protocol versioning