test: cover -externalip bypassing -onlynet
What changed, and why it matters
This commit only adds a new automated test to Bitcoin Core. It checks that the -externalip command-line option can bypass the -onlynet restriction when a user explicitly configures an external address, while normal local-address registration still respects network reachability rules. There is no change to production code, no bug fix, and no security vulnerability being patched.
No security action needed. This is a test-only commit improving unit coverage for an existing interaction between -onlynet and -externalip. Reviewers may optionally confirm the test accurately reflects intended production behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a BOOST_AUTO_TEST_CASE named addlocal_onlynet_externalip in src/test/net_tests.cpp. The test simulates -onlynet=ipv4 -externalip=
Changed components
src/test/net_tests.cppInspect captured patch +43 / −0
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index 32801d97..495e6f7d 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -1590,4 +1590,47 @@ BOOST_AUTO_TEST_CASE(private_broadcast_version_does_not_update_addrman_services)
m_node.peerman->FinalizeNode(node);
}
+BOOST_AUTO_TEST_CASE(addlocal_onlynet_externalip)
+{
+ // Test that `-externalip` addresses bypass `-onlynet`, but score alone does
+ // not.
+
+ CAddress addr_onion;
+ BOOST_REQUIRE(addr_onion.SetSpecial("pg6mmjiyjmcrsslvykfwnntlaru7p5svn6y2ymmju6nubxndf4pscryd.onion"));
+ BOOST_REQUIRE(addr_onion.IsValid());
+ BOOST_REQUIRE(addr_onion.IsTor());
+
+ const auto reachable_nets_at_start{g_reachable_nets.All()};
+ const bool discover_orig{fDiscover};
+
+ // Simulate using -onlynet=ipv4 -externalip=<onion>
+ g_reachable_nets.RemoveAll();
+ g_reachable_nets.Add(NET_IPV4);
+ fDiscover = false;
+
+ // Now AddLocal with a non-manual score should fail for an unreachable network.
+ BOOST_CHECK(!AddLocal(addr_onion, LOCAL_BIND));
+ BOOST_CHECK(!IsLocal(addr_onion));
+
+ BOOST_CHECK(!AddLocal(addr_onion, LOCAL_MANUAL));
+ BOOST_CHECK(!IsLocal(addr_onion));
+
+ // Whereas AddLocal for -externalip should succeed.
+ BOOST_CHECK(AddLocal(addr_onion, LOCAL_MANUAL, /*add_even_if_unreachable=*/true));
+ BOOST_CHECK(IsLocal(addr_onion));
+
+ // Normal AddLocal on a reachable network still works.
+ const CNetAddr addr_ipv4{LookupHost("1.2.3.4", false).value()};
+ BOOST_CHECK(AddLocal(addr_ipv4, LOCAL_MANUAL));
+ BOOST_CHECK(IsLocal(CService{addr_ipv4, GetListenPort()}));
+
+ RemoveLocal(CService{addr_ipv4, GetListenPort()});
+ RemoveLocal(addr_onion);
+ g_reachable_nets.RemoveAll();
+ for (const auto& net : reachable_nets_at_start) {
+ g_reachable_nets.Add(net);
+ }
+ fDiscover = discover_orig;
+}
+
BOOST_AUTO_TEST_SUITE_END()
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.