global: snapshot

This commit is contained in:
nym21
2025-05-27 15:19:53 +02:00
parent 34919aba05
commit 93e01902e3
84 changed files with 2445 additions and 1394 deletions

View File

@@ -5,11 +5,11 @@
use std::path::{Path, PathBuf};
use brk_core::Version;
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
pub use brk_parser::rpc;
use brk_vec::{AnyCollectableVec, Compressed, Computation, Version};
use brk_vec::{AnyCollectableVec, Compressed, Computation};
mod states;
mod stores;

View File

@@ -2,7 +2,6 @@ use brk_core::Dollars;
use super::{RealizedState, SupplyState};
// Vecs ? probably
#[derive(Debug, Default, Clone)]
pub struct CohortState {
pub supply: SupplyState,
@@ -11,6 +10,12 @@ pub struct CohortState {
}
impl CohortState {
pub fn reset_single_iteration_values(&mut self) {
if let Some(realized) = self.realized.as_mut() {
realized.reset_single_iteration_values();
}
}
pub fn increment(&mut self, supply_state: &SupplyState, price: Option<Dollars>) {
self.supply += supply_state;
if let Some(realized) = self.realized.as_mut() {
@@ -25,7 +30,28 @@ impl CohortState {
}
}
pub fn send(&mut self, supply_state: &SupplyState, price: Option<Dollars>) {}
pub fn receive(&mut self, supply_state: &SupplyState, price: Option<Dollars>) {
self.supply += supply_state;
if let Some(realized) = self.realized.as_mut() {
realized.receive(supply_state, price.unwrap());
}
}
pub fn receive(&mut self, supply_state: &SupplyState, price: Option<Dollars>) {}
pub fn send(
&mut self,
supply_state: &SupplyState,
current_price: Option<Dollars>,
prev_price: Option<Dollars>,
older_than_hour: bool,
) {
self.supply -= supply_state;
if let Some(realized) = self.realized.as_mut() {
realized.send(
supply_state,
current_price.unwrap(),
prev_price.unwrap(),
older_than_hour,
);
}
}
}

View File

@@ -107,31 +107,31 @@ impl<T> OutputsBySize<T> {
pub fn get_mut(&mut self, group: usize) -> &mut T {
if group == 0 {
&mut self._0sat
} else if group == 10 {
} else if group == 1 {
&mut self.from_1sat_to_10sats
} else if group == 100 {
} else if group == 10 {
&mut self.from_10sats_to_100sats
} else if group == 1_000 {
} else if group == 100 {
&mut self.from_100sats_to_1_000sats
} else if group == 10_000 {
} else if group == 1_000 {
&mut self.from_1_000sats_to_10_000sats
} else if group == 100_000 {
} else if group == 10_000 {
&mut self.from_10_000sats_to_100_000sats
} else if group == 1_000_000 {
} else if group == 100_000 {
&mut self.from_100_000sats_to_1_000_000sats
} else if group == 10_000_000 {
} else if group == 1_000_000 {
&mut self.from_1_000_000sats_to_10_000_000sats
} else if group == 1_00_000_000 {
} else if group == 10_000_000 {
&mut self.from_10_000_000sats_to_1btc
} else if group == 10_00_000_000 {
} else if group == 1_00_000_000 {
&mut self.from_1btc_to_10btc
} else if group == 100_00_000_000 {
} else if group == 10_00_000_000 {
&mut self.from_10btc_to_100btc
} else if group == 1_000_00_000_000 {
} else if group == 100_00_000_000 {
&mut self.from_100btc_to_1_000btc
} else if group == 10_000_00_000_000 {
} else if group == 1_000_00_000_000 {
&mut self.from_1_000btc_to_10_000btc
} else if group == 100_000_00_000_000 {
} else if group == 10_000_00_000_000 {
&mut self.from_10_000btc_to_100_000btc
} else {
&mut self.from_100_000btc

View File

@@ -24,7 +24,7 @@ impl<T> OutputsByType<T> {
OutputType::P2A => &self.spendable.p2a,
OutputType::Empty => &self.spendable.empty,
OutputType::Unknown => &self.spendable.unknown,
OutputType::OpReturn => &self.unspendable.op_return,
OutputType::OpReturn => &self.unspendable.opreturn,
}
}
@@ -41,7 +41,7 @@ impl<T> OutputsByType<T> {
OutputType::P2A => &mut self.spendable.p2a,
OutputType::Unknown => &mut self.spendable.unknown,
OutputType::Empty => &mut self.spendable.empty,
OutputType::OpReturn => &mut self.unspendable.op_return,
OutputType::OpReturn => &mut self.unspendable.opreturn,
}
}

View File

@@ -2,12 +2,12 @@ use std::ops::{Add, AddAssign};
#[derive(Default, Clone)]
pub struct OutputsByUnspendableType<T> {
pub op_return: T,
pub opreturn: T,
}
impl<T> OutputsByUnspendableType<T> {
pub fn as_vec(&self) -> [&T; 1] {
[&self.op_return]
[&self.opreturn]
}
}
@@ -18,7 +18,7 @@ where
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
op_return: self.op_return + rhs.op_return,
opreturn: self.opreturn + rhs.opreturn,
}
}
}
@@ -28,6 +28,6 @@ where
T: AddAssign,
{
fn add_assign(&mut self, rhs: Self) {
self.op_return += rhs.op_return;
self.opreturn += rhs.opreturn;
}
}

View File

@@ -2,7 +2,7 @@ use brk_vec::StoredIndex;
use rayon::prelude::*;
use std::{collections::BTreeMap, ops::ControlFlow};
use brk_core::{Dollars, HalvingEpoch, Height, Timestamp};
use brk_core::{CheckedSub, Dollars, HalvingEpoch, Height, Timestamp};
mod by_epoch;
mod by_from;
@@ -133,16 +133,27 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
.collect::<Vec<_>>();
let last_timestamp = chain_state.last().unwrap().timestamp;
let current_price = chain_state.last().unwrap().price;
height_to_sent.into_iter().for_each(|(height, sent)| {
let block_state = chain_state.get(height.unwrap_to_usize()).unwrap();
let price = block_state.price;
let prev_price = block_state.price;
let days_old = block_state
.timestamp
.difference_in_days_between(last_timestamp);
self.all.1.state.decrement(&sent.spendable_supply, price);
let older_than_hour =
jiff::Timestamp::from(last_timestamp.checked_sub(block_state.timestamp).unwrap())
.as_second()
>= 60 * 60;
self.all.1.state.send(
&sent.spendable_supply,
current_price,
prev_price,
older_than_hour,
);
time_based_vecs
.iter_mut()
@@ -154,25 +165,32 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
_ => unreachable!(),
})
.for_each(|(_, vecs)| {
vecs.state.decrement(&sent.spendable_supply, price);
vecs.state.send(
&sent.spendable_supply,
current_price,
prev_price,
older_than_hour,
);
});
sent.by_type.spendable.as_typed_vec().into_iter().for_each(
|(output_type, supply_state)| {
self.by_type
.get_mut(output_type)
.1
.state
.decrement(supply_state, price)
self.by_type.get_mut(output_type).1.state.send(
supply_state,
current_price,
prev_price,
older_than_hour,
)
},
);
sent.by_size.into_iter().for_each(|(group, supply_state)| {
self.by_size
.get_mut(group)
.1
.state
.decrement(&supply_state, price);
self.by_size.get_mut(group).1.state.send(
&supply_state,
current_price,
prev_price,
older_than_hour,
);
});
});
}
@@ -189,7 +207,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
.into_iter()
.chain(self.by_up_to.as_mut_vec().map(|(_, v)| v))
.for_each(|v| {
v.state.increment(&supply_state, price);
v.state.receive(&supply_state, price);
});
self.by_type
@@ -200,8 +218,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
OutputFilter::Type(output_type) => *output_type,
_ => unreachable!(),
};
vecs.state
.increment(received.by_type.get(output_type), price)
vecs.state.receive(received.by_type.get(output_type), price)
});
received
@@ -212,7 +229,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
.get_mut(group)
.1
.state
.increment(&supply_state, price);
.receive(&supply_state, price);
});
}
}

View File

@@ -1,49 +1,98 @@
use std::cmp::Ordering;
use brk_core::{Bitcoin, CheckedSub, Dollars};
use super::SupplyState;
#[derive(Debug, Default, Clone)]
pub struct RealizedState {
pub realized_cap: Dollars,
// pub realized_profit: Dollars, // sent price vs now price
// pub realized_loss: Dollars, // sent price vs now price
// pub value_created: Dollars, // supply * price now
// pub adjusted_value_created: Dollars, // supply - up to 1 hour supply * price now
// pub value_destroyed: Dollars, // supply * price then
// pub adjusted_value_destroyed: Dollars, // supply - up to 1 hour supply * price then
pub cap: Dollars,
pub profit: Dollars,
pub loss: Dollars,
pub value_created: Dollars,
pub adj_value_created: Dollars,
pub value_destroyed: Dollars,
pub adj_value_destroyed: Dollars,
}
impl RealizedState {
pub const NAN: Self = Self {
realized_cap: Dollars::NAN,
// realized_profit: Dollars::NAN,
// realized_loss: Dollars::NAN,
// value_created: Dollars::NAN,
// adjusted_value_created: Dollars::NAN,
// value_destroyed: Dollars::NAN,
// adjusted_value_destroyed: Dollars::NAN,
cap: Dollars::NAN,
profit: Dollars::NAN,
loss: Dollars::NAN,
value_created: Dollars::NAN,
adj_value_created: Dollars::NAN,
value_destroyed: Dollars::NAN,
adj_value_destroyed: Dollars::NAN,
};
pub fn increment(&mut self, supply_state: &SupplyState, price: Dollars) {
if supply_state.value.is_not_zero() {
if self.realized_cap == Dollars::NAN {
self.realized_cap = Dollars::ZERO;
// self.realized_profit = Dollars::ZERO;
// self.realized_loss = Dollars::ZERO;
// self.value_created = Dollars::ZERO;
// self.adjusted_value_created = Dollars::ZERO;
// self.value_destroyed = Dollars::ZERO;
// self.adjusted_value_destroyed = Dollars::ZERO;
}
self.realized_cap += price * Bitcoin::from(supply_state.value);
pub fn reset_single_iteration_values(&mut self) {
if self.cap != Dollars::NAN {
self.profit = Dollars::ZERO;
self.loss = Dollars::ZERO;
self.value_created = Dollars::ZERO;
self.adj_value_created = Dollars::ZERO;
self.value_destroyed = Dollars::ZERO;
self.adj_value_destroyed = Dollars::ZERO;
}
}
pub fn increment(&mut self, supply_state: &SupplyState, price: Dollars) {
if supply_state.value.is_zero() {
return;
}
if self.cap == Dollars::NAN {
self.cap = Dollars::ZERO;
self.profit = Dollars::ZERO;
self.loss = Dollars::ZERO;
self.value_created = Dollars::ZERO;
self.adj_value_created = Dollars::ZERO;
self.value_destroyed = Dollars::ZERO;
self.adj_value_destroyed = Dollars::ZERO;
}
let value = price * Bitcoin::from(supply_state.value);
self.cap += value;
}
pub fn decrement(&mut self, supply_state: &SupplyState, price: Dollars) {
self.realized_cap = self
.realized_cap
.checked_sub(price * Bitcoin::from(supply_state.value))
.unwrap();
let value = price * Bitcoin::from(supply_state.value);
self.cap = self.cap.checked_sub(value).unwrap();
}
pub fn receive(&mut self, supply_state: &SupplyState, current_price: Dollars) {
self.increment(supply_state, current_price);
}
pub fn send(
&mut self,
supply_state: &SupplyState,
current_price: Dollars,
prev_price: Dollars,
older_than_hour: bool,
) {
let current_value = current_price * Bitcoin::from(supply_state.value);
let prev_value = prev_price * Bitcoin::from(supply_state.value);
self.value_created += current_value;
self.value_destroyed += prev_value;
if older_than_hour {
self.adj_value_created += current_value;
self.adj_value_destroyed += prev_value;
}
match current_price.cmp(&prev_price) {
Ordering::Greater => {
self.profit += current_value.checked_sub(prev_value).unwrap();
}
Ordering::Less => {
self.loss += prev_value.checked_sub(current_value).unwrap();
}
Ordering::Equal => {}
}
self.decrement(supply_state, prev_price);
}
}

View File

@@ -1,6 +1,6 @@
use std::path::Path;
use brk_vec::Version;
use brk_core::Version;
use fjall::TransactionalKeyspace;
const _VERSION: Version = Version::ZERO;

View File

@@ -2,12 +2,11 @@ use std::{fs, path::Path};
use brk_core::{
CheckedSub, DifficultyEpoch, HalvingEpoch, Height, StoredU32, StoredU64, StoredUsize,
Timestamp, Weight,
Timestamp, Version, Weight,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::bitcoin;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, Computation, EagerVec, Version};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, Computation, EagerVec};
use super::{
Indexes,
@@ -71,7 +70,9 @@ impl Vecs {
true,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
indexes_to_block_weight: ComputedVecsFromHeight::forced_import(
path,
@@ -79,7 +80,9 @@ impl Vecs {
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
path,
@@ -87,7 +90,9 @@ impl Vecs {
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
height_to_vbytes: EagerVec::forced_import(
path,
@@ -101,7 +106,9 @@ impl Vecs {
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
difficultyepoch_to_timestamp: EagerVec::forced_import(
path,

View File

@@ -1,9 +1,9 @@
use std::{fs, path::Path};
use brk_core::StoredU8;
use brk_core::{StoredU8, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyVec, Compressed, Computation, Version};
use brk_vec::{AnyCollectableVec, AnyVec, Compressed, Computation};
use super::{
Indexes,

View File

@@ -2,12 +2,12 @@ use std::{fs, path::Path};
use brk_core::{
Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex,
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, WeekIndex, YearIndex,
OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, Computation, EagerVec, Version};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, Computation, EagerVec};
use super::{
Indexes,

View File

@@ -1,11 +1,8 @@
use std::path::Path;
use brk_core::{CheckedSub, StoredUsize};
use brk_core::{CheckedSub, Result, StoredUsize, Version};
use brk_exit::Exit;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, Compressed, EagerVec, Result, StoredIndex, StoredType,
Version,
};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, EagerVec, StoredIndex, StoredType};
use color_eyre::eyre::ContextCompat;
use crate::utils::get_percentile;
@@ -29,7 +26,7 @@ where
pub _10p: Option<Box<EagerVec<I, T>>>,
pub min: Option<Box<EagerVec<I, T>>>,
pub last: Option<Box<EagerVec<I, T>>>,
pub total: Option<Box<EagerVec<I, T>>>,
pub cumulative: Option<Box<EagerVec<I, T>>>,
}
const VERSION: Version = Version::ZERO;
@@ -141,11 +138,11 @@ where
.unwrap(),
)
}),
total: options.total.then(|| {
cumulative: options.cumulative.then(|| {
Box::new(
EagerVec::forced_import(
path,
&prefix("total"),
&prefix("cumulative"),
version + VERSION + Version::ZERO,
compressed,
)
@@ -207,20 +204,20 @@ where
source: &impl AnyIterableVec<I, T>,
exit: &Exit,
) -> Result<()> {
if self.total.is_none() {
if self.cumulative.is_none() {
return Ok(());
};
let index = self.starting_index(max_from);
let total_vec = self.total.as_mut().unwrap();
let cumulative_vec = self.cumulative.as_mut().unwrap();
let mut total = index.decremented().map_or(T::from(0_usize), |index| {
total_vec.iter().unwrap_get_inner(index)
let mut cumulative = index.decremented().map_or(T::from(0_usize), |index| {
cumulative_vec.iter().unwrap_get_inner(index)
});
source.iter_at(index).try_for_each(|(i, v)| -> Result<()> {
total = total.clone() + v.into_inner();
total_vec.forced_push_at(i, total.clone(), exit)
cumulative = cumulative.clone() + v.into_inner();
cumulative_vec.forced_push_at(i, cumulative.clone(), exit)
})?;
self.safe_flush(exit)?;
@@ -248,11 +245,11 @@ where
let mut count_indexes_iter = count_indexes.iter();
let mut source_iter = source.iter();
let total_vec = self.total.as_mut();
let cumulative_vec = self.cumulative.as_mut();
let mut total = total_vec.map(|total_vec| {
let mut cumulative = cumulative_vec.map(|cumulative_vec| {
index.decremented().map_or(T::from(0_usize), |index| {
total_vec.iter().unwrap_get_inner(index)
cumulative_vec.iter().unwrap_get_inner(index)
})
});
@@ -286,8 +283,9 @@ where
last.forced_push_at(index, v, exit)?;
}
let needs_sum_or_total = self.sum.is_some() || self.total.is_some();
let needs_average_sum_or_total = needs_sum_or_total || self.average.is_some();
let needs_sum_or_cumulative = self.sum.is_some() || self.cumulative.is_some();
let needs_average_sum_or_cumulative =
needs_sum_or_cumulative || self.average.is_some();
let needs_sorted = self.max.is_some()
|| self._90p.is_some()
|| self._75p.is_some()
@@ -295,7 +293,7 @@ where
|| self._25p.is_some()
|| self._10p.is_some()
|| self.min.is_some();
let needs_values = needs_sorted || needs_average_sum_or_total;
let needs_values = needs_sorted || needs_average_sum_or_cumulative;
if needs_values {
source_iter.set(first_index);
@@ -356,7 +354,7 @@ where
}
}
if needs_average_sum_or_total {
if needs_average_sum_or_cumulative {
let len = values.len();
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
@@ -365,15 +363,15 @@ where
average.forced_push_at(i, avg, exit)?;
}
if needs_sum_or_total {
if needs_sum_or_cumulative {
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
if let Some(total_vec) = self.total.as_mut() {
let t = total.as_ref().unwrap().clone() + sum;
total.replace(t.clone());
total_vec.forced_push_at(i, t, exit)?;
if let Some(cumulative_vec) = self.cumulative.as_mut() {
let t = cumulative.as_ref().unwrap().clone() + sum;
cumulative.replace(t.clone());
cumulative_vec.forced_push_at(i, t, exit)?;
}
}
}
@@ -423,9 +421,9 @@ where
let mut source_average_iter = source.average.as_ref().map(|f| f.iter());
let mut source_sum_iter = source.sum.as_ref().map(|f| f.iter());
let mut total = self.total.as_mut().map(|total_vec| {
let mut cumulative = self.cumulative.as_mut().map(|cumulative_vec| {
index.decremented().map_or(T::from(0_usize), |index| {
total_vec.iter().unwrap_get_inner(index)
cumulative_vec.iter().unwrap_get_inner(index)
})
});
@@ -457,10 +455,11 @@ where
last.forced_push_at(index, v, exit)?;
}
let needs_sum_or_total = self.sum.is_some() || self.total.is_some();
let needs_average_sum_or_total = needs_sum_or_total || self.average.is_some();
let needs_sum_or_cumulative = self.sum.is_some() || self.cumulative.is_some();
let needs_average_sum_or_cumulative =
needs_sum_or_cumulative || self.average.is_some();
let needs_sorted = self.max.is_some() || self.min.is_some();
let needs_values = needs_sorted || needs_average_sum_or_total;
let needs_values = needs_sorted || needs_average_sum_or_cumulative;
if needs_values {
if needs_sorted {
@@ -487,7 +486,7 @@ where
}
}
if needs_average_sum_or_total {
if needs_average_sum_or_cumulative {
if let Some(average) = self.average.as_mut() {
let source_average_iter = source_average_iter.as_mut().unwrap();
source_average_iter.set(first_index);
@@ -497,14 +496,14 @@ where
.collect::<Vec<_>>();
let len = values.len();
let total = values.into_iter().fold(T::from(0), |a, b| a + b);
// TODO: Multiply by count then divide by total
let cumulative = values.into_iter().fold(T::from(0), |a, b| a + b);
// TODO: Multiply by count then divide by cumulative
// Right now it's not 100% accurate as there could be more or less elements in the lower timeframe (28 days vs 31 days in a month for example)
let avg = total / len;
let avg = cumulative / len;
average.forced_push_at(i, avg, exit)?;
}
if needs_sum_or_total {
if needs_sum_or_cumulative {
let source_sum_iter = source_sum_iter.as_mut().unwrap();
source_sum_iter.set(first_index);
let values = source_sum_iter
@@ -518,10 +517,10 @@ where
sum_vec.forced_push_at(i, sum.clone(), exit)?;
}
if let Some(total_vec) = self.total.as_mut() {
let t = total.as_ref().unwrap().clone() + sum;
total.replace(t.clone());
total_vec.forced_push_at(i, t, exit)?;
if let Some(cumulative_vec) = self.cumulative.as_mut() {
let t = cumulative.as_ref().unwrap().clone() + sum;
cumulative.replace(t.clone());
cumulative_vec.forced_push_at(i, t, exit)?;
}
}
}
@@ -581,8 +580,8 @@ where
self.last.as_ref().unwrap()
}
#[allow(unused)]
pub fn unwrap_total(&self) -> &EagerVec<I, T> {
self.total.as_ref().unwrap()
pub fn unwrap_cumulative(&self) -> &EagerVec<I, T> {
self.cumulative.as_ref().unwrap()
}
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
@@ -609,8 +608,8 @@ where
if let Some(sum) = self.sum.as_ref() {
v.push(sum.as_ref());
}
if let Some(total) = self.total.as_ref() {
v.push(total.as_ref());
if let Some(cumulative) = self.cumulative.as_ref() {
v.push(cumulative.as_ref());
}
if let Some(_90p) = self._90p.as_ref() {
v.push(_90p.as_ref());
@@ -650,8 +649,8 @@ where
if let Some(sum) = self.sum.as_mut() {
sum.safe_flush(exit)?;
}
if let Some(total) = self.total.as_mut() {
total.safe_flush(exit)?;
if let Some(cumulative) = self.cumulative.as_mut() {
cumulative.safe_flush(exit)?;
}
if let Some(_90p) = self._90p.as_mut() {
_90p.safe_flush(exit)?;
@@ -691,8 +690,8 @@ where
if let Some(sum) = self.sum.as_mut() {
sum.validate_computed_version_or_reset_file(Version::ZERO + version)?;
}
if let Some(total) = self.total.as_mut() {
total.validate_computed_version_or_reset_file(Version::ZERO + version)?;
if let Some(cumulative) = self.cumulative.as_mut() {
cumulative.validate_computed_version_or_reset_file(Version::ZERO + version)?;
}
if let Some(_90p) = self._90p.as_mut() {
_90p.validate_computed_version_or_reset_file(Version::ZERO + version)?;
@@ -724,7 +723,7 @@ pub struct StorableVecGeneatorOptions {
min: bool,
first: bool,
last: bool,
total: bool,
cumulative: bool,
}
impl StorableVecGeneatorOptions {
@@ -788,8 +787,8 @@ impl StorableVecGeneatorOptions {
self
}
pub fn add_total(mut self) -> Self {
self.total = true;
pub fn add_cumulative(mut self) -> Self {
self.cumulative = true;
self
}
@@ -848,8 +847,8 @@ impl StorableVecGeneatorOptions {
}
#[allow(unused)]
pub fn rm_total(mut self) -> Self {
self.total = false;
pub fn rm_cumulative(mut self) -> Self {
self.cumulative = false;
self
}
@@ -890,7 +889,7 @@ impl StorableVecGeneatorOptions {
self.min,
self.first,
self.last,
self.total,
self.cumulative,
]
.iter()
.filter(|b| **b)
@@ -900,7 +899,7 @@ impl StorableVecGeneatorOptions {
pub fn copy_self_extra(&self) -> Self {
Self {
total: self.total,
cumulative: self.cumulative,
..Self::default()
}
}

View File

@@ -1,9 +1,11 @@
use std::path::Path;
use brk_core::{DateIndex, DecadeIndex, MonthIndex, QuarterIndex, WeekIndex, YearIndex};
use brk_core::{
DateIndex, DecadeIndex, MonthIndex, QuarterIndex, Result, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, EagerVec, Result, Version};
use brk_vec::{AnyCollectableVec, Compressed, EagerVec};
use crate::vecs::{Indexes, indexes};

View File

@@ -1,11 +1,12 @@
use std::path::Path;
use brk_core::{
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, WeekIndex, YearIndex,
DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, Result, Version,
WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, EagerVec, Result, Version};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, EagerVec};
use crate::vecs::{Indexes, indexes};

View File

@@ -1,9 +1,9 @@
use std::path::Path;
use brk_core::{DifficultyEpoch, Height};
use brk_core::{DifficultyEpoch, Height, Result, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, EagerVec, Result, Version};
use brk_vec::{AnyCollectableVec, Compressed, EagerVec};
use crate::vecs::{Indexes, indexes};

View File

@@ -2,13 +2,12 @@ use std::path::Path;
use brk_core::{
Bitcoin, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, MonthIndex, QuarterIndex,
Sats, TxIndex, WeekIndex, YearIndex,
Result, Sats, TxIndex, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyVec, CollectableVec, Compressed, EagerVec, Result, StoredIndex,
VecIterator, Version,
AnyCollectableVec, AnyVec, CollectableVec, Compressed, EagerVec, StoredIndex, VecIterator,
};
use crate::vecs::{Indexes, fetched, indexes};
@@ -425,12 +424,12 @@ impl ComputedVecsFromTxindex<Bitcoin> {
exit,
)?;
}
if let Some(total) = self.height.total.as_mut() {
total.forced_push_at(
if let Some(cumulative) = self.height.cumulative.as_mut() {
cumulative.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_total()
.unwrap_cumulative()
.into_iter()
.unwrap_get_inner(height),
),
@@ -608,13 +607,13 @@ impl ComputedVecsFromTxindex<Dollars> {
exit,
)?;
}
if let Some(total) = self.height.total.as_mut() {
total.forced_push_at(
if let Some(cumulative) = self.height.cumulative.as_mut() {
cumulative.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_total()
.unwrap_cumulative()
.into_iter()
.unwrap_get_inner(height),
exit,

View File

@@ -1,11 +1,11 @@
use std::{f32, path::Path};
use brk_core::{Date, DateIndex, Dollars, StoredF32};
use brk_core::{Date, DateIndex, Dollars, Result, StoredF32, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, Compressed, EagerVec, Result,
StoredIndex, VecIterator, Version,
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, Compressed, EagerVec, StoredIndex,
VecIterator,
};
use crate::{

View File

@@ -1,11 +1,9 @@
use std::path::Path;
use brk_core::{Bitcoin, Dollars, Height, Sats};
use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, CollectableVec, Compressed, EagerVec, Result, StoredVec, Version,
};
use brk_vec::{AnyCollectableVec, CollectableVec, Compressed, EagerVec, StoredVec};
use crate::vecs::{Indexes, fetched, indexes};

View File

@@ -1,11 +1,11 @@
use std::path::Path;
use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex};
use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Compressed,
Computation, ComputedVecFrom3, LazyVecFrom1, StoredIndex, StoredVec, Version,
Computation, ComputedVecFrom3, LazyVecFrom1, StoredIndex, StoredVec,
};
use crate::vecs::{Indexes, fetched, indexes};

View File

@@ -5,13 +5,13 @@ use brk_core::{
InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2ABytes, P2AIndex, P2MSIndex, P2PK33Bytes,
P2PK33Index, P2PK65Bytes, P2PK65Index, P2PKHBytes, P2PKHIndex, P2SHBytes, P2SHIndex, P2TRBytes,
P2TRIndex, P2WPKHBytes, P2WPKHIndex, P2WSHBytes, P2WSHIndex, QuarterIndex, Sats, StoredUsize,
Timestamp, TxIndex, Txid, UnknownOutputIndex, WeekIndex, YearIndex,
Timestamp, TxIndex, Txid, UnknownOutputIndex, Version, WeekIndex, YearIndex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, CloneableAnyIterableVec, Compressed, Computation, ComputedVec,
ComputedVecFrom1, ComputedVecFrom2, EagerVec, StoredIndex, VecIterator, Version,
ComputedVecFrom1, ComputedVecFrom2, EagerVec, StoredIndex, VecIterator,
};
const VERSION: Version = Version::ZERO;

View File

@@ -1,9 +1,9 @@
use std::{fs, path::Path, thread};
use brk_core::{Date, DateIndex, Dollars, Sats, StoredF32, StoredUsize};
use brk_core::{Date, DateIndex, Dollars, Sats, StoredF32, StoredUsize, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, Computation, StoredIndex, VecIterator, Version};
use brk_vec::{AnyCollectableVec, Compressed, Computation, StoredIndex, VecIterator};
use super::{
Indexes, fetched,
@@ -1097,17 +1097,17 @@ impl Vecs {
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
let mut total_subsidy_in_btc = transactions
let mut cumulative_subsidy_in_btc = transactions
.indexes_to_subsidy
.bitcoin
.dateindex
.unwrap_total()
.unwrap_cumulative()
.into_iter();
v.compute_transform(
starting_indexes.dateindex,
&fetched.timeindexes_to_close.dateindex,
|(i, close, ..)| {
let supply = total_subsidy_in_btc.unwrap_get_inner(i);
let supply = cumulative_subsidy_in_btc.unwrap_get_inner(i);
(i, *close * supply)
},
exit,

View File

@@ -1,9 +1,9 @@
use std::{fs, path::Path};
use brk_core::{DifficultyEpoch, HalvingEpoch, StoredF64};
use brk_core::{DifficultyEpoch, HalvingEpoch, StoredF64, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, Computation, VecIterator, Version};
use brk_vec::{AnyCollectableVec, Compressed, Computation, VecIterator};
use super::{
Indexes,

View File

@@ -1,9 +1,10 @@
use std::{fs, path::Path};
use brk_core::Version;
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, Computation, Version};
use brk_vec::{AnyCollectableVec, Compressed, Computation};
pub mod blocks;
pub mod constants;

View File

@@ -2,15 +2,13 @@ use std::{fs, path::Path};
use brk_core::{
CheckedSub, Feerate, HalvingEpoch, Height, InputIndex, OutputIndex, Sats, StoredU32,
StoredUsize, TxIndex, TxVersion, Weight,
StoredUsize, TxIndex, TxVersion, Version, Weight,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::bitcoin;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Compressed, Computation,
ComputedVec, ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, StoredIndex, VecIterator,
Version,
};
use super::{
@@ -244,7 +242,7 @@ impl Vecs {
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
// .add_total(),
// .add_cumulative(),
// )?;
let txindex_to_output_value = ComputedVec::forced_import_or_init_from_3(
@@ -293,7 +291,7 @@ impl Vecs {
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
// .add_total(),
// .add_cumulative(),
// )?;
let txindex_to_fee = ComputedVecFrom2::forced_import_or_init_from_2(
@@ -351,7 +349,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
path,
@@ -364,7 +362,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
path,
@@ -377,7 +375,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
path,
@@ -385,7 +383,9 @@ impl Vecs {
true,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
indexes_to_tx_v2: ComputedVecsFromHeight::forced_import(
path,
@@ -393,7 +393,9 @@ impl Vecs {
true,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
indexes_to_tx_v3: ComputedVecsFromHeight::forced_import(
path,
@@ -401,7 +403,9 @@ impl Vecs {
true,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)?,
indexes_to_fee: ComputedValueVecsFromTxindex::forced_import(
path,
@@ -414,7 +418,7 @@ impl Vecs {
fetched,
StorableVecGeneatorOptions::default()
.add_sum()
.add_total()
.add_cumulative()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -461,7 +465,7 @@ impl Vecs {
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_sum()
.add_total()
.add_cumulative()
.add_minmax()
.add_average(),
compute_dollars,
@@ -474,7 +478,7 @@ impl Vecs {
compressed,
StorableVecGeneatorOptions::default()
.add_sum()
.add_total()
.add_cumulative()
.add_percentiles()
.add_minmax()
.add_average(),
@@ -486,7 +490,9 @@ impl Vecs {
true,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
compute_dollars,
)?,
indexes_to_p2a_count: ComputedVecsFromHeight::forced_import(
@@ -500,7 +506,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2ms_count: ComputedVecsFromHeight::forced_import(
path,
@@ -513,7 +519,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2pk33_count: ComputedVecsFromHeight::forced_import(
path,
@@ -526,7 +532,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2pk65_count: ComputedVecsFromHeight::forced_import(
path,
@@ -539,7 +545,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2pkh_count: ComputedVecsFromHeight::forced_import(
path,
@@ -552,7 +558,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2sh_count: ComputedVecsFromHeight::forced_import(
path,
@@ -565,7 +571,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2tr_count: ComputedVecsFromHeight::forced_import(
path,
@@ -578,7 +584,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2wpkh_count: ComputedVecsFromHeight::forced_import(
path,
@@ -591,7 +597,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_p2wsh_count: ComputedVecsFromHeight::forced_import(
path,
@@ -604,7 +610,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_opreturn_count: ComputedVecsFromHeight::forced_import(
path,
@@ -617,7 +623,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_unknownoutput_count: ComputedVecsFromHeight::forced_import(
path,
@@ -630,7 +636,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_emptyoutput_count: ComputedVecsFromHeight::forced_import(
path,
@@ -643,7 +649,7 @@ impl Vecs {
.add_minmax()
.add_percentiles()
.add_sum()
.add_total(),
.add_cumulative(),
)?,
indexes_to_exact_utxo_count: ComputedVecsFromHeight::forced_import(
path,
@@ -1088,16 +1094,16 @@ impl Vecs {
let mut input_count_iter = self
.indexes_to_input_count
.height
.unwrap_total()
.unwrap_cumulative()
.into_iter();
let mut opreturn_count_iter = self
.indexes_to_opreturn_count
.height_extra
.unwrap_total()
.unwrap_cumulative()
.into_iter();
v.compute_transform(
starting_indexes.height,
self.indexes_to_output_count.height.unwrap_total(),
self.indexes_to_output_count.height.unwrap_cumulative(),
|(h, output_count, ..)| {
let input_count = input_count_iter.unwrap_get_inner(h);
let opreturn_count = opreturn_count_iter.unwrap_get_inner(h);

View File

@@ -1,11 +1,9 @@
use std::{fs, path::Path};
use brk_core::{CheckedSub, Dollars, Height, Sats, StoredUsize};
use brk_core::{CheckedSub, Dollars, Height, Result, Sats, StoredUsize, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyVec, Compressed, Computation, EagerVec, Result, VecIterator, Version,
};
use brk_vec::{AnyCollectableVec, AnyVec, Compressed, Computation, EagerVec, VecIterator};
use crate::{
states::{CohortState, RealizedState},
@@ -32,6 +30,19 @@ pub struct Vecs {
pub height_to_utxo_count: EagerVec<Height, StoredUsize>,
pub indexes_to_utxo_count: ComputedVecsFromHeight<StoredUsize>,
pub height_to_realized_profit: Option<EagerVec<Height, Dollars>>,
pub indexes_to_realized_profit: Option<ComputedVecsFromHeight<Dollars>>,
pub height_to_realized_loss: Option<EagerVec<Height, Dollars>>,
pub indexes_to_realized_loss: Option<ComputedVecsFromHeight<Dollars>>,
pub height_to_value_created: Option<EagerVec<Height, Dollars>>,
pub indexes_to_value_created: Option<ComputedVecsFromHeight<Dollars>>,
pub height_to_adjusted_value_created: Option<EagerVec<Height, Dollars>>,
pub indexes_to_adjusted_value_created: Option<ComputedVecsFromHeight<Dollars>>,
pub height_to_value_destroyed: Option<EagerVec<Height, Dollars>>,
pub indexes_to_value_destroyed: Option<ComputedVecsFromHeight<Dollars>>,
pub height_to_adjusted_value_destroyed: Option<EagerVec<Height, Dollars>>,
pub indexes_to_adjusted_value_destroyed: Option<ComputedVecsFromHeight<Dollars>>,
pub indexes_to_realized_price: Option<ComputedVecsFromHeight<Dollars>>,
pub indexes_to_realized_price_extra: Option<ComputedRatioVecsFromDateIndex>,
}
@@ -134,6 +145,130 @@ impl Vecs {
)
.unwrap()
}),
height_to_realized_profit: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("realized_profit"),
version + VERSION + Version::ZERO,
compressed,
)
.unwrap()
}),
indexes_to_realized_profit: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_profit"),
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)
.unwrap()
}),
height_to_realized_loss: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("realized_loss"),
version + VERSION + Version::ZERO,
compressed,
)
.unwrap()
}),
indexes_to_realized_loss: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("realized_loss"),
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
)
.unwrap()
}),
height_to_value_created: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("value_created"),
version + VERSION + Version::ZERO,
compressed,
)
.unwrap()
}),
indexes_to_value_created: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("value_created"),
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum(),
)
.unwrap()
}),
height_to_adjusted_value_created: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("adjusted_value_created"),
version + VERSION + Version::ZERO,
compressed,
)
.unwrap()
}),
indexes_to_adjusted_value_created: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("adjusted_value_created"),
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum(),
)
.unwrap()
}),
height_to_value_destroyed: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("value_destroyed"),
version + VERSION + Version::ZERO,
compressed,
)
.unwrap()
}),
indexes_to_value_destroyed: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("value_destroyed"),
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum(),
)
.unwrap()
}),
height_to_adjusted_value_destroyed: compute_dollars.then(|| {
EagerVec::forced_import(
path,
&suffix("adjusted_value_destroyed"),
version + VERSION + Version::ZERO,
compressed,
)
.unwrap()
}),
indexes_to_adjusted_value_destroyed: compute_dollars.then(|| {
ComputedVecsFromHeight::forced_import(
path,
&suffix("adjusted_value_destroyed"),
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_sum(),
)
.unwrap()
}),
})
}
@@ -144,6 +279,24 @@ impl Vecs {
self.height_to_realized_cap
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_realized_profit
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_realized_loss
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_value_created
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_adjusted_value_created
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_value_destroyed
.as_ref()
.map_or(usize::MAX, |v| v.len()),
self.height_to_adjusted_value_destroyed
.as_ref()
.map_or(usize::MAX, |v| v.len()),
]
.into_iter()
.map(Height::from)
@@ -169,7 +322,7 @@ impl Vecs {
.unwrap_get_inner(prev_height);
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
self.state.realized.as_mut().unwrap().realized_cap = height_to_realized_cap
self.state.realized.as_mut().unwrap().cap = height_to_realized_cap
.into_iter()
.unwrap_get_inner(prev_height);
}
@@ -191,6 +344,73 @@ impl Vecs {
height_to_realized_cap.validate_computed_version_or_reset_file(
base_version + height_to_realized_cap.inner_version(),
)?;
let height_to_realized_profit_inner_version = self
.height_to_realized_profit
.as_ref()
.unwrap()
.inner_version();
self.height_to_realized_profit
.as_mut()
.unwrap()
.validate_computed_version_or_reset_file(
base_version + height_to_realized_profit_inner_version,
)?;
let height_to_realized_loss_inner_version = self
.height_to_realized_loss
.as_ref()
.unwrap()
.inner_version();
self.height_to_realized_loss
.as_mut()
.unwrap()
.validate_computed_version_or_reset_file(
base_version + height_to_realized_loss_inner_version,
)?;
let height_to_value_created_inner_version = self
.height_to_value_created
.as_ref()
.unwrap()
.inner_version();
self.height_to_value_created
.as_mut()
.unwrap()
.validate_computed_version_or_reset_file(
base_version + height_to_value_created_inner_version,
)?;
let height_to_adjusted_value_created_inner_version = self
.height_to_adjusted_value_created
.as_ref()
.unwrap()
.inner_version();
self.height_to_adjusted_value_created
.as_mut()
.unwrap()
.validate_computed_version_or_reset_file(
base_version + height_to_adjusted_value_created_inner_version,
)?;
let height_to_value_destroyed_inner_version = self
.height_to_value_destroyed
.as_ref()
.unwrap()
.inner_version();
self.height_to_value_destroyed
.as_mut()
.unwrap()
.validate_computed_version_or_reset_file(
base_version + height_to_value_destroyed_inner_version,
)?;
let height_to_adjusted_value_destroyed_inner_version = self
.height_to_adjusted_value_destroyed
.as_ref()
.unwrap()
.inner_version();
self.height_to_adjusted_value_destroyed
.as_mut()
.unwrap()
.validate_computed_version_or_reset_file(
base_version + height_to_adjusted_value_destroyed_inner_version,
)?;
}
Ok(())
@@ -211,18 +431,37 @@ impl Vecs {
)?;
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
height_to_realized_cap.forced_push_at(
height,
self.state
.realized
.as_ref()
.unwrap_or_else(|| {
dbg!(&self.state);
panic!();
})
.realized_cap,
exit,
)?;
let realized = self.state.realized.as_ref().unwrap_or_else(|| {
dbg!(&self.state);
panic!();
});
height_to_realized_cap.forced_push_at(height, realized.cap, exit)?;
self.height_to_realized_profit
.as_mut()
.unwrap()
.forced_push_at(height, realized.profit, exit)?;
self.height_to_realized_loss
.as_mut()
.unwrap()
.forced_push_at(height, realized.loss, exit)?;
self.height_to_value_created
.as_mut()
.unwrap()
.forced_push_at(height, realized.value_created, exit)?;
self.height_to_adjusted_value_created
.as_mut()
.unwrap()
.forced_push_at(height, realized.adj_value_created, exit)?;
self.height_to_value_destroyed
.as_mut()
.unwrap()
.forced_push_at(height, realized.value_destroyed, exit)?;
self.height_to_adjusted_value_destroyed
.as_mut()
.unwrap()
.forced_push_at(height, realized.adj_value_destroyed, exit)?;
}
Ok(())
}
@@ -234,6 +473,30 @@ impl Vecs {
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
height_to_realized_cap.safe_flush(exit)?;
self.height_to_realized_profit
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_realized_loss
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_value_created
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_adjusted_value_created
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_value_destroyed
.as_mut()
.unwrap()
.safe_flush(exit)?;
self.height_to_adjusted_value_destroyed
.as_mut()
.unwrap()
.safe_flush(exit)?;
}
Ok(())
@@ -270,41 +533,102 @@ impl Vecs {
exit,
Some(self.height_to_realized_cap.as_ref().unwrap()),
)?;
}
if let Some(indexes_to_realized_price) = self.indexes_to_realized_price.as_mut() {
indexes_to_realized_price.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
vec.compute_divide(
starting_indexes.height,
self.height_to_realized_cap.as_ref().unwrap(),
&**self.indexes_to_supply.bitcoin.height.as_ref().unwrap(),
exit,
)
},
)?;
}
self.indexes_to_realized_price
.as_mut()
.unwrap()
.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
vec.compute_divide(
starting_indexes.height,
self.height_to_realized_cap.as_ref().unwrap(),
&**self.indexes_to_supply.bitcoin.height.as_ref().unwrap(),
exit,
)
},
)?;
if let Some(indexes_to_realized_price_extra) = self.indexes_to_realized_price_extra.as_mut()
{
indexes_to_realized_price_extra.compute_rest(
indexer,
indexes,
fetched.as_ref().unwrap(),
starting_indexes,
exit,
Some(
self.indexes_to_realized_price
.as_ref()
.unwrap()
.dateindex
.unwrap_last(),
),
)?;
self.indexes_to_realized_price_extra
.as_mut()
.unwrap()
.compute_rest(
indexer,
indexes,
fetched.as_ref().unwrap(),
starting_indexes,
exit,
Some(
self.indexes_to_realized_price
.as_ref()
.unwrap()
.dateindex
.unwrap_last(),
),
)?;
self.indexes_to_realized_profit
.as_mut()
.unwrap()
.compute_rest(
indexes,
starting_indexes,
exit,
Some(self.height_to_realized_profit.as_ref().unwrap()),
)?;
self.indexes_to_realized_loss
.as_mut()
.unwrap()
.compute_rest(
indexes,
starting_indexes,
exit,
Some(self.height_to_realized_loss.as_ref().unwrap()),
)?;
self.indexes_to_value_created
.as_mut()
.unwrap()
.compute_rest(
indexes,
starting_indexes,
exit,
Some(self.height_to_value_created.as_ref().unwrap()),
)?;
self.indexes_to_adjusted_value_created
.as_mut()
.unwrap()
.compute_rest(
indexes,
starting_indexes,
exit,
Some(self.height_to_adjusted_value_created.as_ref().unwrap()),
)?;
self.indexes_to_value_destroyed
.as_mut()
.unwrap()
.compute_rest(
indexes,
starting_indexes,
exit,
Some(self.height_to_value_destroyed.as_ref().unwrap()),
)?;
self.indexes_to_adjusted_value_destroyed
.as_mut()
.unwrap()
.compute_rest(
indexes,
starting_indexes,
exit,
Some(self.height_to_adjusted_value_destroyed.as_ref().unwrap()),
)?;
}
Ok(())
@@ -330,6 +654,42 @@ impl Vecs {
self.indexes_to_realized_price_extra
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.height_to_realized_profit
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.indexes_to_realized_profit
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.height_to_realized_loss
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.indexes_to_realized_loss
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.height_to_value_created
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.indexes_to_value_created
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.height_to_adjusted_value_created
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.indexes_to_adjusted_value_created
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.height_to_value_destroyed
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.indexes_to_value_destroyed
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.height_to_adjusted_value_destroyed
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.indexes_to_adjusted_value_destroyed
.as_ref()
.map_or(vec![], |v| v.vecs()),
]
.into_iter()
.flatten()
@@ -350,6 +710,19 @@ impl Clone for Vecs {
height_to_utxo_count: self.height_to_utxo_count.clone(),
indexes_to_utxo_count: self.indexes_to_utxo_count.clone(),
height_to_realized_profit: self.height_to_realized_profit.clone(),
indexes_to_realized_profit: self.indexes_to_realized_profit.clone(),
height_to_realized_loss: self.height_to_realized_loss.clone(),
indexes_to_realized_loss: self.indexes_to_realized_loss.clone(),
height_to_value_created: self.height_to_value_created.clone(),
indexes_to_value_created: self.indexes_to_value_created.clone(),
height_to_adjusted_value_created: self.height_to_adjusted_value_created.clone(),
indexes_to_adjusted_value_created: self.indexes_to_adjusted_value_created.clone(),
height_to_value_destroyed: self.height_to_value_destroyed.clone(),
indexes_to_value_destroyed: self.indexes_to_value_destroyed.clone(),
height_to_adjusted_value_destroyed: self.height_to_adjusted_value_destroyed.clone(),
indexes_to_adjusted_value_destroyed: self.indexes_to_adjusted_value_destroyed.clone(),
indexes_to_realized_price: self.indexes_to_realized_price.clone(),
indexes_to_realized_price_extra: self.indexes_to_realized_price_extra.clone(),
}

View File

@@ -1,11 +1,11 @@
use std::{cmp::Ordering, collections::BTreeMap, mem, path::Path, thread};
use brk_core::{Height, InputIndex, OutputIndex, OutputType, Sats};
use brk_core::{Height, InputIndex, OutputIndex, OutputType, Sats, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyVec, BaseVecIterator, CollectableVec, Compressed, Computation, EagerVec,
GenericStoredVec, StoredIndex, StoredVec, UnsafeSlice, VecIterator, Version,
GenericStoredVec, StoredIndex, StoredVec, UnsafeSlice, VecIterator,
};
use log::info;
use rayon::prelude::*;
@@ -24,6 +24,7 @@ use super::{
pub mod cohort;
const VERSION: Version = Version::ZERO;
const BYSIZE_VERSION: Version = Version::ONE;
#[derive(Clone)]
pub struct Vecs {
@@ -32,8 +33,8 @@ pub struct Vecs {
// cointime,...
pub height_to_unspendable_supply: EagerVec<Height, Sats>,
pub indexes_to_unspendable_supply: ComputedValueVecsFromHeight,
// pub height_to_opreturn_supply: EagerVec<Height, Sats>,
// pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight,
pub height_to_opreturn_supply: EagerVec<Height, Sats>,
pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight,
utxos_vecs: Outputs<(OutputFilter, cohort::Vecs)>,
}
@@ -74,6 +75,21 @@ impl Vecs {
StorableVecGeneatorOptions::default().add_last(),
compute_dollars,
)?,
height_to_opreturn_supply: EagerVec::forced_import(
path,
"opreturn_supply",
version + VERSION + Version::ZERO,
compressed,
)?,
indexes_to_opreturn_supply: ComputedValueVecsFromHeight::forced_import(
path,
"opreturn_supply",
false,
version + VERSION + Version::ZERO,
compressed,
StorableVecGeneatorOptions::default().add_last(),
compute_dollars,
)?,
utxos_vecs: {
Outputs::<(OutputFilter, cohort::Vecs)>::from(Outputs {
all: cohort::Vecs::forced_import(
@@ -540,7 +556,7 @@ impl Vecs {
Some("0sat"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_1sat_to_10sats: cohort::Vecs::forced_import(
@@ -548,7 +564,7 @@ impl Vecs {
Some("from_1sat_to_10sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_10sats_to_100sats: cohort::Vecs::forced_import(
@@ -556,7 +572,7 @@ impl Vecs {
Some("from_10sats_to_100sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_100sats_to_1_000sats: cohort::Vecs::forced_import(
@@ -564,7 +580,7 @@ impl Vecs {
Some("from_100sats_to_1_000sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_1_000sats_to_10_000sats: cohort::Vecs::forced_import(
@@ -572,7 +588,7 @@ impl Vecs {
Some("from_1_000sats_to_10_000sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_10_000sats_to_100_000sats: cohort::Vecs::forced_import(
@@ -580,7 +596,7 @@ impl Vecs {
Some("from_10_000sats_to_100_000sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_100_000sats_to_1_000_000sats: cohort::Vecs::forced_import(
@@ -588,7 +604,7 @@ impl Vecs {
Some("from_100_000sats_to_1_000_000sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_1_000_000sats_to_10_000_000sats: cohort::Vecs::forced_import(
@@ -596,7 +612,7 @@ impl Vecs {
Some("from_1_000_000sats_to_10_000_000sats"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_10_000_000sats_to_1btc: cohort::Vecs::forced_import(
@@ -604,7 +620,7 @@ impl Vecs {
Some("from_10_000_000sats_to_1btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_1btc_to_10btc: cohort::Vecs::forced_import(
@@ -612,7 +628,7 @@ impl Vecs {
Some("from_1btc_to_10btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_10btc_to_100btc: cohort::Vecs::forced_import(
@@ -620,7 +636,7 @@ impl Vecs {
Some("from_10btc_to_100btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_100btc_to_1_000btc: cohort::Vecs::forced_import(
@@ -628,7 +644,7 @@ impl Vecs {
Some("from_100btc_to_1_000btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_1_000btc_to_10_000btc: cohort::Vecs::forced_import(
@@ -636,7 +652,7 @@ impl Vecs {
Some("from_1_000btc_to_10_000btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_10_000btc_to_100_000btc: cohort::Vecs::forced_import(
@@ -644,7 +660,7 @@ impl Vecs {
Some("from_10_000btc_to_100_000btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
from_100_000btc: cohort::Vecs::forced_import(
@@ -652,7 +668,7 @@ impl Vecs {
Some("from_100_000btc"),
_computation,
compressed,
version + VERSION + Version::ZERO,
version + BYSIZE_VERSION + Version::ZERO,
fetched,
)?,
},
@@ -790,9 +806,9 @@ impl Vecs {
version + VERSION + Version::ZERO,
fetched,
)?,
// op_return: cohort::Vecs::forced_import(
// opreturn: cohort::Vecs::forced_import(
// path,
// Some("op_return"),
// Some("opreturn"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
@@ -925,6 +941,10 @@ impl Vecs {
.validate_computed_version_or_reset_file(
base_version + self.height_to_unspendable_supply.inner_version(),
)?;
self.height_to_opreturn_supply
.validate_computed_version_or_reset_file(
base_version + self.height_to_opreturn_supply.inner_version(),
)?;
let mut chain_state: Vec<BlockState>;
let mut chain_state_starting_height = Height::from(self.chain_state.len());
@@ -972,7 +992,8 @@ impl Vecs {
let starting_height = starting_indexes
.height
.min(stateful_starting_height)
.min(Height::from(self.height_to_unspendable_supply.len()));
.min(Height::from(self.height_to_unspendable_supply.len()))
.min(Height::from(self.height_to_opreturn_supply.len()));
// ---
// INIT
@@ -990,12 +1011,25 @@ impl Vecs {
Sats::ZERO
};
let mut opreturn_supply = if let Some(prev_height) = starting_height.decremented() {
self.height_to_opreturn_supply
.into_iter()
.unwrap_get_inner(prev_height)
} else {
Sats::ZERO
};
let mut height = Height::ZERO;
(starting_height.unwrap_to_usize()..height_to_first_outputindex_iter.len())
.map(Height::from)
.try_for_each(|_height| -> color_eyre::Result<()> {
height = _height;
self.utxos_vecs
.as_mut_vec()
.iter_mut()
.for_each(|(_, v)| v.state.reset_single_iteration_values());
info!("Processing utxo set at {height}...");
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
@@ -1130,6 +1164,8 @@ impl Vecs {
.sum::<Sats>()
+ height_to_unclaimed_rewards_iter.unwrap_get_inner(height);
opreturn_supply += received.by_type.unspendable.opreturn.value;
if height == Height::new(0) {
received = Transacted::default();
unspendable_supply += Sats::FIFTY_BTC;
@@ -1183,6 +1219,9 @@ impl Vecs {
exit,
)?;
self.height_to_opreturn_supply
.forced_push_at(height, opreturn_supply, exit)?;
Ok(())
})?;
@@ -1199,6 +1238,10 @@ impl Vecs {
.par_iter_mut()
.try_for_each(|(_, v)| v.safe_flush_height_vecs(exit))?;
self.height_to_unspendable_supply.safe_flush(exit)?;
flat_vecs_
.par_iter_mut()
.try_for_each(|(_, v)| v.safe_flush_height_vecs(exit))?;
self.height_to_opreturn_supply.safe_flush(exit)?;
info!("Computing rest...");
@@ -1214,6 +1257,14 @@ impl Vecs {
exit,
Some(&self.height_to_unspendable_supply),
)?;
self.indexes_to_opreturn_supply.compute_rest(
indexer,
indexes,
fetched,
starting_indexes,
exit,
Some(&self.height_to_opreturn_supply),
)?;
info!("Chain state...");
@@ -1239,7 +1290,11 @@ impl Vecs {
.flat_map(|v| v.vecs())
.collect::<Vec<_>>(),
self.indexes_to_unspendable_supply.vecs(),
vec![&self.height_to_unspendable_supply],
self.indexes_to_opreturn_supply.vecs(),
vec![
&self.height_to_unspendable_supply,
&self.height_to_opreturn_supply,
],
]
.into_iter()
.flatten()