diff --git a/src/coinjoin/client.h b/src/coinjoin/client.h index 382af36306..5a615a6ce9 100644 --- a/src/coinjoin/client.h +++ b/src/coinjoin/client.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include diff --git a/src/coinjoin/server.h b/src/coinjoin/server.h index f5539cd783..5f528a2bfb 100644 --- a/src/coinjoin/server.h +++ b/src/coinjoin/server.h @@ -7,7 +7,7 @@ #include -#include +#include class CActiveMasternodeManager; class CChainState; diff --git a/src/evo/mnauth.h b/src/evo/mnauth.h index c109961d8e..514503c39f 100644 --- a/src/evo/mnauth.h +++ b/src/evo/mnauth.h @@ -6,7 +6,7 @@ #define BITCOIN_EVO_MNAUTH_H #include -#include +#include #include class CActiveMasternodeManager; diff --git a/src/governance/governance.h b/src/governance/governance.h index aa1dec1306..1417344551 100644 --- a/src/governance/governance.h +++ b/src/governance/governance.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index 2deeebfd90..dad4930d86 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include #include diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index 4756011e14..ad6d22c304 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -13,8 +13,8 @@ #include #include +#include -#include #include #include diff --git a/src/llmq/signing.h b/src/llmq/signing.h index ae2fd48224..562e533b2f 100644 --- a/src/llmq/signing.h +++ b/src/llmq/signing.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f78889857d..c7338ebec7 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -584,8 +584,9 @@ public: bool IsInvInFilter(NodeId nodeid, const uint256& hash) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); private: - /** Helper to process result of external handlers of message */ + /** Helpers to process result of external handlers of message */ void ProcessPeerMsgRet(const PeerMsgRet& ret, CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + void PostProcessMessage(MessageProcessingResult&& ret, NodeId node) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); /** Consider evicting an outbound peer based on the amount of time they've been behind our tip */ void ConsiderEviction(CNode& pto, Peer& peer, std::chrono::seconds time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_msgproc_mutex); @@ -3309,6 +3310,16 @@ void PeerManagerImpl::ProcessPeerMsgRet(const PeerMsgRet& ret, CNode& pfrom) if (!ret) Misbehaving(pfrom.GetId(), ret.error().score, ret.error().message); } +void PeerManagerImpl::PostProcessMessage(MessageProcessingResult&& ret, NodeId node) +{ + if (ret.m_error) { + Misbehaving(node, ret.m_error->score, ret.m_error->message); + } + if (ret.m_inventory) { + RelayInv(ret.m_inventory.value(), MIN_PEER_PROTO_VERSION); + } +} + void PeerManagerImpl::ProcessMessage( CNode& pfrom, const std::string& msg_type, diff --git a/src/net_processing.h b/src/net_processing.h index 295fcc1d6e..a857201516 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -127,6 +127,9 @@ public: virtual void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv, const std::chrono::microseconds time_received, const std::atomic& interruptMsgProc) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex) = 0; + /** Finish message processing. Used for some specific messages */ + virtual void PostProcessMessage(MessageProcessingResult&& ret, NodeId node = -1) = 0; + /** This function is used for testing the stale tip eviction logic, see denialofservice_tests.cpp */ virtual void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) = 0; diff --git a/src/net_types.h b/src/net_types.h index 927d261072..6a7e5f41bc 100644 --- a/src/net_types.h +++ b/src/net_types.h @@ -5,8 +5,6 @@ #ifndef BITCOIN_NET_TYPES_H #define BITCOIN_NET_TYPES_H -#include - #include #include #include @@ -60,21 +58,5 @@ UniValue BanMapToJson(const banmap_t& bans); */ void BanMapFromJson(const UniValue& bans_json, banmap_t& bans); -struct MisbehavingError -{ - int score; - std::string message; - - MisbehavingError(int s) : score{s} {} - - // Constructor does a perfect forwarding reference - template - MisbehavingError(int s, T&& msg) : - score{s}, - message{std::forward(msg)} - {} -}; - -using PeerMsgRet = tl::expected; #endif // BITCOIN_NET_TYPES_H diff --git a/src/protocol.h b/src/protocol.h index aa07b3caeb..b5f10f6f50 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -17,6 +17,9 @@ #include #include +#include + + #include #include #include @@ -561,5 +564,36 @@ public: uint256 hash; }; +struct MisbehavingError +{ + int score; + std::string message; + + MisbehavingError(int s) : score{s} {} + + // Constructor does a perfect forwarding reference + template + MisbehavingError(int s, T&& msg) : + score{s}, + message{std::forward(msg)} + {} +}; + +using PeerMsgRet = tl::expected; + +struct MessageProcessingResult +{ + std::optional m_error; + std::optional m_inventory; + + MessageProcessingResult() = default; + MessageProcessingResult(MisbehavingError error) : + m_error(error) + {} + MessageProcessingResult(CInv inv) : + m_inventory(inv) + { + } +}; #endif // BITCOIN_PROTOCOL_H