mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
6c07c2c80c
b3a515c0bec97633a76bec101af47c3c90c0b749 Clarify comments around outbound peer eviction (Suhas Daftuar) daffaf03fbede6c01287779e464379ee3acb005a Periodically make block-relay connections and sync headers (Suhas Daftuar) 3cc8a7a0f5fa183cd7f0cf5e56f16f9a9d1f2441 Use conn_type to identify block-relay peers, rather than m_tx_relay == nullptr (Suhas Daftuar) 91d61952a82af3e8887e8ae532ecc19d87fe9073 Simplify and clarify extra outbound peer counting (Suhas Daftuar) Pull request description: To make eclipse attacks more difficult, regularly initiate outbound connections and stay connected long enough to sync headers and potentially learn of new blocks. If we learn a new block, rotate out an existing block-relay peer in favor of the new peer. This augments the existing outbound peer rotation that exists -- currently we make new full-relay connections when our tip is stale, which we disconnect after waiting a small time to see if we learn a new block. As block-relay connections use minimal bandwidth, we can make these connections regularly and not just when our tip is stale. Like feeler connections, these connections are not aggressive; whenever our timer fires (once every 5 minutes on average), we'll try to initiate a new block-relay connection as described, but if we fail to connect we just wait for our timer to fire again before repeating with a new peer. ACKs for top commit: ariard: Code Review ACK b3a515c, only change since last time is dropping a useless `cs_main` taking. I manually tested a previous version of the PR, and not substantial change has been introduced since then which would alter behavior IMO. jonatack: Tested ACK b3a515c0bec97633a76bec101af47c3c90c0b749 over several weeks, though this change and behavior could benefit from test coverage and other follow-ups (refactoring, etc.) described in the review feedback. I did not verify the behavior of `m_start_extra_block_relay_peers` only being enabled after initial chain sync. Since my last review, one unneeded `cs_main` lock was removed. Tree-SHA512: 75fc6f8e8003e88e93f86b845caf2d30b8b9c0dbb0a6b8aabe4e24ea4f6327351f736a068a3b2720a8a581b789942a3a47f921e2afdb47e88bc50d078aa37b6f
86 lines
3.3 KiB
C++
86 lines
3.3 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_NET_PROCESSING_H
|
|
#define BITCOIN_NET_PROCESSING_H
|
|
|
|
#include <net.h>
|
|
#include <sync.h>
|
|
#include <validationinterface.h>
|
|
|
|
#include <atomic>
|
|
|
|
class CAddrMan;
|
|
class CTxMemPool;
|
|
class ChainstateManager;
|
|
class CCoinJoinServer;
|
|
struct CJContext;
|
|
struct LLMQContext;
|
|
class CGovernanceManager;
|
|
|
|
extern RecursiveMutex cs_main;
|
|
extern RecursiveMutex g_cs_orphans;
|
|
|
|
/** Default for -maxorphantxsize, maximum size in megabytes the orphan map can grow before entries are removed */
|
|
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS_SIZE = 10; // this allows around 100 TXs of max size (and many more of normal size)
|
|
/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
|
|
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
|
|
static const bool DEFAULT_PEERBLOOMFILTERS = true;
|
|
static const bool DEFAULT_PEERBLOCKFILTERS = false;
|
|
|
|
struct CNodeStateStats {
|
|
int m_misbehavior_score = 0;
|
|
int nSyncHeight = -1;
|
|
int nCommonHeight = -1;
|
|
std::vector<int> vHeightInFlight;
|
|
};
|
|
|
|
class PeerManager : public CValidationInterface, public NetEventsInterface
|
|
{
|
|
public:
|
|
static std::unique_ptr<PeerManager> make(const CChainParams& chainparams, CConnman& connman, CAddrMan& addrman,
|
|
BanMan* banman, CScheduler &scheduler, ChainstateManager& chainman,
|
|
CTxMemPool& pool, CGovernanceManager& govman, const std::unique_ptr<CJContext>& cj_ctx,
|
|
const std::unique_ptr<LLMQContext>& llmq_ctx, bool ignore_incoming_txs);
|
|
virtual ~PeerManager() { }
|
|
|
|
/** Get statistics from node state */
|
|
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) = 0;
|
|
|
|
/** Whether this node ignores txs received over p2p. */
|
|
virtual bool IgnoresIncomingTxs() = 0;
|
|
|
|
/** Relay transaction to all peers. */
|
|
virtual void RelayTransaction(const uint256& txid)
|
|
EXCLUSIVE_LOCKS_REQUIRED(cs_main) = 0;
|
|
|
|
/** Set the best height */
|
|
virtual void SetBestHeight(int height) = 0;
|
|
|
|
/**
|
|
* Increment peer's misbehavior score. If the new value surpasses banscore (specified on startup or by default), mark node to be discouraged, meaning the peer might be disconnected & added to the discouragement filter.
|
|
*/
|
|
virtual void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message = "") = 0;
|
|
|
|
/**
|
|
* Evict extra outbound peers. If we think our tip may be stale, connect to an extra outbound.
|
|
* Public for unit testing.
|
|
*/
|
|
virtual void CheckForStaleTipAndEvictPeers() = 0;
|
|
|
|
/** Process a single message from a peer. Public for fuzz testing */
|
|
virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
|
|
int64_t nTimeReceived, const std::atomic<bool>& interruptMsgProc) = 0;
|
|
|
|
virtual bool IsBanned(NodeId pnode) = 0;
|
|
|
|
/** Whether we've completed initial sync yet, for determining when to turn
|
|
* on extra block-relay-only peers. */
|
|
bool m_initial_sync_finished{false};
|
|
|
|
};
|
|
|
|
#endif // BITCOIN_NET_PROCESSING_H
|