mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
d804a753af
* Merge #13134: net: Add option `-enablebip61` to configure sending of BIP61 notifications 87fe292d897e09e176ac7e254144466c319cc9ac doc: Mention disabling BIP61 in bips.md (Wladimir J. van der Laan) fe16dd8226d924f44432c5b5014aa49ff45c82ff net: Add option `-enablebip61` to configure sending of BIP61 notifications (Wladimir J. van der Laan) Pull request description: This commit adds a boolean option `-peersendreject`, defaulting to `1`, that can be used to disable the sending of [BIP61](https://github.com/bitcoin/bips/blob/master/bip-0061.mediawiki) `reject` messages. This functionality has been requested for various reasons: - security (DoS): reject messages can reveal internal state that can be used to target certain resources such as the mempool more easily. - bandwidth: a typical node sends lots of reject messages; this counts against upstream bandwidth. Also the reject messages tend to be larger than the message that was rejected. On the other hand, reject messages can be useful while developing client software (I found them indispensable while creating bitcoin-submittx), as well as for our own test cases, so whatever the default becomes on the long run, IMO the functionality should be retained as option. But that's a discussion for later, for now it's simply a node operator decision. Also adds a RPC test that checks the functionality. Tree-SHA512: 9488cc53e13cd8e5c6f8eb472a44309572673405c1d1438c3488f627fae622c95e2198bde5ed7d29e56b948e2918bf1920239e9f865889f4c37c097c37a4d7a9 * 0.17 -> 0.16 Signed-off-by: Pasta <pasta@dashboost.org> * tx1 -> base_ tx fixing 13134 Signed-off-by: Pasta <pasta@dashboost.org> * move added bip61 message checking up Signed-off-by: Pasta <pasta@dashboost.org> * Dash specific code, only send reject messages if bip61 is enabled Signed-off-by: Pasta <pasta@dashboost.org> * Fix invalidtxrequest.py Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
97 lines
4.5 KiB
C++
97 lines
4.5 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 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 <validationinterface.h>
|
|
#include <consensus/params.h>
|
|
|
|
/** 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)
|
|
/** Expiration time for orphan transactions in seconds */
|
|
static const int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
|
|
/** Minimum time between orphan transactions expire time checks in seconds */
|
|
static const int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
|
|
/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
|
|
static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN = 100;
|
|
|
|
/** Headers download timeout expressed in microseconds
|
|
* Timeout = base + per_header * (expected number of headers) */
|
|
static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000; // 15 minutes
|
|
static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER = 1000; // 1ms/header
|
|
/** Protect at least this many outbound peers from disconnection due to slow/
|
|
* behind headers chain.
|
|
*/
|
|
static constexpr int32_t MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT = 4;
|
|
/** Timeout for (unprotected) outbound peers to sync to our chainwork, in seconds */
|
|
static constexpr int64_t CHAIN_SYNC_TIMEOUT = 20 * 60; // 20 minutes
|
|
|
|
/** How frequently to check for stale tips, in seconds */
|
|
static constexpr int64_t STALE_CHECK_INTERVAL = 150; // 2.5 minutes (~block interval)
|
|
/** How frequently to check for extra outbound peers and disconnect, in seconds */
|
|
static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45;
|
|
/** Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */
|
|
static constexpr int64_t MINIMUM_CONNECT_TIME = 30;
|
|
|
|
/** Default for BIP61 (sending reject messages) */
|
|
static constexpr bool DEFAULT_ENABLE_BIP61 = true;
|
|
/** Enable BIP61 (sending reject messages) */
|
|
extern bool g_enable_bip61;
|
|
|
|
class PeerLogicValidation : public CValidationInterface, public NetEventsInterface {
|
|
private:
|
|
CConnman* const connman;
|
|
|
|
public:
|
|
explicit PeerLogicValidation(CConnman* connmanIn, CScheduler &scheduler);
|
|
|
|
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected, const std::vector<CTransactionRef>& vtxConflicted) override;
|
|
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
|
|
void BlockChecked(const CBlock& block, const CValidationState& state) override;
|
|
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override;
|
|
|
|
|
|
void InitializeNode(CNode* pnode) override;
|
|
void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) override;
|
|
/** Process protocol messages received from a given node */
|
|
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt, bool &fRetDidWork) override;
|
|
/**
|
|
* Send queued protocol messages to be sent to a give node.
|
|
*
|
|
* @param[in] pto The node which we are sending messages to.
|
|
* @param[in] interrupt Interrupt condition for processing threads
|
|
* @return True if there is more work to be done
|
|
*/
|
|
bool SendMessages(CNode* pto, std::atomic<bool>& interrupt) override;
|
|
|
|
void ConsiderEviction(CNode *pto, int64_t time_in_seconds);
|
|
void CheckForStaleTipAndEvictPeers(const Consensus::Params &consensusParams);
|
|
void EvictExtraOutboundPeers(int64_t time_in_seconds);
|
|
|
|
private:
|
|
int64_t m_stale_tip_check_time; //! Next time to check for stale tip
|
|
};
|
|
|
|
struct CNodeStateStats {
|
|
int nMisbehavior;
|
|
int nSyncHeight;
|
|
int nCommonHeight;
|
|
std::vector<int> vHeightInFlight;
|
|
};
|
|
|
|
/** Get statistics from node state */
|
|
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats);
|
|
/** Increase a node's misbehavior score. */
|
|
void Misbehaving(NodeId nodeid, int howmuch, const std::string& message="");
|
|
bool IsBanned(NodeId nodeid);
|
|
|
|
void EraseObjectRequest(NodeId nodeId, const CInv& inv);
|
|
void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool fForce=false);
|
|
size_t GetRequestedObjectCount(NodeId nodeId);
|
|
|
|
#endif // BITCOIN_NET_PROCESSING_H
|