mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-30 01:20:00 -07:00
computer: indexes + rolling
This commit is contained in:
@@ -1,21 +1,43 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::ComputeIndexes;
|
||||
use crate::{blocks, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
count_vecs: &blocks::CountVecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.size
|
||||
.compute_cumulative(starting_indexes, &indexer.vecs.blocks.total_size, exit)?;
|
||||
let window_starts = count_vecs.window_starts();
|
||||
|
||||
self.vbytes.compute_cumulative(starting_indexes, exit)?;
|
||||
// vbytes = ceil(weight / 4), stored at height level
|
||||
self.vbytes.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
exit,
|
||||
|height| {
|
||||
Ok(height.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.blocks.weight,
|
||||
|(h, weight, ..)| (h, StoredU64::from(weight.to_vbytes_floor())),
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
)?;
|
||||
|
||||
// size from indexer total_size
|
||||
self.size.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&indexer.vecs.blocks.total_size,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ use brk_types::Version;
|
||||
use vecdb::{Database, ReadableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull, WeightToVbytes}};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightCumFull, ComputedHeightDerivedCumFull},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -14,14 +17,13 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
vbytes: LazyComputedFromHeightFull::forced_import::<WeightToVbytes>(
|
||||
vbytes: ComputedFromHeightCumFull::forced_import(
|
||||
db,
|
||||
"block_vbytes",
|
||||
version,
|
||||
&indexer.vecs.blocks.weight,
|
||||
indexes,
|
||||
)?,
|
||||
size: ComputedHeightDerivedFull::forced_import(
|
||||
size: ComputedHeightDerivedCumFull::forced_import(
|
||||
db,
|
||||
"block_size",
|
||||
indexer.vecs.blocks.total_size.read_only_boxed_clone(),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredU64, Weight};
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull};
|
||||
use crate::internal::{ComputedFromHeightCumFull, ComputedHeightDerivedCumFull};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub vbytes: LazyComputedFromHeightFull<StoredU64, Weight, M>,
|
||||
pub size: ComputedHeightDerivedFull<StoredU64, M>,
|
||||
pub vbytes: ComputedFromHeightCumFull<StoredU64, M>,
|
||||
pub size: ComputedHeightDerivedCumFull<StoredU64, M>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user