From 2b482dc1f3fb248ccbe7eeb8c9c07d4bf1295a70 Mon Sep 17 00:00:00 2001 From: glozow Date: Wed, 1 May 2024 13:38:19 +0100 Subject: [PATCH] [refactor] have ProcessPackageResult take a PackageToValidate --- src/net_processing.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index ec334abf35f..d64c85ae9af 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -600,14 +600,6 @@ private: void ProcessValidTx(NodeId nodeid, const CTransactionRef& tx, const std::list& replaced_transactions) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main); - /** Handle the results of package validation: calls ProcessValidTx and ProcessInvalidTx for - * individual transactions, and caches rejection for the package as a group. - * @param[in] senders Must contain the nodeids of the peers that provided each transaction - * in package, in the same order. - * */ - void ProcessPackageResult(const Package& package, const PackageMempoolAcceptResult& package_result, const std::vector& senders) - EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main); - struct PackageToValidate { const Package m_txns; const std::vector m_senders; @@ -632,6 +624,12 @@ private: } }; + /** Handle the results of package validation: calls ProcessValidTx and ProcessInvalidTx for + * individual transactions, and caches rejection for the package as a group. + */ + void ProcessPackageResult(const PackageToValidate& package_to_validate, const PackageMempoolAcceptResult& package_result) + EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main); + /** Look for a child of this transaction in the orphanage to form a 1-parent-1-child package, * skipping any combinations that have already been tried. Return the resulting package along with * the senders of its respective transactions, or std::nullopt if no package is found. */ @@ -3251,12 +3249,15 @@ void PeerManagerImpl::ProcessValidTx(NodeId nodeid, const CTransactionRef& tx, c } } -void PeerManagerImpl::ProcessPackageResult(const Package& package, const PackageMempoolAcceptResult& package_result, const std::vector& senders) +void PeerManagerImpl::ProcessPackageResult(const PackageToValidate& package_to_validate, const PackageMempoolAcceptResult& package_result) { AssertLockNotHeld(m_peer_mutex); AssertLockHeld(g_msgproc_mutex); AssertLockHeld(cs_main); + const auto& package = package_to_validate.m_txns; + const auto& senders = package_to_validate.m_senders; + if (package_result.m_state.IsInvalid()) { m_recent_rejects_reconsiderable.insert(GetPackageHash(package)); } @@ -4548,7 +4549,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, const auto package_result{ProcessNewPackage(m_chainman.ActiveChainstate(), m_mempool, package_to_validate->m_txns, /*test_accept=*/false, /*client_maxfeerate=*/std::nullopt)}; LogDebug(BCLog::TXPACKAGES, "package evaluation for %s: %s\n", package_to_validate->ToString(), package_result.m_state.IsValid() ? "package accepted" : "package rejected"); - ProcessPackageResult(package_to_validate->m_txns, package_result, package_to_validate->m_senders); + ProcessPackageResult(package_to_validate.value(), package_result); } } // If a tx is detected by m_recent_rejects it is ignored. Because we haven't @@ -4663,7 +4664,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, const auto package_result{ProcessNewPackage(m_chainman.ActiveChainstate(), m_mempool, package_to_validate->m_txns, /*test_accept=*/false, /*client_maxfeerate=*/std::nullopt)}; LogDebug(BCLog::TXPACKAGES, "package evaluation for %s: %s\n", package_to_validate->ToString(), package_result.m_state.IsValid() ? "package accepted" : "package rejected"); - ProcessPackageResult(package_to_validate->m_txns, package_result, package_to_validate->m_senders); + ProcessPackageResult(package_to_validate.value(), package_result); } }