global: fixes

This commit is contained in:
nym21
2026-04-27 12:52:02 +02:00
parent b24bfdc15c
commit 76869ed2b6
114 changed files with 6623 additions and 1981 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ pub struct Vecs<M: StorageMode = Rw> {
pub _9m: M::Stored<EagerVec<PcoVec<Height, Height>>>, // 270d
pub _350d: M::Stored<EagerVec<PcoVec<Height, Height>>>,
pub _12m: M::Stored<EagerVec<PcoVec<Height, Height>>>, // 360d
pub _1y: CachedVec<M::Stored<EagerVec<PcoVec<Height, Height>>>>, // 365d
pub _1y: CachedVec<M::Stored<EagerVec<PcoVec<Height, Height>>>>, // 365d
pub _14m: M::Stored<EagerVec<PcoVec<Height, Height>>>, // 420d
pub _2y: M::Stored<EagerVec<PcoVec<Height, Height>>>, // 730d
pub _26m: M::Stored<EagerVec<PcoVec<Height, Height>>>, // 780d
@@ -165,9 +165,7 @@ impl ActivityCountVecs {
self.reactivated.block.push(counts.reactivated.into());
self.sending.block.push(counts.sending.into());
self.receiving.block.push(counts.receiving.into());
self.bidirectional
.block
.push(counts.bidirectional.into());
self.bidirectional.block.push(counts.bidirectional.into());
let active = counts.sending + counts.receiving - counts.bidirectional;
self.active.block.push(active.into());
}
@@ -14,8 +14,7 @@ use super::TotalAddrCountVecs;
/// New address count per block (global + per-type).
#[derive(Deref, DerefMut, Traversable)]
pub struct NewAddrCountVecs<M: StorageMode = Rw>(
#[traversable(flatten)]
pub WithAddrTypes<PerBlockCumulativeRolling<StoredU64, StoredU64, M>>,
#[traversable(flatten)] pub WithAddrTypes<PerBlockCumulativeRolling<StoredU64, StoredU64, M>>,
);
impl NewAddrCountVecs {
@@ -28,7 +27,11 @@ impl NewAddrCountVecs {
Ok(Self(WithAddrTypes::<
PerBlockCumulativeRolling<StoredU64, StoredU64>,
>::forced_import(
db, "new_addr_count", version, indexes, cached_starts
db,
"new_addr_count",
version,
indexes,
cached_starts,
)?))
}
@@ -92,34 +92,30 @@ impl AddrEventsVecs {
cached_starts,
)
};
let import_percent = |name: &str| -> Result<WithAddrTypes<
PercentCumulativeRolling<BasisPoints16>,
>> {
Ok(WithAddrTypes {
all: PercentCumulativeRolling::forced_import(db, name, version, indexes)?,
by_addr_type: ByAddrType::new_with_name(|type_name| {
PercentCumulativeRolling::forced_import(
db,
&format!("{type_name}_{name}"),
version,
indexes,
)
})?,
})
};
let import_percent =
|name: &str| -> Result<WithAddrTypes<PercentCumulativeRolling<BasisPoints16>>> {
Ok(WithAddrTypes {
all: PercentCumulativeRolling::forced_import(db, name, version, indexes)?,
by_addr_type: ByAddrType::new_with_name(|type_name| {
PercentCumulativeRolling::forced_import(
db,
&format!("{type_name}_{name}"),
version,
indexes,
)
})?,
})
};
let output_to_reused_addr_count =
import_count(&format!("output_to_{name}_addr_count"))?;
let output_to_reused_addr_share =
import_percent(&format!("output_to_{name}_addr_share"))?;
let output_to_reused_addr_count = import_count(&format!("output_to_{name}_addr_count"))?;
let output_to_reused_addr_share = import_percent(&format!("output_to_{name}_addr_share"))?;
let spendable_output_to_reused_addr_share = PercentCumulativeRolling::forced_import(
db,
&format!("spendable_output_to_{name}_addr_share"),
version,
indexes,
)?;
let input_from_reused_addr_count =
import_count(&format!("input_from_{name}_addr_count"))?;
let input_from_reused_addr_count = import_count(&format!("input_from_{name}_addr_count"))?;
let input_from_reused_addr_share =
import_percent(&format!("input_from_{name}_addr_share"))?;
@@ -229,12 +225,13 @@ impl AddrEventsVecs {
starting_indexes.height,
exit,
)?;
self.spendable_output_to_reused_addr_share.compute_count_ratio(
&self.output_to_reused_addr_count.all,
&outputs_by_type.spendable_output_count,
starting_indexes.height,
exit,
)?;
self.spendable_output_to_reused_addr_share
.compute_count_ratio(
&self.output_to_reused_addr_count.all,
&outputs_by_type.spendable_output_count,
starting_indexes.height,
exit,
)?;
self.input_from_reused_addr_share.all.compute_count_ratio(
&self.input_from_reused_addr_count.all,
&inputs_by_type.input_count.all,
@@ -246,7 +243,9 @@ impl AddrEventsVecs {
.by_addr_type
.get_mut_unwrap(otype)
.compute_count_ratio(
self.output_to_reused_addr_count.by_addr_type.get_unwrap(otype),
self.output_to_reused_addr_count
.by_addr_type
.get_unwrap(otype),
outputs_by_type.output_count.by_type.get(otype),
starting_indexes.height,
exit,
@@ -255,7 +254,9 @@ impl AddrEventsVecs {
.by_addr_type
.get_mut_unwrap(otype)
.compute_count_ratio(
self.input_from_reused_addr_count.by_addr_type.get_unwrap(otype),
self.input_from_reused_addr_count
.by_addr_type
.get_unwrap(otype),
inputs_by_type.input_count.by_type.get(otype),
starting_indexes.height,
exit,
@@ -2,9 +2,7 @@ use brk_types::{FundedAddrData, Height, OutputType, Sats};
use crate::distribution::{block::TrackingStatus, vecs::AddrMetricsVecs};
use super::{
AddrTypeToActivityCounts, AddrTypeToAddrCount, ExposedAddrState, ReusedAddrState,
};
use super::{AddrTypeToActivityCounts, AddrTypeToAddrCount, ExposedAddrState, ReusedAddrState};
/// Bundle of per-block runtime state for the full address-metrics pipeline.
/// Feeds `process_received` / `process_sent` and is pushed to [`AddrMetricsVecs`]
@@ -162,7 +160,8 @@ impl AddrMetricsState {
also_received,
will_be_empty,
);
self.exposed.on_send(output_type, addr_data, pre, will_be_empty);
self.exposed
.on_send(output_type, addr_data, pre, will_be_empty);
}
}
@@ -67,8 +67,7 @@ pub(crate) fn process_funded_addrs(
// Pure pushes - no holes remain
addrs_data.funded.reserve_pushed(pushes_iter.len());
for (next_index, (addr_type, type_index, data)) in
(addrs_data.funded.len()..).zip(pushes_iter)
for (next_index, (addr_type, type_index, data)) in (addrs_data.funded.len()..).zip(pushes_iter)
{
addrs_data.funded.push(data);
result.get_mut(addr_type).unwrap().insert(
@@ -138,9 +137,7 @@ pub(crate) fn process_empty_addrs(
// Pure pushes - no holes remain
addrs_data.empty.reserve_pushed(pushes_iter.len());
for (next_index, (addr_type, type_index, data)) in
(addrs_data.empty.len()..).zip(pushes_iter)
{
for (next_index, (addr_type, type_index, data)) in (addrs_data.empty.len()..).zip(pushes_iter) {
addrs_data.empty.push(data);
result.get_mut(addr_type).unwrap().insert(
type_index,
@@ -1,9 +1,9 @@
use std::{cmp::Reverse, collections::BinaryHeap, fs, path::Path};
use brk_cohort::{AGE_RANGE_NAMES, CohortContext, Filtered, PROFITABILITY_RANGE_COUNT, TERM_NAMES};
use rayon::prelude::*;
use brk_error::Result;
use brk_types::{BasisPoints16, Cents, CentsCompact, UrpdRaw, Date, Dollars, Sats};
use brk_types::{BasisPoints16, Cents, CentsCompact, Date, Dollars, Sats, UrpdRaw};
use rayon::prelude::*;
use crate::distribution::metrics::{CostBasis, ProfitabilityMetrics};
@@ -190,7 +190,10 @@ pub(crate) fn process_blocks(
.first_index
.collect_range_at(start_usize, end_usize);
debug!("recovering addr metrics state from height {}", starting_height);
debug!(
"recovering addr metrics state from height {}",
starting_height
);
let mut state = AddrMetricsState::from((&vecs.addrs, starting_height));
debug!("addr metrics state recovered");
@@ -9,7 +9,7 @@ use crate::{
metrics::ImportConfig,
state::{CohortState, CostBasisOps, RealizedOps},
},
internal::{ValuePerBlockCumulativeRolling, PerBlockCumulativeRolling},
internal::{PerBlockCumulativeRolling, ValuePerBlockCumulativeRolling},
prices,
};
@@ -7,11 +7,11 @@ use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
use crate::{
indexes,
internal::{
ValuePerBlock, ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, FiatType,
FiatPerBlock, FiatPerBlockCumulativeWithSums, NumericValue, PerBlock,
FiatPerBlock, FiatPerBlockCumulativeWithSums, FiatType, NumericValue, PerBlock,
PerBlockCumulativeRolling, PercentPerBlock, PercentRollingWindows, Price,
PriceWithRatioExtendedPerBlock, PriceWithRatioPerBlock, RatioPerBlock,
RollingWindow24hPerBlock, RollingWindows, RollingWindowsFrom1w, WindowStartVec, Windows,
RollingWindow24hPerBlock, RollingWindows, RollingWindowsFrom1w, ValuePerBlock,
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, WindowStartVec, Windows,
},
};
@@ -201,7 +201,10 @@ impl CostBasis {
if invested_raw == 0 {
return (h, spot);
}
(h, Cents::new((capitalized_cap.inner() / invested_raw) as u64))
(
h,
Cents::new((capitalized_cap.inner() / invested_raw) as u64),
)
},
exit,
)?;
@@ -215,7 +218,10 @@ impl CostBasis {
if invested_raw == 0 {
return (h, spot);
}
(h, Cents::new((capitalized_cap.inner() / invested_raw) as u64))
(
h,
Cents::new((capitalized_cap.inner() / invested_raw) as u64),
)
},
exit,
)?;
@@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, Exit, Rw, StorageMode, WritableVec};
use crate::{
indexes,
internal::{
ValuePerBlock, ValuePerBlockWithDeltas, PerBlock, RatioPerBlock, WindowStartVec, Windows,
PerBlock, RatioPerBlock, ValuePerBlock, ValuePerBlockWithDeltas, WindowStartVec, Windows,
},
prices,
};
@@ -11,11 +11,11 @@ use crate::{
blocks,
distribution::state::{CohortState, CostBasisData, RealizedState, WithCapital},
internal::{
ValuePerBlockCumulativeRolling, FiatPerBlockCumulativeWithSums, PercentPerBlock,
PercentRollingWindows, PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32,
RatioCentsSignedCentsBps32, RatioCentsSignedDollarsBps32, RatioDollarsBp32,
RatioPerBlockPercentiles, RatioPerBlockStdDevBands, RatioSma, RollingWindows,
RollingWindowsFrom1w,
FiatPerBlockCumulativeWithSums, PercentPerBlock, PercentRollingWindows,
PriceWithRatioExtendedPerBlock, RatioCents64, RatioCentsBp32, RatioCentsSignedCentsBps32,
RatioCentsSignedDollarsBps32, RatioDollarsBp32, RatioPerBlockPercentiles,
RatioPerBlockStdDevBands, RatioSma, RollingWindows, RollingWindowsFrom1w,
ValuePerBlockCumulativeRolling,
},
prices,
};
@@ -76,13 +76,12 @@ impl SupplyBase {
all_supply_sats: &impl ReadableVec<Height, Sats>,
exit: &Exit,
) -> Result<()> {
self.dominance
.compute_binary::<Sats, Sats, RatioSatsBp16>(
max_from,
&self.total.sats.height,
all_supply_sats,
exit,
)
self.dominance.compute_binary::<Sats, Sats, RatioSatsBp16>(
max_from,
&self.total.sats.height,
all_supply_sats,
exit,
)
}
pub(crate) fn compute_from_stateful(
@@ -7,7 +7,7 @@ use vecdb::{AnyStoredVec, AnyVec, Exit, Rw, StorageMode, WritableVec};
use crate::{distribution::state::UnrealizedState, prices};
use crate::internal::{
ValuePerBlock, HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, LazyValuePerBlock,
HalveCents, HalveDollars, HalveSats, HalveSatsToBitcoin, LazyValuePerBlock, ValuePerBlock,
};
use crate::distribution::metrics::ImportConfig;
@@ -2,6 +2,6 @@ mod avg_amount;
mod base;
mod core;
pub use avg_amount::AvgAmountMetrics;
pub use self::core::SupplyCore;
pub use avg_amount::AvgAmountMetrics;
pub use base::SupplyBase;
@@ -215,8 +215,12 @@ impl<R: RealizedOps, C: CostBasisOps> CohortState<R, C> {
pre.prev_capitalized_cap,
);
self.cost_basis
.decrement(pre.prev_price, pre.sats, pre.prev_ps, pre.prev_capitalized_cap);
self.cost_basis.decrement(
pre.prev_price,
pre.sats,
pre.prev_ps,
pre.prev_capitalized_cap,
);
}
pub(crate) fn send_utxo(
@@ -5,14 +5,14 @@ use std::{
};
use brk_error::{Error, Result};
use brk_types::{
Cents, CentsCompact, CentsSats, CentsSquaredSats, UrpdRaw, Height, Sats,
};
use brk_types::{Cents, CentsCompact, CentsSats, CentsSquaredSats, Height, Sats, UrpdRaw};
use rustc_hash::FxHashMap;
use vecdb::{Bytes, unlikely};
use super::{Accumulate, CachedUnrealizedState, UnrealizedState};
use crate::distribution::state::pending::{PendingCapDelta, PendingDelta, PendingCapitalizedCapRawDelta};
use crate::distribution::state::pending::{
PendingCapDelta, PendingCapitalizedCapRawDelta, PendingDelta,
};
/// Type alias for the price-to-sats map used in cost basis data.
pub(super) type CostBasisMap = BTreeMap<CentsCompact, Sats>;
@@ -200,12 +200,14 @@ impl RealizedOps for CoreRealizedState {
#[inline]
fn increment_snapshot(&mut self, price_sats: CentsSats, _capitalized_cap: CentsSquaredSats) {
self.minimal.increment_snapshot(price_sats, _capitalized_cap);
self.minimal
.increment_snapshot(price_sats, _capitalized_cap);
}
#[inline]
fn decrement_snapshot(&mut self, price_sats: CentsSats, _capitalized_cap: CentsSquaredSats) {
self.minimal.decrement_snapshot(price_sats, _capitalized_cap);
self.minimal
.decrement_snapshot(price_sats, _capitalized_cap);
}
#[inline]
@@ -301,7 +303,8 @@ impl RealizedOps for RealizedState {
fn increment(&mut self, price: Cents, sats: Sats) {
self.core.increment(price, sats);
if sats.is_not_zero() {
self.capitalized_cap_raw += CentsSats::from_price_sats(price, sats).to_capitalized_cap(price);
self.capitalized_cap_raw +=
CentsSats::from_price_sats(price, sats).to_capitalized_cap(price);
}
}
+4 -3
View File
@@ -220,8 +220,7 @@ impl Vecs {
let addr_count = AddrCountsVecs::forced_import(&db, "addr_count", version, indexes)?;
let empty_addr_count =
AddrCountsVecs::forced_import(&db, "empty_addr_count", version, indexes)?;
let addr_activity =
AddrActivityVecs::forced_import(&db, version, indexes, cached_starts)?;
let addr_activity = AddrActivityVecs::forced_import(&db, version, indexes, cached_starts)?;
// Stored total = addr_count + empty_addr_count (global + per-type, with all derived indexes)
let total_addr_count = TotalAddrCountVecs::forced_import(&db, version, indexes)?;
@@ -548,7 +547,9 @@ impl Vecs {
self.addrs.empty.compute_rest(starting_indexes, exit)?;
let t = &self.utxo_cohorts.type_;
let type_supply_sats = ByAddrType::new(|filter| {
let Filter::Type(ot) = filter else { unreachable!() };
let Filter::Type(ot) = filter else {
unreachable!()
};
&t.get(ot).metrics.supply.total.sats.height
});
let all_supply_sats = &self.utxo_cohorts.all.metrics.supply.total.sats.height;
@@ -61,7 +61,11 @@ impl Vecs {
Ok(())
},
|agg| {
push_block(&mut self.input_count, agg.entries_all, &agg.entries_per_type);
push_block(
&mut self.input_count,
agg.entries_all,
&agg.entries_per_type,
);
push_block(&mut self.tx_count, agg.txs_all, &agg.txs_per_type);
if self.input_count.all.block.batch_limit_reached() {
@@ -81,8 +85,7 @@ impl Vecs {
self.input_count
.compute_rest(starting_indexes.height, exit)?;
self.tx_count
.compute_rest(starting_indexes.height, exit)?;
self.tx_count.compute_rest(starting_indexes.height, exit)?;
}
for (otype, source) in self.input_count.by_type.iter_typed() {
@@ -6,9 +6,7 @@ use vecdb::Database;
use super::{Vecs, WithInputTypes};
use crate::{
indexes,
internal::{
PerBlockCumulativeRolling, PercentCumulativeRolling, WindowStartVec, Windows,
},
internal::{PerBlockCumulativeRolling, PercentCumulativeRolling, WindowStartVec, Windows},
};
impl Vecs {
@@ -18,26 +16,24 @@ impl Vecs {
indexes: &indexes::Vecs,
cached_starts: &Windows<&WindowStartVec>,
) -> Result<Self> {
let input_count = WithInputTypes::<
PerBlockCumulativeRolling<StoredU64, StoredU64>,
>::forced_import_with(
db,
"input_count_bis",
|t| format!("{t}_prevout_count"),
version,
indexes,
cached_starts,
)?;
let tx_count = WithInputTypes::<
PerBlockCumulativeRolling<StoredU64, StoredU64>,
>::forced_import_with(
db,
"non_coinbase_tx_count",
|t| format!("tx_count_with_{t}_prevout"),
version,
indexes,
cached_starts,
)?;
let input_count =
WithInputTypes::<PerBlockCumulativeRolling<StoredU64, StoredU64>>::forced_import_with(
db,
"input_count_bis",
|t| format!("{t}_prevout_count"),
version,
indexes,
cached_starts,
)?;
let tx_count =
WithInputTypes::<PerBlockCumulativeRolling<StoredU64, StoredU64>>::forced_import_with(
db,
"non_coinbase_tx_count",
|t| format!("tx_count_with_{t}_prevout"),
version,
indexes,
cached_starts,
)?;
let input_share = SpendableType::try_new(|_, name| {
PercentCumulativeRolling::forced_import(
@@ -68,7 +68,9 @@ where
dep_version: Version,
at_height: Height,
) -> Result<()> {
self.all.block.validate_and_truncate(dep_version, at_height)?;
self.all
.block
.validate_and_truncate(dep_version, at_height)?;
for v in self.by_type.iter_mut() {
v.block.validate_and_truncate(dep_version, at_height)?;
}
+1 -2
View File
@@ -20,8 +20,7 @@ impl Vecs {
self.spent.compute(indexer, starting_indexes, exit)?;
self.count
.compute(indexer, indexes, blocks, starting_indexes, exit)?;
self.per_sec
.compute(&self.count, starting_indexes, exit)?;
self.per_sec.compute(&self.count, starting_indexes, exit)?;
self.by_type.compute(indexer, starting_indexes, exit)?;
let exit = exit.clone();
@@ -81,4 +81,3 @@ pub(crate) fn walk_blocks(
Ok(())
}
@@ -6,7 +6,7 @@ use vecdb::{Database, Exit, Rw, StorageMode};
use crate::{
indexes,
internal::{
FiatType, FiatBlock, FiatPerBlock, LazyRollingSumsFiatFromHeight, WindowStartVec, Windows,
FiatBlock, FiatPerBlock, FiatType, LazyRollingSumsFiatFromHeight, WindowStartVec, Windows,
},
};
@@ -9,7 +9,7 @@ use crate::{
internal::{BpsType, LazyRollingDeltasFiatFromHeight, WindowStartVec, Windows},
};
use super::{FiatType, FiatPerBlockCumulativeWithSums};
use super::{FiatPerBlockCumulativeWithSums, FiatType};
#[derive(Deref, DerefMut, Traversable)]
pub struct FiatPerBlockCumulativeWithSumsAndDeltas<C, CS, B, M: StorageMode = Rw>
@@ -6,7 +6,7 @@ use vecdb::{DeltaSub, LazyDeltaVec, LazyVecFrom1, ReadOnlyClone, ReadableCloneab
use crate::{
indexes,
internal::{
FiatType, DerivedResolutions, LazyPerBlock, LazyRollingSumFromHeight, Resolutions,
DerivedResolutions, FiatType, LazyPerBlock, LazyRollingSumFromHeight, Resolutions,
WindowStartVec, Windows,
},
};
@@ -19,9 +19,7 @@ pub struct LazyRollingSumFiatFromHeight<C: FiatType> {
#[derive(Clone, Deref, DerefMut, Traversable)]
#[traversable(transparent)]
pub struct LazyRollingSumsFiatFromHeight<C: FiatType>(
pub Windows<LazyRollingSumFiatFromHeight<C>>,
);
pub struct LazyRollingSumsFiatFromHeight<C: FiatType>(pub Windows<LazyRollingSumFiatFromHeight<C>>);
impl<C: FiatType> LazyRollingSumsFiatFromHeight<C> {
pub fn new(
@@ -10,7 +10,7 @@ use crate::{
internal::{BpsType, LazyRollingDeltasFiatFromHeight, WindowStartVec, Windows},
};
use super::{FiatType, FiatPerBlock};
use super::{FiatPerBlock, FiatType};
#[derive(Deref, DerefMut, Traversable)]
pub struct FiatPerBlockWithDeltas<C, CS, B, M: StorageMode = Rw>
@@ -44,7 +44,9 @@ where
Self {
height: LazyVecFrom1::transformed::<F>(name, version, height_source),
resolutions: Box::new(DerivedResolutions::from_derived_computed::<F>(
name, version, resolutions,
name,
version,
resolutions,
)),
}
}
@@ -10,7 +10,9 @@ use vecdb::{BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, VecVa
use crate::{
indexes,
internal::{BpsType, PerBlockCumulativeRolling, PercentPerBlock, PercentRollingWindows, RatioU64Bp16},
internal::{
BpsType, PerBlockCumulativeRolling, PercentPerBlock, PercentRollingWindows, RatioU64Bp16,
},
};
#[derive(Traversable)]
@@ -27,8 +27,7 @@ impl<B: BpsType> LazyPercentCumulativeRolling<B> {
version: Version,
source: &PercentCumulativeRolling<B>,
) -> Self {
let cumulative =
LazyPercentPerBlock::from_percent::<F>(name, version, &source.cumulative);
let cumulative = LazyPercentPerBlock::from_percent::<F>(name, version, &source.cumulative);
let rolling = LazyPercentRollingWindows::from_rolling::<F>(name, version, &source.rolling);
Self {
cumulative,
@@ -46,12 +46,7 @@ where
starts_version,
move || cached.cached(),
);
let resolutions = Resolutions::forced_import(
&full_name,
avg.clone(),
version,
indexes,
);
let resolutions = Resolutions::forced_import(&full_name, avg.clone(), version, indexes);
LazyRollingAvgFromHeight {
height: avg,
resolutions: Box::new(resolutions),
@@ -369,12 +369,8 @@ where
move || cached.cached()
},
);
let change_resolutions = Resolutions::forced_import(
&cents_name,
change_vec.clone(),
version,
indexes,
);
let change_resolutions =
Resolutions::forced_import(&cents_name, change_vec.clone(), version, indexes);
let cents = LazyDeltaFromHeight {
height: change_vec,
resolutions: Box::new(change_resolutions),
@@ -7,7 +7,7 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
ValuePerBlockCumulative, LazyRollingAvgsAmountFromHeight, LazyRollingSumsAmountFromHeight,
LazyRollingAvgsAmountFromHeight, LazyRollingSumsAmountFromHeight, ValuePerBlockCumulative,
WindowStartVec, Windows,
},
prices,
@@ -7,7 +7,7 @@ use vecdb::{Database, EagerVec, Exit, PcoVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
ValuePerBlockCumulativeRolling, RollingDistributionValuePerBlock, WindowStartVec,
RollingDistributionValuePerBlock, ValuePerBlockCumulativeRolling, WindowStartVec,
WindowStarts, Windows,
},
prices,
@@ -6,7 +6,7 @@ use derive_more::{Deref, DerefMut};
use vecdb::UnaryTransform;
use crate::internal::{
ValuePerBlock, Identity, LazyValue, LazyValueDerivedResolutions, SatsToBitcoin,
Identity, LazyValue, LazyValueDerivedResolutions, SatsToBitcoin, ValuePerBlock,
};
/// Lazy value wrapper with height + all derived last transforms from ValuePerBlock.
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::{Bitcoin, Cents, Dollars, Sats, Version};
use vecdb::UnaryTransform;
use crate::internal::{ValuePerBlock, DerivedResolutions};
use crate::internal::{DerivedResolutions, ValuePerBlock};
#[derive(Clone, Traversable)]
pub struct LazyValueDerivedResolutions {
@@ -7,7 +7,7 @@ use vecdb::{Database, Exit, ReadableVec, Rw, StorageMode};
use crate::{
indexes,
internal::{
ValuePerBlock, DistributionStats, WindowStarts, Windows,
DistributionStats, ValuePerBlock, WindowStarts, Windows,
algo::compute_rolling_distribution_from_starts,
},
};
@@ -8,7 +8,9 @@ use brk_indexer::Indexer;
use brk_traversable::Traversable;
use brk_types::{Indexes, TxIndex, VSize};
use schemars::JsonSchema;
use vecdb::{Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw, StorageMode, Version};
use vecdb::{
Database, EagerVec, Exit, ImportableVec, PcoVec, ReadableVec, Rw, StorageMode, Version,
};
use crate::{
indexes,
@@ -13,7 +13,7 @@ use vecdb::{AnyStoredVec, AnyVec, Database, EagerVec, Exit, PcoVec, WritableVec}
use crate::{indexes, prices};
use super::{
ValuePerBlock, BpsType, NumericValue, PerBlock, PerBlockCumulativeRolling, PercentPerBlock,
BpsType, NumericValue, PerBlock, PerBlockCumulativeRolling, PercentPerBlock, ValuePerBlock,
WindowStartVec, Windows,
};
@@ -83,11 +83,7 @@ where
}
/// Compute `all.height` as the per-block sum of the per-type vecs.
pub(crate) fn compute_rest(
&mut self,
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
pub(crate) fn compute_rest(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
let sources: Vec<&EagerVec<PcoVec<Height, T>>> =
self.by_addr_type.values().map(|v| &v.height).collect();
self.all
@@ -109,13 +105,8 @@ where
indexes: &indexes::Vecs,
cached_starts: &Windows<&WindowStartVec>,
) -> Result<Self> {
let all = PerBlockCumulativeRolling::forced_import(
db,
name,
version,
indexes,
cached_starts,
)?;
let all =
PerBlockCumulativeRolling::forced_import(db, name, version, indexes, cached_starts)?;
let by_addr_type = ByAddrType::new_with_name(|type_name| {
PerBlockCumulativeRolling::forced_import(
db,
+1 -1
View File
@@ -9,7 +9,7 @@ use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod, Vecs};
use crate::{
indexes,
internal::{
ValuePerBlock, PercentPerBlock, Price,
PercentPerBlock, Price, ValuePerBlock,
db_utils::{finalize_db, open_db},
},
};
+1 -1
View File
@@ -3,7 +3,7 @@ use brk_types::{BasisPointsSigned32, Cents, Height, Sats};
use vecdb::{Database, EagerVec, PcoVec, Rw, StorageMode};
use super::{ByDcaCagr, ByDcaClass, ByDcaPeriod};
use crate::internal::{ValuePerBlock, PerBlock, PercentPerBlock, Price};
use crate::internal::{PerBlock, PercentPerBlock, Price, ValuePerBlock};
#[derive(Traversable)]
pub struct PeriodVecs<M: StorageMode = Rw> {
+5 -8
View File
@@ -87,9 +87,8 @@ impl Computer {
let cached_starts = blocks.lookback.cached_window_starts();
let (inputs, outputs, mining, transactions, pools, cointime) = timed(
"Imported inputs/outputs/mining/tx/pools/cointime",
|| {
let (inputs, outputs, mining, transactions, pools, cointime) =
timed("Imported inputs/outputs/mining/tx/pools/cointime", || {
thread::scope(|s| -> Result<_> {
let inputs_handle = big_thread().spawn_scoped(s, || -> Result<_> {
Ok(Box::new(inputs::Vecs::forced_import(
@@ -152,8 +151,7 @@ impl Computer {
Ok((inputs, outputs, mining, transactions, pools, cointime))
})
},
)?;
})?;
// Market, indicators, and distribution are independent; import in parallel.
// Supply depends on distribution so it runs after.
@@ -271,9 +269,8 @@ impl Computer {
{
info!("Removing obsolete database folder: {}", name);
let path = entry.path();
fs::remove_dir_all(&path).map_err(|e| {
std::io::Error::other(format!("remove_dir_all {path:?}: {e}"))
})?;
fs::remove_dir_all(&path)
.map_err(|e| std::io::Error::other(format!("remove_dir_all {path:?}: {e}")))?;
}
}
@@ -6,9 +6,9 @@ use super::Vecs;
use crate::{
indexes,
internal::{
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, ValuePerBlockFull,
LazyPercentCumulativeRolling, OneMinusBp16, PercentCumulativeRolling, RatioRollingWindows,
WindowStartVec, Windows,
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, ValuePerBlockFull, WindowStartVec,
Windows,
},
};
@@ -3,8 +3,8 @@ use brk_types::{BasisPoints16, BasisPoints32, Height, Sats};
use vecdb::{EagerVec, PcoVec, Rw, StorageMode};
use crate::internal::{
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, ValuePerBlockFull,
LazyPercentCumulativeRolling, PercentCumulativeRolling, RatioRollingWindows,
ValuePerBlockCumulative, ValuePerBlockCumulativeRolling, ValuePerBlockFull,
};
#[derive(Traversable)]
@@ -68,10 +68,14 @@ impl Vecs {
Ok(())
},
|agg| {
push_block(&mut self.output_count, agg.entries_all, &agg.entries_per_type);
push_block(
&mut self.output_count,
agg.entries_all,
&agg.entries_per_type,
);
push_block(&mut self.tx_count, agg.txs_all, &agg.txs_per_type);
let spendable_total = agg.entries_all
- agg.entries_per_type[OutputType::OpReturn as usize];
let spendable_total =
agg.entries_all - agg.entries_per_type[OutputType::OpReturn as usize];
self.spendable_output_count
.block
.push(StoredU64::from(spendable_total));
@@ -97,8 +101,7 @@ impl Vecs {
.compute_rest(starting_indexes.height, exit)?;
self.spendable_output_count
.compute_rest(starting_indexes.height, exit)?;
self.tx_count
.compute_rest(starting_indexes.height, exit)?;
self.tx_count.compute_rest(starting_indexes.height, exit)?;
}
for (otype, source) in self.output_count.by_type.iter_typed() {
@@ -16,26 +16,24 @@ impl Vecs {
indexes: &indexes::Vecs,
cached_starts: &Windows<&WindowStartVec>,
) -> Result<Self> {
let output_count = WithOutputTypes::<
PerBlockCumulativeRolling<StoredU64, StoredU64>,
>::forced_import_with(
db,
"output_count_bis",
|t| format!("{t}_output_count"),
version,
indexes,
cached_starts,
)?;
let tx_count = WithOutputTypes::<
PerBlockCumulativeRolling<StoredU64, StoredU64>,
>::forced_import_with(
db,
"tx_count_bis",
|t| format!("tx_count_with_{t}_output"),
version,
indexes,
cached_starts,
)?;
let output_count =
WithOutputTypes::<PerBlockCumulativeRolling<StoredU64, StoredU64>>::forced_import_with(
db,
"output_count_bis",
|t| format!("{t}_output_count"),
version,
indexes,
cached_starts,
)?;
let tx_count =
WithOutputTypes::<PerBlockCumulativeRolling<StoredU64, StoredU64>>::forced_import_with(
db,
"tx_count_bis",
|t| format!("tx_count_with_{t}_output"),
version,
indexes,
cached_starts,
)?;
let spendable_output_count = PerBlockCumulativeRolling::forced_import(
db,
@@ -67,7 +67,9 @@ where
dep_version: Version,
at_height: Height,
) -> Result<()> {
self.all.block.validate_and_truncate(dep_version, at_height)?;
self.all
.block
.validate_and_truncate(dep_version, at_height)?;
for v in self.by_type.iter_mut() {
v.block.validate_and_truncate(dep_version, at_height)?;
}
+1 -2
View File
@@ -22,8 +22,7 @@ impl Vecs {
self.count
.compute(indexer, indexes, blocks, starting_indexes, exit)?;
self.per_sec
.compute(&self.count, starting_indexes, exit)?;
self.per_sec.compute(&self.count, starting_indexes, exit)?;
self.value
.compute(indexer, prices, starting_indexes, exit)?;
self.by_type.compute(indexer, starting_indexes, exit)?;
+1 -1
View File
@@ -7,7 +7,7 @@ use vecdb::{BinaryTransform, Database, Exit, ReadableVec, Rw, StorageMode, Versi
use crate::{
blocks, indexes,
internal::{
ValuePerBlockCumulativeRolling, MaskSats, PercentRollingWindows, RatioU64Bp16,
MaskSats, PercentRollingWindows, RatioU64Bp16, ValuePerBlockCumulativeRolling,
WindowStartVec, Windows,
},
mining, prices,
@@ -14,9 +14,7 @@ impl PoolHeights {
let mut map: FxHashMap<PoolSlug, Vec<Height>> = FxHashMap::default();
let reader = pool.reader();
for h in 0..len {
map.entry(reader.get(h))
.or_default()
.push(Height::from(h));
map.entry(reader.get(h)).or_default().push(Height::from(h));
}
Self(Arc::new(RwLock::new(map)))
}
+5 -1
View File
@@ -84,7 +84,11 @@ impl Vecs {
.height
.len()
.min(starting_indexes.height.to_usize());
self.spot.cents.height.inner.truncate_if_needed_at(truncate_to)?;
self.spot
.cents
.height
.inner
.truncate_if_needed_at(truncate_to)?;
if self.spot.cents.height.len() < START_HEIGHT {
for line in brk_oracle::PRICES
+3 -6
View File
@@ -6,7 +6,7 @@ use brk_types::Version;
use crate::{
cointime, distribution, indexes,
internal::{
LazyValuePerBlock, LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, PercentPerBlock,
LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, LazyValuePerBlock, PercentPerBlock,
RollingWindows, WindowStartVec, Windows,
db_utils::{finalize_db, open_db},
},
@@ -63,11 +63,8 @@ impl Vecs {
indexes,
)?;
let hodled_or_lost = LazyValuePerBlock::identity(
"hodled_or_lost_supply",
&cointime.supply.vaulted,
version,
);
let hodled_or_lost =
LazyValuePerBlock::identity("hodled_or_lost_supply", &cointime.supply.vaulted, version);
let this = Self {
db,
+1 -1
View File
@@ -4,7 +4,7 @@ use vecdb::{Database, Rw, StorageMode};
use super::{burned, velocity};
use crate::internal::{
LazyValuePerBlock, LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, PercentPerBlock,
LazyFiatPerBlock, LazyRollingDeltasFiatFromHeight, LazyValuePerBlock, PercentPerBlock,
RollingWindows,
};
@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ValuePerBlockCumulativeRolling, PerBlock, WindowStartVec, Windows},
internal::{PerBlock, ValuePerBlockCumulativeRolling, WindowStartVec, Windows},
};
impl Vecs {
@@ -2,7 +2,7 @@ use brk_traversable::Traversable;
use brk_types::StoredF32;
use vecdb::{Rw, StorageMode};
use crate::internal::{ValuePerBlockCumulativeRolling, PerBlock, Windows};
use crate::internal::{PerBlock, ValuePerBlockCumulativeRolling, Windows};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {