Skip to content

Commit e057e01

Browse files
committed
Merge #21162: Net Processing: Move RelayTransaction() into PeerManager
680eb56 [net processing] Don't pass CConnman to RelayTransactions (John Newbery) a38a4e8 [net processing] Move RelayTransaction into PeerManager (John Newbery) Pull request description: This is the first part of #21160. It moves the RelayTransaction() function to be a member function of the PeerManager class. This is required in order to move the transaction inventory data into the Peer object, since Peer objects are only accessible from within PeerManager. ACKs for top commit: ajtowns: ACK 680eb56 Tree-SHA512: 8c93491a4392b6369bb7f090de326a63cd62a088de59026e202f226f64ded50a0cf1a95ed703328860f02a9d2f64d3a87ca1bca9a6075b978bd111d384766235
2 parents bf7c22f + 680eb56 commit e057e01

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class PeerManagerImpl final : public PeerManager
247247
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) override;
248248
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
249249
void SendPings() override;
250+
void RelayTransaction(const uint256& txid, const uint256& wtxid) override;
250251
void SetBestHeight(int height) override { m_best_height = height; };
251252
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) override;
252253
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
@@ -260,7 +261,7 @@ class PeerManagerImpl final : public PeerManager
260261
void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
261262

262263
/** Retrieve unbroadcast transactions from the mempool and reattempt sending to peers */
263-
void ReattemptInitialBroadcast(CScheduler& scheduler) const;
264+
void ReattemptInitialBroadcast(CScheduler& scheduler);
264265

265266
/** Get a shared pointer to the Peer object.
266267
* May return an empty shared_ptr if the Peer object can't be found. */
@@ -949,7 +950,7 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
949950
}
950951
}
951952

952-
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler) const
953+
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
953954
{
954955
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
955956

@@ -958,7 +959,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler) const
958959

959960
if (tx != nullptr) {
960961
LOCK(cs_main);
961-
RelayTransaction(txid, tx->GetWitnessHash(), m_connman);
962+
RelayTransaction(txid, tx->GetWitnessHash());
962963
} else {
963964
m_mempool.RemoveUnbroadcastTx(txid, true);
964965
}
@@ -1460,9 +1461,9 @@ void PeerManagerImpl::SendPings()
14601461
for(auto& it : m_peer_map) it.second->m_ping_queued = true;
14611462
}
14621463

1463-
void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman)
1464+
void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid)
14641465
{
1465-
connman.ForEachNode([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
1466+
m_connman.ForEachNode([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
14661467
AssertLockHeld(::cs_main);
14671468

14681469
CNodeState* state = State(pnode->GetId());
@@ -2042,7 +2043,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
20422043

20432044
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
20442045
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
2045-
RelayTransaction(orphanHash, porphanTx->GetWitnessHash(), m_connman);
2046+
RelayTransaction(orphanHash, porphanTx->GetWitnessHash());
20462047
m_orphanage.AddChildrenToWorkSet(*porphanTx, orphan_work_set);
20472048
m_orphanage.EraseTx(orphanHash);
20482049
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
@@ -3046,7 +3047,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
30463047
LogPrintf("Not relaying non-mempool transaction %s from forcerelay peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
30473048
} else {
30483049
LogPrintf("Force relaying tx %s from peer=%d\n", tx.GetHash().ToString(), pfrom.GetId());
3049-
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
3050+
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
30503051
}
30513052
}
30523053
return;
@@ -3061,7 +3062,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
30613062
// requests for it.
30623063
m_txrequest.ForgetTxHash(tx.GetHash());
30633064
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
3064-
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
3065+
RelayTransaction(tx.GetHash(), tx.GetWitnessHash());
30653066
m_orphanage.AddChildrenToWorkSet(tx, peer->m_orphan_work_set);
30663067

30673068
pfrom.nLastTXTime = GetTime();

src/net_processing.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
4747
/** Whether this node ignores txs received over p2p. */
4848
virtual bool IgnoresIncomingTxs() = 0;
4949

50+
/** Relay transaction to all peers. */
51+
virtual void RelayTransaction(const uint256& txid, const uint256& wtxid)
52+
EXCLUSIVE_LOCKS_REQUIRED(cs_main) = 0;
53+
5054
/** Send ping message to all peers */
5155
virtual void SendPings() = 0;
5256

@@ -71,7 +75,4 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
7175
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) = 0;
7276
};
7377

74-
/** Relay transaction to every node */
75-
void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
76-
7778
#endif // BITCOIN_NET_PROCESSING_H

src/node/transaction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ static TransactionError HandleATMPError(const TxValidationState& state, std::str
2929
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
3030
{
3131
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
32-
// node.connman is assigned both before chain clients and before RPC server is accepting calls,
33-
// and reset after chain clients and RPC sever are stopped. node.connman should never be null here.
34-
assert(node.connman);
32+
// node.peerman is assigned both before chain clients and before RPC server is accepting calls,
33+
// and reset after chain clients and RPC sever are stopped. node.peerman should never be null here.
34+
assert(node.peerman);
3535
assert(node.mempool);
3636
std::promise<void> promise;
3737
uint256 hashTx = tx->GetHash();
@@ -101,7 +101,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
101101
node.mempool->AddUnbroadcastTx(hashTx);
102102

103103
LOCK(cs_main);
104-
RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);
104+
node.peerman->RelayTransaction(hashTx, tx->GetWitnessHash());
105105
}
106106

107107
return TransactionError::OK;

0 commit comments

Comments
 (0)