mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 16:49:58 -07:00
computer: snapshot
This commit is contained in:
@@ -22,61 +22,56 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent_sum.sats.height.compute_filtered_sum_from_indexes(
|
||||
let window_starts = blocks.count.window_starts();
|
||||
|
||||
self.sent_sum.compute(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.input_value,
|
||||
|sats| !sats.is_max(),
|
||||
&window_starts,
|
||||
prices,
|
||||
exit,
|
||||
|sats_vec| {
|
||||
Ok(sats_vec.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.sats.height.compute_sum_from_indexes(
|
||||
self.received_sum.compute(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.output_value,
|
||||
&window_starts,
|
||||
prices,
|
||||
exit,
|
||||
|sats_vec| {
|
||||
Ok(sats_vec.compute_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
&indexes.height.txindex_count,
|
||||
&fees_vecs.output_value,
|
||||
exit,
|
||||
)?)
|
||||
},
|
||||
)?;
|
||||
|
||||
// Compute USD from sats × price
|
||||
self.sent_sum
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
self.received_sum
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
// 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,
|
||||
&self.sent_sum.sats,
|
||||
exit,
|
||||
)?;
|
||||
self.annualized_volume
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
// Rolling sums for sent and received
|
||||
let window_starts = blocks.count.window_starts();
|
||||
self.sent_sum_rolling.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.sent_sum.sats.height,
|
||||
&self.sent_sum.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
self.received_sum_rolling.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.received_sum.sats.height,
|
||||
&self.received_sum.usd.height,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// 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,
|
||||
&blocks.interval.height,
|
||||
|(h, tx_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
let per_sec = if interval_f64 > 0.0 {
|
||||
@@ -93,7 +88,7 @@ impl Vecs {
|
||||
self.inputs_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&inputs_count.height.sum_cumulative.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
&blocks.interval.height,
|
||||
|(h, input_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
let per_sec = if interval_f64 > 0.0 {
|
||||
@@ -109,8 +104,8 @@ impl Vecs {
|
||||
// outputs_per_sec: per-block output count / block interval
|
||||
self.outputs_per_sec.height.compute_transform2(
|
||||
starting_indexes.height,
|
||||
&outputs_count.total_count.sum_cumulative.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
&outputs_count.total_count.height.sum_cumulative.sum.0,
|
||||
&blocks.interval.height,
|
||||
|(h, output_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
let per_sec = if interval_f64 > 0.0 {
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightLast},
|
||||
internal::{ComputedFromHeightLast, ValueFromHeightLast, ValueFromHeightLastRolling},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -16,16 +16,10 @@ impl Vecs {
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
Ok(Self {
|
||||
sent_sum: ValueFromHeightLast::forced_import(
|
||||
sent_sum: ValueFromHeightLastRolling::forced_import(
|
||||
db, "sent_sum", version, indexes,
|
||||
)?,
|
||||
sent_sum_rolling: StoredValueRollingWindows::forced_import(
|
||||
db, "sent_sum", version, indexes,
|
||||
)?,
|
||||
received_sum: ValueFromHeightLast::forced_import(
|
||||
db, "received_sum", version, indexes,
|
||||
)?,
|
||||
received_sum_rolling: StoredValueRollingWindows::forced_import(
|
||||
received_sum: ValueFromHeightLastRolling::forced_import(
|
||||
db, "received_sum", version, indexes,
|
||||
)?,
|
||||
annualized_volume: ValueFromHeightLast::forced_import(
|
||||
|
||||
@@ -3,18 +3,16 @@ use brk_types::StoredF32;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{
|
||||
ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightLast,
|
||||
ComputedFromHeightLast, ValueFromHeightLast, ValueFromHeightLastRolling,
|
||||
};
|
||||
|
||||
/// Volume metrics
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
#[traversable(flatten)]
|
||||
pub sent_sum: ValueFromHeightLast<M>,
|
||||
pub sent_sum_rolling: StoredValueRollingWindows<M>,
|
||||
pub sent_sum: ValueFromHeightLastRolling<M>,
|
||||
#[traversable(flatten)]
|
||||
pub received_sum: ValueFromHeightLast<M>,
|
||||
pub received_sum_rolling: StoredValueRollingWindows<M>,
|
||||
pub received_sum: ValueFromHeightLastRolling<M>,
|
||||
#[traversable(flatten)]
|
||||
pub annualized_volume: ValueFromHeightLast<M>,
|
||||
pub tx_per_sec: ComputedFromHeightLast<StoredF32, M>,
|
||||
|
||||
Reference in New Issue
Block a user