Does a Node connect to all the peers in the network? Or just a few?

If its just a few, how many? If its just a few, what about if all of those nodes in the list are malicious?


A node is only called a peer if you're connected to it. So by definition you are always connected to all your peers.

I assume you're asking whether you're connected to every node in the network. The answer is no; most Bitcoin node software implementations only connected to around 8 others.

What happens if one is malicious? Bitcoin is trust-minimized by design. This means that it verifies to the extent possible whether incoming data is correct. Where this isn't possible, it uses a objective and unforgeable metric (proof of work) to select the winner in case there are multiple acceptable possibilities (blocks).

For most types of attacks, the assumption is that at least one of your peers is honest. If that's the case, you'll eventually learn the best valid version of history the rest of the network learns too. If all your peers are malicious, they may prevent you from seeing actual history - though it is very hard even in this case to forge and invalid version of history and convince your node of that.

  • Why if we have just one honest node I’ll learn the best valid version? One honest node out of 8 means the 12.5% of your nodes, meaning, if we validate the truth by using percentage, 87.5% (malicious nodes) Vs 12.5% (the only honest one)? We would take the malicious nodes as if they were valid. – Juan Feb 22 at 14:58
  • 1
    It doesn't matter how many peers say what. As long as you learn from one peer about the real chain, you will switch to it, because it will be unambiguously a better chain than what other nodes told you. – Pieter Wuille Feb 22 at 15:17
  • How would you know what chain is valid since it’s the first time you’re getting it? By checking the PofW? – Juan Feb 22 at 15:19
  • 2
    A chain is valid if it satisfies all the rules (no invalid signatures, no double spends, no printing money, ...). When there are multiple valid chains, you accept the one with most proof of work. – Pieter Wuille Feb 22 at 15:21

The default number is 8 peers, but you can change it on the configurations. If a peer starts acting maliciously, the node will block it and find another one.

  • How would the node know that X peer is acting maliciously ? Since 1) The node might be getting the information for the first time. 2) The node could become malicious since its peers are malicious too. – Juan Feb 22 at 14:36
  • Your node has the genesis block on its source code, from there it can verify any block its peers send to it. – Pitchas Feb 22 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.