Repository navigation
net: advertise -externalip addresses - #34538
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/34538. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste 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. |
|
I've taken a very slightly different approach at fixing this, and would value your opinion(s) on :) |
chriszeng1010
left a comment
There was a problem hiding this comment.
Tested ACK
Built and rantest_bitcoin --run_test=net_testson Windows/MSYS2. New addlocal_onlynet_externalip test passes.
seduless
left a comment
There was a problem hiding this comment.
Tested ACK 383763f9ee3ca307c2b881f0fcf4de660073aa84
Reproduced #25336 on regtest: started a node with -onlynet=ipv4 -externalip=<onion_address>, confirmed getnetworkinfo shows empty localaddresses on master. With the fix applied, the onion address appears at score 4.
Traced all LOCAL_MANUAL callers and found no inconsistency with IsPeerAddrLocalGood.
383763f to
6e73dcf
Compare
seduless
left a comment
There was a problem hiding this comment.
re-ACK 6e73dcf700796146b33f3788b2ff7f659244f909
vasild
left a comment
There was a problem hiding this comment.
ACK 6e73dcf700796146b33f3788b2ff7f659244f909
Note that AddLocal(..., LOCAL_MANUAL) is called from 3 places:
- For addresses given to
-externalip=..., the focus of this PR. - For our listening Tor address that is automatically created with the Tor router when
-listenonion=1. So this setup will be affected by this PR:-onlynet=ipv4 -listenonion=1. Before this PR we would not advertise the Tor address and now we will. - For our listening I2P address that is created with the I2P SAM proxy when
-i2psam=... -i2pacceptincoming=1is used. Similarly to Tor this would affect-onlynet=ipv4 -i2psam=... -i2pacceptincoming=1.
I think those 2. and 3. are welcomed changes. Maybe deserve a release note.
Will resolve #25669
| RemoveLocal(addr_onion); | ||
| g_reachable_nets.Add(NET_ONION); | ||
| fDiscover = true; |
There was a problem hiding this comment.
I guess this is an attempt to restore the global state to what it was at the beginning of the test. Here are more robust ways to that:
For g_reachable_nets:
... test ...
// Assumes that g_reachable_nets was in its default-constructed state at the start of the test.
g_reachable_nets.Reset();or (no assumptions)
const auto reachable_nets_at_start{g_reachable_nets.All()};
... test ...
g_reachable_nets.RemoveAll();
for (const auto& net : reachable_nets_at_start) {
g_reachable_nets.Add(net);
}For fDiscover:
const bool discover_orig{fDiscover};
... test ...
fDiscover = discover_orig;There was a problem hiding this comment.
Good point, thanks, I agree. I changed the test to restore both global states as you suggested, in e459f651c89
6e73dcf to
3c63971
Compare
😃 Release note added in 3c63971454722a9ab399d49b1195fdd640867e31 |
vasild
left a comment
There was a problem hiding this comment.
ACK 3c63971454722a9ab399d49b1195fdd640867e31
|
Might want to add "Fixes: #25669" to the OP. |
seduless
left a comment
There was a problem hiding this comment.
re-ACK 3c63971454722a9ab399d49b1195fdd640867e31
|
Might be better to set a bit somewhere for The configuration and expected/implicit behaviours here seem very confusing and fragile in general here; eg I think this code is (or reads as-if it is) treating |
3c63971 to
7b28ef4
Compare
vasild
left a comment
There was a problem hiding this comment.
ACK 7b28ef41495f57d5b8f3fa67d467c16b0660b331
Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
ACK 7b28ef41495f57d5b8f3fa67d467c16b0660b331
-----BEGIN PGP SIGNATURE-----
iQQzBAEBCAAdFiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmnc9GUACgkQVN8G9ktV
y7+ZJh//Zu1zi8Nw9TRVdTs4570wepmtW+Q111PgjBnhtogGa06gn2Qp5ootOu71
EILvuN4XUFj16UhQ25ZXGaFjmozGSVlWkG54Rr92wjOGxkb8jEXoLmtwgoUoEpWG
n6eUEUYKJ3xuwwCCgAmJTJc8Rxa/AIMSC5Qok0h+2DcoF5ff/+T4SoB2vs5xJllA
VtokRm0nQbjV/oq2MvFcWTcgS6M0nKKQmKNmWuEwG8Q5Is4vN/xergGvPN7VkeNu
WCHAz6N7LnWMwU6sqSQBrOEvGWB32xxdqSnq0JoA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
=Sl7e
-----END PGP SIGNATURE-----
vasild's public key is on openpgp.org
| @@ -274,7 +274,7 @@ void ClearLocal() | |||
| } | |||
|
|
|||
| // learn a new local address | |||
| bool AddLocal(const CService& addr_, int nScore) | |||
| bool AddLocal(const CService& addr_, int nScore, bool fExternalIP) | |||
There was a problem hiding this comment.
Naming, feel free to ignore:
The linkage between this argument and the -externalip configuration option is only outside of the AddLocal() function. So, looking at the function alone and not its callers, the name fExternalIP is odd.
From the point of view of the AddLocal() function, the meaning of its new argument is "ignore reachable nets" or "add even if unreachable". It is better to name it after that.
This would show in the future if there is a new caller of AddLocal() who wants to pass true to "add even if unreachable" for a reason other than that the address comes from -externalip. Then the caller would have to use /*fExternalIP=*/true even if he has nothing to do with -externalip.
There was a problem hiding this comment.
Thanks. I addressed both of your review points at once by renaming the new param to add_even_if_unreachable in b1874343f0cf2c90605bff448ab174f3ed7a169a
| @@ -302,9 +302,9 @@ bool AddLocal(const CService& addr_, int nScore) | |||
| return true; | |||
| } | |||
|
|
|||
| bool AddLocal(const CNetAddr &addr, int nScore) | |||
| bool AddLocal(const CNetAddr& addr, int nScore, bool fExternalIP) | |||
There was a problem hiding this comment.
My understanding and preference is that we follow the naming convention regardless of surrounding code that might use the old convention. That is, name the new parameter external_ip instead of fExternalIP. Then, if you want, in another commit, for consistency rename nScore to score.
7b28ef4 to
d63f6a9
Compare
vasild
left a comment
There was a problem hiding this comment.
ACK d63f6a97bf1e16305c1044e8b0bd7dff015966ec
Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
ACK d63f6a97bf1e16305c1044e8b0bd7dff015966ec
-----BEGIN PGP SIGNATURE-----
iQQzBAEBCAAdFiEE5k2NRWFNsHVF2czBVN8G9ktVy78FAmnzUA0ACgkQVN8G9ktV
y7++CB/+JRiXIJkDGHb7DTN7SI6Qo1Ru5J7YGYQ63wTSLSBoKK/gZw7W+T6ki38V
Dz6rB3hCwfkwFIiF9UWxTeVEvrpvk9znJbZ2nAXxjaYm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NFYWD4+OXpG5GsO0lEABTB+vGtis4x06fhnNl9B/bBgUM5jNr
NFeczGcsfs3V0BO2RAzIHg+7jes/KsjkdB6OpxVtRBNA2kN6Jct9sgUvY0HXPWIc
2FBxhjJKKG0cepwooZ/5CTcmTOHHtavrxutuO4Ng3NbbekF6f0yFXwUSuuZ+kobq
ySi4Pw6X1oNSGB/Ig+dD2HGChVUZow==
=oZXa
-----END PGP SIGNATURE-----
vasild's public key is on openpgp.org
I should have updated after my last push here, sorry. I think the current approach in d63f6a97bf1e16305c1044e8b0bd7dff015966ec addresses the (correct) concerns you had: the reachable-net bypass is no longer derived from the stored local-address score, but is passed explicitly only from the -externalip init path. So peer observations can still change nScore, but cannot cause a non-externalip address to start bypassing -onlynet. I considered adding persistent state to LocalServiceInfo, but it makes the AddLocal path a (tiny) bit more complicated and I don't see another user of that state. Do you know of one outside of this reachable-net decision? The diff wouldn't be large, but I think this is fine as it is here too. |
mzumsande
left a comment
There was a problem hiding this comment.
ACK d63f6a97bf1e16305c1044e8b0bd7dff015966ec
I think the behavior of the current version may match user expectations best.
Though it still doesn't match the documentation of -onlynet ("Inbound and manual connections are not affected by this option.") when the automatic discovery is supppressed for non-reachable networks, including cases like -onlynet=ipv4 -listenonion=1.
Prepare for letting explicitly configured local addresses bypass the reachable-net filter without tying that behavior to LOCAL_MANUAL score. Pass an `add_even_if_unreachable` bool through `AddLocal()`, defaulting to `false`.
When -onlynet excludes a network, AddLocal() rejects local addresses from that network. This also rejects addresses explicitly configured via -externalip, so a configuration like -onlynet=ipv4 -externalip=<onion> never advertises the onion address. Set the AddLocal() unreachable-net override only when adding -externalip addresses so the bypass remains limited to explicit user configuration.
Add unit coverage for the -onlynet/-externalip interaction. Check that an unreachable address still fails with normal AddLocal() arguments, while the same address succeeds when the unreachable-net override is set for explicit local-address configuration.
Extend p2p_addr_selfannouncement to restart the node with -onlynet=ipv4 -externalip=<onion> and verify the onion address appears in localaddresses despite its network being unreachable.
d63f6a9 to
dab7f2c
Compare
I agree somewhat, but IMO listenonion=1 is a fair bit more ambiguous as it is automatically creating a service which, if advertised with a configuration like |
|
ACK dab7f2c |
b51e8e5 test: cover -externalip/onlynet interaction in functional test (will) 82c721c test: cover -externalip bypassing -onlynet (will) 153892d net: let -externalip bypass -onlynet (will) 52547ec net: add an add_even_if_unreachable argument to AddLocal (will) Pull request description: `-onlynet` is documented to restrict automatic outbound connections, but it also currently prevents `-externalip` addresses from being advertised when their network is not in the `-onlynet` set. This happens because `AddLocal()` rejects addresses outside `g_reachable_nets`, regardless of whether the address was explicitly configured by the user. Previous attempts to fix this (#24835 and #25690) removed the `g_reachable_nets` check from `AddLocal()`. This PR instead adds an explicit `add_even_if_unreachable` argument to `AddLocal()`. The argument defaults to `false`, and is set to `true` only when adding addresses from `-externalip`. As a result, explicitly configured `-externalip` addresses can still be advertised even when their network is excluded by `-onlynet`, while discovered, mapped, bound, Tor control, and I2P SAM addresses continue to use the existing reachable-network filter. This keeps the fix scoped to `-externalip` and addresses the concern raised in #25690: > I think it might also be weird for a user to activate -onlynet and keep on advertising their clearnet address to the network The branch adds unit coverage for `AddLocal()` and functional coverage in `p2p_addr_selfannouncement.py` for `-onlynet=ipv4 -externalip=<onion>`. Fixes: #25336 Fixes: #25669 ACKs for top commit: achow101: ACK b51e8e5 mzumsande: re-ACK b51e8e5 w0xlt: ACK b51e8e5 Tree-SHA512: a4ac9334b85da8b6902d3850e21d3a1c9d7dce70bcb79182448c8d5684e24462cd6e440385af7aa4420d9582e4dff9dc9e827ca7a6da0363fff2d3c531784d9b
…d9ec7f3d4 70d9ec7f3d4 Merge bitcoin/bitcoin#34538: net: advertise -externalip addresses 7bff765d514 Merge bitcoin/bitcoin#35639: external_signer: validate fingerprint from enumerate response 773b1c9aa58 Merge bitcoin/bitcoin#35572: coins: make cursor iteration DB-only 8d9e4f8dbd8 Merge bitcoin/bitcoin#35633: wallet: avoid call bumpfeediscount with negative values c4216e885a6 Merge bitcoin/bitcoin#35723: fuzz: Drop unnecessary mutexes 240d5f743aa fuzz: Drop unnecessary mutexes cf0368fb76e Merge bitcoin/bitcoin#35720: ipc: Update libmultiprocess subtree and drop fuzz test workaround 2d4065d1fe4 Merge bitcoin/bitcoin#35718: ci: Update lint container dependencies 8d9fbf76664 Merge bitcoin/bitcoin#35380: kernel: expose witness stack and scriptSig for btck_TransactionInput fab8eeed82c fuzz: clang-format LIMITED_WHILE fa0d777ce2a fuzz: Clang-format LIMITED_WHILE like while fa1a9bde5a6 fuzz: Remove unused workaround after fix in libmultiprocess byte-span serializer fa55385ab36 fuzz: Use LIMITED_WHILE over for-loop with consumed size integral fa911d815db Merge commit '6d5f753921578eefdd3fce64cfc8ee7951b6cbc4' into HEAD 6d5f7539215 Squashed 'src/ipc/libmultiprocess/' changes from 28e056576a..e8de5c7b68 900a7785bf5 ci: use Ubuntu 26.04 for lint container 058a73a0aea ci: use uv 11.x 14f4ddcb554 ci: mypy 2.3.0 54e1a95a12e Merge bitcoin/bitcoin#35719: ci: disable Qt build in OpenBSD cross job b0e09511586 ci: disable Qt build in OpenBSD cross job 734c34bafda Merge bitcoin/bitcoin#35427: depends: Build `qt` and `qrencode` packages on OpenBSD ee61b11a9e7 Merge bitcoin/bitcoin#35200: node: smooth oversized `dbcache` warnings e3554bf361f Merge bitcoin/bitcoin#35579: wallet: reserve walletrescan before checking wallet is at the tip 11ae4265522 Merge bitcoin/bitcoin#35715: cmake: Fix WITH_EXTERNAL_LIBMULTIPROCESS + BUILD_FUZZ_BINARY e544413c0de Merge bitcoin/bitcoin#32763: wallet: Replace CWalletTx::mapValue and vOrderForm with explicit class members fe1cb6e40d7 Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code 441f3114f57 Merge bitcoin/bitcoin#35659: Clarify supported *BSD releases and drop outdated workarounds 0399df827c6 Merge bitcoin/bitcoin#35708: depends: capnp 1.5.0 1ab1fdd4696 Merge bitcoin/bitcoin#35705: bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase db35b9238fc ipc # build: Fix fuzz target CMakeLists.txt for external libmultiprocess d18fec892e2 Merge bitcoin/bitcoin#35698: doc: Update enum class constant naming style guide a2e4cd7ad2a depends: capnp 1.5.0 7508ac319d9 bench: replace CreateMockableWalletDatabase with MakeInMemoryWalletDatabase 907e284e303 Merge bitcoin/bitcoin#35701: test: Remove `mock_process.cpp` c8459b6bdcd Merge bitcoin/bitcoin#35568: txospenderindex: disable bloom filters to optimize disk usage 63c5f9d22c0 test: Remove `mock_process.cpp` ef101b04a8d Merge bitcoin/bitcoin#35655: wallet: Use in-memory SQLite for temporary wallet in exportwatchonlywallet b6becf3534c Merge bitcoin/bitcoin#35684: Update libmultiprocess subtree to add `max_connections` option 930f25050f7 Merge bitcoin/bitcoin#35700: doc: archive release notes for v29.4 9b2b3f4ec6f doc: archive release notes for v29.4 297fd1489bb Merge bitcoin/bitcoin#35412: ci: add NetBSD Clang cross job e314869066b Merge bitcoin/bitcoin#35695: Remove myself as security contact e3d67a5eae5 Merge bitcoin/bitcoin#35691: chainparams: delete my DNS seed a8223bb4e62 wallet: Introduce WalletError with machine-readable error code fad5809cb92 doc: Update enum class constant naming style guide 7d8137c1417 Merge bitcoin/bitcoin#34897: indexes: Don't commit ahead of the flushed chainstate 629df81e4c6 Remove myself as security contact d164a043426 node: smooth oversized `-dbcache` warnings d9080639804 chainparams: delete my DNS seed e9ed898a0da validation: Don't use m_chain.Tip() in FlushStateToDisk 3679f1ecf5e index: Don't commit ahead of the flushed chainstate 65735728a5a index: Remove return value from Commit() 09c06960c6a validation: track last flushed block 13c02b5466d test: add test for index commits ahead of the last flushed block c43b7a1115f ci: add netBSD cross CI job 699c21aea47 depends: add netbsd_LDFLAGS 777d23f25c7 test: add regression test for in-memory SQLiteDatabase reopen d1e7f8c986f wallet: use in-memory SQLite for temporary wallet in exportwatchonlywallet ee43743f126 wallet: store m_additional_flags in SQLiteDatabase to fix reopen path a9d1b652f32 Merge commit '707d0ded84563386f770ec17970834c65f8fa938' into pr/subtree-12 707d0ded845 Squashed 'src/ipc/libmultiprocess/' changes from 16bf05dea02..28e056576a3 6667dc4eec7 kernel: expose scriptSig for btck_TransactionInput e6de3a2d3c7 kernel: expose witness stack for btck_TransactionInput 3ae3a94f2bd wallet: avoid call bumpfeediscount with negative values dab7f2c984b test: cover -externalip/onlynet interaction in functional test 657a5aa3f3d test: cover -externalip bypassing -onlynet 8c87e32bd39 net: let -externalip bypass -onlynet f4af02e827b net: add an add_even_if_unreachable argument to AddLocal 2bab6bc73f2 refactor: Drop support for FreeBSD < 14 91b5c8a07c6 refactor: Remove FreeBSD-specific workaround 56701ff6d5c doc: Clarify supported *BSD releases 6d0ea4cf5bd doc: add release notes a2b1c86903a txospenderindex: disable bloom filters to optimize disk usage 4c9de7d5b32 external_signer: validate fingerprint from enumerate response fed3cf6f0ed wallet: Replace CWalletTx's vOrderForm with specific fields 4f8823e8e11 wallet: Drop vOrderForm from CommitTransaction 9e62e4b1f34 test: slow down rescaning process a2b0bfcd854 wallet: Drop mapValue from CWalletTx cb99864c91c wallet: Throw if unknown entry is found in mapValue 98d5cdae663 wallet: Make CWalletTx "replaces_txid" and "replaced_by_txid" member variables 7ef8a6efc2a wallet: Make CWalletTx "comment" and "to" member variables 2155e913d3e wallet: Make CWalletTx "from" and "message" member variables c6ba98dcc8a wallet: Drop mapValue from CommitTransaction 00abb174a80 wallet: Pass comment and comment_to to CommitTransaction 1a219a37a21 wallet: Pass replaces_txid to CommitTransaction outside of mapValue 72db4accbf5 coins: drop stale cursor null checks 3d2f2d8de09 coins: pass UTXO stats view by reference 35aedb28236 coins: drop cursor from base view c6fbe2f66cf coins: pass DB view to cursor users 336f5a738b3 wallet: reserve walletrescan before checking wallet is at the tip a54ec373a69 depends: Build `qt` and `qrencode` packages for OpenBSD hosts git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 70d9ec7f3d452789d04dce81dc02db0b3b778bb5
dab7f2c984bdf10ed65fec6e7b602486f853c456 test: cover -externalip/onlynet interaction in functional test (will)
657a5aa3f3d0e8533d3d7dadfcc3b2908be83601 test: cover -externalip bypassing -onlynet (will)
8c87e32bd3937251d6f30295cc1924048e5b74d1 net: let -externalip bypass -onlynet (will)
f4af02e827b97a051bd12b813d4e09fcc41b45c3 net: add an add_even_if_unreachable argument to AddLocal (will)
Pull request description:
`-onlynet` is documented to restrict automatic outbound connections, but it also currently prevents `-externalip` addresses from being advertised when their network is not in the `-onlynet` set. This happens because `AddLocal()` rejects addresses outside `g_reachable_nets`, regardless of whether the address was explicitly configured by the user.
Previous attempts to fix this (#24835 and #25690) removed the `g_reachable_nets` check from `AddLocal()`.
This PR instead adds an explicit `add_even_if_unreachable` argument to `AddLocal()`. The argument defaults to `false`, and is set to `true` only when adding addresses from `-externalip`.
As a result, explicitly configured `-externalip` addresses can still be advertised even when their network is excluded by `-onlynet`, while discovered, mapped, bound, Tor control, and I2P SAM addresses continue to use the existing reachable-network filter.
This keeps the fix scoped to `-externalip` and addresses the concern raised in #25690:
> I think it might also be weird for a user to activate -onlynet and keep on advertising their clearnet address to the network
The branch adds unit coverage for `AddLocal()` and functional coverage in `p2p_addr_selfannouncement.py` for `-onlynet=ipv4 -externalip=<onion>`.
Fixes: #25336
Fixes: #25669
ACKs for top commit:
achow101:
ACK dab7f2c984bdf10ed65fec6e7b602486f853c456
mzumsande:
re-ACK dab7f2c984bdf10ed65fec6e7b602486f853c456
w0xlt:
ACK dab7f2c984bdf10ed65fec6e7b602486f853c456
Tree-SHA512: a4ac9334b85da8b6902d3850e21d3a1c9d7dce70bcb79182448c8d5684e24462cd6e440385af7aa4420d9582e4dff9dc9e827ca7a6da0363fff2d3c531784d9b
…65fc94a39 5c65fc94a39 kernel: Add sans utxo set block validation b369e88ad40 kernel: Add outpoint equals operator e65476d050f kernel: Add outpoint creation to C header d54e309d00d kernel: Add coin creation to C header 644f73541f2 kernel: Add transaction is coinbase to C header REVERT: 70d9ec7f3d4 Merge bitcoin/bitcoin#34538: net: advertise -externalip addresses REVERT: 7bff765d514 Merge bitcoin/bitcoin#35639: external_signer: validate fingerprint from enumerate response REVERT: 773b1c9aa58 Merge bitcoin/bitcoin#35572: coins: make cursor iteration DB-only REVERT: dab7f2c984b test: cover -externalip/onlynet interaction in functional test REVERT: 657a5aa3f3d test: cover -externalip bypassing -onlynet REVERT: 8c87e32bd39 net: let -externalip bypass -onlynet REVERT: f4af02e827b net: add an add_even_if_unreachable argument to AddLocal REVERT: 4c9de7d5b32 external_signer: validate fingerprint from enumerate response REVERT: 72db4accbf5 coins: drop stale cursor null checks REVERT: 3d2f2d8de09 coins: pass UTXO stats view by reference REVERT: 35aedb28236 coins: drop cursor from base view REVERT: c6fbe2f66cf coins: pass DB view to cursor users git-subtree-dir: libbitcoinkernel-sys/bitcoin git-subtree-split: 5c65fc94a3997356374568783045e465f3cae706
-onlynetis documented to restrict automatic outbound connections, but it also currently prevents-externalipaddresses from being advertised when their network is not in the-onlynetset. This happens becauseAddLocal()rejects addresses outsideg_reachable_nets, regardless of whether the address was explicitly configured by the user.Previous attempts to fix this (#24835 and #25690) removed the
g_reachable_netscheck fromAddLocal().This PR instead adds an explicit
add_even_if_unreachableargument toAddLocal(). The argument defaults tofalse, and is set totrueonly when adding addresses from-externalip.As a result, explicitly configured
-externalipaddresses can still be advertised even when their network is excluded by-onlynet, while discovered, mapped, bound, Tor control, and I2P SAM addresses continue to use the existing reachable-network filter.This keeps the fix scoped to
-externalipand addresses the concern raised in #25690:The branch adds unit coverage for
AddLocal()and functional coverage inp2p_addr_selfannouncement.pyfor-onlynet=ipv4 -externalip=<onion>.Fixes: #25336
Fixes: #25669