mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 08:09:58 -07:00
global: big snapshot
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Height, StoredU32};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
use vecdb::{EagerVec, Exit, PcoVec, TypedVecIterator};
|
||||
|
||||
use super::super::time;
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes, internal::ComputedBlockLast};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -16,67 +16,104 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let mut height_to_timestamp_fixed_iter =
|
||||
time.height_to_timestamp_fixed.into_iter();
|
||||
let mut prev = Height::ZERO;
|
||||
self.height_to_24h_block_count.compute_transform(
|
||||
starting_indexes.height,
|
||||
&time.height_to_timestamp_fixed,
|
||||
|(h, t, ..)| {
|
||||
while t.difference_in_days_between(height_to_timestamp_fixed_iter.get_unwrap(prev))
|
||||
> 0
|
||||
{
|
||||
prev.increment();
|
||||
if prev > h {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
(h, StoredU32::from(*h + 1 - *prev))
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_count
|
||||
self.block_count
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_range(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.block.height_to_weight,
|
||||
&indexer.vecs.blocks.weight,
|
||||
|h| (h, StoredU32::from(1_u32)),
|
||||
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(())
|
||||
})?;
|
||||
// Compute rolling window starts
|
||||
self.compute_rolling_start(time, starting_indexes, exit, 1, |s| &mut s._24h_start)?;
|
||||
self.compute_rolling_start(time, starting_indexes, exit, 7, |s| &mut s._1w_start)?;
|
||||
self.compute_rolling_start(time, starting_indexes, exit, 30, |s| &mut s._1m_start)?;
|
||||
self.compute_rolling_start(time, starting_indexes, exit, 365, |s| &mut s._1y_start)?;
|
||||
|
||||
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.sum.inner(),
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
// Compute rolling window block counts
|
||||
self.compute_rolling_block_count(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self._24h_start.clone(),
|
||||
|s| &mut s._24h_block_count,
|
||||
)?;
|
||||
self.compute_rolling_block_count(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self._1w_start.clone(),
|
||||
|s| &mut s._1w_block_count,
|
||||
)?;
|
||||
self.compute_rolling_block_count(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self._1m_start.clone(),
|
||||
|s| &mut s._1m_block_count,
|
||||
)?;
|
||||
self.compute_rolling_block_count(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
&self._1y_start.clone(),
|
||||
|s| &mut s._1y_block_count,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compute_rolling_start<F>(
|
||||
&mut self,
|
||||
time: &time::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
days: usize,
|
||||
get_field: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnOnce(&mut Self) -> &mut EagerVec<PcoVec<Height, Height>>,
|
||||
{
|
||||
let mut iter = time.timestamp_fixed.into_iter();
|
||||
let mut prev = Height::ZERO;
|
||||
Ok(get_field(self).compute_transform(
|
||||
starting_indexes.height,
|
||||
&time.timestamp_fixed,
|
||||
|(h, t, ..)| {
|
||||
while t.difference_in_days_between(iter.get_unwrap(prev)) >= days {
|
||||
prev.increment();
|
||||
if prev > h {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
(h, prev)
|
||||
},
|
||||
exit,
|
||||
)?)
|
||||
}
|
||||
|
||||
fn compute_rolling_block_count<F>(
|
||||
&mut self,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
start_height: &EagerVec<PcoVec<Height, Height>>,
|
||||
get_field: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnOnce(&mut Self) -> &mut ComputedBlockLast<StoredU32>,
|
||||
{
|
||||
get_field(self).compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
start_height,
|
||||
|(h, start, ..)| (h, StoredU32::from(*h + 1 - *start)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::{StoredU64, Version};
|
||||
use vecdb::{Database, EagerVec, ImportableVec, IterableCloneableVec, LazyVecFrom1};
|
||||
use vecdb::{Database, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
@@ -10,74 +10,48 @@ use crate::{
|
||||
TARGET_BLOCKS_PER_YEAR,
|
||||
},
|
||||
indexes,
|
||||
internal::{ComputedBlockSumCum, ComputedDateLast},
|
||||
internal::{ComputedBlockLast, ComputedBlockSumCum, LazyPeriodVecs},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
dateindex_to_block_count_target: LazyVecFrom1::init(
|
||||
block_count_target: LazyPeriodVecs::new(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.dateindex_to_dateindex.boxed_clone(),
|
||||
indexes,
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DAY)),
|
||||
),
|
||||
weekindex_to_block_count_target: LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.weekindex_to_weekindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_WEEK)),
|
||||
),
|
||||
monthindex_to_block_count_target: LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.monthindex_to_monthindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_MONTH)),
|
||||
),
|
||||
quarterindex_to_block_count_target: LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.quarterindex_to_quarterindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_QUARTER)),
|
||||
),
|
||||
semesterindex_to_block_count_target: LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.semesterindex_to_semesterindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_SEMESTER)),
|
||||
),
|
||||
yearindex_to_block_count_target: LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.yearindex_to_yearindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_YEAR)),
|
||||
),
|
||||
decadeindex_to_block_count_target: LazyVecFrom1::init(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes.time.decadeindex_to_decadeindex.boxed_clone(),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DECADE)),
|
||||
),
|
||||
height_to_24h_block_count: EagerVec::forced_import(db, "24h_block_count", version)?,
|
||||
indexes_to_block_count: ComputedBlockSumCum::forced_import(
|
||||
block_count: ComputedBlockSumCum::forced_import(db, "block_count", version, indexes)?,
|
||||
_24h_start: ImportableVec::forced_import(db, "24h_start", version)?,
|
||||
_1w_start: ImportableVec::forced_import(db, "1w_start", version)?,
|
||||
_1m_start: ImportableVec::forced_import(db, "1m_start", version)?,
|
||||
_1y_start: ImportableVec::forced_import(db, "1y_start", version)?,
|
||||
_24h_block_count: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"block_count",
|
||||
"24h_block_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_1w_block_count: ComputedDateLast::forced_import(
|
||||
_1w_block_count: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"1w_block_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_1m_block_count: ComputedDateLast::forced_import(
|
||||
_1m_block_count: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"1m_block_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_1y_block_count: ComputedDateLast::forced_import(
|
||||
_1y_block_count: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"1y_block_count",
|
||||
version,
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{
|
||||
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, SemesterIndex, StoredU32, StoredU64,
|
||||
WeekIndex, YearIndex,
|
||||
};
|
||||
use vecdb::LazyVecFrom1;
|
||||
use brk_types::{Height, StoredU32, StoredU64};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{ComputedBlockSumCum, ComputedDateLast};
|
||||
use crate::internal::{ComputedBlockLast, ComputedBlockSumCum, LazyPeriodVecs};
|
||||
|
||||
#[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 yearindex_to_block_count_target: LazyVecFrom1<YearIndex, StoredU64, YearIndex, YearIndex>,
|
||||
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: 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>,
|
||||
pub block_count_target: LazyPeriodVecs<StoredU64>,
|
||||
pub block_count: ComputedBlockSumCum<StoredU32>,
|
||||
// Rolling window starts (height-indexed only, no date aggregation needed)
|
||||
pub _24h_start: EagerVec<PcoVec<Height, Height>>,
|
||||
pub _1w_start: EagerVec<PcoVec<Height, Height>>,
|
||||
pub _1m_start: EagerVec<PcoVec<Height, Height>>,
|
||||
pub _1y_start: EagerVec<PcoVec<Height, Height>>,
|
||||
// Rolling window block counts
|
||||
pub _24h_block_count: ComputedBlockLast<StoredU32>,
|
||||
pub _1w_block_count: ComputedBlockLast<StoredU32>,
|
||||
pub _1m_block_count: ComputedBlockLast<StoredU32>,
|
||||
pub _1y_block_count: ComputedBlockLast<StoredU32>,
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ use brk_error::Result;
|
||||
use brk_types::StoredU32;
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use super::super::TARGET_BLOCKS_PER_DAY_F32;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -14,12 +14,13 @@ impl Vecs {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let mut height_to_difficultyepoch_iter =
|
||||
indexes.block.height_to_difficultyepoch.into_iter();
|
||||
self.indexes_to_difficultyepoch.compute_all(starting_indexes, exit, |vec| {
|
||||
let mut height_count_iter = indexes.time.dateindex_to_height_count.into_iter();
|
||||
indexes.height.difficultyepoch.into_iter();
|
||||
self.difficultyepoch
|
||||
.compute_all(starting_indexes, exit, |vec| {
|
||||
let mut height_count_iter = indexes.dateindex.height_count.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.time.dateindex_to_first_height,
|
||||
&indexes.dateindex.first_height,
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
@@ -32,27 +33,35 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_blocks_before_next_difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
self.blocks_before_next_difficulty_adjustment.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.block.height_to_height,
|
||||
&indexes.height.identity,
|
||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_diff_adj())),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_days_before_next_difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
self.days_before_next_difficulty_adjustment.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_blocks_before_next_difficulty_adjustment.height,
|
||||
&self.blocks_before_next_difficulty_adjustment.height,
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
},
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -13,19 +13,19 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_difficultyepoch: ComputedDateLast::forced_import(
|
||||
difficultyepoch: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"difficultyepoch",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_blocks_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
|
||||
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(
|
||||
days_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"days_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::internal::{ComputedBlockLast, ComputedDateLast};
|
||||
/// Difficulty epoch metrics and countdown
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
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>,
|
||||
pub difficultyepoch: ComputedDateLast<DifficultyEpoch>,
|
||||
pub blocks_before_next_difficulty_adjustment: ComputedBlockLast<StoredU32>,
|
||||
pub days_before_next_difficulty_adjustment: ComputedBlockLast<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ use brk_error::Result;
|
||||
use brk_types::StoredU32;
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use super::super::TARGET_BLOCKS_PER_DAY_F32;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -13,12 +13,13 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
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| {
|
||||
let mut height_count_iter = indexes.time.dateindex_to_height_count.into_iter();
|
||||
let mut height_to_halvingepoch_iter = indexes.height.halvingepoch.into_iter();
|
||||
self.halvingepoch
|
||||
.compute_all(starting_indexes, exit, |vec| {
|
||||
let mut height_count_iter = indexes.dateindex.height_count.into_iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.time.dateindex_to_first_height,
|
||||
&indexes.dateindex.first_height,
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
@@ -31,35 +32,27 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_blocks_before_next_halving.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
self.blocks_before_next_halving
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexes.block.height_to_height,
|
||||
&indexes.height.identity,
|
||||
|(h, ..)| (h, StoredU32::from(h.left_before_next_halving())),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
self.indexes_to_days_before_next_halving.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
self.days_before_next_halving
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_blocks_before_next_halving.height,
|
||||
&self.blocks_before_next_halving.height,
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -13,19 +13,14 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_halvingepoch: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"halvingepoch",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_blocks_before_next_halving: ComputedBlockLast::forced_import(
|
||||
halvingepoch: ComputedDateLast::forced_import(db, "halvingepoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"blocks_before_next_halving",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_days_before_next_halving: ComputedBlockLast::forced_import(
|
||||
days_before_next_halving: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"days_before_next_halving",
|
||||
version + v2,
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::internal::{ComputedBlockLast, ComputedDateLast};
|
||||
/// Halving epoch metrics and countdown
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_halvingepoch: ComputedDateLast<HalvingEpoch>,
|
||||
pub indexes_to_blocks_before_next_halving: ComputedBlockLast<StoredU32>,
|
||||
pub indexes_to_days_before_next_halving: ComputedBlockLast<StoredF32>,
|
||||
pub halvingepoch: ComputedDateLast<HalvingEpoch>,
|
||||
pub blocks_before_next_halving: ComputedBlockLast<StoredU32>,
|
||||
pub days_before_next_halving: ComputedBlockLast<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -11,12 +11,7 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_block_interval.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.height_to_interval,
|
||||
exit,
|
||||
)?;
|
||||
self.interval.derive_from(indexes, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{CheckedSub, Height, Timestamp, Version};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom1};
|
||||
use vecdb::{Database, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::DerivedComputedBlockDistribution};
|
||||
use crate::{indexes, internal::LazyBlockDistribution};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -13,34 +13,25 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let height_to_interval = LazyVecFrom1::init(
|
||||
"interval",
|
||||
let interval = LazyBlockDistribution::forced_import_with_init(
|
||||
db,
|
||||
"block_interval",
|
||||
version,
|
||||
indexer.vecs.block.height_to_timestamp.boxed_clone(),
|
||||
indexer.vecs.blocks.timestamp.clone(),
|
||||
indexes,
|
||||
|height: Height, timestamp_iter| {
|
||||
let timestamp = timestamp_iter.get(height)?;
|
||||
let timestamp = timestamp_iter.get_at(height.to_usize())?;
|
||||
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
|
||||
timestamp_iter
|
||||
.get(prev_h)
|
||||
.get_at(prev_h.to_usize())
|
||||
.map_or(Timestamp::ZERO, |prev_t| {
|
||||
timestamp.checked_sub(prev_t).unwrap_or(Timestamp::ZERO)
|
||||
})
|
||||
});
|
||||
Some(interval)
|
||||
},
|
||||
);
|
||||
|
||||
let indexes_to_block_interval = DerivedComputedBlockDistribution::forced_import(
|
||||
db,
|
||||
"block_interval",
|
||||
height_to_interval.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
height_to_interval,
|
||||
indexes_to_block_interval,
|
||||
})
|
||||
Ok(Self { interval })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, Timestamp};
|
||||
use vecdb::LazyVecFrom1;
|
||||
use brk_types::Timestamp;
|
||||
|
||||
use crate::internal::DerivedComputedBlockDistribution;
|
||||
use crate::internal::LazyBlockDistribution;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub height_to_interval: LazyVecFrom1<Height, Timestamp, Height, Timestamp>,
|
||||
pub indexes_to_block_interval: DerivedComputedBlockDistribution<Timestamp>,
|
||||
#[traversable(flatten)]
|
||||
pub interval: LazyBlockDistribution<Timestamp>,
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ use brk_indexer::Indexer;
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::{ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64, count, rewards};
|
||||
use super::Vecs;
|
||||
use super::super::{count, rewards, ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64};
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -17,31 +17,31 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_difficulty.derive_from(
|
||||
self.difficulty.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&indexer.vecs.block.height_to_difficulty,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.indexes_to_difficulty_as_hash
|
||||
self.difficulty_as_hash
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
let multiplier = 2.0_f64.powi(32) / 600.0;
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.block.height_to_difficulty,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_rate
|
||||
self.hash_rate
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_to_24h_block_count,
|
||||
&self.indexes_to_difficulty_as_hash.height,
|
||||
&count_vecs._24h_block_count.height,
|
||||
&self.difficulty_as_hash.height,
|
||||
|(i, block_count_sum, difficulty_as_hash, ..)| {
|
||||
(
|
||||
i,
|
||||
@@ -56,67 +56,67 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_rate_1w_sma.compute_all(starting_indexes, exit, |v| {
|
||||
self.hash_rate_1w_sma
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sma(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_hash_rate.dateindex.inner(),
|
||||
self.hash_rate.dateindex.inner(),
|
||||
7,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_rate_1m_sma.compute_all(starting_indexes, exit, |v| {
|
||||
self.hash_rate_1m_sma
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sma(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_hash_rate.dateindex.inner(),
|
||||
self.hash_rate.dateindex.inner(),
|
||||
30,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_rate_2m_sma.compute_all(starting_indexes, exit, |v| {
|
||||
self.hash_rate_2m_sma
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sma(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_hash_rate.dateindex.inner(),
|
||||
self.hash_rate.dateindex.inner(),
|
||||
2 * 30,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_rate_1y_sma.compute_all(starting_indexes, exit, |v| {
|
||||
self.hash_rate_1y_sma
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sma(
|
||||
starting_indexes.dateindex,
|
||||
self.indexes_to_hash_rate.dateindex.inner(),
|
||||
self.hash_rate.dateindex.inner(),
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_difficulty_adjustment.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
self.difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_percentage_change(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.block.height_to_difficulty,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
1,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_price_ths
|
||||
self.hash_price_ths
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&rewards_vecs.height_to_24h_coinbase_usd_sum,
|
||||
&self.indexes_to_hash_rate.height,
|
||||
rewards_vecs._24h_coinbase_sum.dollars.as_ref().unwrap(),
|
||||
&self.hash_rate.height,
|
||||
|(i, coinbase_sum, hashrate, ..)| {
|
||||
let hashrate_ths = *hashrate / ONE_TERA_HASH;
|
||||
let price = if hashrate_ths == 0.0 {
|
||||
@@ -131,23 +131,23 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_price_phs
|
||||
self.hash_price_phs
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_price_ths.height,
|
||||
&self.hash_price_ths.height,
|
||||
|(i, price, ..)| (i, (*price * 1000.0).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_value_ths
|
||||
self.hash_value_ths
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&rewards_vecs.height_to_24h_coinbase_sum,
|
||||
&self.indexes_to_hash_rate.height,
|
||||
&rewards_vecs._24h_coinbase_sum.sats,
|
||||
&self.hash_rate.height,
|
||||
|(i, coinbase_sum, hashrate, ..)| {
|
||||
let hashrate_ths = *hashrate / ONE_TERA_HASH;
|
||||
let value = if hashrate_ths == 0.0 {
|
||||
@@ -162,78 +162,78 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_value_phs
|
||||
self.hash_value_phs
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_value_ths.height,
|
||||
&self.hash_value_ths.height,
|
||||
|(i, value, ..)| (i, (*value * 1000.0).into()),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_price_ths_min
|
||||
self.hash_price_ths_min
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_all_time_low_(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_price_ths.height,
|
||||
&self.hash_price_ths.height,
|
||||
exit,
|
||||
true,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_price_phs_min
|
||||
self.hash_price_phs_min
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_all_time_low_(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_price_phs.height,
|
||||
&self.hash_price_phs.height,
|
||||
exit,
|
||||
true,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_value_ths_min
|
||||
self.hash_value_ths_min
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_all_time_low_(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_value_ths.height,
|
||||
&self.hash_value_ths.height,
|
||||
exit,
|
||||
true,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_value_phs_min
|
||||
self.hash_value_phs_min
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_all_time_low_(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_value_phs.height,
|
||||
&self.hash_value_phs.height,
|
||||
exit,
|
||||
true,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_price_rebound
|
||||
self.hash_price_rebound
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_percentage_difference(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_price_phs.height,
|
||||
&self.indexes_to_hash_price_phs_min.height,
|
||||
&self.hash_price_phs.height,
|
||||
&self.hash_price_phs_min.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_hash_value_rebound
|
||||
self.hash_value_rebound
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_percentage_difference(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_hash_value_phs.height,
|
||||
&self.indexes_to_hash_value_phs_min.height,
|
||||
&self.hash_value_phs.height,
|
||||
&self.hash_value_phs_min.height,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
|
||||
@@ -20,111 +20,106 @@ impl Vecs {
|
||||
let v5 = Version::new(5);
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_hash_rate: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_rate",
|
||||
version + v5,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_rate_1w_sma: ComputedDateLast::forced_import(
|
||||
hash_rate: ComputedBlockLast::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
hash_rate_1w_sma: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_1w_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_rate_1m_sma: ComputedDateLast::forced_import(
|
||||
hash_rate_1m_sma: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_1m_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_rate_2m_sma: ComputedDateLast::forced_import(
|
||||
hash_rate_2m_sma: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_2m_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_rate_1y_sma: ComputedDateLast::forced_import(
|
||||
hash_rate_1y_sma: ComputedDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_1y_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_price_ths: ComputedBlockLast::forced_import(
|
||||
hash_price_ths: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_price_ths",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_price_ths_min: ComputedBlockLast::forced_import(
|
||||
hash_price_ths_min: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_price_ths_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_price_phs: ComputedBlockLast::forced_import(
|
||||
hash_price_phs: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_price_phs",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_price_phs_min: ComputedBlockLast::forced_import(
|
||||
hash_price_phs_min: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_price_phs_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_price_rebound: ComputedBlockLast::forced_import(
|
||||
hash_price_rebound: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_price_rebound",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_value_ths: ComputedBlockLast::forced_import(
|
||||
hash_value_ths: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_value_ths",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_value_ths_min: ComputedBlockLast::forced_import(
|
||||
hash_value_ths_min: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_value_ths_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_value_phs: ComputedBlockLast::forced_import(
|
||||
hash_value_phs: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_value_phs",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_value_phs_min: ComputedBlockLast::forced_import(
|
||||
hash_value_phs_min: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_value_phs_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_hash_value_rebound: ComputedBlockLast::forced_import(
|
||||
hash_value_rebound: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"hash_value_rebound",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
// Derived from external indexer data - no height storage needed
|
||||
indexes_to_difficulty: DerivedComputedBlockLast::forced_import(
|
||||
difficulty: DerivedComputedBlockLast::forced_import(
|
||||
db,
|
||||
"difficulty",
|
||||
indexer.vecs.block.height_to_difficulty.boxed_clone(),
|
||||
indexer.vecs.blocks.difficulty.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_difficulty_as_hash: ComputedBlockLast::forced_import(
|
||||
difficulty_as_hash: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"difficulty_as_hash",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_difficulty_adjustment: ComputedBlockSum::forced_import(
|
||||
difficulty_adjustment: ComputedBlockSum::forced_import(
|
||||
db,
|
||||
"difficulty_adjustment",
|
||||
version,
|
||||
|
||||
@@ -8,23 +8,23 @@ use crate::internal::{
|
||||
/// Mining-related metrics: hash rate, hash price, hash value, difficulty
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
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>,
|
||||
pub hash_rate: ComputedBlockLast<StoredF64>,
|
||||
pub hash_rate_1w_sma: ComputedDateLast<StoredF64>,
|
||||
pub hash_rate_1m_sma: ComputedDateLast<StoredF32>,
|
||||
pub hash_rate_2m_sma: ComputedDateLast<StoredF32>,
|
||||
pub hash_rate_1y_sma: ComputedDateLast<StoredF32>,
|
||||
pub hash_price_ths: ComputedBlockLast<StoredF32>,
|
||||
pub hash_price_ths_min: ComputedBlockLast<StoredF32>,
|
||||
pub hash_price_phs: ComputedBlockLast<StoredF32>,
|
||||
pub hash_price_phs_min: ComputedBlockLast<StoredF32>,
|
||||
pub hash_price_rebound: ComputedBlockLast<StoredF32>,
|
||||
pub hash_value_ths: ComputedBlockLast<StoredF32>,
|
||||
pub hash_value_ths_min: ComputedBlockLast<StoredF32>,
|
||||
pub hash_value_phs: ComputedBlockLast<StoredF32>,
|
||||
pub hash_value_phs_min: ComputedBlockLast<StoredF32>,
|
||||
pub 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>,
|
||||
pub difficulty: DerivedComputedBlockLast<StoredF64>,
|
||||
pub difficulty_as_hash: ComputedBlockLast<StoredF32>,
|
||||
pub difficulty_adjustment: ComputedBlockSum<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Exit, IterableVec, TypedVecIterator, VecIndex};
|
||||
|
||||
use super::super::count;
|
||||
use super::Vecs;
|
||||
use crate::{indexes, price, transactions, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes, price, transactions};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -19,16 +19,16 @@ impl Vecs {
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_coinbase
|
||||
self.coinbase
|
||||
.compute_all(indexes, price, starting_indexes, exit, |vec| {
|
||||
let mut txindex_to_first_txoutindex_iter =
|
||||
indexer.vecs.tx.txindex_to_first_txoutindex.iter()?;
|
||||
indexer.vecs.transactions.first_txoutindex.iter()?;
|
||||
let mut txindex_to_output_count_iter =
|
||||
indexes.transaction.txindex_to_output_count.iter();
|
||||
let mut txoutindex_to_value_iter = indexer.vecs.txout.txoutindex_to_value.iter()?;
|
||||
indexes.txindex.output_count.iter();
|
||||
let mut txoutindex_to_value_iter = indexer.vecs.outputs.value.iter()?;
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.tx.height_to_first_txindex,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
|(height, txindex, ..)| {
|
||||
let first_txoutindex = txindex_to_first_txoutindex_iter
|
||||
.get_unwrap(txindex)
|
||||
@@ -48,10 +48,10 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let mut height_to_coinbase_iter = self.indexes_to_coinbase.sats.height.into_iter();
|
||||
self.height_to_24h_coinbase_sum.compute_transform(
|
||||
let mut height_to_coinbase_iter = self.coinbase.sats.height.into_iter();
|
||||
self._24h_coinbase_sum.sats.compute_transform(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_to_24h_block_count,
|
||||
&count_vecs._24h_block_count.height,
|
||||
|(h, count, ..)| {
|
||||
let range = *h - (*count - 1)..=*h;
|
||||
let sum = range
|
||||
@@ -64,11 +64,13 @@ impl Vecs {
|
||||
)?;
|
||||
drop(height_to_coinbase_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(
|
||||
if let (Some(dollars_out), Some(dollars_in)) =
|
||||
(&mut self._24h_coinbase_sum.dollars, &self.coinbase.dollars)
|
||||
{
|
||||
let mut height_to_coinbase_iter = dollars_in.height.into_iter();
|
||||
dollars_out.compute_transform(
|
||||
starting_indexes.height,
|
||||
&count_vecs.height_to_24h_block_count,
|
||||
&count_vecs._24h_block_count.height,
|
||||
|(h, count, ..)| {
|
||||
let range = *h - (*count - 1)..=*h;
|
||||
let sum = range
|
||||
@@ -81,13 +83,12 @@ impl Vecs {
|
||||
)?;
|
||||
}
|
||||
|
||||
self.indexes_to_subsidy
|
||||
self.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,
|
||||
&transactions_fees.indexes_to_fee.sats.height.sum_cum.sum.0,
|
||||
&self.coinbase.sats.height,
|
||||
&transactions_fees.fee.sats.height.sum_cum.sum.0,
|
||||
|(height, coinbase, fees, ..)| {
|
||||
(
|
||||
height,
|
||||
@@ -102,15 +103,11 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.indexes_to_unclaimed_rewards.compute_all(
|
||||
indexes,
|
||||
price,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec| {
|
||||
self.unclaimed_rewards
|
||||
.compute_all(indexes, price, starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.indexes_to_subsidy.sats.height,
|
||||
&self.subsidy.sats.height,
|
||||
|(height, subsidy, ..)| {
|
||||
let halving = HalvingEpoch::from(height);
|
||||
let expected = Sats::FIFTY_BTC / 2_usize.pow(halving.to_usize() as u32);
|
||||
@@ -119,14 +116,12 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
})?;
|
||||
|
||||
// KISS: dateindex.sum_cum.sum.0 is now a concrete field
|
||||
self.dateindex_to_fee_dominance.compute_transform2(
|
||||
self.fee_dominance.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&transactions_fees.indexes_to_fee.sats.dateindex.sum_cum.sum.0,
|
||||
&self.indexes_to_coinbase.sats.dateindex.sum_cum.sum.0,
|
||||
&transactions_fees.fee.sats.dateindex.sum_cum.sum.0,
|
||||
&self.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 {
|
||||
@@ -139,10 +134,10 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.dateindex_to_subsidy_dominance.compute_transform2(
|
||||
self.subsidy_dominance.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&self.indexes_to_subsidy.sats.dateindex.sum_cum.sum.0,
|
||||
&self.indexes_to_coinbase.sats.dateindex.sum_cum.sum.0,
|
||||
&self.subsidy.sats.dateindex.sum_cum.sum.0,
|
||||
&self.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 {
|
||||
@@ -155,9 +150,9 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
if let Some(sma) = self.indexes_to_subsidy_usd_1y_sma.as_mut() {
|
||||
if let Some(sma) = self.subsidy_usd_1y_sma.as_mut() {
|
||||
let date_to_coinbase_usd_sum = &self
|
||||
.indexes_to_coinbase
|
||||
.coinbase
|
||||
.dollars
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{Database, EagerVec, ImportableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedDateLast, ValueBlockFull, ValueBlockSumCum},
|
||||
internal::{ComputedDateLast, ValueBlockFull, ValueBlockHeight, ValueBlockSumCum},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -16,40 +16,36 @@ impl Vecs {
|
||||
compute_dollars: bool,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
height_to_24h_coinbase_sum: EagerVec::forced_import(db, "24h_coinbase_sum", version)?,
|
||||
height_to_24h_coinbase_usd_sum: EagerVec::forced_import(
|
||||
_24h_coinbase_sum: ValueBlockHeight::forced_import(
|
||||
db,
|
||||
"24h_coinbase_usd_sum",
|
||||
"24h_coinbase_sum",
|
||||
version,
|
||||
compute_dollars,
|
||||
)?,
|
||||
indexes_to_coinbase: ValueBlockFull::forced_import(
|
||||
coinbase: ValueBlockFull::forced_import(
|
||||
db,
|
||||
"coinbase",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?,
|
||||
indexes_to_subsidy: ValueBlockFull::forced_import(
|
||||
subsidy: ValueBlockFull::forced_import(
|
||||
db,
|
||||
"subsidy",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?,
|
||||
indexes_to_unclaimed_rewards: ValueBlockSumCum::forced_import(
|
||||
unclaimed_rewards: ValueBlockSumCum::forced_import(
|
||||
db,
|
||||
"unclaimed_rewards",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?,
|
||||
dateindex_to_fee_dominance: EagerVec::forced_import(db, "fee_dominance", version)?,
|
||||
dateindex_to_subsidy_dominance: EagerVec::forced_import(
|
||||
db,
|
||||
"subsidy_dominance",
|
||||
version,
|
||||
)?,
|
||||
indexes_to_subsidy_usd_1y_sma: compute_dollars
|
||||
fee_dominance: EagerVec::forced_import(db, "fee_dominance", version)?,
|
||||
subsidy_dominance: EagerVec::forced_import(db, "subsidy_dominance", version)?,
|
||||
subsidy_usd_1y_sma: compute_dollars
|
||||
.then(|| {
|
||||
ComputedDateLast::forced_import(db, "subsidy_usd_1y_sma", version, indexes)
|
||||
})
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{DateIndex, Dollars, Height, Sats, StoredF32};
|
||||
use brk_types::{DateIndex, Dollars, StoredF32};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{ComputedDateLast, ValueBlockFull, ValueBlockSumCum};
|
||||
use crate::internal::{ComputedDateLast, ValueBlockFull, ValueBlockHeight, 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: 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<ComputedDateLast<Dollars>>,
|
||||
pub _24h_coinbase_sum: ValueBlockHeight,
|
||||
pub coinbase: ValueBlockFull,
|
||||
pub subsidy: ValueBlockFull,
|
||||
pub unclaimed_rewards: ValueBlockSumCum,
|
||||
pub fee_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
|
||||
pub subsidy_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
|
||||
pub subsidy_usd_1y_sma: Option<ComputedDateLast<Dollars>>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -13,19 +13,14 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_block_size.derive_from(
|
||||
self.size.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&indexer.vecs.block.height_to_total_size,
|
||||
&indexer.vecs.blocks.total_size,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_vbytes.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&self.height_to_vbytes,
|
||||
exit,
|
||||
)?;
|
||||
self.vbytes.derive_from(indexes, starting_indexes, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Height, StoredU64, Version};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom1, VecIndex};
|
||||
use vecdb::{Database, IterableCloneableVec, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::DerivedComputedBlockFull,
|
||||
};
|
||||
use crate::{indexes, internal::{DerivedComputedBlockFull, LazyComputedBlockFull}};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -16,33 +13,26 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let height_to_vbytes = LazyVecFrom1::init(
|
||||
"vbytes",
|
||||
version,
|
||||
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: DerivedComputedBlockFull::forced_import(
|
||||
db,
|
||||
"block_size",
|
||||
indexer.vecs.block.height_to_total_size.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
indexes_to_block_vbytes: DerivedComputedBlockFull::forced_import(
|
||||
vbytes: LazyComputedBlockFull::forced_import_with_init(
|
||||
db,
|
||||
"block_vbytes",
|
||||
height_to_vbytes.boxed_clone(),
|
||||
version,
|
||||
indexer.vecs.blocks.weight.clone(),
|
||||
indexes,
|
||||
|height: Height, weight_iter| {
|
||||
weight_iter
|
||||
.get_at(height.to_usize())
|
||||
.map(|w| StoredU64::from(w.to_vbytes_floor()))
|
||||
},
|
||||
)?,
|
||||
size: DerivedComputedBlockFull::forced_import(
|
||||
db,
|
||||
"block_size",
|
||||
indexer.vecs.blocks.total_size.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
height_to_vbytes,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU64, Weight};
|
||||
use vecdb::LazyVecFrom1;
|
||||
use brk_types::{StoredU64, Weight};
|
||||
|
||||
use crate::internal::DerivedComputedBlockFull;
|
||||
use crate::internal::{DerivedComputedBlockFull, LazyComputedBlockFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub height_to_vbytes: LazyVecFrom1<Height, StoredU64, Height, Weight>,
|
||||
pub indexes_to_block_size: DerivedComputedBlockFull<StoredU64>,
|
||||
pub indexes_to_block_vbytes: DerivedComputedBlockFull<StoredU64>,
|
||||
pub vbytes: LazyComputedBlockFull<StoredU64, Weight>,
|
||||
pub size: DerivedComputedBlockFull<StoredU64>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::Timestamp;
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
/// Compute height-to-time fields early, before indexes are computed.
|
||||
@@ -16,9 +16,9 @@ impl Vecs {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let mut prev_timestamp_fixed = None;
|
||||
self.height_to_timestamp_fixed.compute_transform(
|
||||
self.timestamp_fixed.compute_transform(
|
||||
starting_height,
|
||||
&indexer.vecs.block.height_to_timestamp,
|
||||
&indexer.vecs.blocks.timestamp,
|
||||
|(h, timestamp, height_to_timestamp_fixed_iter)| {
|
||||
if prev_timestamp_fixed.is_none()
|
||||
&& let Some(prev_h) = h.decremented()
|
||||
@@ -46,16 +46,15 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.timeindexes_to_timestamp
|
||||
.compute_all(starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.time.dateindex_to_date,
|
||||
|(di, d, ..)| (di, Timestamp::from(d)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
self.timestamp.compute_all(|vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&indexes.dateindex.date,
|
||||
|(di, d, ..)| (di, Timestamp::from(d)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Date, DifficultyEpoch, Height, Version};
|
||||
use vecdb::{
|
||||
Database, EagerVec, ImportableVec, IterableCloneableVec, LazyVecFrom1, LazyVecFrom2, VecIndex,
|
||||
};
|
||||
use brk_types::{Date, Height, Version};
|
||||
use vecdb::{Database, EagerVec, ImportableVec, IterableCloneableVec, LazyVecFrom1, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedVecsDateFirst};
|
||||
use crate::{indexes, internal::DerivedComputedBlockFirst};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -18,35 +16,25 @@ impl Vecs {
|
||||
let height_to_timestamp_fixed = EagerVec::forced_import(db, "timestamp_fixed", version)?;
|
||||
|
||||
Ok(Self {
|
||||
height_to_date: LazyVecFrom1::init(
|
||||
date: LazyVecFrom1::init(
|
||||
"date",
|
||||
version,
|
||||
indexer.vecs.block.height_to_timestamp.boxed_clone(),
|
||||
indexer.vecs.blocks.timestamp.boxed_clone(),
|
||||
|height: Height, timestamp_iter| {
|
||||
timestamp_iter.get_at(height.to_usize()).map(Date::from)
|
||||
},
|
||||
),
|
||||
height_to_date_fixed: LazyVecFrom1::init(
|
||||
date_fixed: LazyVecFrom1::init(
|
||||
"date_fixed",
|
||||
version,
|
||||
height_to_timestamp_fixed.boxed_clone(),
|
||||
|height: Height, timestamp_iter| timestamp_iter.get(height).map(Date::from),
|
||||
),
|
||||
height_to_timestamp_fixed,
|
||||
difficultyepoch_to_timestamp: LazyVecFrom2::init(
|
||||
"timestamp",
|
||||
version,
|
||||
indexes.block.difficultyepoch_to_first_height.boxed_clone(),
|
||||
indexer.vecs.block.height_to_timestamp.boxed_clone(),
|
||||
|di: DifficultyEpoch, first_height_iter, timestamp_iter| {
|
||||
first_height_iter
|
||||
.get(di)
|
||||
.and_then(|h: Height| timestamp_iter.get(h))
|
||||
},
|
||||
),
|
||||
timeindexes_to_timestamp: ComputedVecsDateFirst::forced_import(
|
||||
timestamp_fixed: height_to_timestamp_fixed,
|
||||
timestamp: DerivedComputedBlockFirst::forced_import(
|
||||
db,
|
||||
"timestamp",
|
||||
indexer.vecs.blocks.timestamp.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Date, DifficultyEpoch, Height, Timestamp};
|
||||
use vecdb::{EagerVec, LazyVecFrom1, LazyVecFrom2, PcoVec};
|
||||
use brk_types::{Date, Height, Timestamp};
|
||||
use vecdb::{EagerVec, LazyVecFrom1, PcoVec};
|
||||
|
||||
use crate::internal::ComputedVecsDateFirst;
|
||||
use crate::internal::DerivedComputedBlockFirst;
|
||||
|
||||
/// Timestamp and date metrics for blocks
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub height_to_date: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
pub height_to_date_fixed: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
pub height_to_timestamp_fixed: EagerVec<PcoVec<Height, Timestamp>>,
|
||||
pub difficultyepoch_to_timestamp:
|
||||
LazyVecFrom2<DifficultyEpoch, Timestamp, DifficultyEpoch, Height, Height, Timestamp>,
|
||||
pub timeindexes_to_timestamp: ComputedVecsDateFirst<Timestamp>,
|
||||
pub date: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
pub date_fixed: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
pub timestamp_fixed: EagerVec<PcoVec<Height, Timestamp>>,
|
||||
pub timestamp: DerivedComputedBlockFirst<Timestamp>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -13,12 +13,8 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.indexes_to_block_weight.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&indexer.vecs.block.height_to_weight,
|
||||
exit,
|
||||
)?;
|
||||
self.weight
|
||||
.derive_from(indexes, starting_indexes, &indexer.vecs.blocks.weight, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ use vecdb::{Database, IterableCloneableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{
|
||||
DerivedComputedBlockFull, LazyBlockFull, WeightToFullness,
|
||||
},
|
||||
internal::{DerivedComputedBlockFull, LazyBlockFull, WeightToFullness},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -18,25 +16,21 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let indexes_to_block_weight = DerivedComputedBlockFull::forced_import(
|
||||
let weight = DerivedComputedBlockFull::forced_import(
|
||||
db,
|
||||
"block_weight",
|
||||
indexer.vecs.block.height_to_weight.boxed_clone(),
|
||||
indexer.vecs.blocks.weight.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let indexes_to_block_fullness =
|
||||
LazyBlockFull::from_derived::<WeightToFullness>(
|
||||
"block_fullness",
|
||||
version,
|
||||
indexer.vecs.block.height_to_weight.boxed_clone(),
|
||||
&indexes_to_block_weight,
|
||||
);
|
||||
let fullness = LazyBlockFull::from_derived::<WeightToFullness>(
|
||||
"block_fullness",
|
||||
version,
|
||||
indexer.vecs.blocks.weight.boxed_clone(),
|
||||
&weight,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_block_weight,
|
||||
indexes_to_block_fullness,
|
||||
})
|
||||
Ok(Self { weight, fullness })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::internal::{DerivedComputedBlockFull, LazyBlockFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_block_weight: DerivedComputedBlockFull<Weight>,
|
||||
/// Block fullness as percentage of max block weight (0-100%)
|
||||
pub indexes_to_block_fullness: LazyBlockFull<StoredF32, Weight>,
|
||||
pub weight: DerivedComputedBlockFull<Weight>,
|
||||
pub fullness: LazyBlockFull<StoredF32, Weight>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user