mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-30 01:20:00 -07:00
global: MASSIVE snapshot
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{ONE_DAY_IN_SEC_F64, StoredF32};
|
||||
use brk_types::StoredF32;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::super::{count, fees};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, inputs, outputs};
|
||||
use crate::{blocks, ComputeIndexes, indexes, inputs, outputs};
|
||||
use crate::transactions::{count, fees};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn compute(
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
blocks: &blocks::Vecs,
|
||||
count_vecs: &count::Vecs,
|
||||
fees_vecs: &fees::Vecs,
|
||||
inputs_count: &inputs::CountVecs,
|
||||
@@ -20,115 +21,81 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent_sum
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_filtered_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.input_value,
|
||||
|sats| !sats.is_max(),
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
self.sent_sum.sats.height.compute_filtered_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.input_value,
|
||||
|sats| !sats.is_max(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.received_sum
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.output_value,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
self.received_sum.sats.height.compute_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.output_value,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.annualized_volume.compute_sats(|v| {
|
||||
v.compute_sum(
|
||||
starting_indexes.dateindex,
|
||||
&self.sent_sum.sats.dateindex.0,
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
// Annualized volume: rolling 1y sum of per-block sent volume
|
||||
self.annualized_volume.sats.height.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.count.height_1y_ago,
|
||||
&self.sent_sum.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
if let Some(sent_sum_dollars) = self.sent_sum.dollars.as_ref() {
|
||||
self.annualized_volume.compute_dollars(|dollars| {
|
||||
dollars.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_sum(
|
||||
starting_indexes.dateindex,
|
||||
&sent_sum_dollars.dateindex.0,
|
||||
365,
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})
|
||||
})?;
|
||||
}
|
||||
// tx_per_sec: per-block tx count / block interval
|
||||
self.tx_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&count_vecs.tx_count.height,
|
||||
&blocks.interval.interval.height,
|
||||
|(h, tx_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
let per_sec = if interval_f64 > 0.0 {
|
||||
StoredF32::from(*tx_count as f64 / interval_f64)
|
||||
} else {
|
||||
StoredF32::NAN
|
||||
};
|
||||
(h, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.tx_per_sec.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&count_vecs.tx_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.dateindex.date,
|
||||
|(i, tx_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(*tx_count as f64 / (completion * ONE_DAY_IN_SEC_F64))
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
// inputs_per_sec: per-block input count / block interval
|
||||
self.inputs_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&inputs_count.height.sum_cum.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
|(h, input_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
let per_sec = if interval_f64 > 0.0 {
|
||||
StoredF32::from(*input_count as f64 / interval_f64)
|
||||
} else {
|
||||
StoredF32::NAN
|
||||
};
|
||||
(h, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.inputs_per_sec
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&inputs_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.dateindex.date,
|
||||
|(i, input_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(*input_count as f64 / (completion * ONE_DAY_IN_SEC_F64))
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.outputs_per_sec
|
||||
.compute_all(starting_indexes, exit, |v| {
|
||||
v.compute_transform2(
|
||||
starting_indexes.dateindex,
|
||||
&outputs_count.total_count.dateindex.sum_cum.sum.0,
|
||||
&indexes.dateindex.date,
|
||||
|(i, output_count, date, ..)| {
|
||||
let completion = date.completion();
|
||||
let per_sec = if completion == 0.0 {
|
||||
StoredF32::NAN
|
||||
} else {
|
||||
StoredF32::from(
|
||||
*output_count as f64 / (completion * ONE_DAY_IN_SEC_F64),
|
||||
)
|
||||
};
|
||||
(i, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
Ok(())
|
||||
})?;
|
||||
// outputs_per_sec: per-block output count / block interval
|
||||
self.outputs_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&outputs_count.total_count.height.sum_cum.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
|(h, output_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
let per_sec = if interval_f64 > 0.0 {
|
||||
StoredF32::from(*output_count as f64 / interval_f64)
|
||||
} else {
|
||||
StoredF32::NAN
|
||||
};
|
||||
(h, per_sec)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user