chore: Improve peer persistence and bootnode loading #128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
network/server: persist only active peers to last_peers.json; server: load custom bootnodes from genesis params and merge with external sources
Context
Two related issues were observed in production-like setups:
last_peers.json, causing them to try reconnecting to dead addresses after restart.params.bootnodeswere present ingenesis.json, the node required an adjacentbootnode.jsonor--bootnodesfile to start. Operators expectedparams.bootnodesin custom genesis to be honored, similar to mainnet/testnet.Changes
Peers()returned all entries in the in-memorys.peersmap without checking whether they’re still connected. During shutdown or disconnect races, stale entries could be written tolast_peers.json.Peers()now filters by live connectedness (network.Connected) before returning the list used byClose()for persistence.last_peers.jsonnow contains only peers confirmed to be connected at persistence time, preventing invalid reconnect attempts after restart.params.bootnodesingenesis.json; only looked for adjacentbootnode.json(node.p2p.staticNodes) or--bootnodes <file>.genesis.params.bootnodes(if present).genesis.params.bootnodesbootnode.json(node.p2p.staticNodes)--bootnodes <file>with schema{ "bootnodes": ["..."] }genesis.jsonwithout needing a separate file or flag. External sources still work and are merged.Files Touched
Peers()before persisting.getBootnodeConfig(), for custom networks, includegenesis.Params.Bootnodesand merge with adjacentbootnode.jsonand--bootnodesfile. Improved error message.Why This Is Safe
Testing
libp2p/last_peers.jsonon the stopped node:Connectedstate at the time of persistence.last_peers.jsonand verify successful reconnects.params.bootnodesingenesis.json→ node starts and dials bootnodes.bootnode.json(staticNodes) → node starts and dials bootnodes.--bootnodesfile provided → merged with above (no duplicates).Backward Compatibility
params.bootnodeswhile keeping existing external file/flag paths.Operational Guidance
genesis.jsonunderparams.bootnodes, and/orbootnode.jsonand/or--bootnodes <file>at runtime.--bootnodes <file>if needed.