Blockchain

The blockchain component is the persistent storage of the blockchain structure, and the chain structure maintained by the entire network. Note: This structure does not store specific transaction data and transaction Writing results. This part of the data is stored in txdb.

Interface

Code is here
blockchain implements the storage and processing logic of the basic chain structure. The following are the interfaces of the core functions. Developers can customize their own chain storage methods and processing logic if required:

func ConvergeType() ConvergeType

ConvergeType() returns the convergence type of the chain (that is, in what form the block was finalized) As we all know, in the blockchain, multiple nodes may produce blocks at the same moment, thus forming a fork. If it does not converge, the system will not know which chain is the main chain. Therefore, convergence is required, and the most common methods of convergence are:

  • Longest sub-chain (Longest): The longest branch will be considered as the main chain, and this method will be rolled back.

  • Heaviest: The fork with the largest number of sub-chains will be considered as the main chain, and this method will be rolled back.

  • Finalize: The block or chain is voted through voting and other methods to finally finalize a fork to become the main chain. Under normal circumstances, the finalized block cannot be rolled back.

func GetGenesis() (*CompactBlock, error)
func SetGenesis(b *CompactBlock) error

Obtain the genesis block from the chain and store the genesis block into the chain.

func AppendBlock(b *CompactBlock) error
func GetBlock(blockHash Hash) (*CompactBlock, error)
func UpdateBlock(b *CompactBlock) error

AppendBlock(block)adds the block to the end of the chain
GetBlock(blockHash)gets a specific block based on the block hash
UpdateBlock(block)updates block data with block hash as index

func Children(prevBlockHash Hash) ([]*CompactBlock, error)  
func Finalize(blockHash Hash) error  
func GetEndBlock() (*CompactBlock, error)
func LastFinalized() (*CompactBlock, error)

Children(blockHash) gets all its subblocks based on a block hash
Finalize(blockHash) finals consensus finalizes a block
GetEndBlock() gets the last unfinalized block
LastFinalized() gets the last finalized block