Blockchain Note – BTC Network

BTC Network Concepts

Bitcoin Network refers to all nodes to which transaction information can be broadcast.

There are two types of nodes: ordinary wallets and miners. Ordinary wallets only report or verify transactions and belong to ordinary users. The miners are responsible for bookkeeping and proof of work, and are professional book maintainers.

If you are a miner, you can’t hide the problem with the cows. You must broadcast to the whole network in the first time, otherwise the bonus belongs to others.
After other miners in the network receive your broadcast, they only verify three things:
1. Are all transaction inputs ≥ transaction output?
2. Have all transactions never occurred?
3. Use your random number hash block. Does the hash value prefix have enough “0”?

New transactions are broadcast, no need to reach all the nodes, as long as enough nodes are reached, they will soon be integrated into one block. At the same time, block broadcasts are fault tolerant to discarded information.

If you are a miner, once you are surrounded by a malicious node, even if you have calculated the workload and can’t broadcast it, then you will lose CPU resources and power, no reward, and you can’t make ends meet.

Routing Attacks

Any block information from the starting point to the target node is in the maze, and each node in the maze is a sign. The routing attack is deliberately pointing the wrong way, let the data packet sway in the maze, and eventually disappear into the network.

BGP: Border Gateway Protocol split attack is a vulnerability in the Diamond Border Gateway Protocol
Even worse is the delayed attack: the network traffic of the Bitcoin node can be intercepted without leaving traces, and the delay block is updated for 20 minutes. Bitcoin systems generally have one block every 10 minutes. A delay of 20 minutes is equivalent to cutting the miners’ ability to profit by mining. Ordinary wallet nodes will not be able to update blocks in time, and may face double payment risks.

Bitcoin is a decentralized network. Shouldn’t it be like a stream of water? There is only one reason for such vulnerability: the nodes are not evenly distributed.

BGP hijacking is the basic way to attack the Bitcoin network. It will form a black hole, and all information will not flow in, reducing network efficiency. When there are more black holes, a boudoir will be formed. Everyone in the boudoir will bury their own coins, until one day the world is transparent. Those who only look at the coins and forget to look up the road, they find that there is actually a world outside. a longer chain, and the original mining reward disappears instantly.

BTC Network in Code

Notes from Chapter 1 of BTC demo

Communicating with other nodes

An essential part of a node is to share and sync the blockchain with other nodes. The following rules are used to keep the network in sync.
  • When a node generates a new block, it broadcasts it to the network
  • When a node connects to a new peer it queries for the latest block
  • When a node encounters a block that has an index larger than the current known block, it either adds the block the its current chain or queries for the full blockchain.

Figure 1. Node communication

We will use websockets for the peer-to-peer communication. The active sockets for each nodes are stored in theconst sockets: WebSocket[]variable. No automatic peer discovery is used. The locations (= Websocket URLs) of the peers must be manually added.

Controlling the node

The user must be able to control the node in some way. This is done by setting up a HTTP server.
const initHttpServer=( myHttpPort:number)=>{
   const app=express();
   app.get('/blocks', (req, res)=>{
   });'/mineBlock', (req, res)=>{
       const newBlock:Block=generateNextBlock(;

   app.get('/peers', (req, res)=>{
       res.send(getSockets().map(( s:any)=>s._socket.remoteAddress+':'+s._socket.remotePort));
   });'/addPeer', (req, res)=>{

   app.listen(myHttpPort, ()=>{
       console.log('Listening http on port: '+myHttpPort);
As seen, the user is able to interact with the node in the following ways:
  • List all blocks
  • Create a new block with a content given by the user
  • List or add peers


It should be noted that the node actually exposes two web servers: One for the user to control the node (HTTP server) and one for the peer-to-peer communication between the nodes. (Websocket HTTP server)

Figure 2. BTC demo network architecture



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s