Our Blog

Full-stack development and intelligence for blockchains

Viewing other nodes on the network (look who's talking to your network)

We tend to take for granted that blockchain networks are just there, but have you ever thought about who else your node is talking to? It’s all well having a node to connect to, but how do you know that your node is speaking with reliable sources? Although it’s easy to overlook this detail, the potential implications are serious.

How do you know what the right number of nodes is?

 

Overview

Ethereum is a decentralized application platform; it is a distributed unstructured peer to peer system built up of many nodes. Because it is unstructured, it means that every node must have a complete copy of all the data on the network. It also means that a node will act as both server (to other peers) and client (fetches data from peers) to the network.

Because each node must fetch all the data for that blockchain, it means that it's open to attack from malicious actors who might want to propagate corrupted data to you. To mitigate this problem, Satoshi Nakamoto (in the bitcoin white paper) proposed that this could be solved by introducing a 'proof of work' consensus algorithm.

Ethereum Nodes on Google EarthEthereum nodes on Google Earth from @peter_szilagyi

Key - green = geth, orange = parity, white = everything else

What has this got to do with Peer Count?

Simply put, you need to have peers to be able to have a network. Otherwise, you're just talking to yourself! You could run a node with a single peer that's connected to the broader network. The downside is that you must trust, completely, that single peer. At the other extreme you could try and connect to all available peers, the problem is that it doesn't scale. You can not talk to everyone in a timely manner. What you need to have is a reasonable number of peers whereby the chances of more than half of them being malicious is low.

How do you prevent yourself being hijacked? 

The way you discover peers needs to be random. The problem is you need to start somewhere, with Ethereum mainnet this is achieved via bootnodes. They are maintained by the Ethereum Foundation and act as a lookup for other nodes. Once you have some peers you can ask for some more peers (neighbours). Your client can walk the network to find sufficiently random peers to connect to. 

Check your peers

It's a good idea to make sure that the peers that you've connected to are sufficiently distributed. There's no point connecting to 15 peers that are owned by the same actor. There's no real foolproof way of doing this, but you can make a start by checking admin.peers from a geth console or by using epirus.

So there you have it, next time you connect to a node for the first time, perhaps start by checking its peer count. If you see at least 15 distinct peers you should be able to have some confidence that your node is talking to the real network!

References:

https://github.com/ethereum/devp2p/blob/master/rlpx.md

https://github.com/ethereum/devp2p/wiki/Discovery-Overview

https://medium.com/loom-network/understanding-blockchain-fundamentals-part-1-byzantine-fault-tolerance-245f46fe8419