ytgui / temp

0 stars 0 forks source link

bitcoin p2p network #105

Closed ytgui closed 4 years ago

ytgui commented 4 years ago

https://bitcoin.org/en/p2p-network-guide https://github.com/perone/protocoin/blob/master/protocoin/clients.py

ytgui commented 4 years ago

Introduction

Full nodes: download and verify every block and transaction prior to relaying them to other nodes. Archival nodes: are full nodes which store the entire blockchain and can serve historical blocks to other nodes. Pruned nodes: are full nodes which do not store the entire blockchain. Many SPV clients also use the Bitcoin network protocol to connect to full nodes.

Consensus rules do not cover networking, so Bitcoin programs may use alternative networks and protocols, such as the high-speed block relay network used by some miners and the dedicated transaction information servers used by some wallets that provide SPV-level security.

Peer Discovery

  1. main net: 8333 port, testnet: 18333 port
  2. dns query for the very first nodes. (insecurity because man-in-the-middle attack)
  3. hardcoded addr as first nodes.
  4. send addr to others.

Connecting To Peers

  1. local sending a version message as (ver_number, block, current_time).
  2. remote response with it's own version message.
  3. both send a verack message to indicate connection establish.
  4. send heartbeat every 30 minutes, with 90 minutes timeout.

Initial Block Download

  1. before validate unconfirmed transactions and new-mined blocks, it need to download and validate from block 1.
  2. block 1 is the block after hardcoded genesis block.
  3. if node offline for a long time, the IBD method is also used.