3737#endif
3838
3939/* * Expiration time for orphan transactions in seconds */
40- static const int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60 ;
40+ static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60 ;
4141/* * Minimum time between orphan transactions expire time checks in seconds */
42- static const int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60 ;
42+ static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60 ;
4343/* * Headers download timeout expressed in microseconds
4444 * Timeout = base + per_header * (expected number of headers) */
4545static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000 ; // 15 minutes
@@ -56,27 +56,14 @@ static constexpr int64_t STALE_CHECK_INTERVAL = 10 * 60; // 10 minutes
5656static constexpr int64_t EXTRA_PEER_CHECK_INTERVAL = 45 ;
5757/* * Minimum time an outbound-peer-eviction candidate must be connected for, in order to evict, in seconds */
5858static constexpr int64_t MINIMUM_CONNECT_TIME = 30 ;
59-
60- static const uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL ; // SHA256("main address relay")[0:8]
61-
59+ /* * SHA256("main address relay")[0:8] */
60+ static constexpr uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL ;
6261// / Age after which a stale block will no longer be served if requested as
6362// / protection against fingerprinting. Set to one month, denominated in seconds.
64- static const int STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60 ;
65-
63+ static constexpr int STALE_RELAY_AGE_LIMIT = 30 * 24 * 60 * 60 ;
6664// / Age after which a block is considered historical for purposes of rate
6765// / limiting block relay. Set to one week, denominated in seconds.
68- static const int HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60 ;
69-
70- std::atomic<int64_t > nTimeBestReceived (0 ); // Used only to inform the wallet of when we last received a block
71-
72- struct IteratorComparator
73- {
74- template <typename I>
75- bool operator ()(const I& a, const I& b) const
76- {
77- return &(*a) < &(*b);
78- }
79- };
66+ static constexpr int HISTORICAL_BLOCK_AGE = 7 * 24 * 60 * 60 ;
8067
8168struct COrphanTx {
8269 // When modifying, adapt the copy of this definition in tests/DoS_tests.
@@ -86,14 +73,12 @@ struct COrphanTx {
8673};
8774static CCriticalSection g_cs_orphans;
8875std::map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY (g_cs_orphans);
89- std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY (g_cs_orphans);
76+
9077void EraseOrphansFor (NodeId peer);
78+
9179/* * Increase a node's misbehavior score. */
9280void Misbehaving (NodeId nodeid, int howmuch, const std::string& message=" " );
9381
94- static size_t vExtraTxnForCompactIt GUARDED_BY (g_cs_orphans) = 0;
95- static std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY (g_cs_orphans);
96-
9782// Internal stuff
9883namespace {
9984 /* * Enable BIP61 (sending reject messages) */
@@ -163,10 +148,24 @@ namespace {
163148 MapRelay mapRelay;
164149 /* * Expiration-time ordered list of (expire time, relay map entry) pairs, protected by cs_main). */
165150 std::deque<std::pair<int64_t , MapRelay::iterator>> vRelayExpiration;
151+
152+ std::atomic<int64_t > nTimeBestReceived (0 ); // Used only to inform the wallet of when we last received a block
153+
154+ struct IteratorComparator
155+ {
156+ template <typename I>
157+ bool operator ()(const I& a, const I& b) const
158+ {
159+ return &(*a) < &(*b);
160+ }
161+ };
162+ std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY (g_cs_orphans);
163+
164+ static size_t vExtraTxnForCompactIt GUARDED_BY (g_cs_orphans) = 0;
165+ static std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY (g_cs_orphans);
166166} // namespace
167167
168168namespace {
169-
170169struct CBlockReject {
171170 unsigned char chRejectCode;
172171 std::string strRejectReason;
@@ -293,10 +292,10 @@ struct CNodeState {
293292};
294293
295294/* * Map maintaining per-node state. Requires cs_main. */
296- std::map<NodeId, CNodeState> mapNodeState;
295+ static std::map<NodeId, CNodeState> mapNodeState;
297296
298297// Requires cs_main.
299- CNodeState *State (NodeId pnode) {
298+ static CNodeState *State (NodeId pnode) {
300299 std::map<NodeId, CNodeState>::iterator it = mapNodeState.find (pnode);
301300 if (it == mapNodeState.end ())
302301 return nullptr ;
@@ -3229,6 +3228,7 @@ void PeerLogicValidation::CheckForStaleTipAndEvictPeers(const Consensus::Params
32293228 }
32303229}
32313230
3231+ namespace {
32323232class CompareInvMempoolOrder
32333233{
32343234 CTxMemPool *mp;
@@ -3245,6 +3245,7 @@ class CompareInvMempoolOrder
32453245 return mp->CompareDepthAndScore (*b, *a);
32463246 }
32473247};
3248+ }
32483249
32493250bool PeerLogicValidation::SendMessages (CNode* pto, std::atomic<bool >& interruptMsgProc)
32503251{
0 commit comments