feat(hardano): add fuzzy block search by slot in Immutable db (#484)
Co-authored-by: Mr-Leshiy <leshiy12345678@gmail.com>
This commit is contained in:
parent
60e07e2f00
commit
9528bedfda
1 changed files with 20 additions and 1 deletions
|
|
@ -75,6 +75,13 @@ fn chunk_binary_search<ChunkT, PointT>(
|
||||||
/// Iterates through the blocks until the given slot and block hash are reached.
|
/// Iterates through the blocks until the given slot and block hash are reached.
|
||||||
/// Returns an iterator over the blocks if the specific block is found,
|
/// Returns an iterator over the blocks if the specific block is found,
|
||||||
/// otherwise returns an error.
|
/// otherwise returns an error.
|
||||||
|
///
|
||||||
|
/// IFF the `block_hash` is zero length, then the search is "fuzzy",
|
||||||
|
/// meaning that it will return the first block whose slot is greater than or
|
||||||
|
/// equal to `slot`.
|
||||||
|
///
|
||||||
|
/// Fuzzy Search allows a block to be found by an "expected slot#" without
|
||||||
|
/// knowing precisely which block is being retrieved.
|
||||||
fn iterate_till_point(
|
fn iterate_till_point(
|
||||||
iter: impl Iterator<Item = FallibleBlock>,
|
iter: impl Iterator<Item = FallibleBlock>,
|
||||||
slot: u64,
|
slot: u64,
|
||||||
|
|
@ -99,7 +106,9 @@ fn iterate_till_point(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if block.hash().as_ref().eq(block_hash) && block.slot() == slot {
|
if (block_hash.is_empty() && block.slot() >= slot)
|
||||||
|
|| (block.hash().as_ref().eq(block_hash) && block.slot() == slot)
|
||||||
|
{
|
||||||
Ok(iter)
|
Ok(iter)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::CannotFindBlock(Point::Specific(
|
Err(Error::CannotFindBlock(Point::Specific(
|
||||||
|
|
@ -169,6 +178,16 @@ pub fn read_blocks(dir: &Path) -> Result<impl Iterator<Item = FallibleBlock>, Er
|
||||||
/// Returns an iterator over the chain from the given point if the specific
|
/// Returns an iterator over the chain from the given point if the specific
|
||||||
/// block is found, otherwise returns an error.
|
/// block is found, otherwise returns an error.
|
||||||
///
|
///
|
||||||
|
/// # Note:
|
||||||
|
///
|
||||||
|
/// If the given `point` is not the Origin, AND the BlockHash of the point is
|
||||||
|
/// zero length. then the search for the first block is "Fuzzy".
|
||||||
|
/// Only the Slot# of the point will be used and the first block to be returned
|
||||||
|
/// will be the block whose slot is >= the given slot# in the point.
|
||||||
|
///
|
||||||
|
/// This allows iteration to commence from a calculated slot# where the precise
|
||||||
|
/// block is unknown, and then continue iterating blocks after that point.
|
||||||
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// * `Error::OriginMissing` - If the first block in the chain is not the
|
/// * `Error::OriginMissing` - If the first block in the chain is not the
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue