Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport: Merge bitcoin#21845 #5993

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <reverse_iterator.h>
#include <scheduler.h>
#include <streams.h>
#include <sync.h>
#include <tinyformat.h>
#include <index/txindex.h>
#include <txmempool.h>
Expand Down Expand Up @@ -407,6 +408,9 @@ class PeerManagerImpl final : public PeerManager
/** Helper to process result of external handlers of message */
void ProcessPeerMsgRet(const PeerMsgRet& ret, CNode& pfrom);

void _RelayTransaction(const uint256& txid)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);

/** Consider evicting an outbound peer based on the amount of time they've been behind our tip */
void ConsiderEviction(CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

Expand Down Expand Up @@ -1428,7 +1432,10 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
CTransactionRef tx = m_mempool.get(txid);

if (tx != nullptr) {
RelayTransaction(txid);
LOCK(cs_main);
{
_RelayTransaction(txid);
}
} else {
m_mempool.RemoveUnbroadcastTx(txid, true);
}
Expand Down Expand Up @@ -2258,6 +2265,11 @@ void PeerManagerImpl::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash,
}

void PeerManagerImpl::RelayTransaction(const uint256& txid)
{
WITH_LOCK(cs_main, _RelayTransaction(txid););
}

void PeerManagerImpl::_RelayTransaction(const uint256& txid)
{
LOCK(m_peer_mutex);
for(auto& it : m_peer_map) {
Expand Down Expand Up @@ -2937,7 +2949,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)

if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
RelayTransaction(porphanTx->GetHash());
_RelayTransaction(porphanTx->GetHash());
for (unsigned int i = 0; i < porphanTx->vout.size(); i++) {
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(orphanHash, i));
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
Expand Down Expand Up @@ -4068,7 +4080,7 @@ void PeerManagerImpl::ProcessMessage(
LogPrintf("Not relaying non-mempool transaction %s from forcerelay peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
} else {
LogPrintf("Force relaying tx %s from peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
RelayTransaction(tx.GetHash());
_RelayTransaction(tx.GetHash());
}
}
return;
Expand All @@ -4086,7 +4098,7 @@ void PeerManagerImpl::ProcessMessage(
}

m_mempool.check(m_chainman.ActiveChainstate());
RelayTransaction(tx.GetHash());
_RelayTransaction(tx.GetHash());

for (unsigned int i = 0; i < tx.vout.size(); i++) {
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(txid, i));
Expand Down
5 changes: 1 addition & 4 deletions src/net_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define BITCOIN_NET_PROCESSING_H

#include <net.h>
#include <sync.h>
#include <validationinterface.h>
#include <version.h>

Expand All @@ -28,7 +27,6 @@ class CTransaction;
struct CJContext;
struct LLMQContext;

extern RecursiveMutex cs_main;
extern RecursiveMutex g_cs_orphans;

/** Default for -maxorphantxsize, maximum size in megabytes the orphan map can grow before entries are removed */
Expand Down Expand Up @@ -94,8 +92,7 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
const int minProtoVersion = MIN_PEER_PROTO_VERSION) = 0;

/** Relay transaction to all peers. */
virtual void RelayTransaction(const uint256& txid)
EXCLUSIVE_LOCKS_REQUIRED(cs_main) = 0;
virtual void RelayTransaction(const uint256& txid) = 0;

/** Set the best height */
virtual void SetBestHeight(int height) = 0;
Expand Down
1 change: 0 additions & 1 deletion src/node/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
// best-effort of initial broadcast
node.mempool->AddUnbroadcastTx(hashTx);

LOCK(cs_main);
node.peerman->RelayTransaction(hashTx);
}

Expand Down