mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Factoring in mmr leaf count function
This commit is contained in:
parent
4022b82817
commit
866ec977da
2 changed files with 10 additions and 6 deletions
|
@ -468,9 +468,8 @@ impl<'a> Extension<'a> {
|
||||||
|
|
||||||
// rewind the kernel file store, the position is the number of kernels
|
// rewind the kernel file store, the position is the number of kernels
|
||||||
// multiplied by their size
|
// multiplied by their size
|
||||||
// the number of kernels is the number of leaves in the MMR, which is the
|
// the number of kernels is the number of leaves in the MMR
|
||||||
// sum of the number of leaf nodes under each peak in the MMR
|
let pos = pmmr::n_leaves(kern_pos_rew);
|
||||||
let pos: u64 = pmmr::peaks(kern_pos_rew).iter().map(|n| (1 << n) as u64).sum();
|
|
||||||
self.kernel_file.rewind(pos * (TxKernel::size() as u64));
|
self.kernel_file.rewind(pos * (TxKernel::size() as u64));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -618,9 +617,7 @@ impl<'a> Extension<'a> {
|
||||||
// make sure we have the right count of kernels using the MMR, the storage
|
// make sure we have the right count of kernels using the MMR, the storage
|
||||||
// file may have a few more
|
// file may have a few more
|
||||||
let mmr_sz = self.kernel_pmmr.unpruned_size();
|
let mmr_sz = self.kernel_pmmr.unpruned_size();
|
||||||
let count: u64 = pmmr::peaks(mmr_sz).iter().map(|n| {
|
let count = pmmr::n_leaves(mmr_sz);
|
||||||
(1 << pmmr::bintree_postorder_height(*n)) as u64
|
|
||||||
}).sum();
|
|
||||||
|
|
||||||
let mut kernel_file = File::open(self.kernel_file.path())?;
|
let mut kernel_file = File::open(self.kernel_file.path())?;
|
||||||
let first: TxKernel = ser::deserialize(&mut kernel_file)?;
|
let first: TxKernel = ser::deserialize(&mut kernel_file)?;
|
||||||
|
|
|
@ -661,6 +661,13 @@ pub fn peaks(num: u64) -> Vec<u64> {
|
||||||
peaks
|
peaks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The number of leaves nodes in a MMR of the provided size.
|
||||||
|
pub fn n_leaves(sz: u64) -> u64 {
|
||||||
|
peaks(sz).iter().map(|n| {
|
||||||
|
(1 << bintree_postorder_height(*n)) as u64
|
||||||
|
}).sum()
|
||||||
|
}
|
||||||
|
|
||||||
/// The height of a node in a full binary tree from its postorder traversal
|
/// The height of a node in a full binary tree from its postorder traversal
|
||||||
/// index. This function is the base on which all others, as well as the MMR,
|
/// index. This function is the base on which all others, as well as the MMR,
|
||||||
/// are built.
|
/// are built.
|
||||||
|
|
Loading…
Reference in a new issue