Skip to content

Conversation

@s-h-ubham
Copy link
Contributor

@s-h-ubham s-h-ubham commented Oct 14, 2025

Summary

This PR enhances bootnode discovery so the server can load bootnodes from more sources without requiring schema changes to the genesis type Bootnodes.

What changed

  • Read bootnodes from:
    • params.bootnodes (existing behavior)
    • Top-level bootnodes in genesis
      • mainnet/testnet: parsed from embedded genesis JSON
      • custom: parsed from the provided genesis file
    • Geth-style adjacent bootnode.json (node.p2p.staticNodes) for mainnet/testnet and custom
    • Geth-style --bootnodes file (node.p2p.staticNodes)
  • No changes to existing chain types; top-level bootnodes are parsed from raw JSON.
  • Automatically generate a geth-style bootnode.json on first run:
    • Written to data-dir/bootnode.json if missing.
    • Also written next to a custom genesis file (same directory) when using --chain custom:....
    • Never overwrites existing files.
  • Minor linter/format fixes:
    • Introduced mainnetNetwork and testnetNetwork constants
    • Whitespace and long-line fixes where necessary

Motivation

Previously, when using --chain testnet, embedded bootnodes weren’t picked up if they were defined at the top level of the genesis JSON (rather than under params.bootnodes). This caused the server to fail with “no bootnodes found” even though bootnodes were present in the config. This PR resolves that gap by supporting both common schemas. Additionally, it now auto-generates a bootnode.json on the first run if bootnode.json is not present, ensuring consistent bootnode persistence across runs

Behavior details

  • If params.bootnodes are present, they are loaded.
  • If top-level bootnodes exist in the genesis, they are merged in:
    • For mainnet/testnet, the embedded genesis blob is parsed.
    • For custom genesis, the genesis file is parsed.
  • If an adjacent geth-style bootnode.json exists (next to custom genesis, in CWD, or in --data-dir), its node.p2p.staticNodes entries are merged in.
  • If --bootnodes is provided, it must be geth-style (node.p2p.staticNodes); these entries are merged in.
  • After merging bootnodes, if no existing bootnode.json is found:
    • The merged list is written to data-dir/bootnode.json.
    • Also written next to a custom genesis file if --chain custom:... is used.
    • Existing files are never overwritten.
  • Duplicates are removed during the merge phase.

Backward compatibility

  • Existing configs with params.bootnodes continue to work unchanged.
  • No type changes were introduced; only parsing logic was expanded.
  • --bootnodes expects geth-style JSON. The previously discussed flat { "bootnodes": [...] } schema is not required or supported for the flag to match the user’s preference.

Examples

  • Top-level in genesis:
{
  "name": "...",
  "genesis": { ... },
  "params": { ... },
  "bootnodes": ["/ip4/…/tcp/…/p2p/…"]
}
  • Geth-style adjacent or --bootnodes file:
{
  "node": {
    "p2p": {
      "staticNodes": [
        "/ip4/…/tcp/…/p2p/…"
      ]
    }
  }
}

Testing

  • Build and run with --chain testnet only; confirm embedded top-level bootnodes are picked up.
  • Run with --chain custom:/path/genesis.json where genesis has top-level bootnodes; confirm picked up.
  • Place geth-style bootnode.json adjacent to genesis and also in CWD or --data-dir; confirm they’re discovered.
  • Provide --bootnodes /abs/path/bootnode.json in geth-style; confirm loaded.
  • Verify no “no bootnodes found” error as long as any one source is available.
  • Verify bootnode.json auto-generation:
    • Confirm data-dir/bootnode.json file is created on first run.
    • Confirm re-running does not overwrite existing files.
    • Confirm file contents match bootnodes.

Notes

  • This change improves resilience and developer ergonomics when working with different genesis formats.

@s-h-ubham s-h-ubham requested a review from R-Santev October 14, 2025 10:27
@s-h-ubham s-h-ubham merged commit 7861072 into develop Oct 15, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants