|
6 | 6 | #ifndef BITCOIN_NET_PROCESSING_H
|
7 | 7 | #define BITCOIN_NET_PROCESSING_H
|
8 | 8 |
|
9 |
| -#include <consensus/params.h> |
10 | 9 | #include <net.h>
|
11 | 10 | #include <sync.h>
|
12 |
| -#include <txrequest.h> |
13 | 11 | #include <validationinterface.h>
|
14 | 12 |
|
15 |
| -class BlockTransactionsRequest; |
16 |
| -class BlockValidationState; |
17 |
| -class CBlockHeader; |
18 | 13 | class CChainParams;
|
19 | 14 | class CTxMemPool;
|
20 | 15 | class ChainstateManager;
|
21 |
| -class TxValidationState; |
22 | 16 |
|
23 | 17 | extern RecursiveMutex cs_main;
|
24 | 18 | extern RecursiveMutex g_cs_orphans;
|
@@ -129,129 +123,6 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
|
129 | 123 | const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0;
|
130 | 124 | };
|
131 | 125 |
|
132 |
| -class PeerManagerImpl final : public PeerManager |
133 |
| -{ |
134 |
| -public: |
135 |
| - PeerManagerImpl(const CChainParams& chainparams, CConnman& connman, BanMan* banman, |
136 |
| - CScheduler& scheduler, ChainstateManager& chainman, CTxMemPool& pool, |
137 |
| - bool ignore_incoming_txs); |
138 |
| - |
139 |
| - /** Overridden from CValidationInterface. */ |
140 |
| - void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override; |
141 |
| - void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override; |
142 |
| - void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override; |
143 |
| - void BlockChecked(const CBlock& block, const BlockValidationState& state) override; |
144 |
| - void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override; |
145 |
| - |
146 |
| - /** Implement NetEventsInterface */ |
147 |
| - void InitializeNode(CNode* pnode) override; |
148 |
| - void FinalizeNode(const CNode& node, bool& fUpdateConnectionTime) override; |
149 |
| - bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override; |
150 |
| - bool SendMessages(CNode* pto) override EXCLUSIVE_LOCKS_REQUIRED(pto->cs_sendProcessing); |
151 |
| - |
152 |
| - /** Implement PeerManager */ |
153 |
| - void CheckForStaleTipAndEvictPeers() override; |
154 |
| - bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) override; |
155 |
| - bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; } |
156 |
| - void SetBestHeight(int height) override { m_best_height = height; }; |
157 |
| - void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) override; |
158 |
| - void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv, |
159 |
| - const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override; |
160 |
| - |
161 |
| -private: |
162 |
| - /** Consider evicting an outbound peer based on the amount of time they've been behind our tip */ |
163 |
| - void ConsiderEviction(CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main); |
164 |
| - |
165 |
| - /** If we have extra outbound peers, try to disconnect the one with the oldest block announcement */ |
166 |
| - void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main); |
167 |
| - |
168 |
| - /** Retrieve unbroadcast transactions from the mempool and reattempt sending to peers */ |
169 |
| - void ReattemptInitialBroadcast(CScheduler& scheduler) const; |
170 |
| - |
171 |
| - /** Get a shared pointer to the Peer object. |
172 |
| - * May return an empty shared_ptr if the Peer object can't be found. */ |
173 |
| - PeerRef GetPeerRef(NodeId id) const; |
174 |
| - |
175 |
| - /** Get a shared pointer to the Peer object and remove it from m_peer_map. |
176 |
| - * May return an empty shared_ptr if the Peer object can't be found. */ |
177 |
| - PeerRef RemovePeer(NodeId id); |
178 |
| - |
179 |
| - /** |
180 |
| - * Potentially mark a node discouraged based on the contents of a BlockValidationState object |
181 |
| - * |
182 |
| - * @param[in] via_compact_block this bool is passed in because net_processing should |
183 |
| - * punish peers differently depending on whether the data was provided in a compact |
184 |
| - * block message or not. If the compact block had a valid header, but contained invalid |
185 |
| - * txs, the peer should not be punished. See BIP 152. |
186 |
| - * |
187 |
| - * @return Returns true if the peer was punished (probably disconnected) |
188 |
| - */ |
189 |
| - bool MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state, |
190 |
| - bool via_compact_block, const std::string& message = ""); |
191 |
| - |
192 |
| - /** |
193 |
| - * Potentially disconnect and discourage a node based on the contents of a TxValidationState object |
194 |
| - * |
195 |
| - * @return Returns true if the peer was punished (probably disconnected) |
196 |
| - */ |
197 |
| - bool MaybePunishNodeForTx(NodeId nodeid, const TxValidationState& state, const std::string& message = ""); |
198 |
| - |
199 |
| - /** Maybe disconnect a peer and discourage future connections from its address. |
200 |
| - * |
201 |
| - * @param[in] pnode The node to check. |
202 |
| - * @return True if the peer was marked for disconnection in this function |
203 |
| - */ |
204 |
| - bool MaybeDiscourageAndDisconnect(CNode& pnode); |
205 |
| - |
206 |
| - void ProcessOrphanTx(std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans); |
207 |
| - /** Process a single headers message from a peer. */ |
208 |
| - void ProcessHeadersMessage(CNode& pfrom, const Peer& peer, |
209 |
| - const std::vector<CBlockHeader>& headers, |
210 |
| - bool via_compact_block); |
211 |
| - |
212 |
| - void SendBlockTransactions(CNode& pfrom, const CBlock& block, const BlockTransactionsRequest& req); |
213 |
| - |
214 |
| - /** Register with TxRequestTracker that an INV has been received from a |
215 |
| - * peer. The announcement parameters are decided in PeerManager and then |
216 |
| - * passed to TxRequestTracker. */ |
217 |
| - void AddTxAnnouncement(const CNode& node, const GenTxid& gtxid, std::chrono::microseconds current_time) |
218 |
| - EXCLUSIVE_LOCKS_REQUIRED(::cs_main); |
219 |
| - |
220 |
| - /** Send a version message to a peer */ |
221 |
| - void PushNodeVersion(CNode& pnode, int64_t nTime); |
222 |
| - |
223 |
| - const CChainParams& m_chainparams; |
224 |
| - CConnman& m_connman; |
225 |
| - /** Pointer to this node's banman. May be nullptr - check existence before dereferencing. */ |
226 |
| - BanMan* const m_banman; |
227 |
| - ChainstateManager& m_chainman; |
228 |
| - CTxMemPool& m_mempool; |
229 |
| - TxRequestTracker m_txrequest GUARDED_BY(::cs_main); |
230 |
| - |
231 |
| - /** The height of the best chain */ |
232 |
| - std::atomic<int> m_best_height{-1}; |
233 |
| - |
234 |
| - int64_t m_stale_tip_check_time; //!< Next time to check for stale tip |
235 |
| - |
236 |
| - /** Whether this node is running in blocks only mode */ |
237 |
| - const bool m_ignore_incoming_txs; |
238 |
| - |
239 |
| - /** Whether we've completed initial sync yet, for determining when to turn |
240 |
| - * on extra block-relay-only peers. */ |
241 |
| - bool m_initial_sync_finished{false}; |
242 |
| - |
243 |
| - /** Protects m_peer_map. This mutex must not be locked while holding a lock |
244 |
| - * on any of the mutexes inside a Peer object. */ |
245 |
| - mutable Mutex m_peer_mutex; |
246 |
| - /** |
247 |
| - * Map of all Peer objects, keyed by peer id. This map is protected |
248 |
| - * by the m_peer_mutex. Once a shared pointer reference is |
249 |
| - * taken, the lock may be released. Individual fields are protected by |
250 |
| - * their own locks. |
251 |
| - */ |
252 |
| - std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex); |
253 |
| -}; |
254 |
| - |
255 | 126 | /** Relay transaction to every node */
|
256 | 127 | void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
257 | 128 |
|
|
0 commit comments