net_processing: rename RelayTransaction to better describe what it does

Rename `PeerManager::RelayTransaction()` to
`PeerManager::ScheduleTxForBroadcastToAll()`. The transaction is not relayed
when the method returns. It is only scheduled for broadcasting at a later
time. Also, there will be another method which only schedules for broadcast
to Tor or I2P peers.
This commit is contained in:
Vasil Dimov 2023-12-20 15:32:17 +01:00
parent 919e6d01e9
commit 44a726133a
No known key found for this signature in database
GPG Key ID: 54DF06F64B55CBBF
3 changed files with 13 additions and 8 deletions

View File

@ -536,7 +536,7 @@ public:
std::vector<node::TxOrphanage::OrphanInfo> GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex); std::vector<node::TxOrphanage::OrphanInfo> GetOrphanTransactions() override EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); PeerManagerInfo GetInfo() const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayTransaction(const Txid& txid, const Wtxid& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void ScheduleTxForBroadcastToAll(const Txid& txid, const Wtxid& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void SetBestBlock(int height, std::chrono::seconds time) override void SetBestBlock(int height, std::chrono::seconds time) override
{ {
m_best_height = height; m_best_height = height;
@ -1579,7 +1579,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
CTransactionRef tx = m_mempool.get(txid); CTransactionRef tx = m_mempool.get(txid);
if (tx != nullptr) { if (tx != nullptr) {
RelayTransaction(txid, tx->GetWitnessHash()); ScheduleTxForBroadcastToAll(txid, tx->GetWitnessHash());
} else { } else {
m_mempool.RemoveUnbroadcastTx(txid, true); m_mempool.RemoveUnbroadcastTx(txid, true);
} }
@ -2124,7 +2124,7 @@ void PeerManagerImpl::SendPings()
for(auto& it : m_peer_map) it.second->m_ping_queued = true; for(auto& it : m_peer_map) it.second->m_ping_queued = true;
} }
void PeerManagerImpl::RelayTransaction(const Txid& txid, const Wtxid& wtxid) void PeerManagerImpl::ScheduleTxForBroadcastToAll(const Txid& txid, const Wtxid& wtxid)
{ {
LOCK(m_peer_mutex); LOCK(m_peer_mutex);
for(auto& it : m_peer_map) { for(auto& it : m_peer_map) {
@ -3024,7 +3024,7 @@ void PeerManagerImpl::ProcessValidTx(NodeId nodeid, const CTransactionRef& tx, c
tx->GetWitnessHash().ToString(), tx->GetWitnessHash().ToString(),
m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000); m_mempool.size(), m_mempool.DynamicMemoryUsage() / 1000);
RelayTransaction(tx->GetHash(), tx->GetWitnessHash()); ScheduleTxForBroadcastToAll(tx->GetHash(), tx->GetWitnessHash());
for (const CTransactionRef& removedTx : replaced_transactions) { for (const CTransactionRef& removedTx : replaced_transactions) {
AddToCompactExtraTransactions(removedTx); AddToCompactExtraTransactions(removedTx);
@ -4286,7 +4286,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
} else { } else {
LogPrintf("Force relaying tx %s (wtxid=%s) from peer=%d\n", LogPrintf("Force relaying tx %s (wtxid=%s) from peer=%d\n",
txid.ToString(), wtxid.ToString(), pfrom.GetId()); txid.ToString(), wtxid.ToString(), pfrom.GetId());
RelayTransaction(txid, wtxid); ScheduleTxForBroadcastToAll(txid, wtxid);
} }
} }

View File

@ -116,8 +116,13 @@ public:
/** Get peer manager info. */ /** Get peer manager info. */
virtual PeerManagerInfo GetInfo() const = 0; virtual PeerManagerInfo GetInfo() const = 0;
/** Relay transaction to all peers. */ /**
virtual void RelayTransaction(const Txid& txid, const Wtxid& wtxid) = 0; * Schedule a transaction to be broadcast to all peers at a later time.
* This function saves the transaction id to `Peer::TxRelay::m_tx_inventory_to_send` for each peer.
* Later, depending on `Peer::TxRelay::m_next_inv_send_time` and if the transaction is in the
* mempool an `INV` about it is sent to the peer.
*/
virtual void ScheduleTxForBroadcastToAll(const Txid& txid, const Wtxid& wtxid) = 0;
/** Send ping message to all peers */ /** Send ping message to all peers */
virtual void SendPings() = 0; virtual void SendPings() = 0;

View File

@ -117,7 +117,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
} }
if (relay) { if (relay) {
node.peerman->RelayTransaction(txid, wtxid); node.peerman->ScheduleTxForBroadcastToAll(txid, wtxid);
} }
return TransactionError::OK; return TransactionError::OK;