mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 09:28:11 -07:00
global: snapshot part 7
This commit is contained in:
@@ -9,7 +9,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Cents, CentsSquaredSats, Dollars, Height, Indexes, Sats, Version};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{
|
||||
AnyStoredVec, Database, Exit, ReadOnlyClone, ReadableVec, Rw, StorageMode, WritableVec,
|
||||
AnyStoredVec, AnyVec, Database, Exit, ReadOnlyClone, ReadableVec, Rw, StorageMode, WritableVec,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -342,7 +342,7 @@ impl UTXOCohorts<Rw> {
|
||||
#[inline(always)]
|
||||
pub(crate) fn push_maturation(&mut self, matured: &AgeRange<Sats>) {
|
||||
for (v, &sats) in self.matured.iter_mut().zip(matured.iter()) {
|
||||
v.block.sats.height.push(sats);
|
||||
v.block.sats.push(sats);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,9 +542,7 @@ impl UTXOCohorts<Rw> {
|
||||
.metrics
|
||||
.activity
|
||||
.transfer_volume
|
||||
.block
|
||||
.cents
|
||||
.height
|
||||
.block.cents
|
||||
.read_only_clone();
|
||||
let under_1h_value_destroyed = self
|
||||
.age_range
|
||||
@@ -554,7 +552,6 @@ impl UTXOCohorts<Rw> {
|
||||
.sopr
|
||||
.value_destroyed
|
||||
.block
|
||||
.height
|
||||
.read_only_clone();
|
||||
|
||||
// "all" cohort computed first (no all_supply_sats needed).
|
||||
@@ -714,8 +711,8 @@ impl UTXOCohorts<Rw> {
|
||||
vecs.extend(self.profitability.collect_all_vecs_mut());
|
||||
for v in self.matured.iter_mut() {
|
||||
let inner = &mut v.inner;
|
||||
vecs.push(&mut inner.block.sats.height);
|
||||
vecs.push(&mut inner.block.cents.height);
|
||||
vecs.push(&mut inner.block.sats);
|
||||
vecs.push(&mut inner.block.cents);
|
||||
vecs.push(&mut inner.cumulative.sats.height);
|
||||
vecs.push(&mut inner.cumulative.cents.height);
|
||||
}
|
||||
@@ -734,7 +731,7 @@ impl UTXOCohorts<Rw> {
|
||||
.chain(
|
||||
self.matured
|
||||
.iter()
|
||||
.map(|v| Height::from(v.block.min_stateful_len())),
|
||||
.map(|v| Height::from(v.block.sats.len())),
|
||||
)
|
||||
.min()
|
||||
.unwrap_or_default()
|
||||
|
||||
@@ -66,7 +66,7 @@ pub(crate) fn process_blocks(
|
||||
let height_to_first_tx_index = &indexer.vecs.transactions.first_tx_index;
|
||||
let height_to_first_txout_index = &indexer.vecs.outputs.first_txout_index;
|
||||
let height_to_first_txin_index = &indexer.vecs.inputs.first_txin_index;
|
||||
let height_to_tx_count = &transactions.count.total.block.height;
|
||||
let height_to_tx_count = &transactions.count.total.block;
|
||||
let height_to_output_count = &outputs.count.total.sum.height;
|
||||
let height_to_input_count = &inputs.count.sum.height;
|
||||
let tx_index_to_output_count = &indexes.tx_index.output_count;
|
||||
@@ -221,7 +221,7 @@ pub(crate) fn process_blocks(
|
||||
.chain(vecs.addrs.empty.par_iter_height_mut())
|
||||
.chain(vecs.addrs.activity.par_iter_height_mut())
|
||||
.chain(rayon::iter::once(
|
||||
&mut vecs.coinblocks_destroyed.block.height as &mut dyn AnyStoredVec,
|
||||
&mut vecs.coinblocks_destroyed.block as &mut dyn AnyStoredVec,
|
||||
))
|
||||
.try_for_each(|v| v.any_truncate_if_needed_at(start))?;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ pub(crate) fn process_blocks(
|
||||
blocks_old as u128 * u64::from(sent.spendable_supply.value) as u128
|
||||
})
|
||||
.sum();
|
||||
vecs.coinblocks_destroyed.block.height.push(
|
||||
vecs.coinblocks_destroyed.block.push(
|
||||
StoredF64::from(total_satblocks as f64 / Sats::ONE_BTC_U128 as f64),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ pub(crate) fn write(
|
||||
.chain(
|
||||
[
|
||||
&mut vecs.supply_state as &mut dyn AnyStoredVec,
|
||||
&mut vecs.coinblocks_destroyed.block.height,
|
||||
&mut vecs.coinblocks_destroyed.block,
|
||||
]
|
||||
.into_par_iter(),
|
||||
)
|
||||
|
||||
@@ -40,9 +40,9 @@ impl ActivityCore {
|
||||
pub(crate) fn min_len(&self) -> usize {
|
||||
self.minimal
|
||||
.min_len()
|
||||
.min(self.coindays_destroyed.block.height.len())
|
||||
.min(self.transfer_volume_in_profit.block.sats.height.len())
|
||||
.min(self.transfer_volume_in_loss.block.sats.height.len())
|
||||
.min(self.coindays_destroyed.block.len())
|
||||
.min(self.transfer_volume_in_profit.block.sats.len())
|
||||
.min(self.transfer_volume_in_loss.block.sats.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -51,28 +51,24 @@ impl ActivityCore {
|
||||
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
|
||||
) {
|
||||
self.minimal.push_state(state);
|
||||
self.coindays_destroyed.block.height.push(
|
||||
self.coindays_destroyed.block.push(
|
||||
StoredF64::from(Bitcoin::from(state.satdays_destroyed)),
|
||||
);
|
||||
self.transfer_volume_in_profit
|
||||
.block
|
||||
.sats
|
||||
.height
|
||||
.block.sats
|
||||
.push(state.realized.sent_in_profit());
|
||||
self.transfer_volume_in_loss
|
||||
.block
|
||||
.sats
|
||||
.height
|
||||
.block.sats
|
||||
.push(state.realized.sent_in_loss());
|
||||
}
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs = self.minimal.collect_vecs_mut();
|
||||
vecs.push(&mut self.coindays_destroyed.block.height);
|
||||
vecs.push(&mut self.transfer_volume_in_profit.inner.block.sats.height);
|
||||
vecs.push(&mut self.transfer_volume_in_profit.inner.block.cents.height);
|
||||
vecs.push(&mut self.transfer_volume_in_loss.inner.block.sats.height);
|
||||
vecs.push(&mut self.transfer_volume_in_loss.inner.block.cents.height);
|
||||
vecs.push(&mut self.coindays_destroyed.block);
|
||||
vecs.push(&mut self.transfer_volume_in_profit.inner.block.sats);
|
||||
vecs.push(&mut self.transfer_volume_in_profit.inner.block.cents);
|
||||
vecs.push(&mut self.transfer_volume_in_loss.inner.block.sats);
|
||||
vecs.push(&mut self.transfer_volume_in_loss.inner.block.cents);
|
||||
vecs
|
||||
}
|
||||
|
||||
@@ -90,9 +86,9 @@ impl ActivityCore {
|
||||
self.minimal
|
||||
.compute_from_stateful(starting_indexes, &minimal_refs, exit)?;
|
||||
|
||||
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.block.height);
|
||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_profit.block.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_loss.block.sats.height);
|
||||
sum_others!(self, starting_indexes, others, exit; coindays_destroyed.block);
|
||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_profit.block.sats);
|
||||
sum_others!(self, starting_indexes, others, exit; transfer_volume_in_loss.block.sats);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@ impl ActivityMinimal {
|
||||
|
||||
pub(crate) fn min_len(&self) -> usize {
|
||||
self.transfer_volume
|
||||
.block
|
||||
.sats
|
||||
.height
|
||||
.block.sats
|
||||
.len()
|
||||
}
|
||||
|
||||
@@ -35,14 +33,14 @@ impl ActivityMinimal {
|
||||
&mut self,
|
||||
state: &CohortState<impl RealizedOps, impl CostBasisOps>,
|
||||
) {
|
||||
self.transfer_volume.block.sats.height.push(state.sent);
|
||||
self.transfer_volume.block.sats.push(state.sent);
|
||||
}
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let inner = &mut self.transfer_volume.inner;
|
||||
vec![
|
||||
&mut inner.block.sats.height as &mut dyn AnyStoredVec,
|
||||
&mut inner.block.cents.height,
|
||||
&mut inner.block.sats as &mut dyn AnyStoredVec,
|
||||
&mut inner.block.cents,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -52,11 +50,11 @@ impl ActivityMinimal {
|
||||
others: &[&Self],
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.transfer_volume.block.sats.height.compute_sum_of_others(
|
||||
self.transfer_volume.block.sats.compute_sum_of_others(
|
||||
starting_indexes.height,
|
||||
&others
|
||||
.iter()
|
||||
.map(|v| &v.transfer_volume.block.sats.height)
|
||||
.map(|v| &v.transfer_volume.block.sats)
|
||||
.collect::<Vec<_>>(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -128,8 +128,8 @@ impl AllCohortMetrics {
|
||||
|
||||
self.asopr.compute_rest_part2(
|
||||
starting_indexes,
|
||||
&self.activity.transfer_volume.block.cents.height,
|
||||
&self.realized.core.sopr.value_destroyed.block.height,
|
||||
&self.activity.transfer_volume.block.cents,
|
||||
&self.realized.core.sopr.value_destroyed.block,
|
||||
under_1h_value_created,
|
||||
under_1h_value_destroyed,
|
||||
exit,
|
||||
|
||||
@@ -80,8 +80,8 @@ impl ExtendedAdjustedCohortMetrics {
|
||||
|
||||
self.asopr.compute_rest_part2(
|
||||
starting_indexes,
|
||||
&self.inner.activity.transfer_volume.block.cents.height,
|
||||
&self.inner.realized.core.sopr.value_destroyed.block.height,
|
||||
&self.inner.activity.transfer_volume.block.cents,
|
||||
&self.inner.realized.core.sopr.value_destroyed.block,
|
||||
under_1h_value_created,
|
||||
under_1h_value_destroyed,
|
||||
exit,
|
||||
|
||||
@@ -34,13 +34,13 @@ impl AdjustedSopr {
|
||||
under_1h_value_destroyed: &impl ReadableVec<Height, Cents>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.transfer_volume.block.height.compute_subtract(
|
||||
self.transfer_volume.block.compute_subtract(
|
||||
starting_indexes.height,
|
||||
base_transfer_volume,
|
||||
under_1h_transfer_volume,
|
||||
exit,
|
||||
)?;
|
||||
self.value_destroyed.block.height.compute_subtract(
|
||||
self.value_destroyed.block.compute_subtract(
|
||||
starting_indexes.height,
|
||||
base_value_destroyed,
|
||||
under_1h_value_destroyed,
|
||||
|
||||
@@ -54,7 +54,7 @@ impl RealizedCore {
|
||||
let neg_loss_base = LazyPerBlock::from_height_source::<NegCentsUnsignedToDollars>(
|
||||
&cfg.name("neg_realized_loss"),
|
||||
cfg.version + Version::ONE,
|
||||
minimal.loss.block.cents.height.read_only_boxed_clone(),
|
||||
minimal.loss.block.cents.read_only_boxed_clone(),
|
||||
cfg.indexes,
|
||||
);
|
||||
|
||||
@@ -107,12 +107,12 @@ impl RealizedCore {
|
||||
#[inline(always)]
|
||||
pub(crate) fn push_state(&mut self, state: &CohortState<impl RealizedOps, impl CostBasisOps>) {
|
||||
self.minimal.push_state(state);
|
||||
self.sopr.value_destroyed.block.height.push(state.realized.value_destroyed());
|
||||
self.sopr.value_destroyed.block.push(state.realized.value_destroyed());
|
||||
}
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
let mut vecs = self.minimal.collect_vecs_mut();
|
||||
vecs.push(&mut self.sopr.value_destroyed.block.height);
|
||||
vecs.push(&mut self.sopr.value_destroyed.block);
|
||||
vecs
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ impl RealizedCore {
|
||||
self.minimal
|
||||
.compute_from_stateful(starting_indexes, &minimal_refs, exit)?;
|
||||
|
||||
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.block.height);
|
||||
sum_others!(self, starting_indexes, others, exit; sopr.value_destroyed.block);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -142,10 +142,10 @@ impl RealizedCore {
|
||||
.value_destroyed
|
||||
.compute_rest(starting_indexes.height, exit)?;
|
||||
|
||||
self.net_pnl.block.cents.height.compute_transform2(
|
||||
self.net_pnl.block.cents.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&self.minimal.profit.block.cents.height,
|
||||
&self.minimal.loss.block.cents.height,
|
||||
&self.minimal.profit.block.cents,
|
||||
&self.minimal.loss.block.cents,
|
||||
|(i, profit, loss, ..)| {
|
||||
(
|
||||
i,
|
||||
|
||||
@@ -183,7 +183,7 @@ impl RealizedFull {
|
||||
.len()
|
||||
.min(self.cap_raw.len())
|
||||
.min(self.investor.cap_raw.len())
|
||||
.min(self.peak_regret.value.block.cents.height.len())
|
||||
.min(self.peak_regret.value.block.cents.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -203,9 +203,7 @@ impl RealizedFull {
|
||||
.push(state.realized.investor_cap_raw());
|
||||
self.peak_regret
|
||||
.value
|
||||
.block
|
||||
.cents
|
||||
.height
|
||||
.block.cents
|
||||
.push(state.realized.peak_regret());
|
||||
}
|
||||
|
||||
@@ -214,7 +212,7 @@ impl RealizedFull {
|
||||
vecs.push(&mut self.investor.price.cents.height);
|
||||
vecs.push(&mut self.cap_raw as &mut dyn AnyStoredVec);
|
||||
vecs.push(&mut self.investor.cap_raw as &mut dyn AnyStoredVec);
|
||||
vecs.push(&mut self.peak_regret.value.block.cents.height);
|
||||
vecs.push(&mut self.peak_regret.value.block.cents);
|
||||
vecs
|
||||
}
|
||||
|
||||
@@ -247,9 +245,7 @@ impl RealizedFull {
|
||||
|
||||
self.peak_regret
|
||||
.value
|
||||
.block
|
||||
.cents
|
||||
.height
|
||||
.block.cents
|
||||
.push(accum.peak_regret());
|
||||
}
|
||||
|
||||
@@ -307,7 +303,7 @@ impl RealizedFull {
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.profit.block.cents.height,
|
||||
&self.core.minimal.profit.block.cents,
|
||||
&self.core.minimal.cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
@@ -315,7 +311,7 @@ impl RealizedFull {
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.loss.block.cents.height,
|
||||
&self.core.minimal.loss.block.cents,
|
||||
&self.core.minimal.cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
@@ -323,16 +319,16 @@ impl RealizedFull {
|
||||
.to_rcap
|
||||
.compute_binary::<CentsSigned, Cents, RatioCentsSignedCentsBps32>(
|
||||
starting_indexes.height,
|
||||
&self.core.net_pnl.block.cents.height,
|
||||
&self.core.net_pnl.block.cents,
|
||||
&self.core.minimal.cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Gross PnL
|
||||
self.gross_pnl.block.cents.height.compute_add(
|
||||
self.gross_pnl.block.cents.compute_add(
|
||||
starting_indexes.height,
|
||||
&self.core.minimal.profit.block.cents.height,
|
||||
&self.core.minimal.loss.block.cents.height,
|
||||
&self.core.minimal.profit.block.cents,
|
||||
&self.core.minimal.loss.block.cents,
|
||||
exit,
|
||||
)?;
|
||||
self.gross_pnl.compute_rest(starting_indexes.height, exit)?;
|
||||
@@ -360,7 +356,7 @@ impl RealizedFull {
|
||||
.to_rcap
|
||||
.compute_binary::<Cents, Cents, RatioCentsBp32>(
|
||||
starting_indexes.height,
|
||||
&self.peak_regret.value.block.cents.height,
|
||||
&self.peak_regret.value.block.cents,
|
||||
&self.core.minimal.cap.cents.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -62,22 +62,22 @@ impl RealizedMinimal {
|
||||
.cents
|
||||
.height
|
||||
.len()
|
||||
.min(self.profit.block.cents.height.len())
|
||||
.min(self.loss.block.cents.height.len())
|
||||
.min(self.profit.block.cents.len())
|
||||
.min(self.loss.block.cents.len())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn push_state(&mut self, state: &CohortState<impl RealizedOps, impl CostBasisOps>) {
|
||||
self.cap.cents.height.push(state.realized.cap());
|
||||
self.profit.block.cents.height.push(state.realized.profit());
|
||||
self.loss.block.cents.height.push(state.realized.loss());
|
||||
self.profit.block.cents.push(state.realized.profit());
|
||||
self.loss.block.cents.push(state.realized.loss());
|
||||
}
|
||||
|
||||
pub(crate) fn collect_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||
vec![
|
||||
&mut self.cap.cents.height as &mut dyn AnyStoredVec,
|
||||
&mut self.profit.block.cents.height,
|
||||
&mut self.loss.block.cents.height,
|
||||
&mut self.profit.block.cents,
|
||||
&mut self.loss.block.cents,
|
||||
]
|
||||
}
|
||||
|
||||
@@ -88,8 +88,8 @@ impl RealizedMinimal {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
sum_others!(self, starting_indexes, others, exit; cap.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; profit.block.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; loss.block.cents.height);
|
||||
sum_others!(self, starting_indexes, others, exit; profit.block.cents);
|
||||
sum_others!(self, starting_indexes, others, exit; loss.block.cents);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -490,6 +490,6 @@ impl Vecs {
|
||||
.min(Height::from(self.addrs.funded.min_stateful_len()))
|
||||
.min(Height::from(self.addrs.empty.min_stateful_len()))
|
||||
.min(Height::from(self.addrs.activity.min_stateful_len()))
|
||||
.min(Height::from(self.coinblocks_destroyed.block.height.len()))
|
||||
.min(Height::from(self.coinblocks_destroyed.block.len()))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user