Chain
三部分:
- 元数据
- 统筹数据
- 关联对象
MVC 里一个功能比较综合的“控制器”。
/// Facade to the blockchain block processing pipeline and storage. Provides
/// the current view of the TxHashSet according to the chain state. Also
/// maintains locking for the pipeline to avoid conflicting processing.
pub struct Chain {
db_root: String,
store: Arc<store::ChainStore>,
adapter: Arc<dyn ChainAdapter + Send + Sync>,
orphans: Arc<OrphanBlockPool>,
txhashset: Arc<RwLock<txhashset::TxHashSet>>,
verifier_cache: Arc<RwLock<dyn VerifierCache>>,
// POW verification function
pow_verifier: fn(&BlockHeader) -> Result<(), pow::Error>,
archive_mode: bool,
stop_state: Arc<Mutex<StopState>>,
genesis: BlockHeader,
}
核心数据
只有
- txhashset TxHashSet
关联对象
- store ChainStore
- adapter ChainAdapter
- orphans OrphanBlockPool
其它
- BlockHeader
作用
“元数据”这部分不是很重要,主要是对其“关联对象”的处理。如:OrphanBlockPool、BlockContext、ChainStore、TxHashSet 等
(注意:这里的部分概念仅是为了方便“链”进行管理,在其它模块,或者说在整个区块链上,意义不大)。
“链”是大脑、是协调者。协调下面的“软件”的多个模块,让它们协作起来。
对其它区块链项目而言,“链”在概念上可以借鉴,但实现上不能直接参考。