3

I was trying to automate peer discovery of my newly launched substrate network, and can't find any documentation related to that, it would be really helpful if someone can point to any available documentation or can tell how to achieve this. Automate means when I launch a new node, it will automatically connect to it's nearest node with it's IP and peer ID

2
  • I have also come across a similar problem. My knowledge on the topic is limited, hence my reply to this being a comment. From what I have gathered, Substrate has two discovery mechanisms: Mdns and kad dht. mDNS means any node in your local network will automatically connect to your node and sync up. With kademlia, all you need to do is connect to someone with more connections than you. Even over an external network, and Your node will automatically look through their peers and connect to good ones based on some factors. Hence this method requires a good bootstrap list
    – islami00
    Feb 18, 2022 at 2:39
  • substrate nodes should self peer if they are running on local host without needing to do any additional configuration.
    – Squirrel
    Feb 19, 2022 at 13:30

1 Answer 1

4

There is a lot of great content here around the networking in Substrate: https://crates.parity.io/sc_network/index.html

Discovery mechanisms

In order for our node to join a peer-to-peer network, it has to know a list of nodes that are part of said network. This includes nodes identities and their address (how to reach them). Building such a list is called the discovery mechanism. There are three mechanisms that Substrate uses:

  1. Bootstrap nodes. These are hard-coded node identities and addresses passed alongside with the network configuration.
  2. mDNS. We perform a UDP broadcast on the local network. Nodes that listen may respond with their identity. More info here. mDNS can be disabled in the network configuration.
  3. Kademlia random walk. Once connected, we perform random Kademlia FIND_NODE requests on the configured Kademlia DHTs (one per configured chain protocol) in order for nodes to propagate to us their view of the network. More information about Kademlia can be found on Wikipedia.

So really you should start with a bootstrap node, and then the other discovery mechanisms can kick in to help connect you to and diversify your nodes.

You can specify bootstrap nodes in your chain specification:

{
  "name": "Polkadot",
  "id": "polkadot",
  "chainType": "Live",
  "bootNodes": [
    "/dns/p2p.0.polkadot.network/tcp/30333/p2p/12D3KooWHsvEicXjWWraktbZ4MQBizuyADQtuEGr3NbDvtm5rFA5",
    "/dns/p2p.1.polkadot.network/tcp/30333/p2p/12D3KooWQz2q2UWVCiy9cFX1hHYEmhSKQB2hjEZCccScHLGUPjcc",
    "/dns/p2p.2.polkadot.network/tcp/30333/p2p/12D3KooWNHxjYbDLLbDNZ2tq1kXgif5MSiLTUWJKcDdedKu4KaG8",
    "/dns/p2p.3.polkadot.network/tcp/30333/p2p/12D3KooWGJQysxrQcSvUWWNw88RkqYvJhH3ZcDpWJ8zrXKhLP5Vr",
    "/dns/p2p.4.polkadot.network/tcp/30333/p2p/12D3KooWKer8bYqpYjwurVABu13mkELpX2X7mSpEicpjShLeg7D6",
    "/dns/p2p.5.polkadot.network/tcp/30333/p2p/12D3KooWSRjL9LcEQd5u2fQTbyLxTEHq1tUFgQ6amXSp8Eu7TfKP",
    "/dns/cc1-0.parity.tech/tcp/30333/p2p/12D3KooWSz8r2WyCdsfWHgPyvD8GKQdJ1UAiRmrcrs8sQB3fe2KU",
    "/dns/cc1-1.parity.tech/tcp/30333/p2p/12D3KooWFN2mhgpkJsDBuNuE5427AcDrsib8EoqGMZmkxWwx3Md4"
  ],
  "telemetryEndpoints": [
    [
      "wss://telemetry.polkadot.io/submit/",
      0
    ]
  ],
...

Or via the command line when starting a node. From --help:

--bootnodes <ADDR>...                                        
    Specify a list of bootnodes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.