Skip to content

Commit 176f929

Browse files
committed
refactor: isolate DKG session networking code in multiple entities
1 parent c76d3f2 commit 176f929

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

src/net_processing.cpp

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ class PeerManagerImpl final : public PeerManager
964964
bool AlreadyHave(const CInv& inv)
965965
EXCLUSIVE_LOCKS_REQUIRED(cs_main, !m_recent_confirmed_transactions_mutex);
966966

967+
bool DKGSessionAlreadyHave(const CInv& inv);
968+
MessageProcessingResult DKGSessionProcessMessage(CNode& pfrom, bool is_masternode, std::string_view msg_type, CDataStream& vRecv);
969+
967970
/**
968971
* Filter for transactions that were recently rejected by the mempool.
969972
* These are not rerequested until the chain tip changes, at which point
@@ -2351,8 +2354,7 @@ bool PeerManagerImpl::AlreadyHave(const CInv& inv)
23512354
case MSG_QUORUM_COMPLAINT:
23522355
case MSG_QUORUM_JUSTIFICATION:
23532356
case MSG_QUORUM_PREMATURE_COMMITMENT:
2354-
return (m_observer_ctx && m_observer_ctx->qdkgsman->AlreadyHave(inv))
2355-
|| (m_active_ctx && m_active_ctx->qdkgsman->AlreadyHave(inv));
2357+
return DKGSessionAlreadyHave(inv);
23562358
case MSG_QUORUM_RECOVERED_SIG:
23572359
// TODO: move it to NetSigning
23582360
return m_llmq_ctx->sigman->AlreadyHave(inv);
@@ -2377,6 +2379,16 @@ bool PeerManagerImpl::AlreadyHave(const CInv& inv)
23772379
return true;
23782380
}
23792381

2382+
bool PeerManagerImpl::DKGSessionAlreadyHave(const CInv& inv)
2383+
{
2384+
if (m_observer_ctx) {
2385+
return m_observer_ctx->qdkgsman->AlreadyHave(inv);
2386+
} else if (m_active_ctx) {
2387+
return m_active_ctx->qdkgsman->AlreadyHave(inv);
2388+
}
2389+
return false;
2390+
}
2391+
23802392
bool PeerManagerImpl::AlreadyHaveBlock(const uint256& block_hash)
23812393
{
23822394
return m_chainman.m_blockman.LookupBlockIndex(block_hash) != nullptr;
@@ -5454,24 +5466,9 @@ void PeerManagerImpl::ProcessMessage(
54545466
PostProcessMessage(m_cj_walletman->processMessage(pfrom, m_chainman.ActiveChainstate(), m_connman, m_mempool, msg_type, vRecv), pfrom.GetId());
54555467
}
54565468
if (m_active_ctx) {
5457-
assert(is_masternode);
54585469
m_active_ctx->shareman->ProcessMessage(pfrom, msg_type, vRecv);
5459-
PostProcessMessage(m_active_ctx->qdkgsman->ProcessMessage(pfrom, is_masternode, msg_type, vRecv), pfrom.GetId());
5460-
}
5461-
if (m_observer_ctx) {
5462-
assert(!is_masternode);
5463-
PostProcessMessage(m_observer_ctx->qdkgsman->ProcessMessage(pfrom, is_masternode, msg_type, vRecv), pfrom.GetId());
5464-
}
5465-
if (!m_active_ctx && !m_observer_ctx) {
5466-
assert(!is_masternode);
5467-
if (msg_type == NetMsgType::QCONTRIB
5468-
|| msg_type == NetMsgType::QCOMPLAINT
5469-
|| msg_type == NetMsgType::QJUSTIFICATION
5470-
|| msg_type == NetMsgType::QPCOMMITMENT
5471-
|| msg_type == NetMsgType::QWATCH) {
5472-
Misbehaving(pfrom.GetId(), /*howmuch=*/10);
5473-
}
54745470
}
5471+
PostProcessMessage(DKGSessionProcessMessage(pfrom, is_masternode, msg_type, vRecv), pfrom.GetId());
54755472
PostProcessMessage(m_sporkman.ProcessMessage(pfrom, m_connman, msg_type, vRecv), pfrom.GetId());
54765473
PostProcessMessage(CMNAuth::ProcessMessage(pfrom, peer->m_their_services, m_connman, m_mn_metaman, (m_active_ctx ? m_active_ctx->nodeman.get() : nullptr), m_mn_sync, m_dmnman->GetListAtChainTip(), msg_type, vRecv), pfrom.GetId());
54775474
PostProcessMessage(m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv), pfrom.GetId());
@@ -5501,6 +5498,26 @@ void PeerManagerImpl::ProcessMessage(
55015498
return;
55025499
}
55035500

5501+
MessageProcessingResult PeerManagerImpl::DKGSessionProcessMessage(CNode& pfrom, bool is_masternode, std::string_view msg_type, CDataStream& vRecv)
5502+
{
5503+
if (m_active_ctx) {
5504+
assert(is_masternode);
5505+
return m_active_ctx->qdkgsman->ProcessMessage(pfrom, is_masternode, msg_type, vRecv);
5506+
} else if (m_observer_ctx) {
5507+
assert(!is_masternode);
5508+
return m_observer_ctx->qdkgsman->ProcessMessage(pfrom, is_masternode, msg_type, vRecv);
5509+
}
5510+
assert(!is_masternode);
5511+
if (msg_type == NetMsgType::QCONTRIB
5512+
|| msg_type == NetMsgType::QCOMPLAINT
5513+
|| msg_type == NetMsgType::QJUSTIFICATION
5514+
|| msg_type == NetMsgType::QPCOMMITMENT
5515+
|| msg_type == NetMsgType::QWATCH) {
5516+
return MisbehavingError{10};
5517+
}
5518+
return {};
5519+
}
5520+
55045521
bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
55055522
{
55065523
{

0 commit comments

Comments
 (0)