以太坊CPP代码分析(一)

区块链的六层结构


数据层:是一个区块 + 链表的数据结构,本质是一个分布式区块链

网络层:p2p网络。

共识层:制定区块链的获取货币的机制。比如比特币用的是POW(Proof of Work工作量证明机制):电脑的性能越好,越容易获取到货币奖励。还有POS(Proof of Stake权益证明机制):类似于众筹分红的概念,会根据你持有的货币数量和时间,给持有者发放利息。还有比如超级账本用的是PBFT(拜赞庭容错)。

激励层:挖矿机制

合约层:以往的区块链是没有这一层的。所以最初的区块链只能进行交易,而无法用于其他的领域或是进行其他的逻辑处理。但是合约层的出现,使得在其他领域使用区块链成为了现实,比如用于IOT。以太坊中这部分包括了EVM(以太坊虚拟机)和智能合约两部分。

应用层:区块链的展示层。如以太坊使用的是truffle和web3-js.区块链的应用层可以是移动端,web端,或是是融合进现有的服务器,把当前的业务服务器当成应用层。

以太坊架构


以太坊最上层的是DApp。它通过Web3.js和智能合约层进行交换。所有的智能合约都运行在EVM(以太坊虚拟机)上,并会用到RPC的调用。在EVM和RPC下面是以太坊的四大核心内容,包括:blockChain, 共识算法,挖矿以及网络层。除了DApp外,其他的所有部分都在以太坊的客户端里,目前最流行的以太坊客户端就是Geth(Go-Ethereum)

以太坊cpp代码结构如下:


官方网站说明:http://www.ethdocs.org/en/latest/ethereum-clients/cpp-ethereum/architecture.html

  • libdevcore: data structures, utilities, rlp, trie, memory db  开发核心库,含数据结构、rlp、trie、数据库、日志、Worker等
  • libdevcrypto: crypto primitives. Depends on libsecp256k1 and libcrypto++. 加密相关,依赖于libsecp256k1 and libcrypto++
  • eth A command-line Ethereum full-node that can be controlled via RPC.  以太坊全节点命令行程序,可以通过RPC控制
  • libethash: ethash mining POW algorithm implementation  ethash挖矿PoW算法的实现
  • libethashseal: generic wrapper around the POW block seal engine. Also contains the genesis states for all ethash-based chains.围绕PoW对块进行封装引擎,所有基于ethash的链含创世状态。
  • libethcore: collection of core data structures and concepts  eth核心数据结构和概念的集合库,如区块头、链参数等
  • libethereum: main consensus engine (minus EVM). Includes the State and BlockChain classes.主要部分,共识引擎(不含EVM),包括state和BlockChain类等
  • ethkey: stand-alone key management独立的密钥管理程序
  • ethvm: stand-alone EVM execution utility 独立的EVM执行工具
  • libevm: Ethereum Virtual Machine implementation (interpreter).EVM解释器
  • libp2p: core peer to peer networking implementation (excluding specific sub-protocols)p2p网络执行核心模块(排除特定子协议)
  • rlp: stand-alone rlp en-/decoder独立的rlp编解码器
  • utils/secp256k1: implementation of the SECP 256k1 ECDSA signing algorithm.实现SECP 256k1 ECDSA签名算法。
  • libweb3jsonrpc: json-rpc server-side endpoint, provides http and IPC (unix socket, windows pipe) connectors JSON-RPC服务端,提供http和rpc链接。
  • libwebthree: service connectors for ethereum, swarm/ipfs and whisper. ethereum的服务连接器,swarm / ipfs和whisper
  • testeth: tests for the modules formerly within the libethereum repo

---------------------------------------其他git文档中未出现的模块-------------------------

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

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



猜你喜欢

转载自blog.csdn.net/metal1/article/details/80116186
今日推荐