Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864959
D16795.id49771.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D16795.id49771.diff
View Options
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1176,6 +1176,8 @@
const Options m_opts;
+ bool RejectIncomingTxs(const CNode &peer) const;
+
/**
* Whether we've completed initial sync yet, for determining when to turn
* on extra block-relay-only peers.
@@ -1780,9 +1782,9 @@
void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid) {
AssertLockHeld(cs_main);
- // Never request high-bandwidth mode from peers if we're blocks-only. Our
- // mempool will not contain the transactions necessary to reconstruct the
- // compact block.
+ // When in -blocksonly mode, never request high-bandwidth mode from peers.
+ // Our mempool will not contain the transactions necessary to reconstruct
+ // the compact block.
if (m_opts.ignore_incoming_txs) {
return;
}
@@ -5191,16 +5193,7 @@
return;
}
- // Reject tx INVs when the -blocksonly setting is enabled, or this is a
- // block-relay-only peer
- bool reject_tx_invs{m_opts.ignore_incoming_txs ||
- pfrom.IsBlockOnlyConn()};
-
- // Allow peers with relay permission to send data other than blocks
- // in blocks only mode
- if (pfrom.HasPermission(NetPermissionFlags::Relay)) {
- reject_tx_invs = false;
- }
+ const bool reject_tx_invs{RejectIncomingTxs(pfrom)};
const auto current_time{GetTime<std::chrono::microseconds>()};
std::optional<BlockHash> best_block;
@@ -5604,12 +5597,7 @@
}
if (msg_type == NetMsgType::TX) {
- // Stop processing the transaction early if
- // 1) We are in blocks only mode and peer has no relay permission; OR
- // 2) This peer is a block-relay-only peer
- if ((m_opts.ignore_incoming_txs &&
- !pfrom.HasPermission(NetPermissionFlags::Relay)) ||
- pfrom.IsBlockOnlyConn()) {
+ if (RejectIncomingTxs(pfrom)) {
LogPrint(BCLog::NET,
"transaction sent in violation of protocol peer=%d\n",
pfrom.GetId());
@@ -8125,6 +8113,19 @@
};
} // namespace
+bool PeerManagerImpl::RejectIncomingTxs(const CNode &peer) const {
+ // block-relay-only peers may never send txs to us
+ if (peer.IsBlockOnlyConn()) {
+ return true;
+ }
+ // In -blocksonly mode, peers need the 'relay' permission to send txs to us
+ if (m_opts.ignore_incoming_txs &&
+ !peer.HasPermission(NetPermissionFlags::Relay)) {
+ return true;
+ }
+ return false;
+}
+
bool PeerManagerImpl::SetupAddressRelay(const CNode &node, Peer &peer) {
// We don't participate in addr relay with outbound block-relay-only
// connections to prevent providing adversaries with the additional
diff --git a/test/functional/p2p_blocksonly.py b/test/functional/p2p_blocksonly.py
--- a/test/functional/p2p_blocksonly.py
+++ b/test/functional/p2p_blocksonly.py
@@ -115,6 +115,15 @@
assert_equal(self.nodes[0].getpeerinfo()[0]["relaytxes"], False)
_, txid, tx_hex = self.check_p2p_tx_violation()
+ self.log.info(
+ "Tests with node in normal mode with block-relay-only connection, sending an inv"
+ )
+ conn = self.nodes[0].add_outbound_p2p_connection(
+ P2PInterface(), p2p_idx=0, connection_type="block-relay-only"
+ )
+ assert_equal(self.nodes[0].getpeerinfo()[0]["relaytxes"], False)
+ self.check_p2p_inv_violation(conn)
+
self.log.info("Check that txs from RPC are not sent to blockrelay connection")
conn = self.nodes[0].add_outbound_p2p_connection(
P2PTxInvStore(), p2p_idx=1, connection_type="block-relay-only"
@@ -128,6 +137,17 @@
conn.sync_with_ping()
assert int(txid, 16) not in conn.get_invs()
+ def check_p2p_inv_violation(self, peer):
+ self.log.info(
+ "Check that tx-invs from P2P are rejected and result in disconnect"
+ )
+ with self.nodes[0].assert_debug_log(
+ ["inv sent in violation of protocol, disconnecting peer"]
+ ):
+ peer.send_message(msg_inv([CInv(t=MSG_TX, h=0x12345)]))
+ peer.wait_for_disconnect()
+ self.nodes[0].disconnect_p2ps()
+
def check_p2p_tx_violation(self):
self.log.info("Check that txs from P2P are rejected and result in disconnect")
spendtx = self.miniwallet.create_self_transfer()
@@ -138,9 +158,7 @@
self.nodes[0].p2ps[0].send_message(msg_tx(spendtx["tx"]))
self.nodes[0].p2ps[0].wait_for_disconnect()
assert_equal(self.nodes[0].getmempoolinfo()["size"], 0)
-
- # Remove the disconnected peer
- del self.nodes[0].p2ps[0]
+ self.nodes[0].disconnect_p2ps()
return spendtx["tx"], spendtx["txid"], spendtx["hex"]
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 23:39 (30 m, 38 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865184
Default Alt Text
D16795.id49771.diff (4 KB)
Attached To
D16795: refactor: Introduce PeerManagerImpl::RejectIncomingTxs
Event Timeline
Log In to Comment