global: one big snapshot

This commit is contained in:
nym21
2025-08-02 16:59:22 +02:00
parent aa8b47a3dd
commit f7aa9424db
252 changed files with 6283 additions and 5264 deletions
@@ -1,16 +1,17 @@
use std::{ops::Deref, path::Path, sync::Arc};
use brk_core::{Bitcoin, DateIndex, Dollars, Height, Result, StoredUsize, Version};
use brk_exit::Exit;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_structs::{Bitcoin, DateIndex, Dollars, Height, StoredU64, Version};
use brk_vecs::{
AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, File, Format, VecIterator,
AnyCollectableVec, AnyIterableVec, AnyStoredVec, AnyVec, Computation, EagerVec, Exit, File,
Format, GenericStoredVec, VecIterator,
};
use crate::{
Indexes, fetched,
Indexes,
grouped::{ComputedVecsFromHeight, Source, VecBuilderOptions},
indexes, market,
indexes, market, price,
stateful::{
common,
r#trait::{CohortVecs, DynCohortVecs},
@@ -28,8 +29,8 @@ pub struct Vecs {
pub inner: common::Vecs,
pub height_to_address_count: EagerVec<Height, StoredUsize>,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredUsize>,
pub height_to_address_count: EagerVec<Height, StoredU64>,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredU64>,
}
impl Vecs {
@@ -41,11 +42,11 @@ impl Vecs {
format: Format,
version: Version,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
states_path: &Path,
compute_relative_to_all: bool,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
) -> Result<Self> {
let compute_dollars = price.is_some();
let suffix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{name}_{s}"));
@@ -79,7 +80,7 @@ impl Vecs {
format,
version,
indexes,
fetched,
price,
compute_relative_to_all,
false,
)?,
@@ -170,10 +171,10 @@ impl DynCohortVecs for Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.indexes_to_address_count.compute_rest(
indexes,
starting_indexes,
@@ -182,7 +183,7 @@ impl DynCohortVecs for Vecs {
)?;
self.inner
.compute_rest_part1(indexer, indexes, fetched, starting_indexes, exit)
.compute_rest_part1(indexer, indexes, price, starting_indexes, exit)
}
fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
@@ -223,7 +224,7 @@ impl CohortVecs for Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
market: &market::Vecs,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
@@ -231,11 +232,11 @@ impl CohortVecs for Vecs {
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.inner.compute_rest_part2(
indexer,
indexes,
fetched,
price,
starting_indexes,
market,
height_to_supply,
@@ -1,16 +1,16 @@
use std::{path::Path, sync::Arc};
use brk_core::{
AddressGroups, Bitcoin, ByAmountRange, ByGreatEqualAmount, ByLowerThanAmount, DateIndex,
Dollars, GroupFilter, Height, Result, Version,
};
use brk_exit::Exit;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_vecs::{AnyIterableVec, Computation, File, Format};
use brk_structs::{
AddressGroups, Bitcoin, ByAmountRange, ByGreatEqualAmount, ByLowerThanAmount, DateIndex,
Dollars, GroupFilter, Height, Version,
};
use brk_vecs::{AnyIterableVec, Computation, Exit, File, Format};
use derive_deref::{Deref, DerefMut};
use crate::{
Indexes, fetched, indexes, market,
Indexes, indexes, market, price,
stateful::{
address_cohort,
r#trait::{CohortVecs, DynCohortVecs},
@@ -29,9 +29,9 @@ impl Vecs {
_computation: Computation,
format: Format,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
states_path: &Path,
) -> color_eyre::Result<Self> {
) -> Result<Self> {
Ok(Self(
AddressGroups {
amount_range: ByAmountRange {
@@ -42,7 +42,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -53,7 +53,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -64,7 +64,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -75,7 +75,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -86,7 +86,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -97,7 +97,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -108,7 +108,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -119,7 +119,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -130,7 +130,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -141,7 +141,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -152,7 +152,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -163,7 +163,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -174,7 +174,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -185,7 +185,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -196,7 +196,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -209,7 +209,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -220,7 +220,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -231,7 +231,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -242,7 +242,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -253,7 +253,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -264,7 +264,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -275,7 +275,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -286,7 +286,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -297,7 +297,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -308,7 +308,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -319,7 +319,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -330,7 +330,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -341,7 +341,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -354,7 +354,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -365,7 +365,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -376,7 +376,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -387,7 +387,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -398,7 +398,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -409,7 +409,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -420,7 +420,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -431,7 +431,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -442,7 +442,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -453,7 +453,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -464,7 +464,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -475,7 +475,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -486,7 +486,7 @@ impl Vecs {
format,
version + VERSION + Version::ZERO,
indexes,
fetched,
price,
states_path,
true,
)?,
@@ -546,12 +546,12 @@ impl Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.as_mut_vecs().into_iter().try_for_each(|(_, v)| {
v.compute_rest_part1(indexer, indexes, fetched, starting_indexes, exit)
v.compute_rest_part1(indexer, indexes, price, starting_indexes, exit)
})
}
@@ -560,7 +560,7 @@ impl Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
market: &market::Vecs,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
@@ -568,13 +568,13 @@ impl Vecs {
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.0.as_boxed_mut_vecs().into_iter().try_for_each(|v| {
v.into_iter().try_for_each(|(_, v)| {
v.compute_rest_part2(
indexer,
indexes,
fetched,
price,
starting_indexes,
market,
height_to_supply,
@@ -1,11 +1,11 @@
use brk_core::{ByAddressType, Height};
use brk_structs::{ByAddressType, Height};
use brk_vecs::VecIterator;
use derive_deref::{Deref, DerefMut};
use crate::stateful::addresstype_to_height_to_addresscount::AddressTypeToHeightToAddressCount;
#[derive(Debug, Default, Deref, DerefMut)]
pub struct AddressTypeToAddressCount(ByAddressType<usize>);
pub struct AddressTypeToAddressCount(ByAddressType<u64>);
impl From<(&AddressTypeToHeightToAddressCount, Height)> for AddressTypeToAddressCount {
fn from((groups, starting_height): (&AddressTypeToHeightToAddressCount, Height)) -> Self {
@@ -1,15 +1,15 @@
use brk_core::{ByAddressType, Height, Result, StoredUsize};
use brk_exit::Exit;
use brk_vecs::EagerVec;
use brk_error::Result;
use brk_structs::{ByAddressType, Height, StoredU64};
use brk_vecs::{EagerVec, Exit, GenericStoredVec};
use derive_deref::{Deref, DerefMut};
use crate::stateful::addresstype_to_addresscount::AddressTypeToAddressCount;
#[derive(Debug, Clone, Deref, DerefMut)]
pub struct AddressTypeToHeightToAddressCount(ByAddressType<EagerVec<Height, StoredUsize>>);
pub struct AddressTypeToHeightToAddressCount(ByAddressType<EagerVec<Height, StoredU64>>);
impl From<ByAddressType<EagerVec<Height, StoredUsize>>> for AddressTypeToHeightToAddressCount {
fn from(value: ByAddressType<EagerVec<Height, StoredUsize>>) -> Self {
impl From<ByAddressType<EagerVec<Height, StoredU64>>> for AddressTypeToHeightToAddressCount {
fn from(value: ByAddressType<EagerVec<Height, StoredU64>>) -> Self {
Self(value)
}
}
@@ -1,6 +1,6 @@
use brk_core::{ByAddressType, StoredUsize};
use brk_exit::Exit;
use brk_vecs::AnyCollectableVec;
use brk_error::Result;
use brk_structs::{ByAddressType, StoredU64};
use brk_vecs::{AnyCollectableVec, Exit};
use derive_deref::{Deref, DerefMut};
use crate::{
@@ -9,12 +9,10 @@ use crate::{
};
#[derive(Clone, Deref, DerefMut)]
pub struct AddressTypeToIndexesToAddressCount(ByAddressType<ComputedVecsFromHeight<StoredUsize>>);
pub struct AddressTypeToIndexesToAddressCount(ByAddressType<ComputedVecsFromHeight<StoredU64>>);
impl From<ByAddressType<ComputedVecsFromHeight<StoredUsize>>>
for AddressTypeToIndexesToAddressCount
{
fn from(value: ByAddressType<ComputedVecsFromHeight<StoredUsize>>) -> Self {
impl From<ByAddressType<ComputedVecsFromHeight<StoredU64>>> for AddressTypeToIndexesToAddressCount {
fn from(value: ByAddressType<ComputedVecsFromHeight<StoredU64>>) -> Self {
Self(value)
}
}
@@ -27,7 +25,7 @@ impl AddressTypeToIndexesToAddressCount {
starting_indexes: &Indexes,
exit: &Exit,
addresstype_to_height_to_addresscount: &AddressTypeToHeightToAddressCount,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.p2pk65.compute_rest(
indexes,
starting_indexes,
@@ -1,6 +1,6 @@
use std::collections::BTreeSet;
use brk_core::TypeIndex;
use brk_structs::TypeIndex;
use derive_deref::{Deref, DerefMut};
use super::ByAddressType;
@@ -1,6 +1,6 @@
use std::{collections::BTreeMap, mem};
use brk_core::TypeIndex;
use brk_structs::TypeIndex;
use derive_deref::{Deref, DerefMut};
use super::ByAddressType;
+82 -56
View File
@@ -1,22 +1,22 @@
use std::sync::Arc;
use brk_core::{
Bitcoin, DateIndex, Dollars, Height, Result, Sats, StoredF32, StoredF64, StoredUsize, Version,
};
use brk_exit::Exit;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_structs::{
Bitcoin, DateIndex, Dollars, Height, Sats, StoredF32, StoredF64, StoredU64, Version,
};
use brk_vecs::{
AnyCollectableVec, AnyIterableVec, AnyVec, CloneableAnyIterableVec, Computation, EagerVec,
File, Format, VecIterator,
AnyCloneableIterableVec, AnyCollectableVec, AnyIterableVec, AnyStoredVec, AnyVec, Computation,
EagerVec, Exit, File, Format, GenericStoredVec, VecIterator,
};
use crate::{
Indexes, fetched,
Indexes,
grouped::{
ComputedHeightValueVecs, ComputedRatioVecsFromDateIndex, ComputedValueVecsFromDateIndex,
ComputedVecsFromDateIndex, ComputedVecsFromHeight, Source, VecBuilderOptions,
},
indexes, market,
indexes, market, price,
states::CohortState,
};
@@ -27,7 +27,7 @@ pub struct Vecs {
// Cumulative
pub height_to_realized_cap: Option<EagerVec<Height, Dollars>>,
pub height_to_supply: EagerVec<Height, Sats>,
pub height_to_utxo_count: EagerVec<Height, StoredUsize>,
pub height_to_utxo_count: EagerVec<Height, StoredU64>,
// Single
pub dateindex_to_supply_even: Option<EagerVec<DateIndex, Sats>>,
pub dateindex_to_supply_in_loss: Option<EagerVec<DateIndex, Sats>>,
@@ -68,7 +68,7 @@ pub struct Vecs {
pub indexes_to_realized_value: Option<ComputedVecsFromHeight<Dollars>>,
pub height_to_supply_value: ComputedHeightValueVecs,
pub indexes_to_supply: ComputedValueVecsFromDateIndex,
pub indexes_to_utxo_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_utxo_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_value_created: Option<ComputedVecsFromHeight<Dollars>>,
pub indexes_to_value_destroyed: Option<ComputedVecsFromHeight<Dollars>>,
pub indexes_to_unrealized_profit: Option<ComputedVecsFromDateIndex<Dollars>>,
@@ -134,11 +134,11 @@ impl Vecs {
format: Format,
version: Version,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
compute_relative_to_all: bool,
ratio_extended: bool,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
) -> Result<Self> {
let compute_dollars = price.is_some();
// let prefix = |s: &str| cohort_name.map_or(s.to_string(), |name| format!("{s}_{name}"));
@@ -1368,7 +1368,7 @@ impl Vecs {
self.height_to_utxo_count.forced_push_at(
height,
StoredUsize::from(state.supply.utxos),
StoredU64::from(state.supply.utxos),
exit,
)?;
@@ -1899,12 +1899,12 @@ impl Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.height_to_supply_value.compute_rest(
fetched,
price,
starting_indexes,
exit,
Some(&self.height_to_supply),
@@ -1913,7 +1913,7 @@ impl Vecs {
self.indexes_to_supply.compute_all(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
|v, _, indexes, starting_indexes, exit| {
@@ -1925,14 +1925,15 @@ impl Vecs {
&indexes.dateindex_to_first_height,
|(i, height, ..)| {
let count = dateindex_to_height_count_iter.unwrap_get_inner(i);
if count == StoredUsize::default() {
if count == StoredU64::default() {
unreachable!()
}
let supply = height_to_supply_iter.unwrap_get_inner(height + (*count - 1));
(i, supply)
},
exit,
)
)?;
Ok(())
},
)?;
@@ -1946,7 +1947,7 @@ impl Vecs {
self.height_to_halved_supply_value.compute_all(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
@@ -1955,14 +1956,15 @@ impl Vecs {
&self.height_to_supply,
|(h, v, ..)| (h, v / 2),
exit,
)
)?;
Ok(())
},
)?;
self.indexes_to_halved_supply.compute_all(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
@@ -1971,7 +1973,8 @@ impl Vecs {
self.indexes_to_supply.sats.dateindex.as_ref().unwrap(),
|(i, sats, ..)| (i, sats / 2),
exit,
)
)?;
Ok(())
},
)?;
@@ -1986,7 +1989,8 @@ impl Vecs {
&self.height_to_satblocks_destroyed,
|(i, v, ..)| (i, StoredF64::from(Bitcoin::from(v))),
exit,
)
)?;
Ok(())
},
)?;
@@ -2001,7 +2005,8 @@ impl Vecs {
&self.height_to_satdays_destroyed,
|(i, v, ..)| (i, StoredF64::from(Bitcoin::from(v))),
exit,
)
)?;
Ok(())
},
)?;
@@ -2013,7 +2018,7 @@ impl Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
market: &market::Vecs,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
@@ -2021,7 +2026,7 @@ impl Vecs {
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
if let Some(v) = self
.indexes_to_supply_relative_to_circulating_supply
.as_mut()
@@ -2037,7 +2042,8 @@ impl Vecs {
&self.height_to_supply_value.bitcoin,
height_to_supply,
exit,
)
)?;
Ok(())
},
)?;
}
@@ -2064,7 +2070,8 @@ impl Vecs {
self.height_to_realized_cap.as_ref().unwrap(),
&self.height_to_supply_value.bitcoin,
exit,
)
)?;
Ok(())
},
)?;
@@ -2074,7 +2081,7 @@ impl Vecs {
.compute_rest(
indexer,
indexes,
fetched.as_ref().unwrap(),
price.as_ref().unwrap(),
starting_indexes,
exit,
Some(
@@ -2120,7 +2127,8 @@ impl Vecs {
self.height_to_realized_loss.as_ref().unwrap(),
|(i, v, ..)| (i, v * -1_i64),
exit,
)
)?;
Ok(())
},
)?;
@@ -2182,7 +2190,8 @@ impl Vecs {
.unwrap_last(),
30,
exit,
)
)?;
Ok(())
},
)?;
@@ -2200,7 +2209,8 @@ impl Vecs {
self.height_to_realized_profit.as_ref().unwrap(),
self.height_to_realized_loss.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2218,7 +2228,8 @@ impl Vecs {
self.height_to_realized_profit.as_ref().unwrap(),
self.height_to_realized_loss.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2282,7 +2293,7 @@ impl Vecs {
.compute_rest(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
Some(self.dateindex_to_supply_in_profit.as_ref().unwrap()),
@@ -2293,7 +2304,7 @@ impl Vecs {
.compute_rest(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
Some(self.dateindex_to_supply_in_loss.as_ref().unwrap()),
@@ -2301,7 +2312,7 @@ impl Vecs {
self.indexes_to_supply_even.as_mut().unwrap().compute_rest(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
Some(self.dateindex_to_supply_even.as_ref().unwrap()),
@@ -2367,7 +2378,8 @@ impl Vecs {
self.dateindex_to_unrealized_loss.as_ref().unwrap(),
|(h, v, ..)| (h, v * -1_i64),
exit,
)
)?;
Ok(())
},
)?;
self.height_to_net_unrealized_profit_and_loss
@@ -2394,7 +2406,8 @@ impl Vecs {
self.dateindex_to_unrealized_profit.as_ref().unwrap(),
self.dateindex_to_unrealized_loss.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
self.height_to_net_unrealized_profit_and_loss_relative_to_market_cap
@@ -2427,7 +2440,8 @@ impl Vecs {
.unwrap(),
market.indexes_to_marketcap.dateindex.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2445,7 +2459,8 @@ impl Vecs {
self.height_to_realized_profit.as_ref().unwrap(),
*height_to_realized_cap.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2463,7 +2478,8 @@ impl Vecs {
self.height_to_realized_loss.as_ref().unwrap(),
*height_to_realized_cap.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2486,7 +2502,8 @@ impl Vecs {
.unwrap(),
*height_to_realized_cap.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2494,7 +2511,7 @@ impl Vecs {
.as_mut()
.unwrap()
.compute_rest(
fetched,
price,
starting_indexes,
exit,
Some(self.height_to_supply_even.as_ref().unwrap()),
@@ -2503,7 +2520,7 @@ impl Vecs {
.as_mut()
.unwrap()
.compute_rest(
fetched,
price,
starting_indexes,
exit,
Some(self.height_to_supply_in_loss.as_ref().unwrap()),
@@ -2512,7 +2529,7 @@ impl Vecs {
.as_mut()
.unwrap()
.compute_rest(
fetched,
price,
starting_indexes,
exit,
Some(self.height_to_supply_in_profit.as_ref().unwrap()),
@@ -2572,7 +2589,8 @@ impl Vecs {
.unwrap(),
self.indexes_to_supply.bitcoin.dateindex.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
self.indexes_to_supply_in_loss_relative_to_own_supply
@@ -2595,7 +2613,8 @@ impl Vecs {
.unwrap(),
self.indexes_to_supply.bitcoin.dateindex.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
self.indexes_to_supply_in_profit_relative_to_own_supply
@@ -2618,7 +2637,8 @@ impl Vecs {
.unwrap(),
self.indexes_to_supply.bitcoin.dateindex.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2640,7 +2660,8 @@ impl Vecs {
.unwrap_cumulative(),
30,
exit,
)
)?;
Ok(())
},
)?;
@@ -2658,7 +2679,8 @@ impl Vecs {
self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change.as_ref().unwrap().dateindex.as_ref().unwrap(),
*dateindex_to_realized_cap.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2676,7 +2698,8 @@ impl Vecs {
self.indexes_to_net_realized_profit_and_loss_cumulative_30d_change.as_ref().unwrap().dateindex.as_ref().unwrap(),
market.indexes_to_marketcap.dateindex.as_ref().unwrap(),
exit,
)
)?;
Ok(())
},
)?;
@@ -2736,7 +2759,8 @@ impl Vecs {
.unwrap(),
dateindex_to_supply,
exit,
)
)?;
Ok(())
},
)?;
self.indexes_to_supply_in_loss_relative_to_circulating_supply
@@ -2759,7 +2783,8 @@ impl Vecs {
.unwrap(),
dateindex_to_supply,
exit,
)
)?;
Ok(())
},
)?;
self.indexes_to_supply_in_profit_relative_to_circulating_supply
@@ -2782,7 +2807,8 @@ impl Vecs {
.unwrap(),
dateindex_to_supply,
exit,
)
)?;
Ok(())
},
)?;
}
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use brk_core::Height;
use brk_structs::Height;
use derive_deref::{Deref, DerefMut};
use crate::stateful::AddressTypeToVec;
+160 -208
View File
@@ -1,31 +1,26 @@
use std::{cmp::Ordering, collections::BTreeMap, mem, path::Path, sync::Arc, thread};
use brk_core::{
use brk_error::Result;
use brk_indexer::Indexer;
use brk_structs::{
AnyAddressDataIndexEnum, AnyAddressIndex, ByAddressType, ByAnyAddress, CheckedSub, DateIndex,
Dollars, EmptyAddressData, EmptyAddressIndex, Height, InputIndex, LoadedAddressData,
LoadedAddressIndex, OutputIndex, OutputType, P2AAddressIndex, P2PK33AddressIndex,
P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex,
P2WSHAddressIndex, Result, Sats, StoredUsize, Timestamp, TypeIndex, Version,
P2WSHAddressIndex, Sats, StoredU64, Timestamp, TypeIndex, Version,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vecs::{
AnyCollectableVec, AnyStampedVec, AnyVec, CollectableVec, Computation, EagerVec, File, Format,
GenericStoredVec, Reader, Stamp, StampedVec, StoredIndex, StoredVec, VecIterator,
AnyCollectableVec, AnyStoredVec, AnyVec, CollectableVec, Computation, EagerVec, Exit, File,
Format, GenericStoredVec, RawVec, Reader, Stamp, StoredIndex, VecIterator,
};
use log::info;
use rayon::prelude::*;
use crate::{
BlockState, SupplyState, Transacted,
grouped::{ComputedVecsFromHeight, Source},
market,
};
use super::{
Indexes, fetched,
BlockState, Indexes, SupplyState, Transacted,
grouped::{ComputedValueVecsFromHeight, VecBuilderOptions},
indexes, transactions,
grouped::{ComputedVecsFromHeight, Source},
indexes, market, price, transactions,
};
mod address_cohort;
@@ -58,7 +53,9 @@ const VERSION: Version = Version::new(21);
#[derive(Clone)]
pub struct Vecs {
pub chain_state: StoredVec<Height, SupplyState>,
file: Arc<File>,
pub chain_state: RawVec<Height, SupplyState>,
pub height_to_unspendable_supply: EagerVec<Height, Sats>,
pub indexes_to_unspendable_supply: ComputedValueVecsFromHeight,
@@ -71,51 +68,52 @@ pub struct Vecs {
pub utxo_cohorts: utxo_cohorts::Vecs,
pub address_cohorts: address_cohorts::Vecs,
pub p2pk33addressindex_to_anyaddressindex: StampedVec<P2PK33AddressIndex, AnyAddressIndex>,
pub p2pk65addressindex_to_anyaddressindex: StampedVec<P2PK65AddressIndex, AnyAddressIndex>,
pub p2pkhaddressindex_to_anyaddressindex: StampedVec<P2PKHAddressIndex, AnyAddressIndex>,
pub p2shaddressindex_to_anyaddressindex: StampedVec<P2SHAddressIndex, AnyAddressIndex>,
pub p2traddressindex_to_anyaddressindex: StampedVec<P2TRAddressIndex, AnyAddressIndex>,
pub p2wpkhaddressindex_to_anyaddressindex: StampedVec<P2WPKHAddressIndex, AnyAddressIndex>,
pub p2wshaddressindex_to_anyaddressindex: StampedVec<P2WSHAddressIndex, AnyAddressIndex>,
pub p2aaddressindex_to_anyaddressindex: StampedVec<P2AAddressIndex, AnyAddressIndex>,
pub loadedaddressindex_to_loadedaddressdata: StampedVec<LoadedAddressIndex, LoadedAddressData>,
pub emptyaddressindex_to_emptyaddressdata: StampedVec<EmptyAddressIndex, EmptyAddressData>,
pub p2pk33addressindex_to_anyaddressindex: RawVec<P2PK33AddressIndex, AnyAddressIndex>,
pub p2pk65addressindex_to_anyaddressindex: RawVec<P2PK65AddressIndex, AnyAddressIndex>,
pub p2pkhaddressindex_to_anyaddressindex: RawVec<P2PKHAddressIndex, AnyAddressIndex>,
pub p2shaddressindex_to_anyaddressindex: RawVec<P2SHAddressIndex, AnyAddressIndex>,
pub p2traddressindex_to_anyaddressindex: RawVec<P2TRAddressIndex, AnyAddressIndex>,
pub p2wpkhaddressindex_to_anyaddressindex: RawVec<P2WPKHAddressIndex, AnyAddressIndex>,
pub p2wshaddressindex_to_anyaddressindex: RawVec<P2WSHAddressIndex, AnyAddressIndex>,
pub p2aaddressindex_to_anyaddressindex: RawVec<P2AAddressIndex, AnyAddressIndex>,
pub loadedaddressindex_to_loadedaddressdata: RawVec<LoadedAddressIndex, LoadedAddressData>,
pub emptyaddressindex_to_emptyaddressdata: RawVec<EmptyAddressIndex, EmptyAddressData>,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_empty_address_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_empty_address_count: ComputedVecsFromHeight<StoredU64>,
}
impl Vecs {
pub fn forced_import(
file: &Arc<File>,
parent: &Path,
version: Version,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
states_path: &Path,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
) -> Result<Self> {
let file = Arc::new(File::open(&parent.join("stateful"))?);
let chain_file = Arc::new(File::open(&states_path.join("chain"))?);
let compute_dollars = price.is_some();
let chain_file = Arc::new(File::open(&parent.join("chain"))?);
Ok(Self {
chain_state: StoredVec::forced_import(
chain_state: RawVec::forced_import(
&chain_file,
"chain",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
height_to_unspendable_supply: EagerVec::forced_import(
file,
&file,
"unspendable_supply",
version + VERSION + Version::ZERO,
format,
)?,
indexes_to_unspendable_supply: ComputedValueVecsFromHeight::forced_import(
file,
&file,
"unspendable_supply",
Source::None,
version + VERSION + Version::ZERO,
@@ -126,13 +124,13 @@ impl Vecs {
indexes,
)?,
height_to_opreturn_supply: EagerVec::forced_import(
file,
&file,
"opreturn_supply",
version + VERSION + Version::ZERO,
format,
)?,
indexes_to_opreturn_supply: ComputedValueVecsFromHeight::forced_import(
file,
&file,
"opreturn_supply",
Source::None,
version + VERSION + Version::ZERO,
@@ -143,7 +141,7 @@ impl Vecs {
indexes,
)?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
file,
&file,
"address_count",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -153,7 +151,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import(
file,
&file,
"empty_address_count",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -165,49 +163,49 @@ impl Vecs {
addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
p2pk65: EagerVec::forced_import(
file,
&file,
"p2pk65_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2pk33: EagerVec::forced_import(
file,
&file,
"p2pk33_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2pkh: EagerVec::forced_import(
file,
&file,
"p2pkh_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2sh: EagerVec::forced_import(
file,
&file,
"p2sh_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2wpkh: EagerVec::forced_import(
file,
&file,
"p2wpkh_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2wsh: EagerVec::forced_import(
file,
&file,
"p2wsh_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2tr: EagerVec::forced_import(
file,
&file,
"p2tr_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2a: EagerVec::forced_import(
file,
&file,
"p2a_address_count",
version + VERSION + Version::ZERO,
format,
@@ -217,49 +215,49 @@ impl Vecs {
addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
p2pk65: EagerVec::forced_import(
file,
&file,
"p2pk65_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2pk33: EagerVec::forced_import(
file,
&file,
"p2pk33_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2pkh: EagerVec::forced_import(
file,
&file,
"p2pkh_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2sh: EagerVec::forced_import(
file,
&file,
"p2sh_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2wpkh: EagerVec::forced_import(
file,
&file,
"p2wpkh_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2wsh: EagerVec::forced_import(
file,
&file,
"p2wsh_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2tr: EagerVec::forced_import(
file,
&file,
"p2tr_empty_address_count",
version + VERSION + Version::ZERO,
format,
)?,
p2a: EagerVec::forced_import(
file,
&file,
"p2a_empty_address_count",
version + VERSION + Version::ZERO,
format,
@@ -269,7 +267,7 @@ impl Vecs {
addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount::from(
ByAddressType {
p2pk65: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2pk65_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -279,7 +277,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2pk33_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -289,7 +287,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2pkh_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -299,7 +297,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2sh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2sh_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -309,7 +307,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2wpkh_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -319,7 +317,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2wsh_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -329,7 +327,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2tr: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2tr_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -339,7 +337,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2a: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2a_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -353,7 +351,7 @@ impl Vecs {
addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount::from(
ByAddressType {
p2pk65: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2pk65_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -363,7 +361,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2pk33_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -373,7 +371,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2pkh_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -383,7 +381,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2sh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2sh_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -393,7 +391,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2wpkh_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -403,7 +401,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2wsh_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -413,7 +411,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2tr: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2tr_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -423,7 +421,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
p2a: ComputedVecsFromHeight::forced_import(
file,
&file,
"p2a_empty_address_count",
Source::None,
version + VERSION + Version::ZERO,
@@ -435,85 +433,77 @@ impl Vecs {
},
),
utxo_cohorts: utxo_cohorts::Vecs::forced_import(
file,
&file,
version,
computation,
format,
indexes,
fetched,
price,
states_path,
)?,
address_cohorts: address_cohorts::Vecs::forced_import(
file,
&file,
version,
computation,
format,
indexes,
fetched,
price,
states_path,
)?,
p2aaddressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2aaddressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2pk33addressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2pk33addressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2pk65addressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2pk65addressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2pkhaddressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2pkhaddressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2shaddressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2shaddressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2traddressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2traddressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2wpkhaddressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2wpkhaddressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
p2wshaddressindex_to_anyaddressindex: StampedVec::forced_import(
file,
p2wshaddressindex_to_anyaddressindex: RawVec::forced_import(
&file,
"anyaddressindex",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
loadedaddressindex_to_loadedaddressdata: StampedVec::forced_import(
file,
loadedaddressindex_to_loadedaddressdata: RawVec::forced_import(
&file,
"loadedaddressdata",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
emptyaddressindex_to_emptyaddressdata: StampedVec::forced_import(
file,
emptyaddressindex_to_emptyaddressdata: RawVec::forced_import(
&file,
"emptyaddressdata",
version + VERSION + Version::ZERO,
Format::Raw,
)?,
file,
})
}
@@ -523,12 +513,12 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
transactions: &transactions::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
market: &market::Vecs,
// Must take ownership as its indexes will be updated for this specific function
starting_indexes: &mut Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
let height_to_first_outputindex = &indexer.vecs.height_to_first_outputindex;
let height_to_first_inputindex = &indexer.vecs.height_to_first_inputindex;
let height_to_first_p2aaddressindex = &indexer.vecs.height_to_first_p2aaddressindex;
@@ -554,12 +544,12 @@ impl Vecs {
.height
.as_ref()
.unwrap();
let height_to_close = fetched
let height_to_close = price
.as_ref()
.map(|fetched| &fetched.chainindexes_to_close.height);
let dateindex_to_close = fetched
.map(|price| &price.chainindexes_to_close.height);
let dateindex_to_close = price
.as_ref()
.map(|fetched| fetched.timeindexes_to_close.dateindex.as_ref().unwrap());
.map(|price| price.timeindexes_to_close.dateindex.as_ref().unwrap());
let height_to_date_fixed = &indexes.height_to_date_fixed;
let dateindex_to_first_height = &indexes.dateindex_to_first_height;
let dateindex_to_height_count = &indexes.dateindex_to_height_count;
@@ -632,56 +622,16 @@ impl Vecs {
.unwrap_or_default(),
)
.min(chain_state_starting_height)
.min(
Height::from(u64::from(
self.p2pk33addressindex_to_anyaddressindex.stamp(),
))
.incremented(),
)
.min(
Height::from(u64::from(
self.p2pk65addressindex_to_anyaddressindex.stamp(),
))
.incremented(),
)
.min(
Height::from(u64::from(self.p2pkhaddressindex_to_anyaddressindex.stamp()))
.incremented(),
)
.min(
Height::from(u64::from(self.p2shaddressindex_to_anyaddressindex.stamp()))
.incremented(),
)
.min(
Height::from(u64::from(self.p2traddressindex_to_anyaddressindex.stamp()))
.incremented(),
)
.min(
Height::from(u64::from(
self.p2wpkhaddressindex_to_anyaddressindex.stamp(),
))
.incremented(),
)
.min(
Height::from(u64::from(self.p2wshaddressindex_to_anyaddressindex.stamp()))
.incremented(),
)
.min(
Height::from(u64::from(self.p2aaddressindex_to_anyaddressindex.stamp()))
.incremented(),
)
.min(
Height::from(u64::from(
self.loadedaddressindex_to_loadedaddressdata.stamp(),
))
.incremented(),
)
.min(
Height::from(u64::from(
self.emptyaddressindex_to_emptyaddressdata.stamp(),
))
.incremented(),
)
.min(Height::from(self.p2pk33addressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2pk65addressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2pkhaddressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2shaddressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2traddressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2wpkhaddressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2wshaddressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.p2aaddressindex_to_anyaddressindex.stamp()).incremented())
.min(Height::from(self.loadedaddressindex_to_loadedaddressdata.stamp()).incremented())
.min(Height::from(self.emptyaddressindex_to_emptyaddressdata.stamp()).incremented())
.min(Height::from(self.height_to_unspendable_supply.len()))
.min(Height::from(self.height_to_opreturn_supply.len()))
.cmp(&chain_state_starting_height)
@@ -745,7 +695,7 @@ impl Vecs {
.try_for_each(|(_, v)| v.state.reset_price_to_amount())?;
};
let last_height = Height::from(u64::from(indexer.vecs.height_to_blockhash.stamp()));
let last_height = Height::from(indexer.vecs.height_to_blockhash.stamp());
if starting_height <= last_height {
let inputindex_to_outputindex_reader = inputindex_to_outputindex.create_reader();
@@ -836,7 +786,7 @@ impl Vecs {
(height.unwrap_to_usize()..height_to_date_fixed.len())
.map(Height::from)
.try_for_each(|_height| -> color_eyre::Result<()> {
.try_for_each(|_height| -> Result<()> {
height = _height;
info!("Processing chain at {height}...");
@@ -903,7 +853,7 @@ impl Vecs {
.tick_tock_next_block(&chain_state, timestamp);
});
let (transacted, addresstype_to_typedindex_to_received_data, receiving_addresstype_to_typeindex_to_addressdatawithsource) = (first_outputindex..first_outputindex + *output_count)
let (transacted, addresstype_to_typedindex_to_received_data, receiving_addresstype_to_typeindex_to_addressdatawithsource) = (first_outputindex..first_outputindex + usize::from(output_count))
.into_par_iter()
.map(OutputIndex::from)
.map(|outputindex| {
@@ -987,7 +937,7 @@ impl Vecs {
);
// Skip coinbase
let (height_to_sent, addresstype_to_typedindex_to_sent_data, sending_addresstype_to_typeindex_to_addressdatawithsource) = (first_inputindex + 1..first_inputindex + *input_count)
let (height_to_sent, addresstype_to_typedindex_to_sent_data, sending_addresstype_to_typeindex_to_addressdatawithsource) = (first_inputindex + 1..first_inputindex + usize::from(input_count))
.into_par_iter()
.map(InputIndex::from)
.map(|inputindex| {
@@ -1287,7 +1237,8 @@ impl Vecs {
.map(|(_, v)| v)
.collect::<Vec<_>>(),
exit,
)
)?;
Ok(())
},
)?;
@@ -1306,14 +1257,15 @@ impl Vecs {
.map(|(_, v)| v)
.collect::<Vec<_>>(),
exit,
)
)?;
Ok(())
},
)?;
self.indexes_to_unspendable_supply.compute_rest(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
Some(&self.height_to_unspendable_supply),
@@ -1321,7 +1273,7 @@ impl Vecs {
self.indexes_to_opreturn_supply.compute_rest(
indexer,
indexes,
fetched,
price,
starting_indexes,
exit,
Some(&self.height_to_opreturn_supply),
@@ -1342,15 +1294,10 @@ impl Vecs {
)?;
self.utxo_cohorts
.compute_rest_part1(indexer, indexes, fetched, starting_indexes, exit)?;
.compute_rest_part1(indexer, indexes, price, starting_indexes, exit)?;
self.address_cohorts.compute_rest_part1(
indexer,
indexes,
fetched,
starting_indexes,
exit,
)?;
self.address_cohorts
.compute_rest_part1(indexer, indexes, price, starting_indexes, exit)?;
info!("Computing rest part 2...");
@@ -1384,7 +1331,7 @@ impl Vecs {
self.utxo_cohorts.compute_rest_part2(
indexer,
indexes,
fetched,
price,
starting_indexes,
market,
height_to_supply,
@@ -1397,7 +1344,7 @@ impl Vecs {
self.address_cohorts.compute_rest_part2(
indexer,
indexes,
fetched,
price,
starting_indexes,
market,
height_to_supply,
@@ -1407,6 +1354,8 @@ impl Vecs {
exit,
)?;
self.file.flush()?;
self.file.punch_holes()?;
Ok(())
}
@@ -1423,16 +1372,16 @@ impl Vecs {
>,
addresstypeindex_to_anyaddressindex_reader_opt: &ByAddressType<Option<Reader>>,
anyaddressindex_to_anyaddressdata_reader_opt: &ByAnyAddress<Option<Reader>>,
p2pk33addressindex_to_anyaddressindex: &StampedVec<P2PK33AddressIndex, AnyAddressIndex>,
p2pk65addressindex_to_anyaddressindex: &StampedVec<P2PK65AddressIndex, AnyAddressIndex>,
p2pkhaddressindex_to_anyaddressindex: &StampedVec<P2PKHAddressIndex, AnyAddressIndex>,
p2shaddressindex_to_anyaddressindex: &StampedVec<P2SHAddressIndex, AnyAddressIndex>,
p2traddressindex_to_anyaddressindex: &StampedVec<P2TRAddressIndex, AnyAddressIndex>,
p2wpkhaddressindex_to_anyaddressindex: &StampedVec<P2WPKHAddressIndex, AnyAddressIndex>,
p2wshaddressindex_to_anyaddressindex: &StampedVec<P2WSHAddressIndex, AnyAddressIndex>,
p2aaddressindex_to_anyaddressindex: &StampedVec<P2AAddressIndex, AnyAddressIndex>,
loadedaddressindex_to_loadedaddressdata: &StampedVec<LoadedAddressIndex, LoadedAddressData>,
emptyaddressindex_to_emptyaddressdata: &StampedVec<EmptyAddressIndex, EmptyAddressData>,
p2pk33addressindex_to_anyaddressindex: &RawVec<P2PK33AddressIndex, AnyAddressIndex>,
p2pk65addressindex_to_anyaddressindex: &RawVec<P2PK65AddressIndex, AnyAddressIndex>,
p2pkhaddressindex_to_anyaddressindex: &RawVec<P2PKHAddressIndex, AnyAddressIndex>,
p2shaddressindex_to_anyaddressindex: &RawVec<P2SHAddressIndex, AnyAddressIndex>,
p2traddressindex_to_anyaddressindex: &RawVec<P2TRAddressIndex, AnyAddressIndex>,
p2wpkhaddressindex_to_anyaddressindex: &RawVec<P2WPKHAddressIndex, AnyAddressIndex>,
p2wshaddressindex_to_anyaddressindex: &RawVec<P2WSHAddressIndex, AnyAddressIndex>,
p2aaddressindex_to_anyaddressindex: &RawVec<P2AAddressIndex, AnyAddressIndex>,
loadedaddressindex_to_loadedaddressdata: &RawVec<LoadedAddressIndex, LoadedAddressData>,
emptyaddressindex_to_emptyaddressdata: &RawVec<EmptyAddressIndex, EmptyAddressData>,
) -> Option<WithAddressDataSource<LoadedAddressData>> {
if *first_addressindexes.get(address_type).unwrap() <= typeindex {
return Some(WithAddressDataSource::New(LoadedAddressData::default()));
@@ -1643,7 +1592,8 @@ impl Vecs {
emptyaddressdata,
)) => self
.emptyaddressindex_to_emptyaddressdata
.update(emptyaddressindex, emptyaddressdata),
.update(emptyaddressindex, emptyaddressdata)
.map_err(|e| e.into()),
WithAddressDataSource::FromLoadedAddressDataVec((
loadedaddressindex,
emptyaddressdata,
@@ -1695,7 +1645,8 @@ impl Vecs {
loadedaddressdata,
)) => self
.loadedaddressindex_to_loadedaddressdata
.update(loadedaddressindex, loadedaddressdata),
.update(loadedaddressindex, loadedaddressdata)
.map_err(|e| e.into()),
WithAddressDataSource::FromEmptyAddressDataVec((
emptyaddressindex,
loadedaddressdata,
@@ -1753,30 +1704,31 @@ impl Vecs {
.p2aaddressindex_to_anyaddressindex
.update_or_push(typeindex.into(), anyaddressindex),
_ => unreachable!(),
}
}?;
Ok(())
})
})?;
self.p2pk33addressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2pk65addressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2pkhaddressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2shaddressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2traddressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2wpkhaddressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2wshaddressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.p2aaddressindex_to_anyaddressindex
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.loadedaddressindex_to_loadedaddressdata
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.emptyaddressindex_to_emptyaddressdata
.flush(Stamp::from(u64::from(height)))?;
.stamped_flush(Stamp::from(height))?;
self.chain_state.truncate_if_needed(Height::ZERO)?;
chain_state.iter().for_each(|block_state| {
@@ -1838,8 +1790,8 @@ impl AddressTypeToVec<(TypeIndex, Sats)> {
WithAddressDataSource<EmptyAddressData>,
>,
price: Option<Dollars>,
addresstype_to_address_count: &mut ByAddressType<usize>,
addresstype_to_empty_address_count: &mut ByAddressType<usize>,
addresstype_to_address_count: &mut ByAddressType<u64>,
addresstype_to_empty_address_count: &mut ByAddressType<u64>,
stored_or_new_addresstype_to_typeindex_to_addressdatawithsource: &mut AddressTypeToTypeIndexTree<
WithAddressDataSource<LoadedAddressData>,
>,
@@ -1928,9 +1880,9 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
WithAddressDataSource<EmptyAddressData>,
>,
price: Option<Dollars>,
addresstype_to_address_count: &mut ByAddressType<usize>,
addresstype_to_empty_address_count: &mut ByAddressType<usize>,
height_to_close_vec: Option<&Vec<brk_core::Close<Dollars>>>,
addresstype_to_address_count: &mut ByAddressType<u64>,
addresstype_to_empty_address_count: &mut ByAddressType<u64>,
height_to_close_vec: Option<&Vec<brk_structs::Close<Dollars>>>,
height_to_timestamp_fixed_vec: &[Timestamp],
height: Height,
timestamp: Timestamp,
+18 -4
View File
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;
use brk_vecs::{StampedVec, StoredIndex, StoredType};
use brk_vecs::{CompressedVec, RawVec, StoredCompressed, StoredIndex, StoredRaw};
#[derive(Debug)]
pub struct RangeMap<I, T>(BTreeMap<I, T>);
@@ -20,12 +20,26 @@ where
}
}
impl<I, T> From<&StampedVec<I, T>> for RangeMap<T, I>
impl<I, T> From<&RawVec<I, T>> for RangeMap<T, I>
where
I: StoredIndex,
T: StoredIndex + StoredType,
T: StoredIndex + StoredRaw,
{
fn from(vec: &StampedVec<I, T>) -> Self {
fn from(vec: &RawVec<I, T>) -> Self {
Self(
vec.into_iter()
.map(|(i, v)| (v.into_owned(), i))
.collect::<BTreeMap<_, _>>(),
)
}
}
impl<I, T> From<&CompressedVec<I, T>> for RangeMap<T, I>
where
I: StoredIndex,
T: StoredIndex + StoredCompressed,
{
fn from(vec: &CompressedVec<I, T>) -> Self {
Self(
vec.into_iter()
.map(|(i, v)| (v.into_owned(), i))
+8 -8
View File
@@ -1,9 +1,9 @@
use brk_core::{Bitcoin, DateIndex, Dollars, Height, Result, Version};
use brk_exit::Exit;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_vecs::{AnyCollectableVec, AnyIterableVec};
use brk_structs::{Bitcoin, DateIndex, Dollars, Height, Version};
use brk_vecs::{AnyCollectableVec, AnyIterableVec, Exit};
use crate::{Indexes, fetched, indexes, market};
use crate::{Indexes, indexes, market, price};
pub trait DynCohortVecs: Send + Sync {
fn starting_height(&self) -> Height;
@@ -30,10 +30,10 @@ pub trait DynCohortVecs: Send + Sync {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()>;
) -> Result<()>;
fn vecs(&self) -> Vec<&dyn AnyCollectableVec>;
}
@@ -51,7 +51,7 @@ pub trait CohortVecs: DynCohortVecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
market: &market::Vecs,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
@@ -59,5 +59,5 @@ pub trait CohortVecs: DynCohortVecs {
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> color_eyre::Result<()>;
) -> Result<()>;
}
+14 -14
View File
@@ -1,12 +1,12 @@
use std::{ops::Deref, path::Path, sync::Arc};
use brk_core::{Bitcoin, DateIndex, Dollars, Height, Result, Version};
use brk_exit::Exit;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_vecs::{AnyCollectableVec, AnyIterableVec, Computation, File, Format};
use brk_structs::{Bitcoin, DateIndex, Dollars, Height, Version};
use brk_vecs::{AnyCollectableVec, AnyIterableVec, Computation, Exit, File, Format};
use crate::{
Indexes, UTXOCohortState, fetched, indexes, market,
Indexes, UTXOCohortState, indexes, market, price,
stateful::{
common,
r#trait::{CohortVecs, DynCohortVecs},
@@ -31,12 +31,12 @@ impl Vecs {
format: Format,
version: Version,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
states_path: &Path,
compute_relative_to_all: bool,
ratio_extended: bool,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
) -> Result<Self> {
let compute_dollars = price.is_some();
Ok(Self {
starting_height: Height::ZERO,
@@ -54,7 +54,7 @@ impl Vecs {
format,
version,
indexes,
fetched,
price,
compute_relative_to_all,
ratio_extended,
)?,
@@ -123,12 +123,12 @@ impl DynCohortVecs for Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.inner
.compute_rest_part1(indexer, indexes, fetched, starting_indexes, exit)
.compute_rest_part1(indexer, indexes, price, starting_indexes, exit)
}
fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
@@ -155,7 +155,7 @@ impl CohortVecs for Vecs {
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
fetched: Option<&fetched::Vecs>,
price: Option<&price::Vecs>,
starting_indexes: &Indexes,
market: &market::Vecs,
height_to_supply: &impl AnyIterableVec<Height, Bitcoin>,
@@ -163,11 +163,11 @@ impl CohortVecs for Vecs {
height_to_realized_cap: Option<&impl AnyIterableVec<Height, Dollars>>,
dateindex_to_realized_cap: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> Result<()> {
self.inner.compute_rest_part2(
indexer,
indexes,
fetched,
price,
starting_indexes,
market,
height_to_supply,
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,4 @@
use brk_core::{EmptyAddressData, EmptyAddressIndex, LoadedAddressData, LoadedAddressIndex};
use brk_structs::{EmptyAddressData, EmptyAddressIndex, LoadedAddressData, LoadedAddressIndex};
#[derive(Debug)]
pub enum WithAddressDataSource<T> {