mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
computer: stateful snapshot
This commit is contained in:
@@ -9,11 +9,11 @@ use std::path::Path;
|
||||
use brk_error::Result;
|
||||
use brk_grouper::{
|
||||
AmountFilter, ByAgeRange, ByAmountRange, ByEpoch, ByGreatEqualAmount, ByLowerThanAmount,
|
||||
ByMaxAge, ByMinAge, BySpendableType, ByTerm, Filter, Filtered, StateLevel, Term, TimeFilter,
|
||||
UTXOGroups,
|
||||
ByMaxAge, ByMinAge, BySpendableType, ByTerm, ByYear, Filter, Filtered, StateLevel, Term,
|
||||
TimeFilter, UTXOGroups,
|
||||
};
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, HalvingEpoch, Height, OutputType, Sats, Version};
|
||||
use brk_types::{Bitcoin, DateIndex, Dollars, HalvingEpoch, Height, OutputType, Sats, Version, Year};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use rayon::prelude::*;
|
||||
use vecdb::{Database, Exit, IterableVec};
|
||||
@@ -75,6 +75,27 @@ impl UTXOCohorts {
|
||||
_4: full(Filter::Epoch(HalvingEpoch::new(4)))?,
|
||||
},
|
||||
|
||||
year: ByYear {
|
||||
_2009: full(Filter::Year(Year::new(2009)))?,
|
||||
_2010: full(Filter::Year(Year::new(2010)))?,
|
||||
_2011: full(Filter::Year(Year::new(2011)))?,
|
||||
_2012: full(Filter::Year(Year::new(2012)))?,
|
||||
_2013: full(Filter::Year(Year::new(2013)))?,
|
||||
_2014: full(Filter::Year(Year::new(2014)))?,
|
||||
_2015: full(Filter::Year(Year::new(2015)))?,
|
||||
_2016: full(Filter::Year(Year::new(2016)))?,
|
||||
_2017: full(Filter::Year(Year::new(2017)))?,
|
||||
_2018: full(Filter::Year(Year::new(2018)))?,
|
||||
_2019: full(Filter::Year(Year::new(2019)))?,
|
||||
_2020: full(Filter::Year(Year::new(2020)))?,
|
||||
_2021: full(Filter::Year(Year::new(2021)))?,
|
||||
_2022: full(Filter::Year(Year::new(2022)))?,
|
||||
_2023: full(Filter::Year(Year::new(2023)))?,
|
||||
_2024: full(Filter::Year(Year::new(2024)))?,
|
||||
_2025: full(Filter::Year(Year::new(2025)))?,
|
||||
_2026: full(Filter::Year(Year::new(2026)))?,
|
||||
},
|
||||
|
||||
type_: BySpendableType {
|
||||
p2pk65: full(Filter::Type(OutputType::P2PK65))?,
|
||||
p2pk33: full(Filter::Type(OutputType::P2PK33))?,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Processing received outputs (new UTXOs).
|
||||
|
||||
use brk_grouper::{Filter, Filtered};
|
||||
use brk_types::{Dollars, Height};
|
||||
use brk_types::{Dollars, Height, Timestamp};
|
||||
|
||||
use crate::stateful::states::Transacted;
|
||||
|
||||
@@ -13,15 +13,23 @@ impl UTXOCohorts {
|
||||
/// New UTXOs are added to:
|
||||
/// - The "up_to_1d" age cohort (all new UTXOs start at 0 days old)
|
||||
/// - The appropriate epoch cohort based on block height
|
||||
/// - The appropriate year cohort based on block timestamp
|
||||
/// - The appropriate output type cohort (P2PKH, P2SH, etc.)
|
||||
/// - The appropriate amount range cohort based on value
|
||||
pub fn receive(&mut self, received: Transacted, height: Height, price: Option<Dollars>) {
|
||||
pub fn receive(
|
||||
&mut self,
|
||||
received: Transacted,
|
||||
height: Height,
|
||||
timestamp: Timestamp,
|
||||
price: Option<Dollars>,
|
||||
) {
|
||||
let supply_state = received.spendable_supply;
|
||||
|
||||
// New UTXOs go into up_to_1d and current epoch
|
||||
// New UTXOs go into up_to_1d, current epoch, and current year
|
||||
[
|
||||
&mut self.0.age_range.up_to_1d,
|
||||
self.0.epoch.mut_vec_from_height(height),
|
||||
self.0.year.mut_vec_from_timestamp(timestamp),
|
||||
]
|
||||
.into_iter()
|
||||
.for_each(|v| {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Processing spent inputs (UTXOs being spent).
|
||||
|
||||
use brk_grouper::{Filter, Filtered, TimeFilter};
|
||||
use brk_types::{CheckedSub, HalvingEpoch, Height};
|
||||
use brk_types::{CheckedSub, HalvingEpoch, Height, Year};
|
||||
use rustc_hash::FxHashMap;
|
||||
use vecdb::VecIndex;
|
||||
|
||||
@@ -26,12 +26,13 @@ impl UTXOCohorts {
|
||||
return;
|
||||
}
|
||||
|
||||
// Time-based cohorts: age_range + epoch
|
||||
// Time-based cohorts: age_range + epoch + year
|
||||
let mut time_cohorts: Vec<_> = self
|
||||
.0
|
||||
.age_range
|
||||
.iter_mut()
|
||||
.chain(self.0.epoch.iter_mut())
|
||||
.chain(self.0.year.iter_mut())
|
||||
.collect();
|
||||
|
||||
let last_block = chain_state.last().unwrap();
|
||||
@@ -62,6 +63,7 @@ impl UTXOCohorts {
|
||||
Filter::Time(TimeFilter::LowerThan(to)) => *to > days_old,
|
||||
Filter::Time(TimeFilter::Range(range)) => range.contains(&days_old),
|
||||
Filter::Epoch(e) => *e == HalvingEpoch::from(height),
|
||||
Filter::Year(y) => *y == Year::from(block_state.timestamp),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.for_each(|vecs| {
|
||||
|
||||
@@ -420,7 +420,7 @@ pub fn process_blocks(
|
||||
});
|
||||
|
||||
// Main thread: Update UTXO cohorts
|
||||
vecs.utxo_cohorts.receive(transacted, height, block_price);
|
||||
vecs.utxo_cohorts.receive(transacted, height, timestamp, block_price);
|
||||
vecs.utxo_cohorts.send(height_to_sent, chain_state);
|
||||
});
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ impl ActivityMetrics {
|
||||
pub fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||
let v0 = Version::ZERO;
|
||||
let compute_dollars = cfg.compute_dollars();
|
||||
let sum = VecBuilderOptions::default().add_sum();
|
||||
let sum_cum = VecBuilderOptions::default().add_sum().add_cumulative();
|
||||
|
||||
Ok(Self {
|
||||
height_to_sent: EagerVec::forced_import(cfg.db, &cfg.name("sent"), cfg.version + v0)?,
|
||||
@@ -52,7 +52,7 @@ impl ActivityMetrics {
|
||||
&cfg.name("sent"),
|
||||
Source::None,
|
||||
cfg.version + v0,
|
||||
sum,
|
||||
sum_cum,
|
||||
compute_dollars,
|
||||
cfg.indexes,
|
||||
)?,
|
||||
@@ -75,7 +75,7 @@ impl ActivityMetrics {
|
||||
Source::Compute,
|
||||
cfg.version + v0,
|
||||
cfg.indexes,
|
||||
sum,
|
||||
sum_cum,
|
||||
)?,
|
||||
|
||||
indexes_to_coindays_destroyed: ComputedVecsFromHeight::forced_import(
|
||||
@@ -84,7 +84,7 @@ impl ActivityMetrics {
|
||||
Source::Compute,
|
||||
cfg.version + v0,
|
||||
cfg.indexes,
|
||||
sum,
|
||||
sum_cum,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user