computer: snapshot

This commit is contained in:
nym21
2026-02-26 23:01:51 +01:00
parent cccaf6b206
commit 78fc5ffcf7
69 changed files with 1578 additions and 2205 deletions

View File

@@ -15,30 +15,31 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
let mut prev_timestamp = None;
self.interval.height.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.timestamp,
|(h, timestamp, ..)| {
let interval = if let Some(prev_h) = h.decremented() {
let prev = prev_timestamp.unwrap_or_else(|| {
indexer.vecs.blocks.timestamp.collect_one(prev_h).unwrap()
});
timestamp.checked_sub(prev).unwrap_or(Timestamp::ZERO)
} else {
Timestamp::ZERO
};
prev_timestamp = Some(timestamp);
(h, interval)
},
exit,
)?;
let window_starts = count_vecs.window_starts();
self.interval_rolling.compute_distribution(
self.0.compute(
starting_indexes.height,
&window_starts,
&self.interval.height,
exit,
|vec| {
vec.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.timestamp,
|(h, timestamp, ..)| {
let interval = if let Some(prev_h) = h.decremented() {
let prev = prev_timestamp.unwrap_or_else(|| {
indexer.vecs.blocks.timestamp.collect_one(prev_h).unwrap()
});
timestamp.checked_sub(prev).unwrap_or(Timestamp::ZERO)
} else {
Timestamp::ZERO
};
prev_timestamp = Some(timestamp);
(h, interval)
},
exit,
)?;
Ok(())
},
)?;
Ok(())

View File

@@ -3,10 +3,7 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedFromHeightLast, RollingDistribution},
};
use crate::{indexes, internal::ComputedFromHeightDistribution};
impl Vecs {
pub(crate) fn forced_import(
@@ -15,14 +12,8 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
let interval =
ComputedFromHeightLast::forced_import(db, "block_interval", version, indexes)?;
ComputedFromHeightDistribution::forced_import(db, "block_interval", version, indexes)?;
let interval_rolling =
RollingDistribution::forced_import(db, "block_interval", version, indexes)?;
Ok(Self {
interval,
interval_rolling,
})
Ok(Self(interval))
}
}

View File

@@ -1,12 +1,13 @@
use derive_more::{Deref, DerefMut};
use brk_traversable::Traversable;
use brk_types::Timestamp;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedFromHeightLast, RollingDistribution};
use crate::internal::ComputedFromHeightDistribution;
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
#[derive(Deref, DerefMut, Traversable)]
pub struct Vecs<M: StorageMode = Rw>(
#[traversable(flatten)]
pub interval: ComputedFromHeightLast<Timestamp, M>,
pub interval_rolling: RollingDistribution<Timestamp, M>,
}
pub ComputedFromHeightDistribution<Timestamp, M>,
);

View File

@@ -23,18 +23,19 @@ impl Vecs {
exit,
)?;
self.fullness.height.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.weight,
|(h, weight, ..)| (h, StoredF32::from(weight.fullness())),
exit,
)?;
self.fullness_rolling.compute_distribution(
self.fullness.compute(
starting_indexes.height,
&window_starts,
&self.fullness.height,
exit,
|vec| {
vec.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.weight,
|(h, weight, ..)| (h, StoredF32::from(weight.fullness())),
exit,
)?;
Ok(())
},
)?;
Ok(())

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedFromHeightLast, ComputedHeightDerivedCumulativeFull, RollingDistribution},
internal::{ComputedFromHeightDistribution, ComputedHeightDerivedCumulativeFull},
};
impl Vecs {
@@ -22,15 +22,8 @@ impl Vecs {
)?;
let fullness =
ComputedFromHeightLast::forced_import(db, "block_fullness", version, indexes)?;
ComputedFromHeightDistribution::forced_import(db, "block_fullness", version, indexes)?;
let fullness_rolling =
RollingDistribution::forced_import(db, "block_fullness", version, indexes)?;
Ok(Self {
weight,
fullness,
fullness_rolling,
})
Ok(Self { weight, fullness })
}
}

View File

@@ -2,13 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{StoredF32, Weight};
use vecdb::{Rw, StorageMode};
use crate::internal::{
ComputedFromHeightLast, ComputedHeightDerivedCumulativeFull, RollingDistribution,
};
use crate::internal::{ComputedFromHeightDistribution, ComputedHeightDerivedCumulativeFull};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub weight: ComputedHeightDerivedCumulativeFull<Weight, M>,
pub fullness: ComputedFromHeightLast<StoredF32, M>,
pub fullness_rolling: RollingDistribution<StoredF32, M>,
pub fullness: ComputedFromHeightDistribution<StoredF32, M>,
}