Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35319. ReviewsSee the guideline for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Just to clarify the impact, does this mean that "ipv4-through-tor" private broadcast connections that fall back to v1 (e.g. because the peer does not support it) are re-attempted as clearnet connections, and therefore directly reveal the IP address of the tx sender? |
|
Whoops! Seems like a great time to get some V2 tests in p2p_private_broadcast.py :) Looks like we mainly disable it currently. How does this play with |
|
(answers without testing, just by reading the code) @dergoegge, yes, exactly! @willcl-ark, I think it will do v1 to the original address and schedule a new connection. I am looking to add a test for this. Trying to avoid extending |
Here are two preliminary tests. Both fail without this PR and pass with this PR: Unit test Functional test What do you think? PS should be possible to make a functional test that does not need non-testing code modifications. That would exercise the |
This seems like a bug or at least is confusing: in addition to connecting to a new peer (since |
|
tried a slightly different tactic to reduce chance of future regressions, seeing what people think about it: https://github.com/instagibbs/bitcoin/commits/2026-05-private_tx_proxy/ |
I think this is helpful as a unit test, though imo it'd be great if the existing p2p_private_broadcast.py functional test could be changed to also test the downgrade which might let us get coverage for the extra connection mentioned here.
Is there a specific reason it can't be added to the existing functional test? Is it too complicated? I think modifying non-test code here is a downside. I think @instagibbs branch would let you do the functional test without modifying addnode since there's no threading |
My thoughts in: instagibbs@fc8ed47#r186068246 or instagibbs@fc8ed47#commitcomment-186068694 (not sure if github deleted one of those) |
@Crypt-iQ, from #35319 (comment):
Probably it can be added and doing so it tempting and will probably result in less number of lines added. However I have walked this road before and it does not lead to a nice place - eventually we end up with a huge test that is difficult to manage and debug once some piece of it fails. I would rather try to split
Hmm... threading (as in passing around the |
I think that would be good, if there is time to do that before the minor release.
By this I meant that in your functional test above you needed to modify
Github deleted one (time to move...). I think the layering violation point makes sense, though I'll point out there is some awareness of private broadcast in |
|
alternative test attempt for consideration in part/full/whatever. For convenience adds a service flag arg for debug only rpc, though not strictly required. It's kinda long, but should be fairly robust to regressions? |
|
What about adding something like this so we don't connect directly for any reason: diff --git a/src/net.cpp b/src/net.cpp
index 7edb8eacf4..430db0eb08 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -488,6 +488,9 @@ CNode* CConnman::ConnectNode(CAddress addrConnect,
LogDebug(BCLog::PROXY, "Using proxy: %s to connect to %s\n", use_proxy->ToString(), target_addr.ToStringAddrPort());
sock = ConnectThroughProxy(*use_proxy, target_addr.ToStringAddr(), target_addr.GetPort(), proxyConnectionFailed);
} else {
+ if (conn_type == ConnectionType::PRIVATE_BROADCAST && target_addr.GetSAFamily() != AF_UNSPEC) {
+ continue;
+ }
// no proxy needed (none set for target network)
sock = ConnectDirectly(target_addr, conn_type == ConnectionType::MANUAL);
} |
65c790e to
280708c
Compare
|
Makes sense, a kind of safety net for the future. Added with some mods: no need to check the address type - all private broadcast connections require a proxy. And made it an |
Can you also add a release note (which we will also use for the minor release notes), which explains the issue, so anyone using -privatebroadcast can know if they've been impacted (I can't recall if all users may be affected, or if there are any "safe" configurations). |
`OpenNetworkConnection()` supports overriding the proxy to use for connecting. However when v2 connection is attempted and it fails a v1 connection is tried without that proxy. Store the override proxy in `CNode` and pass it to `CConnman::m_reconnections` to be used for v1 retries.
Private broadcast connections use either Tor or I2P, which require a proxy intrinsically or IPv4 or IPv6 which must use a proxy in the context of private broadcast to avoid leaking the originator's IP address. Add a safety check to guard against future mistakes. Co-authored-by: Andrew Toth <[email protected]>
280708c to
32d072a
Compare
|
|
|
Can we get the unit test added here at least? |
|
Can we remove diff on 32d072adiff --git a/src/net.cpp b/src/net.cpp
index 3e2b81b09a..a97341cec2 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1919,7 +1919,7 @@ bool CConnman::AddConnection(const std::string& address, ConnectionType conn_typ
CountingSemaphoreGrant<> grant(*semOutbound, true);
if (!grant) return false;
- OpenNetworkConnection(CAddress(), false, std::move(grant), address.c_str(), conn_type, /*use_v2transport=*/use_v2transport);
+ OpenNetworkConnection(CAddress(), false, std::move(grant), address.c_str(), conn_type, /*use_v2transport=*/use_v2transport, std::nullopt);
return true;
}
@@ -2443,7 +2443,7 @@ void CConnman::ProcessAddrFetch()
CAddress addr;
CountingSemaphoreGrant<> grant(*semOutbound, /*fTry=*/true);
if (grant) {
- OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport);
+ OpenNetworkConnection(addr, false, std::move(grant), strDest.c_str(), ConnectionType::ADDR_FETCH, use_v2transport, std::nullopt);
}
}
@@ -2572,7 +2572,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
for (const std::string& strAddr : connect)
{
CAddress addr(CService(), NODE_NONE);
- OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/use_v2transport);
+ OpenNetworkConnection(addr, false, {}, strAddr.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/use_v2transport, std::nullopt);
for (int i = 0; i < 10 && i < nLoop; i++)
{
if (!m_interrupt_net->sleep_for(500ms)) {
@@ -2922,7 +2922,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, std
const bool count_failures{((int)outbound_ipv46_peer_netgroups.size() + outbound_privacy_network_peers) >= std::min(m_max_automatic_connections - 1, 2)};
// Use BIP324 transport when both us and them have NODE_V2_P2P set.
const bool use_v2transport(addrConnect.nServices & GetLocalServices() & NODE_P2P_V2);
- OpenNetworkConnection(addrConnect, count_failures, std::move(grant), /*pszDest=*/nullptr, conn_type, use_v2transport);
+ OpenNetworkConnection(addrConnect, count_failures, std::move(grant), /*pszDest=*/nullptr, conn_type, use_v2transport, std::nullopt);
}
}
}
@@ -3022,7 +3022,7 @@ void CConnman::ThreadOpenAddedConnections()
}
tried = true;
CAddress addr(CService(), NODE_NONE);
- OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport);
+ OpenNetworkConnection(addr, false, std::move(grant), info.m_params.m_added_node.c_str(), ConnectionType::MANUAL, info.m_params.m_use_v2transport, std::nullopt);
if (!m_interrupt_net->sleep_for(500ms)) return;
grant = CountingSemaphoreGrant<>(*semAddnode, /*fTry=*/true);
}
diff --git a/src/net.h b/src/net.h
index fe8322d1f3..a56f9a20d1 100644
--- a/src/net.h
+++ b/src/net.h
@@ -1191,7 +1191,7 @@ public:
const char* pszDest,
ConnectionType conn_type,
bool use_v2transport,
- const std::optional<Proxy>& proxy_override = std::nullopt)
+ const std::optional<Proxy>& proxy_override)
EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex, !m_unused_i2p_sessions_mutex);
/// Group of private broadcast related members.
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 20bb1cb480..06c756fd69 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -358,7 +358,7 @@ static RPCMethod addnode()
if (command == "onetry")
{
CAddress addr;
- connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grant_outbound=*/{}, std::string{node_arg}.c_str(), ConnectionType::MANUAL, use_v2transport);
+ connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grant_outbound=*/{}, std::string{node_arg}.c_str(), ConnectionType::MANUAL, use_v2transport, std::nullopt);
return UniValue::VNULL;
}
Edit: changed diff to use |
|
@andrewtoth I'd expect a solid regression test, unless there's compelling reasoning given otherwise. I can work on modifying the last test I posted to make no rpc changes if that simplifies things |
I am working on a functional test that exercises this via the natural path of a private broadcast to IPv4 address with p2p_v2=1 flag which actually does not support v2 and a subsequent v1 retry. If that works, I think it will trump the other tests. Since it needs the test set up for private broadcast (e.g. addrman filled, automatic connections enabled, SOCKS5 proxy with a destinations factory, etc) that duplicates with parts of
Ok, will do. |
Done in #35410, which contains this PR + a functional test. I did not append the test here to this PR because I feel that the mood among reviewers might be to merge the fix and debate on the test longer. With two PRs reviewers can choose - review only the fix (here) or review the fix and the test (#35410). There are a bunch of tests for this which fail without the fix and pass with the fix. That should give some confidence to reviewers that the fix indeed works even if they do not thoroughly review the tests themselves: #35319 (comment) #35319 (comment) #35410 |
This is not what i get from reading the thread. All 3 active reviewers explicitly asked you to add a test here. I’m also baffled that you’d expect a fix for a critical bug in a feature we just shipped to be merged without a test confirming that it actually fixes the issue. |
…nections bf0d257 net: un-default the OpenNetworkConnection()'s proxy_override argument (Eugene Siegel) 5a3756d test: add a regression test for private broadcast v1 retries (Vasil Dimov) ab35a02 test: make reusable filling of a node's addrman (Vasil Dimov) 2333be9 test: make reusable starting a standalone P2P listener (Vasil Dimov) 2ffa81f test: make reusable SOCKS5 server starting (Vasil Dimov) 32d072a doc: add release notes for #35319 (Vasil Dimov) d01b461 net: ensure no direct private broadcast connections (Vasil Dimov) fd230f9 net: use the proxy if overriden when doing v2->v1 reconnections (Vasil Dimov) Pull request description: This PR includes #35319 and on top of that adds a regression functional test. The functional test exercises the relevant code paths without modifying non-test code. To do that it does: * Add a bunch of IPv4 addresses to the node's addrman (they will be added without P2P_V2 flag). * Get them to report P2P_V2 in their service flags and connect to each one, so that the flags in addrman are updated to contain P2P_V2. * Get one successful connection to a Tor peer (.onion) so that bitcoind assumes the configured Tor proxy works and is indeed a proxy to the Tor network. This will make it open private broadcast connections also to IPv4 addresses via that proxy. * Start some private broadcast connections. * Remember the destination IPv4 address of the first connection and get it to fail the v2 transport. * Wait for a subsequent connection also through the Tor proxy to the same IPv4 and expect it to be v1, i.e. the v2->v1 downgrade retry. The test fails without the fix - the v1 retry never arrives to the Tor proxy. And passes with the fix. The fix is in the first commit here and in #35319, can remove it by `git show fd230f9 | git apply -R`. ACKs for top commit: Crypt-iQ: reACK bf0d257 andrewtoth: ACK bf0d257 instagibbs: ACK bf0d257 sedited: utACK bf0d257 Tree-SHA512: 11e89be36577199e0312e5e63efeac04e295faaba1cf1c13a30e683d35f473c8dbb419d1897b0333c2e993c10637adecafcf90fe08c812065c793cbc903744c9
…1 reconnections bf0d257 net: un-default the OpenNetworkConnection()'s proxy_override argument (Eugene Siegel) 5a3756d test: add a regression test for private broadcast v1 retries (Vasil Dimov) ab35a02 test: make reusable filling of a node's addrman (Vasil Dimov) 2333be9 test: make reusable starting a standalone P2P listener (Vasil Dimov) 2ffa81f test: make reusable SOCKS5 server starting (Vasil Dimov) 32d072a doc: add release notes for bitcoin#35319 (Vasil Dimov) d01b461 net: ensure no direct private broadcast connections (Vasil Dimov) fd230f9 net: use the proxy if overriden when doing v2->v1 reconnections (Vasil Dimov) Pull request description: This PR includes bitcoin#35319 and on top of that adds a regression functional test. The functional test exercises the relevant code paths without modifying non-test code. To do that it does: * Add a bunch of IPv4 addresses to the node's addrman (they will be added without P2P_V2 flag). * Get them to report P2P_V2 in their service flags and connect to each one, so that the flags in addrman are updated to contain P2P_V2. * Get one successful connection to a Tor peer (.onion) so that bitcoind assumes the configured Tor proxy works and is indeed a proxy to the Tor network. This will make it open private broadcast connections also to IPv4 addresses via that proxy. * Start some private broadcast connections. * Remember the destination IPv4 address of the first connection and get it to fail the v2 transport. * Wait for a subsequent connection also through the Tor proxy to the same IPv4 and expect it to be v1, i.e. the v2->v1 downgrade retry. The test fails without the fix - the v1 retry never arrives to the Tor proxy. And passes with the fix. The fix is in the first commit here and in bitcoin#35319, can remove it by `git show fd230f9 | git apply -R`. ACKs for top commit: Crypt-iQ: reACK bf0d257 andrewtoth: ACK bf0d257 instagibbs: ACK bf0d257 sedited: utACK bf0d257 Tree-SHA512: 11e89be36577199e0312e5e63efeac04e295faaba1cf1c13a30e683d35f473c8dbb419d1897b0333c2e993c10637adecafcf90fe08c812065c793cbc903744c9
…ng v2->v1 reconnections 33082c7 net: un-default the OpenNetworkConnection()'s proxy_override argument (Eugene Siegel) 105ee73 test: add a regression test for private broadcast v1 retries (Vasil Dimov) 03e590e test: make reusable filling of a node's addrman (Vasil Dimov) c00f441 test: make reusable starting a standalone P2P listener (Vasil Dimov) 950dd17 test: make reusable SOCKS5 server starting (Vasil Dimov) ec3cbfb doc: add release notes for #35319 (Vasil Dimov) ab44455 net: ensure no direct private broadcast connections (Vasil Dimov) 78b2340 net: use the proxy if overriden when doing v2->v1 reconnections (Vasil Dimov) Pull request description: This PR includes bitcoin/bitcoin#35319 and on top of that adds a regression functional test. The functional test exercises the relevant code paths without modifying non-test code. To do that it does: * Add a bunch of IPv4 addresses to the node's addrman (they will be added without P2P_V2 flag). * Get them to report P2P_V2 in their service flags and connect to each one, so that the flags in addrman are updated to contain P2P_V2. * Get one successful connection to a Tor peer (.onion) so that bitcoind assumes the configured Tor proxy works and is indeed a proxy to the Tor network. This will make it open private broadcast connections also to IPv4 addresses via that proxy. * Start some private broadcast connections. * Remember the destination IPv4 address of the first connection and get it to fail the v2 transport. * Wait for a subsequent connection also through the Tor proxy to the same IPv4 and expect it to be v1, i.e. the v2->v1 downgrade retry. The test fails without the fix - the v1 retry never arrives to the Tor proxy. And passes with the fix. The fix is in the first commit here and in bitcoin/bitcoin#35319, can remove it by `git show 78b2340 | git apply -R`. ACKs for top commit: Crypt-iQ: reACK 33082c7 andrewtoth: ACK 33082c7 instagibbs: ACK 33082c7 sedited: utACK 33082c7 Tree-SHA512: 11e89be36577199e0312e5e63efeac04e295faaba1cf1c13a30e683d35f473c8dbb419d1897b0333c2e993c10637adecafcf90fe08c812065c793cbc903744c9
…ng v2->v1 reconnections bf0d257c11bebc42b88b7e96368ed2be48bc0ad1 net: un-default the OpenNetworkConnection()'s proxy_override argument (Eugene Siegel) 5a3756d150fc095d0038592c6338225db48fd4b5 test: add a regression test for private broadcast v1 retries (Vasil Dimov) ab35a028eded00008841a3ec8662823090bfc68b test: make reusable filling of a node's addrman (Vasil Dimov) 2333be9cbc58dd2a533c9bd604b9db593b1d96a7 test: make reusable starting a standalone P2P listener (Vasil Dimov) 2ffa81fac40fd4d03bdcfd37479a6f3305afb483 test: make reusable SOCKS5 server starting (Vasil Dimov) 32d072a49f3048dffe2397ceb2155770a3e09af5 doc: add release notes for #35319 (Vasil Dimov) d01b461f71e255dcb5d7d0ee84a560f26cfe0b6f net: ensure no direct private broadcast connections (Vasil Dimov) fd230f942d8377cafcc346f1605d5aa00db2cc40 net: use the proxy if overriden when doing v2->v1 reconnections (Vasil Dimov) Pull request description: This PR includes bitcoin/bitcoin#35319 and on top of that adds a regression functional test. The functional test exercises the relevant code paths without modifying non-test code. To do that it does: * Add a bunch of IPv4 addresses to the node's addrman (they will be added without P2P_V2 flag). * Get them to report P2P_V2 in their service flags and connect to each one, so that the flags in addrman are updated to contain P2P_V2. * Get one successful connection to a Tor peer (.onion) so that bitcoind assumes the configured Tor proxy works and is indeed a proxy to the Tor network. This will make it open private broadcast connections also to IPv4 addresses via that proxy. * Start some private broadcast connections. * Remember the destination IPv4 address of the first connection and get it to fail the v2 transport. * Wait for a subsequent connection also through the Tor proxy to the same IPv4 and expect it to be v1, i.e. the v2->v1 downgrade retry. The test fails without the fix - the v1 retry never arrives to the Tor proxy. And passes with the fix. The fix is in the first commit here and in bitcoin/bitcoin#35319, can remove it by `git show fd230f942d | git apply -R`. ACKs for top commit: Crypt-iQ: reACK bf0d257c11bebc42b88b7e96368ed2be48bc0ad1 andrewtoth: ACK bf0d257c11bebc42b88b7e96368ed2be48bc0ad1 instagibbs: ACK bf0d257c11bebc42b88b7e96368ed2be48bc0ad1 sedited: utACK bf0d257c11bebc42b88b7e96368ed2be48bc0ad1 Tree-SHA512: 11e89be36577199e0312e5e63efeac04e295faaba1cf1c13a30e683d35f473c8dbb419d1897b0333c2e993c10637adecafcf90fe08c812065c793cbc903744c9
OpenNetworkConnection()supports overriding the proxy to use for connecting. However when v2 connection is attempted and it fails a v1 connection is tried without that proxy.Store the override proxy in
CNodeand pass it toCConnman::m_reconnectionsto be used for v1 retries.This is a serious flaw I have overlooked when the override proxy is used for private broadcast connections. Reported in https://www.erisian.com.au/bitcoin-core-dev/log-2026-05-18.html#l-234