mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-26 07:39:59 -07:00
global: snapshot
This commit is contained in:
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use crate::{ComputeIndexes, indexes, price, transactions};
|
||||
use crate::{ComputeIndexes, indexes, transactions};
|
||||
|
||||
use super::Vecs;
|
||||
|
||||
@@ -13,7 +13,6 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
transactions: &transactions::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Core block metrics
|
||||
@@ -29,7 +28,8 @@ impl Vecs {
|
||||
self.time.compute(indexes, starting_indexes, exit)?;
|
||||
|
||||
// Epoch metrics
|
||||
self.difficulty.compute(indexes, starting_indexes, exit)?;
|
||||
self.difficulty
|
||||
.compute(indexer, indexes, starting_indexes, exit)?;
|
||||
self.halving.compute(indexes, starting_indexes, exit)?;
|
||||
|
||||
// Rewards depends on count and transactions fees
|
||||
@@ -39,15 +39,14 @@ impl Vecs {
|
||||
&self.count,
|
||||
&transactions.fees,
|
||||
starting_indexes,
|
||||
price,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Mining depends on count and rewards
|
||||
// Mining depends on count, difficulty, and rewards
|
||||
self.mining.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
&self.count,
|
||||
&self.difficulty,
|
||||
&self.rewards,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::{EagerVec, Exit, PcoVec, TypedVecIterator};
|
||||
|
||||
use super::super::time;
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, internal::ComputedBlockLast};
|
||||
use crate::{ComputeIndexes, indexes, internal::ComputedFromHeightLast};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -104,7 +104,7 @@ impl Vecs {
|
||||
get_field: F,
|
||||
) -> Result<()>
|
||||
where
|
||||
F: FnOnce(&mut Self) -> &mut ComputedBlockLast<StoredU32>,
|
||||
F: FnOnce(&mut Self) -> &mut ComputedFromHeightLast<StoredU32>,
|
||||
{
|
||||
get_field(self).compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform(
|
||||
|
||||
@@ -10,13 +10,13 @@ use crate::{
|
||||
TARGET_BLOCKS_PER_YEAR,
|
||||
},
|
||||
indexes,
|
||||
internal::{ComputedBlockLast, ComputedBlockSumCum, LazyPeriodVecs},
|
||||
internal::{ComputedFromHeightLast, ComputedFromHeightSumCum, LazyFromDate},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
block_count_target: LazyPeriodVecs::new(
|
||||
block_count_target: LazyFromDate::new(
|
||||
"block_count_target",
|
||||
version,
|
||||
indexes,
|
||||
@@ -28,30 +28,30 @@ impl Vecs {
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_YEAR)),
|
||||
|_, _| Some(StoredU64::from(TARGET_BLOCKS_PER_DECADE)),
|
||||
),
|
||||
block_count: ComputedBlockSumCum::forced_import(db, "block_count", version, indexes)?,
|
||||
block_count: ComputedFromHeightSumCum::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(
|
||||
_24h_block_count: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"24h_block_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1w_block_count: ComputedBlockLast::forced_import(
|
||||
_1w_block_count: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"1w_block_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1m_block_count: ComputedBlockLast::forced_import(
|
||||
_1m_block_count: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"1m_block_count",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
_1y_block_count: ComputedBlockLast::forced_import(
|
||||
_1y_block_count: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"1y_block_count",
|
||||
version,
|
||||
|
||||
@@ -2,20 +2,20 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredU32, StoredU64};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{ComputedBlockLast, ComputedBlockSumCum, LazyPeriodVecs};
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromHeightSumCum, LazyFromDate};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub block_count_target: LazyPeriodVecs<StoredU64>,
|
||||
pub block_count: ComputedBlockSumCum<StoredU32>,
|
||||
pub block_count_target: LazyFromDate<StoredU64>,
|
||||
pub block_count: ComputedFromHeightSumCum<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>,
|
||||
pub _24h_block_count: ComputedFromHeightLast<StoredU32>,
|
||||
pub _1w_block_count: ComputedFromHeightLast<StoredU32>,
|
||||
pub _1m_block_count: ComputedFromHeightLast<StoredU32>,
|
||||
pub _1y_block_count: ComputedFromHeightLast<StoredU32>,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use brk_error::Result;
|
||||
use brk_types::StoredU32;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{StoredF32, StoredU32};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::super::TARGET_BLOCKS_PER_DAY_F32;
|
||||
@@ -9,10 +10,45 @@ use crate::{ComputeIndexes, indexes};
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Derive dateindex/period stats from raw difficulty
|
||||
self.raw.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Compute difficulty as hash rate equivalent
|
||||
self.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.blocks.difficulty,
|
||||
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Compute difficulty adjustment percentage
|
||||
self.adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_percentage_change(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
1,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// Compute epoch by dateindex
|
||||
let mut height_to_difficultyepoch_iter = indexes.height.difficultyepoch.into_iter();
|
||||
self.epoch.compute_all(starting_indexes, exit, |vec| {
|
||||
let mut height_count_iter = indexes.dateindex.height_count.into_iter();
|
||||
@@ -31,7 +67,8 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.blocks_before_next_difficulty_adjustment.compute_all(
|
||||
// Compute blocks before next adjustment
|
||||
self.blocks_before_next_adjustment.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
@@ -46,14 +83,15 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
self.days_before_next_difficulty_adjustment.compute_all(
|
||||
// Compute days before next adjustment
|
||||
self.days_before_next_adjustment.compute_all(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v| {
|
||||
v.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.blocks_before_next_difficulty_adjustment.height,
|
||||
&self.blocks_before_next_adjustment.height,
|
||||
|(h, blocks, ..)| (h, (*blocks as f32 / TARGET_BLOCKS_PER_DAY_F32).into()),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -1,26 +1,44 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
use vecdb::{Database, IterableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedBlockLast, ComputedDateLast},
|
||||
internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast,
|
||||
ComputedHeightDerivedLast,
|
||||
},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
epoch: ComputedDateLast::forced_import(db, "difficultyepoch", version, indexes)?,
|
||||
blocks_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
|
||||
raw: ComputedHeightDerivedLast::forced_import(
|
||||
db,
|
||||
"difficulty",
|
||||
indexer.vecs.blocks.difficulty.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
as_hash: ComputedFromHeightLast::forced_import(db, "difficulty_as_hash", version, indexes)?,
|
||||
adjustment: ComputedFromHeightSum::forced_import(db, "difficulty_adjustment", version, indexes)?,
|
||||
epoch: ComputedFromDateLast::forced_import(db, "difficultyepoch", version, indexes)?,
|
||||
blocks_before_next_adjustment: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"blocks_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
days_before_next_difficulty_adjustment: ComputedBlockLast::forced_import(
|
||||
days_before_next_adjustment: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"days_before_next_difficulty_adjustment",
|
||||
version + v2,
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{DifficultyEpoch, StoredF32, StoredU32};
|
||||
use brk_types::{DifficultyEpoch, StoredF32, StoredF64, StoredU32};
|
||||
|
||||
use crate::internal::{ComputedBlockLast, ComputedDateLast};
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, ComputedFromHeightSum, ComputedFromDateLast, ComputedHeightDerivedLast,
|
||||
};
|
||||
|
||||
/// Difficulty epoch metrics and countdown
|
||||
/// Difficulty metrics: raw difficulty, derived stats, adjustment, and countdown
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub epoch: ComputedDateLast<DifficultyEpoch>,
|
||||
pub blocks_before_next_difficulty_adjustment: ComputedBlockLast<StoredU32>,
|
||||
pub days_before_next_difficulty_adjustment: ComputedBlockLast<StoredF32>,
|
||||
/// Raw difficulty with dateindex/period stats - merges with indexer's raw
|
||||
pub raw: ComputedHeightDerivedLast<StoredF64>,
|
||||
pub as_hash: ComputedFromHeightLast<StoredF32>,
|
||||
pub adjustment: ComputedFromHeightSum<StoredF32>,
|
||||
pub epoch: ComputedFromDateLast<DifficultyEpoch>,
|
||||
pub blocks_before_next_adjustment: ComputedFromHeightLast<StoredU32>,
|
||||
pub days_before_next_adjustment: ComputedFromHeightLast<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedBlockLast, ComputedDateLast},
|
||||
internal::{ComputedFromHeightLast, ComputedFromDateLast},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -13,14 +13,14 @@ impl Vecs {
|
||||
let v2 = Version::TWO;
|
||||
|
||||
Ok(Self {
|
||||
epoch: ComputedDateLast::forced_import(db, "halvingepoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedBlockLast::forced_import(
|
||||
epoch: ComputedFromDateLast::forced_import(db, "halvingepoch", version, indexes)?,
|
||||
blocks_before_next_halving: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"blocks_before_next_halving",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
days_before_next_halving: ComputedBlockLast::forced_import(
|
||||
days_before_next_halving: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"days_before_next_halving",
|
||||
version + v2,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{HalvingEpoch, StoredF32, StoredU32};
|
||||
|
||||
use crate::internal::{ComputedBlockLast, ComputedDateLast};
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromDateLast};
|
||||
|
||||
/// Halving epoch metrics and countdown
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub epoch: ComputedDateLast<HalvingEpoch>,
|
||||
pub blocks_before_next_halving: ComputedBlockLast<StoredU32>,
|
||||
pub days_before_next_halving: ComputedBlockLast<StoredF32>,
|
||||
pub epoch: ComputedFromDateLast<HalvingEpoch>,
|
||||
pub blocks_before_next_halving: ComputedFromHeightLast<StoredU32>,
|
||||
pub days_before_next_halving: ComputedFromHeightLast<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -25,16 +25,15 @@ impl Vecs {
|
||||
db.set_min_len(PAGE_SIZE * 50_000_000)?;
|
||||
|
||||
let version = parent_version;
|
||||
let compute_dollars = price.is_some();
|
||||
|
||||
let count = CountVecs::forced_import(&db, version, indexes)?;
|
||||
let interval = IntervalVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let size = SizeVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let weight = WeightVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let time = TimeVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let mining = MiningVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let rewards = RewardsVecs::forced_import(&db, version, indexes, compute_dollars)?;
|
||||
let difficulty = DifficultyVecs::forced_import(&db, version, indexes)?;
|
||||
let mining = MiningVecs::forced_import(&db, version, indexes)?;
|
||||
let rewards = RewardsVecs::forced_import(&db, version, indexes, price)?;
|
||||
let difficulty = DifficultyVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let halving = HalvingVecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{CheckedSub, Height, Timestamp, Version};
|
||||
use vecdb::{Database, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::LazyBlockDistribution};
|
||||
use crate::{indexes, internal::LazyFromHeightDistribution};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -13,7 +13,7 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let interval = LazyBlockDistribution::forced_import_with_init(
|
||||
let interval = LazyFromHeightDistribution::forced_import_with_init(
|
||||
db,
|
||||
"block_interval",
|
||||
version,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Timestamp;
|
||||
|
||||
use crate::internal::LazyBlockDistribution;
|
||||
use crate::internal::LazyFromHeightDistribution;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
#[traversable(flatten)]
|
||||
pub interval: LazyBlockDistribution<Timestamp>,
|
||||
pub interval: LazyFromHeightDistribution<Timestamp>,
|
||||
}
|
||||
|
||||
@@ -1,47 +1,27 @@
|
||||
use brk_error::Result;
|
||||
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::super::{ONE_TERA_HASH, TARGET_BLOCKS_PER_DAY_F64, count, difficulty, rewards};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
count_vecs: &count::Vecs,
|
||||
difficulty_vecs: &difficulty::Vecs,
|
||||
rewards_vecs: &rewards::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.difficulty.derive_from(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
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.blocks.difficulty,
|
||||
|(i, v, ..)| (i, StoredF32::from(*v * multiplier)),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.hash_rate
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&count_vecs._24h_block_count.height,
|
||||
&self.difficulty_as_hash.height,
|
||||
&difficulty_vecs.as_hash.height,
|
||||
|(i, block_count_sum, difficulty_as_hash, ..)| {
|
||||
(
|
||||
i,
|
||||
@@ -100,17 +80,6 @@ impl Vecs {
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.difficulty_adjustment
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_percentage_change(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.blocks.difficulty,
|
||||
1,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.hash_price_ths
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
|
||||
@@ -1,130 +1,108 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::Version;
|
||||
use vecdb::{Database, IterableCloneableVec};
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedBlockLast, ComputedBlockSum, ComputedDateLast, ComputedDerivedBlockLast},
|
||||
internal::{ComputedFromHeightLast, ComputedFromDateLast},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v4 = Version::new(4);
|
||||
let v5 = Version::new(5);
|
||||
|
||||
Ok(Self {
|
||||
hash_rate: ComputedBlockLast::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
hash_rate_1w_sma: ComputedDateLast::forced_import(
|
||||
hash_rate: ComputedFromHeightLast::forced_import(db, "hash_rate", version + v5, indexes)?,
|
||||
hash_rate_1w_sma: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_1w_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_1m_sma: ComputedDateLast::forced_import(
|
||||
hash_rate_1m_sma: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_1m_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_2m_sma: ComputedDateLast::forced_import(
|
||||
hash_rate_2m_sma: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_2m_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_rate_1y_sma: ComputedDateLast::forced_import(
|
||||
hash_rate_1y_sma: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"hash_rate_1y_sma",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_ths: ComputedBlockLast::forced_import(
|
||||
hash_price_ths: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_price_ths",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_ths_min: ComputedBlockLast::forced_import(
|
||||
hash_price_ths_min: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_price_ths_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_phs: ComputedBlockLast::forced_import(
|
||||
hash_price_phs: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_price_phs",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_phs_min: ComputedBlockLast::forced_import(
|
||||
hash_price_phs_min: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_price_phs_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_price_rebound: ComputedBlockLast::forced_import(
|
||||
hash_price_rebound: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_price_rebound",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_ths: ComputedBlockLast::forced_import(
|
||||
hash_value_ths: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_value_ths",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_ths_min: ComputedBlockLast::forced_import(
|
||||
hash_value_ths_min: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_value_ths_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_phs: ComputedBlockLast::forced_import(
|
||||
hash_value_phs: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_value_phs",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_phs_min: ComputedBlockLast::forced_import(
|
||||
hash_value_phs_min: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_value_phs_min",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
hash_value_rebound: ComputedBlockLast::forced_import(
|
||||
hash_value_rebound: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
"hash_value_rebound",
|
||||
version + v4,
|
||||
indexes,
|
||||
)?,
|
||||
// Derived from external indexer data - no height storage needed
|
||||
difficulty: ComputedDerivedBlockLast::forced_import(
|
||||
db,
|
||||
"difficulty",
|
||||
indexer.vecs.blocks.difficulty.boxed_clone(),
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
difficulty_as_hash: ComputedBlockLast::forced_import(
|
||||
db,
|
||||
"difficulty_as_hash",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
difficulty_adjustment: ComputedBlockSum::forced_import(
|
||||
db,
|
||||
"difficulty_adjustment",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredF32, StoredF64};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedBlockLast, ComputedBlockSum, ComputedDateLast, ComputedDerivedBlockLast,
|
||||
};
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromDateLast};
|
||||
|
||||
/// Mining-related metrics: hash rate, hash price, hash value, difficulty
|
||||
/// Mining-related metrics: hash rate, hash price, hash value
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
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 difficulty: ComputedDerivedBlockLast<StoredF64>,
|
||||
pub difficulty_as_hash: ComputedBlockLast<StoredF32>,
|
||||
pub difficulty_adjustment: ComputedBlockSum<StoredF32>,
|
||||
pub hash_rate: ComputedFromHeightLast<StoredF64>,
|
||||
pub hash_rate_1w_sma: ComputedFromDateLast<StoredF64>,
|
||||
pub hash_rate_1m_sma: ComputedFromDateLast<StoredF32>,
|
||||
pub hash_rate_2m_sma: ComputedFromDateLast<StoredF32>,
|
||||
pub hash_rate_1y_sma: ComputedFromDateLast<StoredF32>,
|
||||
pub hash_price_ths: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_price_ths_min: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_price_phs: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_price_phs_min: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_price_rebound: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_value_ths: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_value_ths_min: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_value_phs: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_value_phs_min: ComputedFromHeightLast<StoredF32>,
|
||||
pub hash_value_rebound: ComputedFromHeightLast<StoredF32>,
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ pub struct Vecs {
|
||||
|
||||
pub count: CountVecs,
|
||||
pub interval: IntervalVecs,
|
||||
#[traversable(flatten)]
|
||||
pub size: SizeVecs,
|
||||
#[traversable(flatten)]
|
||||
pub weight: WeightVecs,
|
||||
pub time: TimeVecs,
|
||||
pub mining: MiningVecs,
|
||||
|
||||
@@ -5,10 +5,9 @@ use vecdb::{Exit, IterableVec, TypedVecIterator, VecIndex};
|
||||
|
||||
use super::super::count;
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, price, transactions};
|
||||
use crate::{ComputeIndexes, indexes, transactions};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
@@ -16,11 +15,10 @@ impl Vecs {
|
||||
count_vecs: &count::Vecs,
|
||||
transactions_fees: &transactions::FeesVecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.coinbase
|
||||
.compute_all(indexes, price, starting_indexes, exit, |vec| {
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
let mut txindex_to_first_txoutindex_iter =
|
||||
indexer.vecs.transactions.first_txoutindex.iter()?;
|
||||
let mut txindex_to_output_count_iter =
|
||||
@@ -84,7 +82,7 @@ impl Vecs {
|
||||
}
|
||||
|
||||
self.subsidy
|
||||
.compute_all(indexes, price, starting_indexes, exit, |vec| {
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.coinbase.sats.height,
|
||||
@@ -104,7 +102,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.unclaimed_rewards
|
||||
.compute_all(indexes, price, starting_indexes, exit, |vec| {
|
||||
.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
&self.subsidy.sats.height,
|
||||
|
||||
@@ -5,7 +5,8 @@ use vecdb::{Database, EagerVec, ImportableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedDateLast, ValueBlockFull, ValueBlockHeight, ValueBlockSumCum},
|
||||
internal::{ComputedFromDateLast, ValueFromHeightFull, ValueHeight, ValueFromHeightSumCum},
|
||||
price,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -13,41 +14,31 @@ impl Vecs {
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
compute_dollars: bool,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let compute_dollars = price.is_some();
|
||||
|
||||
Ok(Self {
|
||||
_24h_coinbase_sum: ValueBlockHeight::forced_import(
|
||||
_24h_coinbase_sum: ValueHeight::forced_import(
|
||||
db,
|
||||
"24h_coinbase_sum",
|
||||
version,
|
||||
compute_dollars,
|
||||
)?,
|
||||
coinbase: ValueBlockFull::forced_import(
|
||||
db,
|
||||
"coinbase",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?,
|
||||
subsidy: ValueBlockFull::forced_import(
|
||||
db,
|
||||
"subsidy",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
)?,
|
||||
unclaimed_rewards: ValueBlockSumCum::forced_import(
|
||||
coinbase: ValueFromHeightFull::forced_import(db, "coinbase", version, indexes, price)?,
|
||||
subsidy: ValueFromHeightFull::forced_import(db, "subsidy", version, indexes, price)?,
|
||||
unclaimed_rewards: ValueFromHeightSumCum::forced_import(
|
||||
db,
|
||||
"unclaimed_rewards",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
price,
|
||||
)?,
|
||||
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)
|
||||
ComputedFromDateLast::forced_import(db, "subsidy_usd_1y_sma", version, indexes)
|
||||
})
|
||||
.transpose()?,
|
||||
})
|
||||
|
||||
@@ -2,16 +2,16 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{DateIndex, Dollars, StoredF32};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{ComputedDateLast, ValueBlockFull, ValueBlockHeight, ValueBlockSumCum};
|
||||
use crate::internal::{ComputedFromDateLast, ValueFromHeightFull, ValueHeight, ValueFromHeightSumCum};
|
||||
|
||||
/// Coinbase/subsidy/rewards metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub _24h_coinbase_sum: ValueBlockHeight,
|
||||
pub coinbase: ValueBlockFull,
|
||||
pub subsidy: ValueBlockFull,
|
||||
pub unclaimed_rewards: ValueBlockSumCum,
|
||||
pub _24h_coinbase_sum: ValueHeight,
|
||||
pub coinbase: ValueFromHeightFull,
|
||||
pub subsidy: ValueFromHeightFull,
|
||||
pub unclaimed_rewards: ValueFromHeightSumCum,
|
||||
pub fee_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
|
||||
pub subsidy_dominance: EagerVec<PcoVec<DateIndex, StoredF32>>,
|
||||
pub subsidy_usd_1y_sma: Option<ComputedDateLast<Dollars>>,
|
||||
pub subsidy_usd_1y_sma: Option<ComputedFromDateLast<Dollars>>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Height, StoredU64, Version};
|
||||
use vecdb::{Database, IterableCloneableVec, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::{ComputedDerivedBlockFull, LazyBlockFullHeight}};
|
||||
use crate::{indexes, internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull}};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -14,7 +14,7 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
vbytes: LazyBlockFullHeight::forced_import_with_init(
|
||||
vbytes: LazyComputedFromHeightFull::forced_import_with_init(
|
||||
db,
|
||||
"block_vbytes",
|
||||
version,
|
||||
@@ -26,7 +26,7 @@ impl Vecs {
|
||||
.map(|w| StoredU64::from(w.to_vbytes_floor()))
|
||||
},
|
||||
)?,
|
||||
size: ComputedDerivedBlockFull::forced_import(
|
||||
size: ComputedHeightDerivedFull::forced_import(
|
||||
db,
|
||||
"block_size",
|
||||
indexer.vecs.blocks.total_size.boxed_clone(),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredU64, Weight};
|
||||
|
||||
use crate::internal::{ComputedDerivedBlockFull, LazyBlockFullHeight};
|
||||
use crate::internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub vbytes: LazyBlockFullHeight<StoredU64, Weight>,
|
||||
pub size: ComputedDerivedBlockFull<StoredU64>,
|
||||
pub vbytes: LazyComputedFromHeightFull<StoredU64, Weight>,
|
||||
pub size: ComputedHeightDerivedFull<StoredU64>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{Date, Height, Version};
|
||||
use vecdb::{Database, EagerVec, ImportableVec, IterableCloneableVec, LazyVecFrom1, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedDerivedBlockFirst};
|
||||
use crate::{indexes, internal::ComputedHeightDerivedFirst};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -31,7 +31,7 @@ impl Vecs {
|
||||
|height: Height, timestamp_iter| timestamp_iter.get(height).map(Date::from),
|
||||
),
|
||||
timestamp_fixed: height_to_timestamp_fixed,
|
||||
timestamp: ComputedDerivedBlockFirst::forced_import(
|
||||
timestamp: ComputedHeightDerivedFirst::forced_import(
|
||||
db,
|
||||
"timestamp",
|
||||
indexer.vecs.blocks.timestamp.boxed_clone(),
|
||||
|
||||
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Date, Height, Timestamp};
|
||||
use vecdb::{EagerVec, LazyVecFrom1, PcoVec};
|
||||
|
||||
use crate::internal::ComputedDerivedBlockFirst;
|
||||
use crate::internal::ComputedHeightDerivedFirst;
|
||||
|
||||
/// Timestamp and date metrics for blocks
|
||||
#[derive(Clone, Traversable)]
|
||||
@@ -10,5 +10,5 @@ pub struct Vecs {
|
||||
pub date: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
pub date_fixed: LazyVecFrom1<Height, Date, Height, Timestamp>,
|
||||
pub timestamp_fixed: EagerVec<PcoVec<Height, Timestamp>>,
|
||||
pub timestamp: ComputedDerivedBlockFirst<Timestamp>,
|
||||
pub timestamp: ComputedHeightDerivedFirst<Timestamp>,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use vecdb::{Database, IterableCloneableVec};
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedDerivedBlockFull, LazyBlockFull, WeightToFullness},
|
||||
internal::{ComputedHeightDerivedFull, LazyFromHeightFull, WeightToFullness},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -16,7 +16,7 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let weight = ComputedDerivedBlockFull::forced_import(
|
||||
let weight = ComputedHeightDerivedFull::forced_import(
|
||||
db,
|
||||
"block_weight",
|
||||
indexer.vecs.blocks.weight.boxed_clone(),
|
||||
@@ -24,7 +24,7 @@ impl Vecs {
|
||||
indexes,
|
||||
)?;
|
||||
|
||||
let fullness = LazyBlockFull::from_derived::<WeightToFullness>(
|
||||
let fullness = LazyFromHeightFull::from_derived::<WeightToFullness>(
|
||||
"block_fullness",
|
||||
version,
|
||||
indexer.vecs.blocks.weight.boxed_clone(),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredF32, Weight};
|
||||
|
||||
use crate::internal::{ComputedDerivedBlockFull, LazyBlockFull};
|
||||
use crate::internal::{ComputedHeightDerivedFull, LazyFromHeightFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub weight: ComputedDerivedBlockFull<Weight>,
|
||||
pub fullness: LazyBlockFull<StoredF32, Weight>,
|
||||
pub weight: ComputedHeightDerivedFull<Weight>,
|
||||
pub fullness: LazyFromHeightFull<StoredF32, Weight>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user