mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 08:39:59 -07:00
computer: simplified a bunch of things
This commit is contained in:
@@ -25,11 +25,11 @@ impl Vecs {
|
||||
|
||||
// Versions depends on count
|
||||
self.versions
|
||||
.compute(indexer, starting_indexes, exit)?;
|
||||
.compute(indexer, &blocks.count, starting_indexes, exit)?;
|
||||
|
||||
// Size computes next
|
||||
// Size computes next (uses BlockWindowStarts for 1h/24h rolling)
|
||||
self.size
|
||||
.compute(indexer, indexes, starting_indexes, exit)?;
|
||||
.compute(indexer, indexes, &blocks.count, starting_indexes, exit)?;
|
||||
|
||||
// Fees depends on size, blocks (window starts), prices (USD conversion)
|
||||
self.fees.compute(
|
||||
@@ -48,6 +48,7 @@ impl Vecs {
|
||||
indexer,
|
||||
indexes,
|
||||
blocks,
|
||||
prices,
|
||||
&self.count,
|
||||
&self.fees,
|
||||
&inputs.count,
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{StoredBool, TxIndex, Version};
|
||||
use vecdb::{Database, LazyVecFrom2, ReadableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightCumFull};
|
||||
use crate::{indexes, internal::ComputedFromHeightCumulativeFull};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -24,7 +24,7 @@ impl Vecs {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
tx_count: ComputedFromHeightCumFull::forced_import(
|
||||
tx_count: ComputedFromHeightCumulativeFull::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, Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightCumFull;
|
||||
use crate::internal::ComputedFromHeightCumulativeFull;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub tx_count: ComputedFromHeightCumFull<StoredU64, M>,
|
||||
pub tx_count: ComputedFromHeightCumulativeFull<StoredU64, M>,
|
||||
pub is_coinbase: LazyVecFrom2<TxIndex, StoredBool, TxIndex, Height, Height, TxIndex>,
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ impl Vecs {
|
||||
// Compute fee USD sum per block: price * Bitcoin::from(sats)
|
||||
self.fee_usd_sum.compute_transform2(
|
||||
starting_indexes.height,
|
||||
self.fee.sum_cum.sum.inner(),
|
||||
self.fee.sum_cumulative.sum.inner(),
|
||||
&prices.usd.price,
|
||||
|(h, sats, price, ..)| (h, price * Bitcoin::from(sats)),
|
||||
exit,
|
||||
@@ -93,7 +93,7 @@ impl Vecs {
|
||||
self.fee_rolling.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
self.fee.sum_cum.sum.inner(),
|
||||
self.fee.sum_cumulative.sum.inner(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -101,7 +101,7 @@ impl Vecs {
|
||||
self.fee_rate_rolling.compute_distribution(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
&self.fee_rate.min_max_average.average.0,
|
||||
&self.fee_rate.average.0,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use brk_traversable::Traversable;
|
||||
use brk_types::Version;
|
||||
use vecdb::{Database, PAGE_SIZE};
|
||||
|
||||
use crate::{indexes, prices};
|
||||
use crate::indexes;
|
||||
|
||||
use super::{CountVecs, FeesVecs, SizeVecs, Vecs, VersionsVecs, VolumeVecs};
|
||||
|
||||
@@ -16,7 +16,6 @@ impl Vecs {
|
||||
parent_version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let db = Database::open(&parent_path.join(super::DB_NAME))?;
|
||||
db.set_min_len(PAGE_SIZE * 50_000_000)?;
|
||||
@@ -24,10 +23,10 @@ impl Vecs {
|
||||
let version = parent_version;
|
||||
|
||||
let count = CountVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let size = SizeVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let size = SizeVecs::forced_import(&db, version, indexer)?;
|
||||
let fees = FeesVecs::forced_import(&db, version, indexes)?;
|
||||
let versions = VersionsVecs::forced_import(&db, version, indexes)?;
|
||||
let volume = VolumeVecs::forced_import(&db, version, indexes, prices)?;
|
||||
let volume = VolumeVecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
|
||||
@@ -3,21 +3,24 @@ use brk_indexer::Indexer;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, ComputeIndexes};
|
||||
use crate::{blocks, indexes, ComputeIndexes};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
count_vecs: &blocks::CountVecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let block_windows = count_vecs.block_window_starts();
|
||||
|
||||
self.weight
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
.derive_from(indexer, indexes, starting_indexes, &block_windows, exit)?;
|
||||
|
||||
self.vsize
|
||||
.derive_from(indexer, indexes, starting_indexes, exit)?;
|
||||
.derive_from(indexer, indexes, starting_indexes, &block_windows, exit)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ use brk_types::{TxIndex, VSize, Version, Weight};
|
||||
use vecdb::{Database, ReadableCloneableVec, LazyVecFrom2};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::LazyFromTxDistribution};
|
||||
use crate::internal::LazyFromTxDistribution;
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
) -> Result<Self> {
|
||||
let txindex_to_weight = LazyVecFrom2::init(
|
||||
"tx_weight",
|
||||
@@ -39,14 +38,12 @@ impl Vecs {
|
||||
"tx_vsize",
|
||||
version,
|
||||
txindex_to_vsize,
|
||||
indexes,
|
||||
)?,
|
||||
weight: LazyFromTxDistribution::forced_import(
|
||||
db,
|
||||
"tx_weight",
|
||||
version,
|
||||
txindex_to_weight,
|
||||
indexes,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,21 +4,24 @@ use brk_types::{StoredU64, TxVersion};
|
||||
use vecdb::{Exit, ReadableVec, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{ComputeIndexes, internal::ComputedFromHeightSumCum};
|
||||
use crate::{ComputeIndexes, blocks, internal::ComputedFromHeightCumulativeSum};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
count_vecs: &blocks::CountVecs,
|
||||
starting_indexes: &ComputeIndexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let tx_vany = |tx_vany: &mut ComputedFromHeightSumCum<StoredU64>, txversion: TxVersion| {
|
||||
let window_starts = count_vecs.window_starts();
|
||||
|
||||
let tx_vany = |tx_vany: &mut ComputedFromHeightCumulativeSum<StoredU64>, txversion: TxVersion| {
|
||||
let txversion_vec = &indexer.vecs.transactions.txversion;
|
||||
// Cursor avoids per-transaction PcoVec page decompression.
|
||||
// Txindex values are sequential, so the cursor only advances forward.
|
||||
let mut cursor = txversion_vec.cursor();
|
||||
tx_vany.compute(starting_indexes, exit, |vec| {
|
||||
tx_vany.compute(starting_indexes.height, &window_starts, exit, |vec| {
|
||||
vec.compute_filtered_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
|
||||
@@ -3,14 +3,14 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedFromHeightSumCum};
|
||||
use crate::{indexes, internal::ComputedFromHeightCumulativeSum};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
|
||||
Ok(Self {
|
||||
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)?,
|
||||
v1: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v1", version, indexes)?,
|
||||
v2: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v2", version, indexes)?,
|
||||
v3: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v3", version, indexes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedFromHeightSumCum;
|
||||
use crate::internal::ComputedFromHeightCumulativeSum;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub v1: ComputedFromHeightSumCum<StoredU64, M>,
|
||||
pub v2: ComputedFromHeightSumCum<StoredU64, M>,
|
||||
pub v3: ComputedFromHeightSumCum<StoredU64, M>,
|
||||
pub v1: ComputedFromHeightCumulativeSum<StoredU64, M>,
|
||||
pub v2: ComputedFromHeightCumulativeSum<StoredU64, M>,
|
||||
pub v3: ComputedFromHeightCumulativeSum<StoredU64, M>,
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::StoredF32;
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{blocks, ComputeIndexes, indexes, inputs, outputs};
|
||||
use crate::{blocks, ComputeIndexes, indexes, inputs, outputs, prices};
|
||||
use crate::transactions::{count, fees};
|
||||
|
||||
impl Vecs {
|
||||
@@ -14,6 +14,7 @@ impl Vecs {
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
blocks: &blocks::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
count_vecs: &count::Vecs,
|
||||
fees_vecs: &fees::Vecs,
|
||||
inputs_count: &inputs::CountVecs,
|
||||
@@ -38,6 +39,12 @@ impl Vecs {
|
||||
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,
|
||||
@@ -45,6 +52,8 @@ impl Vecs {
|
||||
&self.sent_sum.sats.height,
|
||||
exit,
|
||||
)?;
|
||||
self.annualized_volume
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
// Rolling sums for sent and received
|
||||
let window_starts = blocks.count.window_starts();
|
||||
@@ -83,7 +92,7 @@ impl Vecs {
|
||||
// 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,
|
||||
&inputs_count.height.sum_cumulative.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
|(h, input_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
@@ -100,7 +109,7 @@ 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_cum.sum.0,
|
||||
&outputs_count.total_count.sum_cumulative.sum.0,
|
||||
&blocks.interval.interval.height,
|
||||
|(h, output_count, interval, ..)| {
|
||||
let interval_f64 = f64::from(*interval);
|
||||
|
||||
@@ -6,7 +6,6 @@ use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, StoredValueRollingWindows, ValueFromHeightLast},
|
||||
prices,
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -14,18 +13,17 @@ impl Vecs {
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
Ok(Self {
|
||||
sent_sum: ValueFromHeightLast::forced_import(
|
||||
db, "sent_sum", version, indexes, prices,
|
||||
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, prices,
|
||||
db, "received_sum", version, indexes,
|
||||
)?,
|
||||
received_sum_rolling: StoredValueRollingWindows::forced_import(
|
||||
db, "received_sum", version, indexes,
|
||||
@@ -35,7 +33,6 @@ impl Vecs {
|
||||
"annualized_volume",
|
||||
version,
|
||||
indexes,
|
||||
prices,
|
||||
)?,
|
||||
tx_per_sec: ComputedFromHeightLast::forced_import(
|
||||
db,
|
||||
|
||||
Reference in New Issue
Block a user