Ethereum Blockchain Java (EthereumJ) Study Notes: Blockchain Structure

This article gives a brief introduction to the code related to the blockchain of EthereumJ.

Ethereum blockchain

The Ethereum blockchain is developed on the basis of the Bitcoin blockchain. The data structure of the blockchain retains the function of the Bitcoin blockchain to verify the authenticity and integrity of the data. At the same time, Ethereum saves the Account's State in the blockchain, such as nonce, balance, etc., which can realize more advanced functions (for details, please refer to: https://blog.ethereum.org/2015/11/15/merkling- in-ethereum/ ).

 

The Ethereum blockchain uses the data structure of Merkle Patricia Tree to save data (for details, please refer to: https://github.com/ethereum/wiki/wiki/Patricia-Tree ), referred to as Trie structure. The Ethereum blockchain uses the Trie structure to store three types of data:

l  Account state。

l Transaction list in each block.

l TransactionReceipt list in each block.

The Trie structures of Transaction list and TransactionReceiptlist only need to be temporarily created to verify the authenticity of each block. The Trie structure of Account state needs to be saved.

 

The Trie structure of Accountstate can refer to the following simple example diagram.


The organizational structure of the block of the Ethereum blockchain can refer to the following simple example diagram.



The function of Prev Hash in Block is similar to that of Bitcoin, and it is used to build a real and complete blockchain. State Root is used to reference account states saved in data storage. Transaction Root and Receipt Root are the hash roots of the Transaction list and TransactionReceipt list in this block, respectively.

EthereumJ blockchain management

This article introduces the Java Classes / Interfaces that are mainly involved in managing the data structure of the Ethereum blockchain in EthereumJ.

l CommonConfig, which mainly defines spring beans of many data sources as the basis for data storage/access.

n  keyValueDataSource

n  blockchainDB

n blockchainSource

n  stateSource,保存account state。

 

l DefaultConfig, defined by using the data source in CommonConfig

n blockStore(), retains Block information.

n transactionStore(), retains Transaction information.

 

l WorldManager, the main management module of EthereumJ, which is responsible for starting some main modules of EthereumJ.

n init(), responsible for starting SyncManager.

n loadBlockchain(), responsible for loading repository, blockStore and blockchain data.

 

l BlockChain/BlockChainImpl, BlockChain defines the interface for accessing the block chain of Ethereum, and BlockChainImpl implements this interface.

n getXXX() is used to get information about various blocks.

n tryToConnect(Block), which is used to add a new block to the blockchain.

 

l Repository/RepositoryRoot (RepositoryImpl), Repostiry defines the interface for accessing the AccoutState of the Ethereum blockchain, and RepositoryRoot (RepositoryImpl) implements this interface.

n getXXX() is used to get various account state information.

n getRoot() gets the stateroot information needed in the block.

n syncToRoot(byte[]), used to follow the new repository to the new state root.

n getSnapshotTo(byte[]), used to get the respository based on the new state root.

 

l PendingState/PendingSateImpl, since the Ethereum blockchain uses a distributed consensus mechanism to confirm new blocks, the confirmation of new blocks requires a waiting window. During the window time, there may be multiple blocks branches. PendingState defines an interface to handle this scenario, and PendingSateImpl implements this interface.

n addPendingTransaction(Transaction), add a new Transaction.

processBest(Block,List<TransactionReceipt>), process the new block.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324648696&siteId=291194637