Skip to content

blockchain

gtygo edited this page Jun 4, 2019 · 3 revisions

Block Structure

type description
hash block hash
header header info
transactions transactions array
signature Signature of the byte stream array
irreversibleinfo Irreversible information of this block
height block height

Block Header Structure

type description
version version number
privous block hash parent block hash
transaction root transactions state root hash
time stamp the number of nanoseconds elapsed since January 1, 1970 UTC
magic magic number
periodhash
candidatehash The hash of the candidate block

Blockchain Update

Blocks need to be securely linked to the blockchain, there are two ways to get a new block.

A new block from P2P network

Due to network delay,We cannot guarantee that the received block can be linked to the chain,We cache the received block through orphan pool.

A new block from local miner

First, we need to use the transaction pool to cache transactions from the p2p network. Then, Waiting for a block to be created by a miner node.


Regardless of where the block comes from,we use the same steps to process it as following.

avatar

when a block needs to be linked to the main chain, the following operations are required.here is a diagram of apply block.

avator

When the length of the block on the side chain exceeds the length on the main chain, we need to reorganize the chain. The following shows how the block is reorganized.here is a diagram of reorganize.

avator

Due to network latency, some blocks may be received at a slower rate. The parent block of these blocks has not yet been added to the chain and will become an orphan block. In the end, we need to deal with these orphan blocks.here is a diagram of process Orphan avator


Synchronization

Sometimes we get a block that is much higher than the current block height. we need to sync blocks from peer nodes to catch up with them. Contentbox provides two method to sync blocks from peers: LightSync and Sync. if the height of the received block is higher than the height of the current chain 32,we'll choose Sync to get a lot of blocks,otherwise we use LightSync

Sync Block synchronization requires three stages to complete: locate Get the fork point from the remote node check Check if the acquired fork point is valid by two remote nodes,The principle of inspection is based on the Merkle tree sync Add blocks to the blockchain in turn

Blocks added to the chain of this process are not broadcast


Here is a diagram of this sync procedure:

avatar

LightSync

if the difference between the received block height and the current chain height is less than 32,we'll use LightSync to get the missing blocks one by one.


Here is a diagram of light sync procedure:

avator


Clone this wiki locally