1
1
mirror of https://github.com/bitcoin/bitcoin.git synced 2024-05-17 23:56:39 +00:00

[net processing] Use ignore_incoming_txs from m_opts

This commit is contained in:
dergoegge 2023-04-20 13:36:36 +02:00
parent 8b87725921
commit 4cfb7b925f
2 changed files with 7 additions and 10 deletions

View File

@ -515,7 +515,7 @@ public:
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; } bool IgnoresIncomingTxs() override { return m_opts.ignore_incoming_txs; }
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); void RelayTransaction(const uint256& txid, const uint256& wtxid) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void SetBestHeight(int height) override { m_best_height = height; }; void SetBestHeight(int height) override { m_best_height = height; };
@ -718,9 +718,6 @@ private:
/** Next time to check for stale tip */ /** Next time to check for stale tip */
std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s}; std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s};
/** Whether this node is running in -blocksonly mode */
const bool m_ignore_incoming_txs;
const Options m_opts; const Options m_opts;
bool RejectIncomingTxs(const CNode& peer) const; bool RejectIncomingTxs(const CNode& peer) const;
@ -1214,7 +1211,7 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
// When in -blocksonly mode, never request high-bandwidth mode from peers. Our // When in -blocksonly mode, never request high-bandwidth mode from peers. Our
// mempool will not contain the transactions necessary to reconstruct the // mempool will not contain the transactions necessary to reconstruct the
// compact block. // compact block.
if (m_ignore_incoming_txs) return; if (m_opts.ignore_incoming_txs) return;
CNodeState* nodestate = State(nodeid); CNodeState* nodestate = State(nodeid);
if (!nodestate || !nodestate->m_provides_cmpctblocks) { if (!nodestate || !nodestate->m_provides_cmpctblocks) {
@ -1825,7 +1822,6 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
m_banman(banman), m_banman(banman),
m_chainman(chainman), m_chainman(chainman),
m_mempool(pool), m_mempool(pool),
m_ignore_incoming_txs(opts.ignore_incoming_txs),
m_opts{opts} m_opts{opts}
{ {
// While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation. // While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
@ -2732,7 +2728,7 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
last_header.nHeight); last_header.nHeight);
} }
if (vGetData.size() > 0) { if (vGetData.size() > 0) {
if (!m_ignore_incoming_txs && if (!m_opts.ignore_incoming_txs &&
nodestate->m_provides_cmpctblocks && nodestate->m_provides_cmpctblocks &&
vGetData.size() == 1 && vGetData.size() == 1 &&
mapBlocksInFlight.size() == 1 && mapBlocksInFlight.size() == 1 &&
@ -3437,7 +3433,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// - we are not in -blocksonly mode. // - we are not in -blocksonly mode.
const auto* tx_relay = peer->GetTxRelay(); const auto* tx_relay = peer->GetTxRelay();
if (tx_relay && WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs) && if (tx_relay && WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs) &&
!pfrom.IsAddrFetchConn() && !m_ignore_incoming_txs) { !pfrom.IsAddrFetchConn() && !m_opts.ignore_incoming_txs) {
const uint64_t recon_salt = m_txreconciliation->PreRegisterPeer(pfrom.GetId()); const uint64_t recon_salt = m_txreconciliation->PreRegisterPeer(pfrom.GetId());
m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDTXRCNCL, m_connman.PushMessage(&pfrom, msg_maker.Make(NetMsgType::SENDTXRCNCL,
TXRECONCILIATION_VERSION, recon_salt)); TXRECONCILIATION_VERSION, recon_salt));
@ -5361,7 +5357,7 @@ void PeerManagerImpl::MaybeSendSendHeaders(CNode& node, Peer& peer)
void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time) void PeerManagerImpl::MaybeSendFeefilter(CNode& pto, Peer& peer, std::chrono::microseconds current_time)
{ {
if (m_ignore_incoming_txs) return; if (m_opts.ignore_incoming_txs) return;
if (pto.GetCommonVersion() < FEEFILTER_VERSION) return; if (pto.GetCommonVersion() < FEEFILTER_VERSION) return;
// peers with the forcerelay permission should not filter txs to us // peers with the forcerelay permission should not filter txs to us
if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return; if (pto.HasPermission(NetPermissionFlags::ForceRelay)) return;
@ -5429,7 +5425,7 @@ bool PeerManagerImpl::RejectIncomingTxs(const CNode& peer) const
if (peer.IsBlockOnlyConn()) return true; if (peer.IsBlockOnlyConn()) return true;
if (peer.IsFeelerConn()) return true; if (peer.IsFeelerConn()) return true;
// In -blocksonly mode, peers need the 'relay' permission to send txs to us // In -blocksonly mode, peers need the 'relay' permission to send txs to us
if (m_ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true; if (m_opts.ignore_incoming_txs && !peer.HasPermission(NetPermissionFlags::Relay)) return true;
return false; return false;
} }

View File

@ -44,6 +44,7 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
{ {
public: public:
struct Options { struct Options {
/** Whether this node is running in -blocksonly mode */
bool ignore_incoming_txs{DEFAULT_BLOCKSONLY}; bool ignore_incoming_txs{DEFAULT_BLOCKSONLY};
}; };