Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: roro9500 on April 13, 2020, 01:06:48 PM



Title: Initial peer discovery
Post by: roro9500 on April 13, 2020, 01:06:48 PM
Hello, I am new (and sorry in advance for my language I am French).



I would like to know how we connect to the blockchain, to the network, when there is no ip?

Indeed we all use bitcoin core (for bitcoin) to connect and retrieve information and update.

However the source code of bitcoin core (I have never read it) does not redirect us to an ip, but people still manage to find themselves, without ever saving the ip.

How can people know or find the information, when the source code of the software does not have ip, they do not know address (ip) which has the information?

Knowing that the ip is the basis of the connection ...


Title: Re: [b]I would like to know how we connect to the blockchain, to the network, when t
Post by: jackg on April 13, 2020, 01:21:40 PM
I think you're asking about how core makes it's initial connections and how it discovers peers?

Core comes with a list of addresses that it knows to be nodes functioning (these are normally core devs or long standing nodes) these nodes send back to your client a list of peers they're connected to (up to 1000 IPs) and you then send a message to some/each of those.. Presumably ip heuristics are used to better locate who to connect to (someone in Europe will be faster to connect to if you're in Europe than the US).

The peers.dat then stores a list of up to 1000 of your nodes fastest peers, once you have a full chain you'll also be included in those peers.dat on standard nodes of other people.


Title: Re: [b]I would like to know how we connect to the blockchain, to the network, when t
Post by: ranochigo on April 13, 2020, 02:24:33 PM
There's a list of DNS seeds[1] within the code itself. The DNS seeds are domains that ONLY give out a list of well connected seed nodes. The seed nodes are the ones which has a high reliability and a good connection. After a connection to the seed node, the client can then obtain more peers information by querying the seed nodes.

If all else fails, there is a hardcoded bunch of seed nodes within the client itself.

[1] https://github.com/bitcoin/bitcoin/blob/b83565625e32b22395e28c1965b2e42fc17f04d7/src/chainparams.cpp#L116


Title: Re: [b]I would like to know how we connect to the blockchain, to the network, when t
Post by: BrewMaster on April 13, 2020, 03:58:03 PM
you are asking about one of the biggest challenges that any peer to peer network faces, which is the "initial" peer discovery. as it was mentioned it is by hardcoded seeders. the problem is that any P2P client has to know at least one IP address of another peer on that network to start its connection. to do that we have these seeders. but as soon as that first connection is made the client is already a part of the network and can find nearly all other peers by communicating with some of them and asking them for a list of other peers (their IP addresses) and by storing them locally the client can connect to those other peers in the future.


Title: Re: Initial peer discovery
Post by: roro9500 on April 14, 2020, 10:07:49 AM
if this is the case, it means that bitcoin core will no longer work for new clients (who have never started it), if the DNS is unavailable.

Is it a certain way of centralization? : /
The DNS can delete ? D:


Title: Re: Initial peer discovery
Post by: ranochigo on April 14, 2020, 10:24:30 AM
if this is the case, it means that bitcoin core will no longer work for new clients (who have never started it), if the DNS is unavailable.

Is it a certain way of centralization? : /
No. Back up nodes are also hard-coded into the source code. In the event that the DNS fails, the client would then try to connect to the reliable nodes that are listed within the code itself. If all else fails, the client has to manually add the IPs himself using the command-line option which is not difficult.

The client would try to establish more nodes to connect to by the getaddr message sent to it's peers and build a peers.dat which includes some nodes which it has succesfully contacted previously.


Title: Re: Initial peer discovery
Post by: roro9500 on April 14, 2020, 11:25:09 AM
OK i understand, very thank !


Title: Re: Initial peer discovery
Post by: hushan on May 03, 2020, 01:21:13 AM
like any p2p networks, a list of initial seed nodes are either preconfigured or harded coded so that the startup and bootstraping can work without knowing all the nodes out there.