原創內容,未經允許不得轉載
本文對源碼的解讀為個人理解,歡迎指正
關聯github倉庫:FISCO-BCOS
內容太多了,慢慢深入閱讀,持續更新中...(2020-04-30)
各模塊的功能:
可以簡單分EVM模塊、賬本模塊、共識同步模塊、網絡模塊
EVM模塊:執行交易
- libethcore
- block區塊定義
- transaction定義
- abi定義
- 并行交易定義
- libevm
- EVMC 提供exec接口
- ExtVmFace 提供evm的call get接口
- VMFactory
- libinterpreter EVM的實現
- VM 虛擬機匯編操作的定義
- VMCall call操作對應匯編的定義
- VMOpt copyCode, exp256 操作工具類
- libexecutive 執行交易
- Executive: call, create,execute
- ExtVM: 生成調用結果或部署結果
- libtxpool 交易池,待確認的交易
- TransactionNonceCheck commonTxCheck
- TxPool insert, clear, pending, verify等對交易池的操作
賬本模塊:
- libstorage 用不同db存儲的數據層
- RocksDBStorage, BasicRocksDB: 基本put commit等操作
- LevelDBStorage: commit, select, setDb..基本put commit等操作
- SQLStorage: 是否與AMDB相關
- ZdbStorage: 在mysql上,創建預編譯、系統表等數據表
- CachedStorage: 緩存存儲,具體未知
- ScalableStorage: 可擴展存儲,與AMDB proxy相關?
- MemoryTable 系統表,如權限控制,crud等
- BinLog: binlog handler(decode, encode, ), binlog storage
- SQLBasicAccess: buildSQL, buildConditions
- SQLConnectionPool: 連接池
- Table: table的基本操作setEntries
- libstoragestate MPT存儲
- StorageState MPT操作 定義對state的操作如,createAccount,createContract,rollback, addBalance
- StorageStateFactory 工廠類
- libledger 數據層上的賬本層
- DBInitializer: 初始化storage相關,create實例
- Ledger, LedgerParam:
- 創建consensusEngine, createRaftSealer, createPBFTSealer, initPBFTEngine
- 初始化blockVerifier, eventLogFilter, initBlockChain, initSync, initTxPool, initSync
- LedgerManager: getGroupListForRpc (.h中獲取BlockChainInterface等face接口)
- libmptstate ethereum原生代碼
- Account 賬戶的定義,nonce, code, balance等, setCode賬戶代碼
- State, MPTState MPTStateFactory
- MPTStateFactory: getState
- State: addAddress, addBalance/subBalance, createAccount, codeHash, addresHash
- MPTState: commit操作,維持MPT State狀態樹,State為數據層的話,MPTState為接口層
共識同步模塊 共識時verifier用到到賬本模塊,用到evm執行
- libconsensus
- Sealer 定義sealer操作(打包區塊), loadTxs, reportNewBlock, isBlockSyncing
- ConsensusEngineBase: 區塊校驗、
- pbft:待詳讀 PBFT分組共識算法、HotStuff共識算法
- raft:待詳讀
- rotating_pbft(RPBFT) 待詳讀 基于pbft的DPOS
- libblockverifier
- BlockVerifier
- executeBlock
- executeTransaction
- parallelExecuteBlock
- DAG, TxDAG 用于并行交易
- ExecutiveContext 執行交易的上下文
- BlockVerifier
- libblockchain
- BlockChainImp 區塊鏈邏輯的實現,檢查構建創世塊、獲取區塊和交易等face接口的實現
- libsync
- DownloadingBlockQueue, DownloadingTxsQueue 與RLP結合
- GossipBlockStatus 傳遞區塊狀態包
- DownloadRequest, RspBlockReq 下載區塊請求
- SyncMaster 同步操作定義,send,broadcast
- SyncTransaction 廣播交易
- SyncMsgEngine msg監聽、收發
- SyncMsgPacket 廣播的消息包
- SyncTreeTopology 網絡拓撲圖 nodeList, nodeInfo
與網絡模塊
- libnetwork
- ASIOInterface boost的網絡模塊,用于socket連接, ssl的websocket連接
- Host: 節點間握手(Server/Client) 與P2P關聯
- handshakeServer ssl
- asyncConnect..
- Session session會話,監聽信息
- PeerWhitelist 白名單
- libp2p
- Service
- heartBeat 與updateStaticNodes保持連接
- asyncSendMessageByNodeID, 或broadcast, multicast
- onMessage, onConnect等
- P2PSession
- heartBeat心跳包
- onTopicMessage等監聽topic信息
- message: P2PMessage P2PMessageRC2
- StatisticHandler block/tx sync的設置,如updateDownloadedTxsCount
- Service
- librpc
- SafeHttpServer 接收/回復rpc API的請求
- Rpc 定義rpc的接口
- JsonHelper HttpMessage等解析工具類
- libchannelserver 基于channel的sdk長連接協議定義,與web3sdk中定義類似,此處為server, sdk為client,可參考另一篇sdk的文章
加密、鑒權模塊
- libdevcrypto:AES(CBC模式), Hash(md, keccak.sha256, secp256k1)
- gm 國密sm2, sm3, sm4, 國密hash, aes等
- libsecurity 落盤加密
- EncryptedLevelDB leveldb文件加密
- EncryptedFile: decryptContents解密文件
- KeyCenter: KeyCenterHttpClient keyServer密鑰管理中心
特性模塊:
- libprecompiled 預編譯合約的實現,包含接口solidity文件。與table直接交互
- libeventfilter event日志的過濾器
- EventLogFilterManager
- EventLogFilterParams
- EventLogFilter: matches
- libdevcore 地址, base64, log, rlp, trie等定義
- libconfig 全局配置 Global configure of the node
- tools shell腳本,build_chain, get_node_certs等
- test 測試類
libinitializer
讀取配置文件,進行初始化,包含:
- Initializer,總的初始化,將P2P, RPC, Secure, Ledger, Log等模塊的初始化集中處理。