Utility structs to handle the 3 hashtrees (output, range proof, kernel) more conveniently and transactionally.
以“树”的形式,保存了整个区块链简要、关键的几个数据。
以“优雅”的方式进行存储,以达到“高效”的读取数据。
主要是 4 个哈希的集合
header_pmmr_h BlockHeader
output_pmmr_h OutputIdentifier
rproof_pmmr_h RangeProof
- kernel_pmmr_h TxKernel
外加关联对象(此处只关联存储对象)
- commit_index ChainStore
方便某些情况下管理“交易”。
可用于快速检索、校验、验证。
TxHashSet
主要是关联 PMMRHandle 和 TxKernel 对象。
是“链”对象的子集。
pub struct TxHashSet {
/// Header MMR to support the header_head chain.
/// This is rewound and applied transactionally with the
/// output, rangeproof and kernel MMRs during an extension or a
/// readonly_extension.
/// It can also be rewound and applied separately via a header_extension.
header_pmmr_h: PMMRHandle<BlockHeader>,
/// Header MMR to support exploratory sync_head.
/// The header_head and sync_head chains can diverge so we need to maintain
/// multiple header MMRs during the sync process.
///
/// Note: this is rewound and applied separately to the other MMRs
/// via a "sync_extension".
sync_pmmr_h: PMMRHandle<BlockHeader>,
output_pmmr_h: PMMRHandle<Output>,
rproof_pmmr_h: PMMRHandle<RangeProof>,
kernel_pmmr_h: PMMRHandle<TxKernel>,
// chain store used as index of commitments to MMR positions
commit_index: Arc<ChainStore>,
}
和下面的 Extension 差不多,只不过它更加具体一点,因为它所使用的 PMMRHandle 本身已经包含 PMMRBackend,所以这里不用指定。
PMMRBackend
xxx
croaring Bitmap
xxx
TxHashSetRoots
/// A helper to hold the roots of the txhashset in order to keep them
/// readable.
#[derive(Debug)]
pub struct TxHashSetRoots {
/// Header root
pub header_root: Hash,
/// Output root
pub output_root: Hash,
/// Range Proof root
pub rproof_root: Hash,
/// Kernel root
pub kernel_root: Hash,
}
Extension
扩展 TxHashSet,大大增强了其功能。
/// Allows the application of new blocks on top of the sum trees in a
/// reversible manner within a unit of work provided by the `extending`
/// function.
pub struct Extension<'a> {
output_pmmr: PMMR<'a, OutputIdentifier, PMMRBackend<OutputIdentifier>>,
rproof_pmmr: PMMR<'a, RangeProof, PMMRBackend<RangeProof>>,
kernel_pmmr: PMMR<'a, TxKernel, PMMRBackend<TxKernel>>,
commit_index: Arc<ChainStore>,
new_output_commits: HashMap<Commitment, u64>,
new_block_markers: HashMap<Hash, BlockMarker>,
rollback: bool,
}
BlockMarker
/// The output and kernel positions that define the size of the MMRs for a
/// particular block.
#[derive(Debug, Clone)]
pub struct BlockMarker {
/// The output (and rangeproof) MMR position of the final output in the
/// block
pub output_pos: u64,
/// The kernel position of the final kernel in the block
pub kernel_pos: u64,
}