Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: tomwoods on March 19, 2014, 02:27:36 AM



Title: How do clients and miners know who is on the network?
Post by: tomwoods on March 19, 2014, 02:27:36 AM
I'm looking into developing a javascript client p2p network. Most P2P networks I've looked into need to communicate with a connection broker in order to discover what other clients are in the network. Even bittorrent clients, need tracker servers.

How is it that the bitcoin network resolves this?

How does a client know what IPs to download the blockchain from?

How do miners know the IPs of other miners in the network?


If you can point me in the right direction to look up this information I would be most thankful


Title: Re: How do clients and miners know who is on the network?
Post by: goatpig on March 19, 2014, 07:56:55 AM
There were plans to change that so im not sure if that was changed yet but at first the bitcoin core client would retrieve peers from a freenode irc channel.


Title: Re: How do clients and miners know who is on the network?
Post by: jl2012 on March 19, 2014, 08:22:39 AM
https://en.bitcoin.it/wiki/Satoshi_Client_Node_Discovery


Title: Re: How do clients and miners know who is on the network?
Post by: benjyz on March 19, 2014, 12:48:08 PM
There is a DNS seed. here are the code parts:

https://github.com/bitcoin/bitcoin/blob/334bd22e75b1955b3dfefbf4f5e065afdbc46ae4/src/net.cpp#L1197
https://github.com/bitcoin/bitcoin/blob/b8d9058a4d1ce28eefa65aa3339bcc52b3c014e9/src/chainparams.cpp#L143

In the beginning there was an IRC channel. torrent is different in that there are many torrents, and not every node has all torrents. whereas in bitcoin every node has the one and only blockchain. it's true that bitcoin is quite similar to torrent.

a correction: in bitcoin there are only nodes (fully P2P). there is no concept of a miner per se.

there were some recent changes to make this not reliant on DNS.

see also:
https://github.com/bitcoin/bitcoin/pull/3875
http://bitcoin.stackexchange.com/questions/14410/how-does-bitcoin-find-peers
http://getaddr.bitnodes.io/


Title: Re: How do clients and miners know who is on the network?
Post by: jimmyscratchlab on March 20, 2014, 12:41:13 PM
I'm looking into developing a javascript client p2p network.

Using WebRTC?


Title: Re: How do clients and miners know who is on the network?
Post by: tomwoods on May 13, 2014, 04:43:34 PM
Thank you all very much. All responses have been very useful.

From what I see,  although the network is decentralized, the initial list of nodes has to come from somewhere. From the code, I gather it has a list of initial seed nodes to download updated lists from. I assume that it is important for the integrity of the network that these hardcoded seed nodes are not compromised or can't easily become subject to persecution from hostile goverments / agents.

The link to the Satoshi Client Node Discovery also gives very good ideas. Thanks.

Using WebRTC?

Yes.


Title: Re: How do clients and miners know who is on the network?
Post by: DeathAndTaxes on May 13, 2014, 04:47:10 PM
From the code, I gather it has a list of initial seed nodes to download updated lists from. I assume that it is important for the integrity of the network that these hardcoded seed nodes are not compromised or can't easily become subject to persecution from hostile goverments / agents.

Not really.  They could all be taken down tomorrow and existing nodes would be unaffected.  New nodes would have difficulty bootstraping but that could be worked around temporarily by having new users manually adding known nodes to the config file.  All a new node needs is a few nodes to connect to as part of the connection handshake involves both nodes sharing their list of known nodes.   So if you known 3 or 4 nodes, you soon know thousands.  All networks have to be bootstrapped in some way.  Of course the goal would be to ensure there are enough bootstraps (both in dns seeds and hardcoded nodes) to make disrupt nearly impossible.

In addition to the dns seeds there is a list of very active high uptime nodes which are hardcoded to the client
https://github.com/bitcoin/bitcoin/blob/b8d9058a4d1ce28eefa65aa3339bcc52b3c014e9/src/chainparams.cpp#L21

This list is updated from version to version.  Peers are monitored to find the ones with the most connections, uptime, and synced bandwidth.  This ensures that even if the dns seeds are offline, new nodes can always find a few reliable, well connected nodes.  Maintain good uptime and large number of inbound connections and you might find your node on that list.

As for miners.  Nodes don't advertising if they are mining or not.  The network doesn't treat miners any different than other nodes.  You don't (normally) send transaction to a miner.  You just relay them to your peers who relay them to their peers, etc.  Within a few hops every node knows of the new transactions.