refactor: drop dependency of EhfSignals on PeerManager

This commit is contained in:
Konstantin Akimov 2024-09-26 23:32:05 +07:00
parent 1d13f010d0
commit d0f17788fc
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
6 changed files with 15 additions and 14 deletions

View File

@ -36,7 +36,8 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis
shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *qman, sporkman, peerman)}, shareman{std::make_unique<llmq::CSigSharesManager>(connman, *sigman, mn_activeman, *qman, sporkman, peerman)},
clhandler{[&]() -> llmq::CChainLocksHandler* const { clhandler{[&]() -> llmq::CChainLocksHandler* const {
assert(llmq::chainLocksHandler == nullptr); assert(llmq::chainLocksHandler == nullptr);
llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(chainstate, *qman, *sigman, *shareman, sporkman, mempool, mn_sync, is_masternode); llmq::chainLocksHandler = std::make_unique<llmq::CChainLocksHandler>(chainstate, *qman, *sigman, *shareman,
sporkman, mempool, mn_sync, is_masternode);
return llmq::chainLocksHandler.get(); return llmq::chainLocksHandler.get();
}()}, }()},
isman{[&]() -> llmq::CInstantSendManager* const { isman{[&]() -> llmq::CInstantSendManager* const {
@ -45,7 +46,7 @@ LLMQContext::LLMQContext(CChainState& chainstate, CConnman& connman, CDeterminis
return llmq::quorumInstantSendManager.get(); return llmq::quorumInstantSendManager.get();
}()}, }()},
ehfSignalsHandler{ ehfSignalsHandler{
std::make_unique<llmq::CEHFSignalsHandler>(chainstate, mnhfman, *sigman, *shareman, mempool, *qman, peerman)} std::make_unique<llmq::CEHFSignalsHandler>(chainstate, mnhfman, *sigman, *shareman, mempool, *qman)}
{ {
} }

View File

@ -14,7 +14,6 @@
#include <consensus/validation.h> #include <consensus/validation.h>
#include <deploymentstatus.h> #include <deploymentstatus.h>
#include <index/txindex.h> // g_txindex #include <index/txindex.h> // g_txindex
#include <net_processing.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <txmempool.h> #include <txmempool.h>
#include <validation.h> #include <validation.h>
@ -23,15 +22,13 @@ namespace llmq {
CEHFSignalsHandler::CEHFSignalsHandler(CChainState& chainstate, CMNHFManager& mnhfman, CSigningManager& sigman, CEHFSignalsHandler::CEHFSignalsHandler(CChainState& chainstate, CMNHFManager& mnhfman, CSigningManager& sigman,
CSigSharesManager& shareman, CTxMemPool& mempool, const CQuorumManager& qman, CSigSharesManager& shareman, CTxMemPool& mempool, const CQuorumManager& qman) :
const std::unique_ptr<PeerManager>& peerman) :
chainstate(chainstate), chainstate(chainstate),
mnhfman(mnhfman), mnhfman(mnhfman),
sigman(sigman), sigman(sigman),
shareman(shareman), shareman(shareman),
mempool(mempool), mempool(mempool),
qman(qman), qman(qman)
m_peerman(peerman)
{ {
sigman.RegisterRecoveredSigsListener(this); sigman.RegisterRecoveredSigsListener(this);
} }
@ -105,6 +102,7 @@ MessageProcessingResult CEHFSignalsHandler::HandleNewRecoveredSig(const CRecover
return {}; return {};
} }
MessageProcessingResult ret;
const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return chainstate.m_chain.Tip())); const auto ehfSignals = mnhfman.GetSignalsStage(WITH_LOCK(cs_main, return chainstate.m_chain.Tip()));
MNHFTxPayload mnhfPayload; MNHFTxPayload mnhfPayload;
for (const auto& deployment : Params().GetConsensus().vDeployments) { for (const auto& deployment : Params().GetConsensus().vDeployments) {
@ -130,13 +128,13 @@ MessageProcessingResult CEHFSignalsHandler::HandleNewRecoveredSig(const CRecover
LOCK(cs_main); LOCK(cs_main);
const MempoolAcceptResult result = AcceptToMemoryPool(chainstate, mempool, tx_to_sent, /* bypass_limits */ false); const MempoolAcceptResult result = AcceptToMemoryPool(chainstate, mempool, tx_to_sent, /* bypass_limits */ false);
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
Assert(m_peerman)->RelayTransaction(tx_to_sent->GetHash()); ret.m_transactions.push_back(tx_to_sent->GetHash());
} else { } else {
LogPrintf("CEHFSignalsHandler::HandleNewRecoveredSig -- AcceptToMemoryPool failed: %s\n", result.m_state.ToString()); LogPrintf("CEHFSignalsHandler::HandleNewRecoveredSig -- AcceptToMemoryPool failed: %s\n", result.m_state.ToString());
} }
} }
break; break;
} }
return {}; return ret;
} }
} // namespace llmq } // namespace llmq

View File

@ -13,7 +13,6 @@ class CBlockIndex;
class CChainState; class CChainState;
class CMNHFManager; class CMNHFManager;
class CTxMemPool; class CTxMemPool;
class PeerManager;
namespace llmq namespace llmq
{ {
@ -30,7 +29,6 @@ private:
CSigSharesManager& shareman; CSigSharesManager& shareman;
CTxMemPool& mempool; CTxMemPool& mempool;
const CQuorumManager& qman; const CQuorumManager& qman;
const std::unique_ptr<PeerManager>& m_peerman;
/** /**
* keep freshly generated IDs for easier filter sigs in HandleNewRecoveredSig * keep freshly generated IDs for easier filter sigs in HandleNewRecoveredSig
@ -39,8 +37,8 @@ private:
std::set<uint256> ids GUARDED_BY(cs); std::set<uint256> ids GUARDED_BY(cs);
public: public:
explicit CEHFSignalsHandler(CChainState& chainstate, CMNHFManager& mnhfman, CSigningManager& sigman, explicit CEHFSignalsHandler(CChainState& chainstate, CMNHFManager& mnhfman, CSigningManager& sigman,
CSigSharesManager& shareman, CTxMemPool& mempool, const CQuorumManager& qman, CSigSharesManager& shareman, CTxMemPool& mempool, const CQuorumManager& qman);
const std::unique_ptr<PeerManager>& peerman);
~CEHFSignalsHandler(); ~CEHFSignalsHandler();

View File

@ -3318,6 +3318,9 @@ void PeerManagerImpl::PostProcessMessage(MessageProcessingResult&& result, NodeI
if (result.m_to_erase) { if (result.m_to_erase) {
WITH_LOCK(cs_main, EraseObjectRequest(node, result.m_to_erase.value())); WITH_LOCK(cs_main, EraseObjectRequest(node, result.m_to_erase.value()));
} }
for (const auto& tx : result.m_transactions) {
WITH_LOCK(cs_main, RelayTransaction(tx));
}
if (result.m_inventory) { if (result.m_inventory) {
RelayInv(result.m_inventory.value(), MIN_PEER_PROTO_VERSION); RelayInv(result.m_inventory.value(), MIN_PEER_PROTO_VERSION);
} }

View File

@ -585,6 +585,7 @@ struct MessageProcessingResult
{ {
std::optional<MisbehavingError> m_error; std::optional<MisbehavingError> m_error;
std::optional<CInv> m_inventory; std::optional<CInv> m_inventory;
std::vector<uint256> m_transactions;
std::optional<CInv> m_to_erase; std::optional<CInv> m_to_erase;
MessageProcessingResult() = default; MessageProcessingResult() = default;

View File

@ -88,7 +88,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
"coinjoin/client -> net_processing -> coinjoin/context -> coinjoin/client" "coinjoin/client -> net_processing -> coinjoin/context -> coinjoin/client"
"coinjoin/context -> coinjoin/server -> net_processing -> coinjoin/context" "coinjoin/context -> coinjoin/server -> net_processing -> coinjoin/context"
"coinjoin/server -> net_processing -> coinjoin/server" "coinjoin/server -> net_processing -> coinjoin/server"
"llmq/context -> llmq/ehf_signals -> net_processing -> llmq/context" "llmq/context -> llmq/instantsend -> net_processing -> llmq/context"
"llmq/chainlocks -> llmq/instantsend -> net_processing -> llmq/chainlocks" "llmq/chainlocks -> llmq/instantsend -> net_processing -> llmq/chainlocks"
"net_processing -> spork -> net_processing" "net_processing -> spork -> net_processing"
"governance/governance -> net_processing -> governance/governance" "governance/governance -> net_processing -> governance/governance"