net: do not read/dump anchors if network is not active #34213
pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2026-01-net-anchors-networkactive changing 2 files +6 −2-
brunoerg commented at 9:26 pm on January 6, 2026: contributorWe currently save 2 block-relay-only (anchor) connections when stopping a node and connect to them right after starting it. However, if you start a node with network disabled (setting -networkactive=0 or disabling using the RPC), it will read the anchors, obviously will not be able to connect to them and then, when stopping the node, considering it will have 0 block-relay-only connections, it will save 0 anchors, basically deleting the previous ones. With this PR, we will only read and write the anchors if the network is active. It will avoid losing the anchors when using the node without network activity and also avoid unecessary actions (like reading the anchors even knowing we have no network activity).
-
DrahtBot added the label P2P on Jan 6, 2026
-
DrahtBot commented at 9:26 pm on January 6, 2026: contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Code Coverage & Benchmarks
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34213.
Reviews
See the guideline for information on the review process.
Type Reviewers ACK bensig Concept ACK waketraindev If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.
-
brunoerg force-pushed on Jan 6, 2026
-
DrahtBot added the label CI failed on Jan 6, 2026
-
DrahtBot commented at 9:31 pm on January 6, 2026: contributor
🚧 At least one of the CI tasks failed. Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/20762589891/job/59621113321 LLM reason (✨ experimental): Linting failed: ruff detected errors (trailing whitespace) in Python code, causing the CI to fail.Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:
-
Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.
-
A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.
-
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
-
-
net: do not read/dump anchors if network is not active 903a37c1e1
-
brunoerg force-pushed on Jan 6, 2026
-
DrahtBot removed the label CI failed on Jan 6, 2026
-
in src/net.cpp:3348 in 903a37c1e1
3344@@ -3345,7 +3345,7 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions) 3345 std::shuffle(seed_nodes.begin(), seed_nodes.end(), FastRandomContext{}); 3346 } 3347 3348- if (m_use_addrman_outgoing) { 3349+ if (m_use_addrman_outgoing && fNetworkActive) {
waketraindev commented at 0:21 am on January 7, 2026:I start some nodes with network inactive.
micro nit (in both cases):
0 if (fNetworkActive && m_use_addrman_outgoing) {
brunoerg commented at 6:25 pm on January 7, 2026:I’ll leave as-is for now.waketraindev commented at 0:22 am on January 7, 2026: contributorConcept ACKwaketraindev commented at 1:50 am on January 7, 2026: contributorHave you considered also adding a DumpAnchors() if anchors_to_dump.size() > 1 when setting network active from true to false?
That would persist the anchors for nodes that do a setnetworkactive false and after shut down and skip dumping them again at shutdown.
brunoerg commented at 6:26 pm on January 7, 2026: contributorHave you considered also adding a DumpAnchors() if anchors_to_dump.size() > 1 when setting network active from true to false?
Yes, but would leave it for a follow-up, it will require more changes than the simple ones to cover the
-networkactivebehavior.bensig commented at 6:40 pm on January 7, 2026: contributorACK 903a37c1e142b4ee6b83fee99735ab69716084ee
Tested,
feature_anchors.pypassesDrahtBot requested review from waketraindev on Jan 7, 2026w0xlt commented at 8:59 pm on January 7, 2026: contributorThis seems like a reasonable change, but it may be better to document that settingfNetworkActiveto false via thesetnetworkactiveRPC can prevent anchors from being preserved.brunoerg commented at 7:48 pm on January 8, 2026: contributorThis seems like a reasonable change, but it may be better to document that setting
fNetworkActiveto false via thesetnetworkactiveRPC can prevent anchors from being preserved.Sounds good, I will add this information in the
setnetworkactiveRPC.
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-01-09 00:13 UTC
More mirrored repositories can be found on mirror.b10c.me