Ethereum CPP code analysis (1)

The six-layer structure of the blockchain


Data layer: It is a block + linked list data structure, which is essentially a distributed blockchain

network layer: p2p network.

Consensus layer: formulate the mechanism for obtaining currency of the blockchain. For example, Bitcoin uses POW (Proof of Work): the better the performance of the computer, the easier it is to obtain monetary rewards. There is also POS (Proof of Stake): similar to the concept of crowdfunding dividends, interest will be paid to holders according to the amount and time of currency you hold. For example, Hyperledger uses PBFT (Byzantine Fault Tolerance).

Incentive layer: mining mechanism

contract layer: the previous blockchain did not have this layer. Therefore, the original blockchain can only conduct transactions, but cannot be used for other fields or other logical processing. But the emergence of the contract layer has made the use of blockchain in other fields a reality, such as for IOT. This part of Ethereum includes EVM (Ethereum Virtual Machine) and smart contracts.

Application layer: The presentation layer of the blockchain. For example, Ethereum uses truffle and web3-js. The application layer of the blockchain can be the mobile terminal, the web terminal, or integrated into the existing server, taking the current business server as the application layer.

Ethereum Architecture


The top layer of Ethereum is DApp. It is exchanged through Web3.js and the smart contract layer. All smart contracts run on EVM (Ethereum Virtual Machine) and use RPC calls. Below EVM and RPC are the four core contents of Ethereum, including: blockchain, consensus algorithm, mining and network layer. Except for the DApp, all other parts are in the Ethereum client. The most popular Ethereum client is Geth (Go-Ethereum)

The structure of the Ethereum cpp code is as follows:


Official site description: http://www.ethdocs.org/en/latest/ethereum-clients/cpp-ethereum/architecture.html

  • lib devcore : data structures, utilities, rlp, trie, memory db development core library, including data structures, rlp, trie, database, log, Worker, etc.
  • lib devcrypto : crypto primitives. Depends on libsecp256k1 and libcrypto++. Encryption related, depends on libsecp256k1 and libcrypto++
  • eth A command-line Ethereum full-node that can be controlled via RPC.
  • lib ethash : ethash mining POW algorithm implementation
  • lib ethashseal : generic wrapper around the POW block seal engine. Also contains the genesis states for all ethash-based chains.
  • lib ethcore : collection of core data structures and concepts eth core data structures and concepts, such as block headers, chain parameters, etc.
  • lib ethereum : main consensus engine (minus EVM). Includes the State and BlockChain classes. The main part, the consensus engine (excluding EVM), includes state and BlockChain classes, etc.
  • ethkey : stand-alone key management stand-alone key management program
  • ethvm : stand-alone EVM execution utility Standalone EVM execution tool
  • lib evm : Ethereum Virtual Machine implementation (interpreter). EVM interpreter
  • lib p2p : core peer to peer networking implementation (excluding specific sub-protocols)p2p network implementation core module (excluding specific sub-protocols)
  • rlp : stand-alone rlp en-/decoder stand-alone rlp codec
  • utils/ secp256k1 : implementation of the SECP 256k1 ECDSA signing algorithm.
  • lib web3jsonrpc : json-rpc server-side endpoint, provides http and IPC (unix socket, windows pipe) connectors JSON-RPC server, provides http and rpc links.
  • lib webthree : service connectors for ethereum, swarm/ipfs and  whisper .
  • testeth: tests for the modules formerly within the libethereum repo

--------------------------------------- Modules not present in other git docs--- ----------------------

libevmasm: EVM assembly tools, also contains the optimizer.
libevmcore: elementary data structures of the EVM, opcodes, gas costs, ...
libethash-cl: ethash mining code for GPU mining (OpenCL)
libwhisper: whisper implementation

testweb3core: tests for the modules formerly within the libweb3core repo
testweb3: tests for the modules formerly within the webthree repo
utils/json_spirit: JSON parser written for Boost’s Spirit library.

utils/libscrypt: scrypt implementation

------------------------------------------------------------------------------------------------



Guess you like

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