上QQ阅读APP看书,第一时间看更新
Broadcasting scenarios
Nodes communicate with each other in a P2P network by setting up multiple one-to-one connections, because there is no single peer that is completely trustable. Maintaining multiple connections forces each node to broadcast any information to its connected peers in order to distribute data to the entire network and maintain the global truth.
In our application, we will be broadcasting information for several scenarios, as shown in the state transition diagram depicted in Figure 4.5:
Figure 4.5: State transition diagram for broadcasting
A node in the network performs broadcasting in the following scenarios:
- When a node creates a new block, it has to broadcast it to all its connected peers in order to spread the block's information
- When a node receives a new block from its peer, it has to broadcast it in order to propagate the block in the P2P network
- When a node receives a block that doesn't fit with the current blockchain, it sends a query message to all its peers in order to find the longest chain