Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: kooler1 on November 30, 2017, 08:20:30 PM



Title: How do blockchain nodes find each other?
Post by: kooler1 on November 30, 2017, 08:20:30 PM
It is well known that blockchain is decentralised and each node stores whole history of transactions (all blocks).

But when you start the node, how does it know how to connect to others to synchronise? Is there central registry of nodes (or IP addresses of nodes) that it checks?


Title: Re: How do blockchain nodes find each other?
Post by: achow101 on November 30, 2017, 08:31:27 PM
Bitcoin Core (the most common type of node) has 3 methods of discovering peers. First it consults an internal database of peers it knows about. For a new node, this will be empty. Then it will consult a set of servers called DNS seeders. The DNS seeders give out the IP addresses of nodes that a node can connect to. The node will connect to these nodes only temporarily to gather the IP addresses of other nodes it can also connect to. It will then connect to those nodes. Lastly, if the previous two were unavailable, the node will consult a built in list of seed nodes. It does the same thing with these seed nodes that it did with nodes returned by the DNS seeders.


Title: Re: How do blockchain nodes find each other?
Post by: kooler1 on November 30, 2017, 08:39:33 PM
Bitcoin Core (the most common type of node) has 3 methods of discovering peers. First it consults an internal database of peers it knows about. For a new node, this will be empty. Then it will consult a set of servers called DNS seeders. The DNS seeders give out the IP addresses of nodes that a node can connect to. The node will connect to these nodes only temporarily to gather the IP addresses of other nodes it can also connect to. It will then connect to those nodes. Lastly, if the previous two were unavailable, the node will consult a built in list of seed nodes. It does the same thing with these seed nodes that it did with nodes returned by the DNS seeders.

Thanks for explanation achow101. Does it mean that DNS seeders (primary and built in) are set of "hardcoded" servers which are basically critical point of bitcoin core and if those servers won't be available whole blockchain will stop functioning (as eventually nodes won't be able to discover each other)?


Title: Re: How do blockchain nodes find each other?
Post by: achow101 on November 30, 2017, 08:45:26 PM
Thanks for explanation achow101. Does it mean that DNS seeders (primary and built in) are set of "hardcoded" servers which are basically critical point of bitcoin core and if those servers won't be available whole blockchain will stop functioning (as eventually nodes won't be able to discover each other)?
No. Nodes can still discover each other without the DNS seeders. The DNS seeders can be swapped out with some other initial discovery process too.

Furthermore, as I said, nodes maintain their own internal database that persists across restarts of nodes that it can connect to. So it will use those nodes instead of the DNS seeders on all starts after the first start. For new nodes, new nodes will fall back to the hundreds of hard coded seed nodes.

Lastly, nodes can be added manually too.


Title: Re: How do blockchain nodes find each other?
Post by: kooler1 on November 30, 2017, 08:48:19 PM
Thanks for explanation achow101. Does it mean that DNS seeders (primary and built in) are set of "hardcoded" servers which are basically critical point of bitcoin core and if those servers won't be available whole blockchain will stop functioning (as eventually nodes won't be able to discover each other)?
No. Nodes can still discover each other without the DNS seeders. The DNS seeders can be swapped out with some other initial discovery process too.

Furthermore, as I said, nodes maintain their own internal database that persists across restarts of nodes that it can connect to. So it will use those nodes instead of the DNS seeders on all starts after the first start. For new nodes, new nodes will fall back to the hundreds of hard coded seed nodes.

Lastly, nodes can be added manually too.

Ah, ok. Thanks for clarification!


Title: Re: How do blockchain nodes find each other?
Post by: hopeAo on December 02, 2017, 03:17:48 PM
It is well known that blockchain is decentralised and each node stores whole history of transactions (all blocks).

But when you start the node, how does it know how to connect to others to synchronise? Is there central registry of nodes (or IP addresses of nodes) that it checks?

For blockchain nodes to find each other it query the DNS using a number of "DNS seeds," which are DNS servers that provide a list of IP addresses of bitcoin nodes. Some of those DNS seeds provide a static list of IP addresses of stable bitcoin listening nodes. Some of the DNS seeds are custom implementations of BIND (Berkeley Internet Name Daemon) that return a random subset from a list of bitcoin node addresses collected by a crawler or a long-running bitcoin node. The Bitcoin Core client contains the names of five different DNS seeds. The diversity of ownership and diversity of implementation of the different DNS seeds offers a high level or reliability for the initial bootstrapping process. In the Bitcoin Core client, the option to use the DNS seeds is controlled by the option switch -dnsseed.







Title: Re: How do blockchain nodes find each other?
Post by: achow101 on December 02, 2017, 06:20:35 PM
Some of those DNS seeds provide a static list of IP addresses of stable bitcoin listening nodes.
None of the DNS seeders provide a static list of IP addresses. They all provide a random subset of IPs that are gathered by a crawler. It is against Bitcoin Core's DNS Seeder policy (https://github.com/bitcoin/bitcoin/blob/master/doc/dnsseed-policy.md) to have a seeder that returns static addresses.