mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-30 09:30:00 -07:00
global: MASSIVE snapshot
This commit is contained in:
32
crates/brk_computer/src/blocks/size/compute.rs
Normal file
32
crates/brk_computer/src/blocks/size/compute.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_block_size.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(&indexer.vecs.block.height_to_total_size),
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_vbytes.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(&self.height_to_vbytes),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
60
crates/brk_computer/src/blocks/size/import.rs
Normal file
60
crates/brk_computer/src/blocks/size/import.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Height, StoredU64, Version};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom1, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedVecsFromHeight, Source, VecBuilderOptions},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
let full_stats = || {
|
||||
VecBuilderOptions::default()
|
||||
.add_average()
|
||||
.add_minmax()
|
||||
.add_percentiles()
|
||||
.add_sum()
|
||||
.add_cumulative()
|
||||
};
|
||||
|
||||
let height_to_vbytes = LazyVecFrom1::init(
|
||||
"vbytes",
|
||||
version + v0,
|
||||
indexer.vecs.block.height_to_weight.boxed_clone(),
|
||||
|height: Height, weight_iter| {
|
||||
weight_iter
|
||||
.get_at(height.to_usize())
|
||||
.map(|w| StoredU64::from(w.to_vbytes_floor()))
|
||||
},
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"block_size",
|
||||
Source::Vec(indexer.vecs.block.height_to_total_size.boxed_clone()),
|
||||
version + v0,
|
||||
indexes,
|
||||
full_stats(),
|
||||
)?,
|
||||
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
|
||||
db,
|
||||
"block_vbytes",
|
||||
Source::Vec(height_to_vbytes.boxed_clone()),
|
||||
version + v0,
|
||||
indexes,
|
||||
full_stats(),
|
||||
)?,
|
||||
height_to_vbytes,
|
||||
})
|
||||
}
|
||||
}
|
||||
5
crates/brk_computer/src/blocks/size/mod.rs
Normal file
5
crates/brk_computer/src/blocks/size/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod compute;
|
||||
mod import;
|
||||
mod vecs;
|
||||
|
||||
pub use vecs::Vecs;
|
||||
12
crates/brk_computer/src/blocks/size/vecs.rs
Normal file
12
crates/brk_computer/src/blocks/size/vecs.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU64, Weight};
|
||||
use vecdb::LazyVecFrom1;
|
||||
|
||||
use crate::internal::ComputedVecsFromHeight;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub height_to_vbytes: LazyVecFrom1<Height, StoredU64, Height, Weight>,
|
||||
pub indexes_to_block_size: ComputedVecsFromHeight<StoredU64>,
|
||||
pub indexes_to_block_vbytes: ComputedVecsFromHeight<StoredU64>,
|
||||
}
|
||||
Reference in New Issue
Block a user