pub struct TxHashSet { /* private fields */ }Expand description
An easy to manipulate structure holding the 3 MMRs necessary to validate blocks and capturing the output set, associated rangeproofs and the kernels. Also handles the index of Commitments to positions in the output and rangeproof MMRs.
Note that the index is never authoritative, only the trees are guaranteed to indicate whether an output is spent or not. The index may have commitments that have already been spent, even with pruning enabled.
Implementations§
Source§impl TxHashSet
impl TxHashSet
Sourcepub fn open(
root_dir: String,
commit_index: Arc<ChainStore>,
header: Option<&BlockHeader>,
) -> Result<TxHashSet, Error>
pub fn open( root_dir: String, commit_index: Arc<ChainStore>, header: Option<&BlockHeader>, ) -> Result<TxHashSet, Error>
Open an existing or new set of backends for the TxHashSet
Sourcepub fn release_backend_files(&mut self)
pub fn release_backend_files(&mut self)
Close all backend file handles
Sourcepub fn get_unspent(
&self,
commit: Commitment,
) -> Result<Option<(OutputIdentifier, CommitPos)>, Error>
pub fn get_unspent( &self, commit: Commitment, ) -> Result<Option<(OutputIdentifier, CommitPos)>, Error>
Check if an output is unspent. We look in the index to find the output MMR pos. Then we check the entry in the output MMR and confirm the hash matches.
Sourcepub fn last_n_output(&self, distance: u64) -> Vec<(Hash, OutputIdentifier)>
pub fn last_n_output(&self, distance: u64) -> Vec<(Hash, OutputIdentifier)>
returns the last N nodes inserted into the tree (i.e. the ‘bottom’ nodes at level 0 TODO: These need to return the actual data from the flat-files instead of hashes now
Sourcepub fn last_n_rangeproof(&self, distance: u64) -> Vec<(Hash, RangeProof)>
pub fn last_n_rangeproof(&self, distance: u64) -> Vec<(Hash, RangeProof)>
as above, for range proofs
Sourcepub fn kernel_pmmr_at(
&self,
header: &BlockHeader,
) -> ReadonlyPMMR<'_, TxKernel, PMMRBackend<TxKernel>>
pub fn kernel_pmmr_at( &self, header: &BlockHeader, ) -> ReadonlyPMMR<'_, TxKernel, PMMRBackend<TxKernel>>
Efficient view into the kernel PMMR based on size in header.
Sourcepub fn output_pmmr_at(
&self,
header: &BlockHeader,
) -> ReadonlyPMMR<'_, OutputIdentifier, PMMRBackend<OutputIdentifier>>
pub fn output_pmmr_at( &self, header: &BlockHeader, ) -> ReadonlyPMMR<'_, OutputIdentifier, PMMRBackend<OutputIdentifier>>
Efficient view into the output PMMR based on size in header.
Sourcepub fn rangeproof_pmmr_at(
&self,
header: &BlockHeader,
) -> ReadonlyPMMR<'_, RangeProof, PMMRBackend<RangeProof>>
pub fn rangeproof_pmmr_at( &self, header: &BlockHeader, ) -> ReadonlyPMMR<'_, RangeProof, PMMRBackend<RangeProof>>
Efficient view into the rangeproof PMMR based on size in header.
Sourcepub fn get_block_header(&self, hash: &Hash) -> Result<BlockHeader, Error>
pub fn get_block_header(&self, hash: &Hash) -> Result<BlockHeader, Error>
Convenience function to query the db for a header by its hash.
Sourcepub fn outputs_by_pmmr_index(
&self,
start_index: u64,
max_count: u64,
max_index: Option<u64>,
) -> (u64, Vec<OutputIdentifier>)
pub fn outputs_by_pmmr_index( &self, start_index: u64, max_count: u64, max_index: Option<u64>, ) -> (u64, Vec<OutputIdentifier>)
returns outputs from the given pmmr index up to the specified limit. Also returns the last index actually populated max index is the last PMMR index to consider, not leaf index
Sourcepub fn rangeproofs_by_pmmr_index(
&self,
start_index: u64,
max_count: u64,
max_index: Option<u64>,
) -> (u64, Vec<RangeProof>)
pub fn rangeproofs_by_pmmr_index( &self, start_index: u64, max_count: u64, max_index: Option<u64>, ) -> (u64, Vec<RangeProof>)
As above, for rangeproofs
Sourcepub fn output_mmr_size(&self) -> u64
pub fn output_mmr_size(&self) -> u64
size of output mmr
Sourcepub fn kernel_mmr_size(&self) -> u64
pub fn kernel_mmr_size(&self) -> u64
size of kernel mmr
Sourcepub fn rangeproof_mmr_size(&self) -> u64
pub fn rangeproof_mmr_size(&self) -> u64
size of rangeproof mmr (can differ from output mmr size during PIBD sync)
Sourcepub fn find_kernel(
&self,
excess: &Commitment,
min_index: Option<u64>,
max_index: Option<u64>,
) -> Option<(TxKernel, u64)>
pub fn find_kernel( &self, excess: &Commitment, min_index: Option<u64>, max_index: Option<u64>, ) -> Option<(TxKernel, u64)>
Find a kernel with a given excess. Work backwards from max_index to min_index
NOTE: this linear search over all kernel history can be VERY expensive
public API access to this method should be limited
Sourcepub fn roots(&self) -> Result<TxHashSetRoots, Error>
pub fn roots(&self) -> Result<TxHashSetRoots, Error>
Get MMR roots.
Sourcepub fn get_output_pos(&self, commit: &Commitment) -> Result<u64, Error>
pub fn get_output_pos(&self, commit: &Commitment) -> Result<u64, Error>
Return Commit’s MMR position
Sourcepub fn merkle_proof(&mut self, commit: Commitment) -> Result<MerkleProof, Error>
pub fn merkle_proof(&mut self, commit: Commitment) -> Result<MerkleProof, Error>
build a new merkle proof for the given output commitment
Sourcepub fn compact(
&mut self,
horizon_header: &BlockHeader,
batch: &Batch<'_>,
) -> Result<(), Error>
pub fn compact( &mut self, horizon_header: &BlockHeader, batch: &Batch<'_>, ) -> Result<(), Error>
Compact the MMR data files and flush the rm logs
Sourcepub fn init_recent_kernel_pos_index(
&self,
header_pmmr: &PMMRHandle<BlockHeader>,
batch: &Batch<'_>,
) -> Result<(), Error>
pub fn init_recent_kernel_pos_index( &self, header_pmmr: &PMMRHandle<BlockHeader>, batch: &Batch<'_>, ) -> Result<(), Error>
(Re)build the NRD kernel_pos index based on 2 weeks of recent kernel history.
Sourcepub fn verify_kernel_pos_index(
&self,
from_header: &BlockHeader,
header_pmmr: &PMMRHandle<BlockHeader>,
batch: &Batch<'_>,
status: Option<Arc<SyncState>>,
stop_state: Option<Arc<StopState>>,
) -> Result<(), Error>
pub fn verify_kernel_pos_index( &self, from_header: &BlockHeader, header_pmmr: &PMMRHandle<BlockHeader>, batch: &Batch<'_>, status: Option<Arc<SyncState>>, stop_state: Option<Arc<StopState>>, ) -> Result<(), Error>
Verify and (re)build the NRD kernel_pos index from the provided header onwards.
Sourcepub fn init_output_pos_index(
&self,
header_pmmr: &PMMRHandle<BlockHeader>,
batch: &Batch<'_>,
) -> Result<(), Error>
pub fn init_output_pos_index( &self, header_pmmr: &PMMRHandle<BlockHeader>, batch: &Batch<'_>, ) -> Result<(), Error>
(Re)build the output_pos index to be consistent with the current UTXO set. Remove any “stale” index entries that do not correspond to outputs in the UTXO set. Add any missing index entries based on UTXO set.