mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 12:52:35 -03:00
[net processing] Add internal _RelayTransactions()
Callers of the external RelayTransactions() no longer need to lock cs_main.
This commit is contained in:
parent
b8593616dc
commit
39e19713cd
3 changed files with 14 additions and 11 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <reverse_iterator.h>
|
#include <reverse_iterator.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <txorphanage.h>
|
#include <txorphanage.h>
|
||||||
|
@ -256,6 +257,9 @@ public:
|
||||||
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override;
|
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void _RelayTransaction(const uint256& txid, const uint256& wtxid)
|
||||||
|
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
/** Consider evicting an outbound peer based on the amount of time they've been behind our tip */
|
/** 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);
|
void ConsiderEviction(CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||||
|
|
||||||
|
@ -1015,7 +1019,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
|
||||||
|
|
||||||
if (tx != nullptr) {
|
if (tx != nullptr) {
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
RelayTransaction(txid, tx->GetWitnessHash());
|
_RelayTransaction(txid, tx->GetWitnessHash());
|
||||||
} else {
|
} else {
|
||||||
m_mempool.RemoveUnbroadcastTx(txid, true);
|
m_mempool.RemoveUnbroadcastTx(txid, true);
|
||||||
}
|
}
|
||||||
|
@ -1511,6 +1515,11 @@ void PeerManagerImpl::SendPings()
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid)
|
void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid)
|
||||||
|
{
|
||||||
|
WITH_LOCK(cs_main, _RelayTransaction(txid, wtxid););
|
||||||
|
}
|
||||||
|
|
||||||
|
void PeerManagerImpl::_RelayTransaction(const uint256& txid, const uint256& wtxid)
|
||||||
{
|
{
|
||||||
m_connman.ForEachNode([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
m_connman.ForEachNode([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||||
AssertLockHeld(::cs_main);
|
AssertLockHeld(::cs_main);
|
||||||
|
@ -2087,7 +2096,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
|
||||||
|
|
||||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
||||||
RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
|
_RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
|
||||||
m_orphanage.AddChildrenToWorkSet(*porphanTx, orphan_work_set);
|
m_orphanage.AddChildrenToWorkSet(*porphanTx, orphan_work_set);
|
||||||
m_orphanage.EraseTx(orphanHash);
|
m_orphanage.EraseTx(orphanHash);
|
||||||
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
|
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
|
||||||
|
@ -3055,7 +3064,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
LogPrintf("Not relaying non-mempool transaction %s from forcerelay peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
|
LogPrintf("Not relaying non-mempool transaction %s from forcerelay peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
|
||||||
} else {
|
} else {
|
||||||
LogPrintf("Force relaying tx %s from peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
|
LogPrintf("Force relaying tx %s from peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
|
||||||
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
|
_RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -3070,7 +3079,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||||
// requests for it.
|
// requests for it.
|
||||||
m_txrequest.ForgetTxHash(tx.GetHash());
|
m_txrequest.ForgetTxHash(tx.GetHash());
|
||||||
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
||||||
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
|
_RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
|
||||||
m_orphanage.AddChildrenToWorkSet(tx, peer->m_orphan_work_set);
|
m_orphanage.AddChildrenToWorkSet(tx, peer->m_orphan_work_set);
|
||||||
|
|
||||||
pfrom.nLastTXTime = GetTime();
|
pfrom.nLastTXTime = GetTime();
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#define BITCOIN_NET_PROCESSING_H
|
#define BITCOIN_NET_PROCESSING_H
|
||||||
|
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <sync.h>
|
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
|
||||||
class CAddrMan;
|
class CAddrMan;
|
||||||
|
@ -15,8 +14,6 @@ class CChainParams;
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
class ChainstateManager;
|
class ChainstateManager;
|
||||||
|
|
||||||
extern RecursiveMutex cs_main;
|
|
||||||
|
|
||||||
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
|
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
|
||||||
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
|
static const unsigned int DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100;
|
||||||
/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
|
/** Default number of orphan+recently-replaced txn to keep around for block reconstruction */
|
||||||
|
@ -49,8 +46,7 @@ public:
|
||||||
virtual bool IgnoresIncomingTxs() = 0;
|
virtual bool IgnoresIncomingTxs() = 0;
|
||||||
|
|
||||||
/** Relay transaction to all peers. */
|
/** Relay transaction to all peers. */
|
||||||
virtual void RelayTransaction(const uint256& txid, const uint256& wtxid)
|
virtual void RelayTransaction(const uint256& txid, const uint256& wtxid) = 0;
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main) = 0;
|
|
||||||
|
|
||||||
/** Send ping message to all peers */
|
/** Send ping message to all peers */
|
||||||
virtual void SendPings() = 0;
|
virtual void SendPings() = 0;
|
||||||
|
|
|
@ -100,8 +100,6 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
||||||
// the mempool tracks locally submitted transactions to make a
|
// the mempool tracks locally submitted transactions to make a
|
||||||
// best-effort of initial broadcast
|
// best-effort of initial broadcast
|
||||||
node.mempool->AddUnbroadcastTx(hashTx);
|
node.mempool->AddUnbroadcastTx(hashTx);
|
||||||
|
|
||||||
LOCK(cs_main);
|
|
||||||
node.peerman->RelayTransaction(hashTx, tx->GetWitnessHash());
|
node.peerman->RelayTransaction(hashTx, tx->GetWitnessHash());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue