1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_NET_PROCESSING_H
7 #define BITCOIN_NET_PROCESSING_H
10 #include "validationinterface.h"
12 /** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
13 static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS
= 100;
14 /** Expiration time for orphan transactions in seconds */
15 static const int64_t ORPHAN_TX_EXPIRE_TIME
= 20 * 60;
16 /** Minimum time between orphan transactions expire time checks in seconds */
17 static const int64_t ORPHAN_TX_EXPIRE_INTERVAL
= 5 * 60;
18 /** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
19 static const unsigned int DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN
= 100;
20 /** Headers download timeout expressed in microseconds
21 * Timeout = base + per_header * (expected number of headers) */
22 static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE
= 15 * 60 * 1000000; // 15 minutes
23 static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER
= 1000; // 1ms/header
25 class PeerLogicValidation
: public CValidationInterface
, public NetEventsInterface
{
30 explicit PeerLogicValidation(CConnman
* connman
);
32 void BlockConnected(const std::shared_ptr
<const CBlock
>& pblock
, const CBlockIndex
* pindexConnected
, const std::vector
<CTransactionRef
>& vtxConflicted
) override
;
33 void UpdatedBlockTip(const CBlockIndex
*pindexNew
, const CBlockIndex
*pindexFork
, bool fInitialDownload
) override
;
34 void BlockChecked(const CBlock
& block
, const CValidationState
& state
) override
;
35 void NewPoWValidBlock(const CBlockIndex
*pindex
, const std::shared_ptr
<const CBlock
>& pblock
) override
;
38 void InitializeNode(CNode
* pnode
) override
;
39 void FinalizeNode(NodeId nodeid
, bool& fUpdateConnectionTime
) override
;
40 /** Process protocol messages received from a given node */
41 bool ProcessMessages(CNode
* pfrom
, std::atomic
<bool>& interrupt
) override
;
43 * Send queued protocol messages to be sent to a give node.
45 * @param[in] pto The node which we are sending messages to.
46 * @param[in] interrupt Interrupt condition for processing threads
47 * @return True if there is more work to be done
49 bool SendMessages(CNode
* pto
, std::atomic
<bool>& interrupt
) override
;
52 struct CNodeStateStats
{
56 std::vector
<int> vHeightInFlight
;
59 /** Get statistics from node state */
60 bool GetNodeStateStats(NodeId nodeid
, CNodeStateStats
&stats
);
61 /** Increase a node's misbehavior score. */
62 void Misbehaving(NodeId nodeid
, int howmuch
);
64 #endif // BITCOIN_NET_PROCESSING_H