Skip to content

Commit a38a4e8

Browse files
committed
[net processing] Move RelayTransaction into PeerManager
We don't mark RelayTransaction as const. Even though it doesn't mutate PeerManagerImpl state, it _is_ mutating the internal state of a CNode object, by updating setInventoryTxToSend. In a subsequent commit, that field will be moved to the Peer object, which is owned by PeerMangerImpl. This requires PeerManagerImpl::ReattemptInitialBroadcast() to no longer be const.
1 parent 92b7efc commit a38a4e8

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class PeerManagerImpl final : public PeerManager
242242
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) override;
243243
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
244244
void SendPings() override;
245+
void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman) override;
245246
void SetBestHeight(int height) override { m_best_height = height; };
246247
void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) override;
247248
void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv,
@@ -255,7 +256,7 @@ class PeerManagerImpl final : public PeerManager
255256
void EvictExtraOutboundPeers(int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
256257

257258
/** Retrieve unbroadcast transactions from the mempool and reattempt sending to peers */
258-
void ReattemptInitialBroadcast(CScheduler& scheduler) const;
259+
void ReattemptInitialBroadcast(CScheduler& scheduler);
259260

260261
/** Get a shared pointer to the Peer object.
261262
* May return an empty shared_ptr if the Peer object can't be found. */
@@ -954,7 +955,7 @@ void PeerManagerImpl::InitializeNode(CNode *pnode)
954955
}
955956
}
956957

957-
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler) const
958+
void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
958959
{
959960
std::set<uint256> unbroadcast_txids = m_mempool.GetUnbroadcastTxs();
960961

@@ -1464,7 +1465,7 @@ void PeerManagerImpl::SendPings()
14641465
for(auto& it : m_peer_map) it.second->m_ping_queued = true;
14651466
}
14661467

1467-
void RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman)
1468+
void PeerManagerImpl::RelayTransaction(const uint256& txid, const uint256& wtxid, const CConnman& connman)
14681469
{
14691470
connman.ForEachNode([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
14701471
AssertLockHeld(::cs_main);

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, const CConnman& connman)
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
3232
// node.connman is assigned both before chain clients and before RPC server is accepting calls,
3333
// and reset after chain clients and RPC sever are stopped. node.connman should never be null here.
3434
assert(node.connman);
35+
assert(node.peerman);
3536
assert(node.mempool);
3637
std::promise<void> promise;
3738
uint256 hashTx = tx->GetHash();
@@ -100,7 +101,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
100101
node.mempool->AddUnbroadcastTx(hashTx);
101102

102103
LOCK(cs_main);
103-
RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);
104+
node.peerman->RelayTransaction(hashTx, tx->GetWitnessHash(), *node.connman);
104105
}
105106

106107
return TransactionError::OK;

0 commit comments

Comments
 (0)