mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 08:39:59 -07:00
global: snapshot
This commit is contained in:
@@ -2,7 +2,7 @@ use brk_error::Result;
|
||||
use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use crate::{indexes, inputs, outputs, price, ComputeIndexes};
|
||||
use crate::{indexes, inputs, outputs, ComputeIndexes};
|
||||
|
||||
use super::Vecs;
|
||||
|
||||
@@ -15,7 +15,6 @@ impl Vecs {
|
||||
inputs: &inputs::Vecs,
|
||||
outputs: &outputs::Vecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Count computes first
|
||||
@@ -49,7 +48,6 @@ impl Vecs {
|
||||
&inputs.count,
|
||||
&outputs.count,
|
||||
starting_indexes,
|
||||
price,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{StoredBool, TxIndex, Version};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedBlockFull};
|
||||
use crate::{indexes, internal::ComputedFromHeightFull};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -27,7 +27,7 @@ impl Vecs {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
tx_count: ComputedBlockFull::forced_import(db, "tx_count", version, indexes)?,
|
||||
tx_count: ComputedFromHeightFull::forced_import(db, "tx_count", version, indexes)?,
|
||||
is_coinbase: txindex_to_is_coinbase,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{Height, StoredBool, StoredU64, TxIndex};
|
||||
use vecdb::LazyVecFrom2;
|
||||
|
||||
use crate::internal::ComputedBlockFull;
|
||||
use crate::internal::ComputedFromHeightFull;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub tx_count: ComputedBlockFull<StoredU64>,
|
||||
pub tx_count: ComputedFromHeightFull<StoredU64>,
|
||||
pub is_coinbase: LazyVecFrom2<TxIndex, StoredBool, TxIndex, Height, Height, TxIndex>,
|
||||
}
|
||||
|
||||
@@ -57,11 +57,13 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// Skip coinbase (first tx per block) since it has no fee
|
||||
self.fee
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
.derive_from_with_skip(indexer, indexes, starting_indexes, exit, 1)?;
|
||||
|
||||
// Skip coinbase (first tx per block) since it has no feerate
|
||||
self.fee_rate
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
.derive_from_with_skip(indexer, indexes, starting_indexes, exit, 1)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,7 +4,10 @@ use brk_types::Version;
|
||||
use vecdb::{Database, EagerVec, ImportableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::{ComputedTxDistribution, ValueTxFull}, price};
|
||||
use crate::{indexes, internal::{ComputedFromTxDistribution, ValueFromTxFull}, price};
|
||||
|
||||
/// Bump this when fee/feerate aggregation logic changes (e.g., skip coinbase).
|
||||
const VERSION: Version = Version::ONE;
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -14,11 +17,12 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let v = version + VERSION;
|
||||
Ok(Self {
|
||||
input_value: EagerVec::forced_import(db, "input_value", version)?,
|
||||
output_value: EagerVec::forced_import(db, "output_value", version)?,
|
||||
fee: ValueTxFull::forced_import(db, "fee", version, indexes, indexer, price)?,
|
||||
fee_rate: ComputedTxDistribution::forced_import(db, "fee_rate", version, indexes)?,
|
||||
fee: ValueFromTxFull::forced_import(db, "fee", v, indexes, indexer, price)?,
|
||||
fee_rate: ComputedFromTxDistribution::forced_import(db, "fee_rate", v, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ use brk_traversable::Traversable;
|
||||
use brk_types::{FeeRate, Sats, TxIndex};
|
||||
use vecdb::{EagerVec, PcoVec};
|
||||
|
||||
use crate::internal::{ComputedTxDistribution, ValueTxFull};
|
||||
use crate::internal::{ComputedFromTxDistribution, ValueFromTxFull};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub input_value: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub output_value: EagerVec<PcoVec<TxIndex, Sats>>,
|
||||
pub fee: ValueTxFull,
|
||||
pub fee_rate: ComputedTxDistribution<FeeRate>,
|
||||
pub fee: ValueFromTxFull,
|
||||
pub fee_rate: ComputedFromTxDistribution<FeeRate>,
|
||||
}
|
||||
|
||||
@@ -22,13 +22,12 @@ impl Vecs {
|
||||
db.set_min_len(PAGE_SIZE * 50_000_000)?;
|
||||
|
||||
let version = parent_version;
|
||||
let compute_dollars = price.is_some();
|
||||
|
||||
let count = CountVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let size = SizeVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let fees = FeesVecs::forced_import(&db, version, indexer, indexes, price)?;
|
||||
let versions = VersionsVecs::forced_import(&db, version, indexes)?;
|
||||
let volume = VolumeVecs::forced_import(&db, version, indexes, compute_dollars)?;
|
||||
let volume = VolumeVecs::forced_import(&db, version, indexes, price)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{TxIndex, VSize, Version, Weight};
|
||||
use vecdb::{Database, IterableCloneableVec, LazyVecFrom2, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::LazyTxDistribution};
|
||||
use crate::{indexes, internal::LazyFromTxDistribution};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
@@ -42,14 +42,14 @@ impl Vecs {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
vsize: LazyTxDistribution::forced_import(
|
||||
vsize: LazyFromTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_vsize",
|
||||
version,
|
||||
txindex_to_vsize,
|
||||
indexes,
|
||||
)?,
|
||||
weight: LazyTxDistribution::forced_import(
|
||||
weight: LazyFromTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_weight",
|
||||
version,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::{StoredU32, VSize, Weight};
|
||||
|
||||
use crate::internal::LazyTxDistribution;
|
||||
use crate::internal::LazyFromTxDistribution;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub vsize: LazyTxDistribution<VSize, StoredU32, StoredU32>,
|
||||
pub weight: LazyTxDistribution<Weight, StoredU32, StoredU32>,
|
||||
pub vsize: LazyFromTxDistribution<VSize, StoredU32, StoredU32>,
|
||||
pub weight: LazyFromTxDistribution<Weight, StoredU32, StoredU32>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{StoredU64, TxVersion};
|
||||
use vecdb::{Exit, TypedVecIterator};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, internal::ComputedBlockSumCum};
|
||||
use crate::{ComputeIndexes, indexes, internal::ComputedFromHeightSumCum};
|
||||
|
||||
impl Vecs {
|
||||
pub fn compute(
|
||||
@@ -14,7 +14,7 @@ impl Vecs {
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let tx_vany = |tx_vany: &mut ComputedBlockSumCum<StoredU64>, txversion: TxVersion| {
|
||||
let tx_vany = |tx_vany: &mut ComputedFromHeightSumCum<StoredU64>, txversion: TxVersion| {
|
||||
let mut txversion_iter = indexer.vecs.transactions.txversion.iter()?;
|
||||
tx_vany.compute_all(indexes, starting_indexes, exit, |vec| {
|
||||
vec.compute_filtered_count_from_indexes(
|
||||
|
||||
@@ -3,14 +3,14 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedBlockSumCum};
|
||||
use crate::{indexes, internal::ComputedFromHeightSumCum};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
v1: ComputedBlockSumCum::forced_import(db, "tx_v1", version, indexes)?,
|
||||
v2: ComputedBlockSumCum::forced_import(db, "tx_v2", version, indexes)?,
|
||||
v3: ComputedBlockSumCum::forced_import(db, "tx_v3", version, indexes)?,
|
||||
v1: ComputedFromHeightSumCum::forced_import(db, "tx_v1", version, indexes)?,
|
||||
v2: ComputedFromHeightSumCum::forced_import(db, "tx_v2", version, indexes)?,
|
||||
v3: ComputedFromHeightSumCum::forced_import(db, "tx_v3", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
|
||||
use crate::internal::ComputedBlockSumCum;
|
||||
use crate::internal::ComputedFromHeightSumCum;
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub v1: ComputedBlockSumCum<StoredU64>,
|
||||
pub v2: ComputedBlockSumCum<StoredU64>,
|
||||
pub v3: ComputedBlockSumCum<StoredU64>,
|
||||
pub v1: ComputedFromHeightSumCum<StoredU64>,
|
||||
pub v2: ComputedFromHeightSumCum<StoredU64>,
|
||||
pub v3: ComputedFromHeightSumCum<StoredU64>,
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Exit;
|
||||
|
||||
use super::super::{count, fees};
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, indexes, inputs, outputs, price};
|
||||
use crate::{ComputeIndexes, indexes, inputs, outputs};
|
||||
|
||||
impl Vecs {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -18,11 +18,10 @@ impl Vecs {
|
||||
inputs_count: &inputs::CountVecs,
|
||||
outputs_count: &outputs::CountVecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
price: Option<&price::Vecs>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.sent_sum
|
||||
.compute_all(indexes, price, starting_indexes, exit, |v| {
|
||||
.compute_all(indexes, starting_indexes, exit, |v| {
|
||||
v.compute_filtered_sum_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
|
||||
@@ -3,40 +3,41 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::{ComputedDateLast, ValueBlockSum, ValueDateLast}};
|
||||
use crate::{indexes, internal::{ComputedFromDateLast, ValueFromHeightSum, ValueFromDateLast}, price};
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
compute_dollars: bool,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
let compute_dollars = price.is_some();
|
||||
|
||||
Ok(Self {
|
||||
sent_sum: ValueBlockSum::forced_import(
|
||||
sent_sum: ValueFromHeightSum::forced_import(
|
||||
db,
|
||||
"sent_sum",
|
||||
version,
|
||||
indexes,
|
||||
compute_dollars,
|
||||
price,
|
||||
)?,
|
||||
annualized_volume: ValueDateLast::forced_import(
|
||||
annualized_volume: ValueFromDateLast::forced_import(
|
||||
db,
|
||||
"annualized_volume",
|
||||
version,
|
||||
compute_dollars,
|
||||
indexes,
|
||||
)?,
|
||||
tx_per_sec: ComputedDateLast::forced_import(db, "tx_per_sec", version + v2, indexes)?,
|
||||
outputs_per_sec: ComputedDateLast::forced_import(
|
||||
tx_per_sec: ComputedFromDateLast::forced_import(db, "tx_per_sec", version + v2, indexes)?,
|
||||
outputs_per_sec: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"outputs_per_sec",
|
||||
version + v2,
|
||||
indexes,
|
||||
)?,
|
||||
inputs_per_sec: ComputedDateLast::forced_import(
|
||||
inputs_per_sec: ComputedFromDateLast::forced_import(
|
||||
db,
|
||||
"inputs_per_sec",
|
||||
version + v2,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::StoredF32;
|
||||
|
||||
use crate::internal::{ComputedDateLast, ValueBlockSum, ValueDateLast};
|
||||
use crate::internal::{ComputedFromDateLast, ValueFromHeightSum, ValueFromDateLast};
|
||||
|
||||
/// Volume metrics
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub sent_sum: ValueBlockSum,
|
||||
pub annualized_volume: ValueDateLast,
|
||||
pub tx_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub outputs_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub inputs_per_sec: ComputedDateLast<StoredF32>,
|
||||
pub sent_sum: ValueFromHeightSum,
|
||||
pub annualized_volume: ValueFromDateLast,
|
||||
pub tx_per_sec: ComputedFromDateLast<StoredF32>,
|
||||
pub outputs_per_sec: ComputedFromDateLast<StoredF32>,
|
||||
pub inputs_per_sec: ComputedFromDateLast<StoredF32>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user