mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-22 08:28:10 -07:00
global: fixes
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user