compsci:cryptocurrency:btc:network

The Bitcoin Network

Bitcoin uses a P2P (peer to peer) protocol to transmit data between wallets. This means that the wallets don't talk to a server, instead the wallets talk to each other. When a wallet connects to the network, it will connect to several other wallets. The wallet can then ask the others for the blocks it is missing, or have transactions propagated through the network.

$ bitcoin-cli getpeerinfo
[
    {
        "addr" : "130.208.143.226:11337",
        "addrlocal" : "159.69.8.182:11337",
        "services" : "00000001",
        "version" : 100000,
        "subver" : "/Satoshi:2.2.4/",
        "inbound" : false,
        "startingheight" : 689015,
        "banscore" : 0,
        "syncnode" : true
    }
]

Before connecting to the network the client will need to know it's own external IP address that others can connect to. This is done by connecting to a public web service that is hard coded into the Bitcoin Core client. The primary service is http://checkip.dyndns.org and the fallback service is http://showmyip.com which will both respond with the client's public IP address.

Note: Should a distributed system depend on a single web service? Are there alternatives?

One challenge with peer to peer networks is peer discovery, i.e. how do we find the IP addresses of other nodes on the network. When the client has previously connected to the Bitcoin network, it will have a list of nodes that it has previously found. If the client is connecting for the first time it will have to use fallback methods.

One method that is not used anymore, was having the client connect to an IRC server (specifically irc.lfnet.org) and put it's own IP address as nickname. It could then join a random channel between #bitcoin00 and #bitcoin99 and issue the who command to get the nicknames (which are IP addresses) of anyone else on the channel. The client would then have a list of peers and get a good connection to the Bitcoin network.

The primary fallback method today is by using DNS seeds. The Bitcoin Core client has a few DNS addresses hard coded (in chainparams.cpp) that will respond with multiple A records with peer IP addresses. Here is an example response from one of them.

dig seed.bitcoinstats.com

;; ANSWER SECTION:
seed.bitcoinstats.com.	60	IN	A	62.210.131.148
seed.bitcoinstats.com.	60	IN	A	110.32.91.113
seed.bitcoinstats.com.	60	IN	A	212.227.253.11
seed.bitcoinstats.com.	60	IN	A	89.142.140.107
seed.bitcoinstats.com.	60	IN	A	63.32.210.247
seed.bitcoinstats.com.	60	IN	A	85.10.206.14
seed.bitcoinstats.com.	60	IN	A	5.79.123.3
seed.bitcoinstats.com.	60	IN	A	144.76.44.114
seed.bitcoinstats.com.	60	IN	A	104.198.84.14
seed.bitcoinstats.com.	60	IN	A	136.243.151.174
seed.bitcoinstats.com.	60	IN	A	77.125.55.110
seed.bitcoinstats.com.	60	IN	A	100.40.18.226
seed.bitcoinstats.com.	60	IN	A	18.204.135.109
seed.bitcoinstats.com.	60	IN	A	129.211.99.116
seed.bitcoinstats.com.	60	IN	A	142.163.72.249
seed.bitcoinstats.com.	60	IN	A	216.93.131.117
seed.bitcoinstats.com.	60	IN	A	195.201.56.56
seed.bitcoinstats.com.	60	IN	A	88.99.89.221
seed.bitcoinstats.com.	60	IN	A	5.9.43.250
seed.bitcoinstats.com.	60	IN	A	188.23.54.87
seed.bitcoinstats.com.	60	IN	A	51.91.66.183
seed.bitcoinstats.com.	60	IN	A	91.89.128.240
seed.bitcoinstats.com.	60	IN	A	173.249.34.251
seed.bitcoinstats.com.	60	IN	A	5.135.186.15
seed.bitcoinstats.com.	60	IN	A	145.14.157.145
  • compsci/cryptocurrency/btc/network.txt
  • Last modified: 2020/06/04 12:22
  • by Brynjar Ingimarsson