global: MASSIVE snapshot

This commit is contained in:
nym21
2026-01-07 01:16:37 +01:00
parent e832ffbe23
commit cb0abc324e
487 changed files with 21155 additions and 13627 deletions

View File

@@ -47,38 +47,35 @@ impl Vecs {
Ok(())
})?;
self.indexes_to_1w_block_count
.compute_all(starting_indexes, exit, |v| {
v.compute_sum(
starting_indexes.dateindex,
self.indexes_to_block_count.dateindex.unwrap_sum(),
7,
exit,
)?;
Ok(())
})?;
self.indexes_to_1w_block_count.compute_all(starting_indexes, exit, |v| {
v.compute_sum(
starting_indexes.dateindex,
self.indexes_to_block_count.dateindex.sum.inner(),
7,
exit,
)?;
Ok(())
})?;
self.indexes_to_1m_block_count
.compute_all(starting_indexes, exit, |v| {
v.compute_sum(
starting_indexes.dateindex,
self.indexes_to_block_count.dateindex.unwrap_sum(),
30,
exit,
)?;
Ok(())
})?;
self.indexes_to_1m_block_count.compute_all(starting_indexes, exit, |v| {
v.compute_sum(
starting_indexes.dateindex,
self.indexes_to_block_count.dateindex.sum.inner(),
30,
exit,
)?;
Ok(())
})?;
self.indexes_to_1y_block_count
.compute_all(starting_indexes, exit, |v| {
v.compute_sum(
starting_indexes.dateindex,
self.indexes_to_block_count.dateindex.unwrap_sum(),
365,
exit,
)?;
Ok(())
})?;
self.indexes_to_1y_block_count.compute_all(starting_indexes, exit, |v| {
v.compute_sum(
starting_indexes.dateindex,
self.indexes_to_block_count.dateindex.sum.inner(),
365,
exit,
)?;
Ok(())
})?;
Ok(())
}

View File

@@ -10,14 +10,11 @@ use crate::{
TARGET_BLOCKS_PER_YEAR,
},
indexes,
internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions},
internal::{ComputedBlockSumCum, ComputedDateLast},
};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
let last = || VecBuilderOptions::default().add_last();
let sum_cum = || VecBuilderOptions::default().add_sum().add_cumulative();
Ok(Self {
dateindex_to_block_count_target: LazyVecFrom1::init(
"block_count_target",
@@ -62,37 +59,29 @@ impl Vecs {
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DECADE)),
),
height_to_24h_block_count: EagerVec::forced_import(db, "24h_block_count", version)?,
indexes_to_block_count: ComputedVecsFromHeight::forced_import(
indexes_to_block_count: ComputedBlockSumCum::forced_import(
db,
"block_count",
Source::Compute,
version,
indexes,
sum_cum(),
)?,
indexes_to_1w_block_count: ComputedVecsFromDateIndex::forced_import(
indexes_to_1w_block_count: ComputedDateLast::forced_import(
db,
"1w_block_count",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_1m_block_count: ComputedVecsFromDateIndex::forced_import(
indexes_to_1m_block_count: ComputedDateLast::forced_import(
db,
"1m_block_count",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_1y_block_count: ComputedVecsFromDateIndex::forced_import(
indexes_to_1y_block_count: ComputedDateLast::forced_import(
db,
"1y_block_count",
Source::Compute,
version,
indexes,
last(),
)?,
})
}

View File

@@ -1,24 +1,28 @@
use brk_traversable::Traversable;
use brk_types::{
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex,
StoredU32, StoredU64, WeekIndex, YearIndex,
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, StoredU32, StoredU64,
WeekIndex, YearIndex,
};
use vecdb::LazyVecFrom1;
use crate::internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
use crate::internal::{ComputedBlockSumCum, ComputedDateLast};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub dateindex_to_block_count_target: LazyVecFrom1<DateIndex, StoredU64, DateIndex, DateIndex>,
pub weekindex_to_block_count_target: LazyVecFrom1<WeekIndex, StoredU64, WeekIndex, WeekIndex>,
pub monthindex_to_block_count_target: LazyVecFrom1<MonthIndex, StoredU64, MonthIndex, MonthIndex>,
pub quarterindex_to_block_count_target: LazyVecFrom1<QuarterIndex, StoredU64, QuarterIndex, QuarterIndex>,
pub semesterindex_to_block_count_target: LazyVecFrom1<SemesterIndex, StoredU64, SemesterIndex, SemesterIndex>,
pub monthindex_to_block_count_target:
LazyVecFrom1<MonthIndex, StoredU64, MonthIndex, MonthIndex>,
pub quarterindex_to_block_count_target:
LazyVecFrom1<QuarterIndex, StoredU64, QuarterIndex, QuarterIndex>,
pub semesterindex_to_block_count_target:
LazyVecFrom1<SemesterIndex, StoredU64, SemesterIndex, SemesterIndex>,
pub yearindex_to_block_count_target: LazyVecFrom1<YearIndex, StoredU64, YearIndex, YearIndex>,
pub decadeindex_to_block_count_target: LazyVecFrom1<DecadeIndex, StoredU64, DecadeIndex, DecadeIndex>,
pub decadeindex_to_block_count_target:
LazyVecFrom1<DecadeIndex, StoredU64, DecadeIndex, DecadeIndex>,
pub height_to_24h_block_count: vecdb::EagerVec<vecdb::PcoVec<brk_types::Height, StoredU32>>,
pub indexes_to_block_count: ComputedVecsFromHeight<StoredU32>,
pub indexes_to_1w_block_count: ComputedVecsFromDateIndex<StoredU32>,
pub indexes_to_1m_block_count: ComputedVecsFromDateIndex<StoredU32>,
pub indexes_to_1y_block_count: ComputedVecsFromDateIndex<StoredU32>,
pub indexes_to_block_count: ComputedBlockSumCum<StoredU32>,
pub indexes_to_1w_block_count: ComputedDateLast<StoredU32>,
pub indexes_to_1m_block_count: ComputedDateLast<StoredU32>,
pub indexes_to_1y_block_count: ComputedDateLast<StoredU32>,
}

View File

@@ -15,8 +15,7 @@ impl Vecs {
) -> Result<()> {
let mut height_to_difficultyepoch_iter =
indexes.block.height_to_difficultyepoch.into_iter();
self.indexes_to_difficultyepoch
.compute_all(starting_indexes, exit, |vec| {
self.indexes_to_difficultyepoch.compute_all(starting_indexes, exit, |vec| {
let mut height_count_iter = indexes.time.dateindex_to_height_count.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
@@ -48,10 +47,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(
starting_indexes.height,
self.indexes_to_blocks_before_next_difficulty_adjustment
.height
.as_ref()
.unwrap(),
&self.indexes_to_blocks_before_next_difficulty_adjustment.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;

View File

@@ -5,41 +5,32 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions},
internal::{ComputedBlockLast, ComputedDateLast},
};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
let v2 = Version::TWO;
let last = || VecBuilderOptions::default().add_last();
Ok(Self {
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
indexes_to_difficultyepoch: ComputedDateLast::forced_import(
db,
"difficultyepoch",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_blocks_before_next_difficulty_adjustment:
ComputedVecsFromHeight::forced_import(
db,
"blocks_before_next_difficulty_adjustment",
Source::Compute,
version + v2,
indexes,
last(),
)?,
indexes_to_days_before_next_difficulty_adjustment:
ComputedVecsFromHeight::forced_import(
db,
"days_before_next_difficulty_adjustment",
Source::Compute,
version + v2,
indexes,
last(),
)?,
indexes_to_blocks_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
db,
"blocks_before_next_difficulty_adjustment",
version + v2,
indexes,
)?,
indexes_to_days_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
db,
"days_before_next_difficulty_adjustment",
version + v2,
indexes,
)?,
})
}
}

View File

@@ -1,12 +1,12 @@
use brk_traversable::Traversable;
use brk_types::{DifficultyEpoch, StoredF32, StoredU32};
use crate::internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
use crate::internal::{ComputedBlockLast, ComputedDateLast};
/// Difficulty epoch metrics and countdown
#[derive(Clone, Traversable)]
pub struct Vecs {
pub indexes_to_difficultyepoch: ComputedVecsFromDateIndex<DifficultyEpoch>,
pub indexes_to_blocks_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredU32>,
pub indexes_to_days_before_next_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_difficultyepoch: ComputedDateLast<DifficultyEpoch>,
pub indexes_to_blocks_before_next_difficulty_adjustment: ComputedBlockLast<StoredU32>,
pub indexes_to_days_before_next_difficulty_adjustment: ComputedBlockLast<StoredF32>,
}

View File

@@ -14,8 +14,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
let mut height_to_halvingepoch_iter = indexes.block.height_to_halvingepoch.into_iter();
self.indexes_to_halvingepoch
.compute_all(starting_indexes, exit, |vec| {
self.indexes_to_halvingepoch.compute_all(starting_indexes, exit, |vec| {
let mut height_count_iter = indexes.time.dateindex_to_height_count.into_iter();
vec.compute_transform(
starting_indexes.dateindex,
@@ -54,10 +53,7 @@ impl Vecs {
|v| {
v.compute_transform(
starting_indexes.height,
self.indexes_to_blocks_before_next_halving
.height
.as_ref()
.unwrap(),
&self.indexes_to_blocks_before_next_halving.height,
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
exit,
)?;

View File

@@ -5,38 +5,31 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions},
internal::{ComputedBlockLast, ComputedDateLast},
};
impl Vecs {
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
let v2 = Version::TWO;
let last = || VecBuilderOptions::default().add_last();
Ok(Self {
indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import(
indexes_to_halvingepoch: ComputedDateLast::forced_import(
db,
"halvingepoch",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_blocks_before_next_halving: ComputedVecsFromHeight::forced_import(
indexes_to_blocks_before_next_halving: ComputedBlockLast::forced_import(
db,
"blocks_before_next_halving",
Source::Compute,
version + v2,
indexes,
last(),
)?,
indexes_to_days_before_next_halving: ComputedVecsFromHeight::forced_import(
indexes_to_days_before_next_halving: ComputedBlockLast::forced_import(
db,
"days_before_next_halving",
Source::Compute,
version + v2,
indexes,
last(),
)?,
})
}

View File

@@ -1,12 +1,12 @@
use brk_traversable::Traversable;
use brk_types::{HalvingEpoch, StoredF32, StoredU32};
use crate::internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
use crate::internal::{ComputedBlockLast, ComputedDateLast};
/// Halving epoch metrics and countdown
#[derive(Clone, Traversable)]
pub struct Vecs {
pub indexes_to_halvingepoch: ComputedVecsFromDateIndex<HalvingEpoch>,
pub indexes_to_blocks_before_next_halving: ComputedVecsFromHeight<StoredU32>,
pub indexes_to_days_before_next_halving: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_halvingepoch: ComputedDateLast<HalvingEpoch>,
pub indexes_to_blocks_before_next_halving: ComputedBlockLast<StoredU32>,
pub indexes_to_days_before_next_halving: ComputedBlockLast<StoredF32>,
}

View File

@@ -2,7 +2,7 @@ use brk_error::Result;
use vecdb::Exit;
use super::Vecs;
use crate::{ComputeIndexes, indexes};
use crate::{indexes, ComputeIndexes};
impl Vecs {
pub fn compute(
@@ -11,11 +11,11 @@ impl Vecs {
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.indexes_to_block_interval.compute_rest(
self.indexes_to_block_interval.derive_from(
indexes,
starting_indexes,
&self.height_to_interval,
exit,
Some(&self.height_to_interval),
)?;
Ok(())

View File

@@ -4,10 +4,7 @@ use brk_types::{CheckedSub, Height, Timestamp, Version};
use vecdb::{Database, IterableCloneableVec, LazyVecFrom1};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedVecsFromHeight, Source, VecBuilderOptions},
};
use crate::{indexes, internal::DerivedComputedBlockDistribution};
impl Vecs {
pub fn forced_import(
@@ -16,13 +13,6 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let stats = || {
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
};
let height_to_interval = LazyVecFrom1::init(
"interval",
version,
@@ -40,16 +30,17 @@ impl Vecs {
},
);
let indexes_to_block_interval = DerivedComputedBlockDistribution::forced_import(
db,
"block_interval",
height_to_interval.boxed_clone(),
version,
indexes,
)?;
Ok(Self {
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
db,
"block_interval",
Source::Vec(height_to_interval.boxed_clone()),
version,
indexes,
stats(),
)?,
height_to_interval,
indexes_to_block_interval,
})
}
}

View File

@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
use brk_types::{Height, Timestamp};
use vecdb::LazyVecFrom1;
use crate::internal::ComputedVecsFromHeight;
use crate::internal::DerivedComputedBlockDistribution;
#[derive(Clone, Traversable)]
pub struct Vecs {
pub height_to_interval: LazyVecFrom1<Height, Timestamp, Height, Timestamp>,
pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>,
pub indexes_to_block_interval: DerivedComputedBlockDistribution<Timestamp>,
}

View File

@@ -5,11 +5,7 @@ use vecdb::Exit;
use super::Vecs;
use super::super::{count, rewards, ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64};
use crate::{
indexes,
utils::OptionExt,
ComputeIndexes,
};
use crate::{indexes, ComputeIndexes};
impl Vecs {
pub fn compute(
@@ -21,11 +17,11 @@ impl Vecs {
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.indexes_to_difficulty.compute_rest(
self.indexes_to_difficulty.derive_from(
indexes,
starting_indexes,
&indexer.vecs.block.height_to_difficulty,
exit,
Some(&indexer.vecs.block.height_to_difficulty),
)?;
self.indexes_to_difficulty_as_hash
@@ -45,7 +41,7 @@ impl Vecs {
v.compute_transform2(
starting_indexes.height,
&count_vecs.height_to_24h_block_count,
self.indexes_to_difficulty_as_hash.height.u(),
&self.indexes_to_difficulty_as_hash.height,
|(i, block_count_sum, difficulty_as_hash, ..)| {
(
i,
@@ -60,44 +56,40 @@ impl Vecs {
Ok(())
})?;
self.indexes_to_hash_rate_1w_sma
.compute_all(starting_indexes, exit, |v| {
self.indexes_to_hash_rate_1w_sma.compute_all(starting_indexes, exit, |v| {
v.compute_sma(
starting_indexes.dateindex,
self.indexes_to_hash_rate.dateindex.unwrap_last(),
self.indexes_to_hash_rate.dateindex.inner(),
7,
exit,
)?;
Ok(())
})?;
self.indexes_to_hash_rate_1m_sma
.compute_all(starting_indexes, exit, |v| {
self.indexes_to_hash_rate_1m_sma.compute_all(starting_indexes, exit, |v| {
v.compute_sma(
starting_indexes.dateindex,
self.indexes_to_hash_rate.dateindex.unwrap_last(),
self.indexes_to_hash_rate.dateindex.inner(),
30,
exit,
)?;
Ok(())
})?;
self.indexes_to_hash_rate_2m_sma
.compute_all(starting_indexes, exit, |v| {
self.indexes_to_hash_rate_2m_sma.compute_all(starting_indexes, exit, |v| {
v.compute_sma(
starting_indexes.dateindex,
self.indexes_to_hash_rate.dateindex.unwrap_last(),
self.indexes_to_hash_rate.dateindex.inner(),
2 * 30,
exit,
)?;
Ok(())
})?;
self.indexes_to_hash_rate_1y_sma
.compute_all(starting_indexes, exit, |v| {
self.indexes_to_hash_rate_1y_sma.compute_all(starting_indexes, exit, |v| {
v.compute_sma(
starting_indexes.dateindex,
self.indexes_to_hash_rate.dateindex.unwrap_last(),
self.indexes_to_hash_rate.dateindex.inner(),
365,
exit,
)?;
@@ -124,7 +116,7 @@ impl Vecs {
v.compute_transform2(
starting_indexes.height,
&rewards_vecs.height_to_24h_coinbase_usd_sum,
self.indexes_to_hash_rate.height.u(),
&self.indexes_to_hash_rate.height,
|(i, coinbase_sum, hashrate, ..)| {
let hashrate_ths = *hashrate / ONE_TERA_HASH;
let price = if hashrate_ths == 0.0 {
@@ -143,7 +135,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(
starting_indexes.height,
self.indexes_to_hash_price_ths.height.u(),
&self.indexes_to_hash_price_ths.height,
|(i, price, ..)| (i, (*price * 1000.0).into()),
exit,
)?;
@@ -155,7 +147,7 @@ impl Vecs {
v.compute_transform2(
starting_indexes.height,
&rewards_vecs.height_to_24h_coinbase_sum,
self.indexes_to_hash_rate.height.u(),
&self.indexes_to_hash_rate.height,
|(i, coinbase_sum, hashrate, ..)| {
let hashrate_ths = *hashrate / ONE_TERA_HASH;
let value = if hashrate_ths == 0.0 {
@@ -174,7 +166,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_transform(
starting_indexes.height,
self.indexes_to_hash_value_ths.height.u(),
&self.indexes_to_hash_value_ths.height,
|(i, value, ..)| (i, (*value * 1000.0).into()),
exit,
)?;
@@ -185,7 +177,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_all_time_low_(
starting_indexes.height,
self.indexes_to_hash_price_ths.height.u(),
&self.indexes_to_hash_price_ths.height,
exit,
true,
)?;
@@ -196,7 +188,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_all_time_low_(
starting_indexes.height,
self.indexes_to_hash_price_phs.height.u(),
&self.indexes_to_hash_price_phs.height,
exit,
true,
)?;
@@ -207,7 +199,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_all_time_low_(
starting_indexes.height,
self.indexes_to_hash_value_ths.height.u(),
&self.indexes_to_hash_value_ths.height,
exit,
true,
)?;
@@ -218,7 +210,7 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_all_time_low_(
starting_indexes.height,
self.indexes_to_hash_value_phs.height.u(),
&self.indexes_to_hash_value_phs.height,
exit,
true,
)?;
@@ -229,8 +221,8 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_percentage_difference(
starting_indexes.height,
self.indexes_to_hash_price_phs.height.u(),
self.indexes_to_hash_price_phs_min.height.u(),
&self.indexes_to_hash_price_phs.height,
&self.indexes_to_hash_price_phs_min.height,
exit,
)?;
Ok(())
@@ -240,8 +232,8 @@ impl Vecs {
.compute_all(indexes, starting_indexes, exit, |v| {
v.compute_percentage_difference(
starting_indexes.height,
self.indexes_to_hash_value_phs.height.u(),
self.indexes_to_hash_value_phs_min.height.u(),
&self.indexes_to_hash_value_phs.height,
&self.indexes_to_hash_value_phs_min.height,
exit,
)?;
Ok(())

View File

@@ -6,7 +6,7 @@ use vecdb::{Database, IterableCloneableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions},
internal::{ComputedBlockLast, ComputedBlockSum, ComputedDateLast, DerivedComputedBlockLast},
};
impl Vecs {
@@ -19,153 +19,116 @@ impl Vecs {
let v4 = Version::new(4);
let v5 = Version::new(5);
let last = || VecBuilderOptions::default().add_last();
let sum = || VecBuilderOptions::default().add_sum();
Ok(Self {
indexes_to_hash_rate: ComputedVecsFromHeight::forced_import(
indexes_to_hash_rate: ComputedBlockLast::forced_import(
db,
"hash_rate",
Source::Compute,
version + v5,
indexes,
last(),
)?,
indexes_to_hash_rate_1w_sma: ComputedVecsFromDateIndex::forced_import(
indexes_to_hash_rate_1w_sma: ComputedDateLast::forced_import(
db,
"hash_rate_1w_sma",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_hash_rate_1m_sma: ComputedVecsFromDateIndex::forced_import(
indexes_to_hash_rate_1m_sma: ComputedDateLast::forced_import(
db,
"hash_rate_1m_sma",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_hash_rate_2m_sma: ComputedVecsFromDateIndex::forced_import(
indexes_to_hash_rate_2m_sma: ComputedDateLast::forced_import(
db,
"hash_rate_2m_sma",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_hash_rate_1y_sma: ComputedVecsFromDateIndex::forced_import(
indexes_to_hash_rate_1y_sma: ComputedDateLast::forced_import(
db,
"hash_rate_1y_sma",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_hash_price_ths: ComputedVecsFromHeight::forced_import(
indexes_to_hash_price_ths: ComputedBlockLast::forced_import(
db,
"hash_price_ths",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_price_ths_min: ComputedVecsFromHeight::forced_import(
indexes_to_hash_price_ths_min: ComputedBlockLast::forced_import(
db,
"hash_price_ths_min",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_price_phs: ComputedVecsFromHeight::forced_import(
indexes_to_hash_price_phs: ComputedBlockLast::forced_import(
db,
"hash_price_phs",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_price_phs_min: ComputedVecsFromHeight::forced_import(
indexes_to_hash_price_phs_min: ComputedBlockLast::forced_import(
db,
"hash_price_phs_min",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_price_rebound: ComputedVecsFromHeight::forced_import(
indexes_to_hash_price_rebound: ComputedBlockLast::forced_import(
db,
"hash_price_rebound",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_value_ths: ComputedVecsFromHeight::forced_import(
indexes_to_hash_value_ths: ComputedBlockLast::forced_import(
db,
"hash_value_ths",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_value_ths_min: ComputedVecsFromHeight::forced_import(
indexes_to_hash_value_ths_min: ComputedBlockLast::forced_import(
db,
"hash_value_ths_min",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_value_phs: ComputedVecsFromHeight::forced_import(
indexes_to_hash_value_phs: ComputedBlockLast::forced_import(
db,
"hash_value_phs",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_value_phs_min: ComputedVecsFromHeight::forced_import(
indexes_to_hash_value_phs_min: ComputedBlockLast::forced_import(
db,
"hash_value_phs_min",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_hash_value_rebound: ComputedVecsFromHeight::forced_import(
indexes_to_hash_value_rebound: ComputedBlockLast::forced_import(
db,
"hash_value_rebound",
Source::Compute,
version + v4,
indexes,
last(),
)?,
indexes_to_difficulty: ComputedVecsFromHeight::forced_import(
// Derived from external indexer data - no height storage needed
indexes_to_difficulty: DerivedComputedBlockLast::forced_import(
db,
"difficulty",
Source::Vec(indexer.vecs.block.height_to_difficulty.boxed_clone()),
indexer.vecs.block.height_to_difficulty.boxed_clone(),
version,
indexes,
last(),
)?,
indexes_to_difficulty_as_hash: ComputedVecsFromHeight::forced_import(
indexes_to_difficulty_as_hash: ComputedBlockLast::forced_import(
db,
"difficulty_as_hash",
Source::Compute,
version,
indexes,
last(),
)?,
indexes_to_difficulty_adjustment: ComputedVecsFromHeight::forced_import(
indexes_to_difficulty_adjustment: ComputedBlockSum::forced_import(
db,
"difficulty_adjustment",
Source::Compute,
version,
indexes,
sum(),
)?,
})
}

View File

@@ -1,27 +1,30 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredF64};
use crate::internal::{ComputedVecsFromDateIndex, ComputedVecsFromHeight};
use crate::internal::{
ComputedBlockLast, ComputedBlockSum, ComputedDateLast, DerivedComputedBlockLast,
};
/// Mining-related metrics: hash rate, hash price, hash value, difficulty
#[derive(Clone, Traversable)]
pub struct Vecs {
pub indexes_to_hash_rate: ComputedVecsFromHeight<StoredF64>,
pub indexes_to_hash_rate_1w_sma: ComputedVecsFromDateIndex<StoredF64>,
pub indexes_to_hash_rate_1m_sma: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_hash_rate_2m_sma: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_hash_rate_1y_sma: ComputedVecsFromDateIndex<StoredF32>,
pub indexes_to_hash_price_ths: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_price_ths_min: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_price_phs: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_price_phs_min: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_price_rebound: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_value_ths: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_value_ths_min: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_value_phs: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_value_phs_min: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_value_rebound: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_difficulty: ComputedVecsFromHeight<StoredF64>,
pub indexes_to_difficulty_as_hash: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_difficulty_adjustment: ComputedVecsFromHeight<StoredF32>,
pub indexes_to_hash_rate: ComputedBlockLast<StoredF64>,
pub indexes_to_hash_rate_1w_sma: ComputedDateLast<StoredF64>,
pub indexes_to_hash_rate_1m_sma: ComputedDateLast<StoredF32>,
pub indexes_to_hash_rate_2m_sma: ComputedDateLast<StoredF32>,
pub indexes_to_hash_rate_1y_sma: ComputedDateLast<StoredF32>,
pub indexes_to_hash_price_ths: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_price_ths_min: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_price_phs: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_price_phs_min: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_price_rebound: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_value_ths: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_value_ths_min: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_value_phs: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_value_phs_min: ComputedBlockLast<StoredF32>,
pub indexes_to_hash_value_rebound: ComputedBlockLast<StoredF32>,
/// Derived from indexer - no height storage needed
pub indexes_to_difficulty: DerivedComputedBlockLast<StoredF64>,
pub indexes_to_difficulty_as_hash: ComputedBlockLast<StoredF32>,
pub indexes_to_difficulty_adjustment: ComputedBlockSum<StoredF32>,
}

View File

@@ -3,14 +3,9 @@ use brk_indexer::Indexer;
use brk_types::{CheckedSub, Dollars, HalvingEpoch, Height, Sats, StoredF32, TxOutIndex};
use vecdb::{Exit, IterableVec, TypedVecIterator, VecIndex};
use super::Vecs;
use crate::{
transactions,
ComputeIndexes,
indexes, price,
utils::OptionExt,
};
use super::super::count;
use super::Vecs;
use crate::{indexes, price, transactions, ComputeIndexes};
impl Vecs {
#[allow(clippy::too_many_arguments)]
@@ -53,13 +48,7 @@ impl Vecs {
Ok(())
})?;
let mut height_to_coinbase_iter = self
.indexes_to_coinbase
.sats
.height
.as_ref()
.unwrap()
.into_iter();
let mut height_to_coinbase_iter = self.indexes_to_coinbase.sats.height.into_iter();
self.height_to_24h_coinbase_sum.compute_transform(
starting_indexes.height,
&count_vecs.height_to_24h_block_count,
@@ -75,12 +64,8 @@ impl Vecs {
)?;
drop(height_to_coinbase_iter);
if let Some(mut height_to_coinbase_iter) = self
.indexes_to_coinbase
.dollars
.as_ref()
.map(|c| c.height.u().into_iter())
{
if let Some(ref dollars) = self.indexes_to_coinbase.dollars {
let mut height_to_coinbase_iter = dollars.height.into_iter();
self.height_to_24h_coinbase_usd_sum.compute_transform(
starting_indexes.height,
&count_vecs.height_to_24h_block_count,
@@ -98,10 +83,11 @@ impl Vecs {
self.indexes_to_subsidy
.compute_all(indexes, price, starting_indexes, exit, |vec| {
// KISS: height.sum_cum.sum.0 is now a concrete field
vec.compute_transform2(
starting_indexes.height,
self.indexes_to_coinbase.sats.height.u(),
transactions_fees.indexes_to_fee.sats.height.unwrap_sum(),
&self.indexes_to_coinbase.sats.height,
&transactions_fees.indexes_to_fee.sats.height.sum_cum.sum.0,
|(height, coinbase, fees, ..)| {
(
height,
@@ -124,7 +110,7 @@ impl Vecs {
|vec| {
vec.compute_transform(
starting_indexes.height,
self.indexes_to_subsidy.sats.height.u(),
&self.indexes_to_subsidy.sats.height,
|(height, subsidy, ..)| {
let halving = HalvingEpoch::from(height);
let expected = Sats::FIFTY_BTC / 2_usize.pow(halving.to_usize() as u32);
@@ -136,10 +122,11 @@ impl Vecs {
},
)?;
// KISS: dateindex.sum_cum.sum.0 is now a concrete field
self.dateindex_to_fee_dominance.compute_transform2(
starting_indexes.dateindex,
transactions_fees.indexes_to_fee.sats.dateindex.unwrap_sum(),
self.indexes_to_coinbase.sats.dateindex.unwrap_sum(),
&transactions_fees.indexes_to_fee.sats.dateindex.sum_cum.sum.0,
&self.indexes_to_coinbase.sats.dateindex.sum_cum.sum.0,
|(i, fee, coinbase, ..)| {
let coinbase_f64 = u64::from(coinbase) as f64;
let dominance = if coinbase_f64 == 0.0 {
@@ -154,8 +141,8 @@ impl Vecs {
self.dateindex_to_subsidy_dominance.compute_transform2(
starting_indexes.dateindex,
self.indexes_to_subsidy.sats.dateindex.unwrap_sum(),
self.indexes_to_coinbase.sats.dateindex.unwrap_sum(),
&self.indexes_to_subsidy.sats.dateindex.sum_cum.sum.0,
&self.indexes_to_coinbase.sats.dateindex.sum_cum.sum.0,
|(i, subsidy, coinbase, ..)| {
let coinbase_f64 = u64::from(coinbase) as f64;
let dominance = if coinbase_f64 == 0.0 {
@@ -169,13 +156,15 @@ impl Vecs {
)?;
if let Some(sma) = self.indexes_to_subsidy_usd_1y_sma.as_mut() {
let date_to_coinbase_usd_sum = self
let date_to_coinbase_usd_sum = &self
.indexes_to_coinbase
.dollars
.as_ref()
.unwrap()
.dateindex
.unwrap_sum();
.sum_cum
.sum
.0;
sma.compute_all(starting_indexes, exit, |v| {
v.compute_sma(

View File

@@ -5,7 +5,7 @@ use vecdb::{Database, EagerVec, ImportableVec};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedValueVecsFromHeight, ComputedVecsFromDateIndex, Source, VecBuilderOptions},
internal::{ComputedDateLast, ValueBlockFull, ValueBlockSumCum},
};
impl Vecs {
@@ -15,8 +15,6 @@ impl Vecs {
indexes: &indexes::Vecs,
compute_dollars: bool,
) -> Result<Self> {
let last = || VecBuilderOptions::default().add_last();
Ok(Self {
height_to_24h_coinbase_sum: EagerVec::forced_import(db, "24h_coinbase_sum", version)?,
height_to_24h_coinbase_usd_sum: EagerVec::forced_import(
@@ -24,42 +22,26 @@ impl Vecs {
"24h_coinbase_usd_sum",
version,
)?,
indexes_to_coinbase: ComputedValueVecsFromHeight::forced_import(
indexes_to_coinbase: ValueBlockFull::forced_import(
db,
"coinbase",
Source::Compute,
version,
VecBuilderOptions::default()
.add_sum()
.add_cumulative()
.add_percentiles()
.add_minmax()
.add_average(),
compute_dollars,
indexes,
compute_dollars,
)?,
indexes_to_subsidy: ComputedValueVecsFromHeight::forced_import(
indexes_to_subsidy: ValueBlockFull::forced_import(
db,
"subsidy",
Source::Compute,
version,
VecBuilderOptions::default()
.add_percentiles()
.add_sum()
.add_cumulative()
.add_minmax()
.add_average(),
compute_dollars,
indexes,
compute_dollars,
)?,
indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight::forced_import(
indexes_to_unclaimed_rewards: ValueBlockSumCum::forced_import(
db,
"unclaimed_rewards",
Source::Compute,
version,
VecBuilderOptions::default().add_sum().add_cumulative(),
compute_dollars,
indexes,
compute_dollars,
)?,
dateindex_to_fee_dominance: EagerVec::forced_import(db, "fee_dominance", version)?,
dateindex_to_subsidy_dominance: EagerVec::forced_import(
@@ -69,14 +51,7 @@ impl Vecs {
)?,
indexes_to_subsidy_usd_1y_sma: compute_dollars
.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
"subsidy_usd_1y_sma",
Source::Compute,
version,
indexes,
last(),
)
ComputedDateLast::forced_import(db, "subsidy_usd_1y_sma", version, indexes)
})
.transpose()?,
})

View File

@@ -2,17 +2,17 @@ use brk_traversable::Traversable;
use brk_types::{DateIndex, Dollars, Height, Sats, StoredF32};
use vecdb::{EagerVec, PcoVec};
use crate::internal::{ComputedValueVecsFromHeight, ComputedVecsFromDateIndex};
use crate::internal::{ComputedDateLast, ValueBlockFull, ValueBlockSumCum};
/// Coinbase/subsidy/rewards metrics
#[derive(Clone, Traversable)]
pub struct Vecs {
pub height_to_24h_coinbase_sum: EagerVec<PcoVec<Height, Sats>>,
pub height_to_24h_coinbase_usd_sum: EagerVec<PcoVec<Height, Dollars>>,
pub indexes_to_coinbase: ComputedValueVecsFromHeight,
pub indexes_to_subsidy: ComputedValueVecsFromHeight,
pub indexes_to_unclaimed_rewards: ComputedValueVecsFromHeight,
pub indexes_to_coinbase: ValueBlockFull,
pub indexes_to_subsidy: ValueBlockFull,
pub indexes_to_unclaimed_rewards: ValueBlockSumCum,
pub dateindex_to_fee_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
pub dateindex_to_subsidy_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
pub indexes_to_subsidy_usd_1y_sma: Option<ComputedVecsFromDateIndex<Dollars>>,
pub indexes_to_subsidy_usd_1y_sma: Option<ComputedDateLast<Dollars>>,
}

View File

@@ -13,18 +13,18 @@ impl Vecs {
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.indexes_to_block_size.compute_rest(
self.indexes_to_block_size.derive_from(
indexes,
starting_indexes,
&indexer.vecs.block.height_to_total_size,
exit,
Some(&indexer.vecs.block.height_to_total_size),
)?;
self.indexes_to_block_vbytes.compute_rest(
self.indexes_to_block_vbytes.derive_from(
indexes,
starting_indexes,
&self.height_to_vbytes,
exit,
Some(&self.height_to_vbytes),
)?;
Ok(())

View File

@@ -6,7 +6,7 @@ use vecdb::{Database, IterableCloneableVec, LazyVecFrom1, VecIndex};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedVecsFromHeight, Source, VecBuilderOptions},
internal::DerivedComputedBlockFull,
};
impl Vecs {
@@ -16,15 +16,6 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let full_stats = || {
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
.add_sum()
.add_cumulative()
};
let height_to_vbytes = LazyVecFrom1::init(
"vbytes",
version,
@@ -37,21 +28,19 @@ impl Vecs {
);
Ok(Self {
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
indexes_to_block_size: DerivedComputedBlockFull::forced_import(
db,
"block_size",
Source::Vec(indexer.vecs.block.height_to_total_size.boxed_clone()),
indexer.vecs.block.height_to_total_size.boxed_clone(),
version,
indexes,
full_stats(),
)?,
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
indexes_to_block_vbytes: DerivedComputedBlockFull::forced_import(
db,
"block_vbytes",
Source::Vec(height_to_vbytes.boxed_clone()),
height_to_vbytes.boxed_clone(),
version,
indexes,
full_stats(),
)?,
height_to_vbytes,
})

View File

@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
use brk_types::{Height, StoredU64, Weight};
use vecdb::LazyVecFrom1;
use crate::internal::ComputedVecsFromHeight;
use crate::internal::DerivedComputedBlockFull;
#[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>,
pub indexes_to_block_size: DerivedComputedBlockFull<StoredU64>,
pub indexes_to_block_vbytes: DerivedComputedBlockFull<StoredU64>,
}

View File

@@ -6,10 +6,7 @@ use vecdb::{
};
use super::Vecs;
use crate::{
indexes,
internal::{ComputedVecsFromDateIndex, Source, VecBuilderOptions},
};
use crate::{indexes, internal::ComputedVecsDateFirst};
impl Vecs {
pub fn forced_import(
@@ -47,13 +44,11 @@ impl Vecs {
.and_then(|h: Height| timestamp_iter.get(h))
},
),
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
timeindexes_to_timestamp: ComputedVecsDateFirst::forced_import(
db,
"timestamp",
Source::Compute,
version,
indexes,
VecBuilderOptions::default().add_first(),
)?,
})
}

View File

@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::{Date, DifficultyEpoch, Height, Timestamp};
use vecdb::{EagerVec, LazyVecFrom1, LazyVecFrom2, PcoVec};
use crate::internal::ComputedVecsFromDateIndex;
use crate::internal::ComputedVecsDateFirst;
/// Timestamp and date metrics for blocks
#[derive(Clone, Traversable)]
@@ -12,5 +12,5 @@ pub struct Vecs {
pub height_to_timestamp_fixed: EagerVec<PcoVec<Height, Timestamp>>,
pub difficultyepoch_to_timestamp:
LazyVecFrom2<DifficultyEpoch, Timestamp, DifficultyEpoch, Height, Height, Timestamp>,
pub timeindexes_to_timestamp: ComputedVecsFromDateIndex<Timestamp>,
pub timeindexes_to_timestamp: ComputedVecsDateFirst<Timestamp>,
}

View File

@@ -13,11 +13,11 @@ impl Vecs {
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.indexes_to_block_weight.compute_rest(
self.indexes_to_block_weight.derive_from(
indexes,
starting_indexes,
&indexer.vecs.block.height_to_weight,
exit,
Some(&indexer.vecs.block.height_to_weight),
)?;
Ok(())

View File

@@ -7,7 +7,7 @@ use super::Vecs;
use crate::{
indexes,
internal::{
ComputedVecsFromHeight, LazyVecsFromHeight, Source, VecBuilderOptions, WeightToFullness,
DerivedComputedBlockFull, LazyBlockFull, WeightToFullness,
},
};
@@ -18,30 +18,21 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let full_stats = || {
VecBuilderOptions::default()
.add_average()
.add_minmax()
.add_percentiles()
.add_sum()
.add_cumulative()
};
let indexes_to_block_weight = ComputedVecsFromHeight::forced_import(
let indexes_to_block_weight = DerivedComputedBlockFull::forced_import(
db,
"block_weight",
Source::Vec(indexer.vecs.block.height_to_weight.boxed_clone()),
indexer.vecs.block.height_to_weight.boxed_clone(),
version,
indexes,
full_stats(),
)?;
let indexes_to_block_fullness = LazyVecsFromHeight::from_computed::<WeightToFullness>(
"block_fullness",
version,
indexer.vecs.block.height_to_weight.boxed_clone(),
&indexes_to_block_weight,
);
let indexes_to_block_fullness =
LazyBlockFull::from_derived::<WeightToFullness>(
"block_fullness",
version,
indexer.vecs.block.height_to_weight.boxed_clone(),
&indexes_to_block_weight,
);
Ok(Self {
indexes_to_block_weight,

View File

@@ -1,11 +1,11 @@
use brk_traversable::Traversable;
use brk_types::{StoredF32, Weight};
use crate::internal::{ComputedVecsFromHeight, LazyVecsFromHeight};
use crate::internal::{DerivedComputedBlockFull, LazyBlockFull};
#[derive(Clone, Traversable)]
pub struct Vecs {
pub indexes_to_block_weight: ComputedVecsFromHeight<Weight>,
pub indexes_to_block_weight: DerivedComputedBlockFull<Weight>,
/// Block fullness as percentage of max block weight (0-100%)
pub indexes_to_block_fullness: LazyVecsFromHeight<StoredF32, Weight>,
pub indexes_to_block_fullness: LazyBlockFull<StoredF32, Weight>,
}