mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_types::{Indexes, Timestamp};
|
||||
use brk_types::{Indexes, StoredF32};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::transactions::{count, fees};
|
||||
use crate::{blocks, indexes, inputs, internal::PerSec, outputs, prices};
|
||||
use crate::{blocks, indexes, inputs, outputs, prices};
|
||||
|
||||
const WINDOW_SECS: [f64; 4] = [
|
||||
86400.0,
|
||||
7.0 * 86400.0,
|
||||
30.0 * 86400.0,
|
||||
365.0 * 86400.0,
|
||||
];
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -38,30 +45,37 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
self.tx_per_sec
|
||||
.height
|
||||
.compute_binary::<_, Timestamp, PerSec>(
|
||||
starting_indexes.height,
|
||||
&count_vecs.total.base.height,
|
||||
&blocks.interval.base,
|
||||
exit,
|
||||
)?;
|
||||
self.inputs_per_sec
|
||||
.height
|
||||
.compute_binary::<_, Timestamp, PerSec>(
|
||||
starting_indexes.height,
|
||||
&inputs_count.sum.height,
|
||||
&blocks.interval.base,
|
||||
exit,
|
||||
)?;
|
||||
self.outputs_per_sec
|
||||
.height
|
||||
.compute_binary::<_, Timestamp, PerSec>(
|
||||
starting_indexes.height,
|
||||
&outputs_count.total.sum.height,
|
||||
&blocks.interval.base,
|
||||
exit,
|
||||
)?;
|
||||
let h = starting_indexes.height;
|
||||
let tx_sums = count_vecs.total.rolling.sum.0.as_array();
|
||||
let input_sums = inputs_count.rolling.sum.0.as_array();
|
||||
let output_sums = outputs_count.total.rolling.sum.0.as_array();
|
||||
|
||||
for (i, &secs) in WINDOW_SECS.iter().enumerate() {
|
||||
self.tx_per_sec.as_mut_array()[i]
|
||||
.height
|
||||
.compute_transform(
|
||||
h,
|
||||
&tx_sums[i].height,
|
||||
|(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)),
|
||||
exit,
|
||||
)?;
|
||||
self.inputs_per_sec.as_mut_array()[i]
|
||||
.height
|
||||
.compute_transform(
|
||||
h,
|
||||
&input_sums[i].height,
|
||||
|(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)),
|
||||
exit,
|
||||
)?;
|
||||
self.outputs_per_sec.as_mut_array()[i]
|
||||
.height
|
||||
.compute_transform(
|
||||
h,
|
||||
&output_sums[i].height,
|
||||
|(h, sum, ..)| (h, StoredF32::from(*sum as f64 / secs)),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, PerBlock},
|
||||
internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, PerBlock, Windows},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -15,7 +15,7 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
let v = version + Version::TWO;
|
||||
Ok(Self {
|
||||
transfer_volume: AmountPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
@@ -24,19 +24,15 @@ impl Vecs {
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
tx_per_sec: PerBlock::forced_import(db, "tx_per_sec", version + v2, indexes)?,
|
||||
outputs_per_sec: PerBlock::forced_import(
|
||||
db,
|
||||
"outputs_per_sec",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
inputs_per_sec: PerBlock::forced_import(
|
||||
db,
|
||||
"inputs_per_sec",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
tx_per_sec: Windows::try_from_fn(|suffix| {
|
||||
PerBlock::forced_import(db, &format!("tx_per_sec_{suffix}"), v, indexes)
|
||||
})?,
|
||||
outputs_per_sec: Windows::try_from_fn(|suffix| {
|
||||
PerBlock::forced_import(db, &format!("outputs_per_sec_{suffix}"), v, indexes)
|
||||
})?,
|
||||
inputs_per_sec: Windows::try_from_fn(|suffix| {
|
||||
PerBlock::forced_import(db, &format!("inputs_per_sec_{suffix}"), v, indexes)
|
||||
})?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF32;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{AmountPerBlockCumulativeWithSums, PerBlock};
|
||||
use crate::internal::{AmountPerBlockCumulativeWithSums, PerBlock, Windows};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub transfer_volume: AmountPerBlockCumulativeWithSums<M>,
|
||||
pub tx_per_sec: PerBlock<StoredF32, M>,
|
||||
pub outputs_per_sec: PerBlock<StoredF32, M>,
|
||||
pub inputs_per_sec: PerBlock<StoredF32, M>,
|
||||
pub tx_per_sec: Windows<PerBlock<StoredF32, M>>,
|
||||
pub outputs_per_sec: Windows<PerBlock<StoredF32, M>>,
|
||||
pub inputs_per_sec: Windows<PerBlock<StoredF32, M>>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user