mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 16:49:58 -07:00
global: big snapshot
This commit is contained in:
@@ -26,7 +26,7 @@ impl Vecs {
|
||||
|
||||
// Versions depends on count
|
||||
self.versions
|
||||
.compute(indexer, &blocks.lookback, starting_indexes, exit)?;
|
||||
.compute(indexer, starting_indexes, exit)?;
|
||||
|
||||
// Size computes next (uses 6-block rolling window)
|
||||
self.size
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_types::{StoredBool, TxIndex, Version};
|
||||
use vecdb::{Database, LazyVecFrom2, ReadableCloneableVec};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedPerBlockFull};
|
||||
use crate::{indexes, internal::{CachedWindowStarts, ComputedPerBlockFull}};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
@@ -12,6 +12,7 @@ impl Vecs {
|
||||
version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let txindex_to_is_coinbase = LazyVecFrom2::init(
|
||||
"is_coinbase",
|
||||
@@ -26,7 +27,13 @@ impl Vecs {
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
total: ComputedPerBlockFull::forced_import(db, "tx_count", version, indexes)?,
|
||||
total: ComputedPerBlockFull::forced_import(
|
||||
db,
|
||||
"tx_count",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
is_coinbase: txindex_to_is_coinbase,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use brk_types::Version;
|
||||
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{finalize_db, open_db},
|
||||
internal::{finalize_db, open_db, CachedWindowStarts},
|
||||
};
|
||||
|
||||
use super::{CountVecs, FeesVecs, SizeVecs, Vecs, VersionsVecs, VolumeVecs};
|
||||
@@ -17,15 +17,16 @@ impl Vecs {
|
||||
parent_version: Version,
|
||||
indexer: &Indexer,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let db = open_db(parent_path, super::DB_NAME, 50_000_000)?;
|
||||
let version = parent_version;
|
||||
|
||||
let count = CountVecs::forced_import(&db, version, indexer, indexes)?;
|
||||
let count = CountVecs::forced_import(&db, version, indexer, indexes, cached_starts)?;
|
||||
let size = SizeVecs::forced_import(&db, version, indexer)?;
|
||||
let fees = FeesVecs::forced_import(&db, version)?;
|
||||
let versions = VersionsVecs::forced_import(&db, version, indexes)?;
|
||||
let volume = VolumeVecs::forced_import(&db, version, indexes)?;
|
||||
let versions = VersionsVecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
let volume = VolumeVecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
|
||||
let this = Self {
|
||||
db,
|
||||
|
||||
@@ -4,25 +4,22 @@ use brk_types::{Indexes, StoredU64, TxVersion};
|
||||
use vecdb::{Exit, ReadableVec, VecIndex};
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{blocks, internal::ComputedPerBlockCumulativeSum};
|
||||
use crate::internal::ComputedPerBlockCumulativeWithSums;
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
lookback: &blocks::LookbackVecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let window_starts = lookback.window_starts();
|
||||
|
||||
let tx_vany = |tx_vany: &mut ComputedPerBlockCumulativeSum<StoredU64>,
|
||||
let tx_vany = |tx_vany: &mut ComputedPerBlockCumulativeWithSums<StoredU64, 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.height, &window_starts, exit, |vec| {
|
||||
tx_vany.compute(starting_indexes.height, exit, |vec| {
|
||||
vec.compute_filtered_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.transactions.first_txindex,
|
||||
|
||||
@@ -3,18 +3,22 @@ use brk_types::Version;
|
||||
use vecdb::Database;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::{indexes, internal::ComputedPerBlockCumulativeSum};
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{CachedWindowStarts, ComputedPerBlockCumulativeWithSums},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
v1: ComputedPerBlockCumulativeSum::forced_import(db, "tx_v1", version, indexes)?,
|
||||
v2: ComputedPerBlockCumulativeSum::forced_import(db, "tx_v2", version, indexes)?,
|
||||
v3: ComputedPerBlockCumulativeSum::forced_import(db, "tx_v3", version, indexes)?,
|
||||
v1: ComputedPerBlockCumulativeWithSums::forced_import(db, "tx_v1", version, indexes, cached_starts)?,
|
||||
v2: ComputedPerBlockCumulativeWithSums::forced_import(db, "tx_v2", version, indexes, cached_starts)?,
|
||||
v3: ComputedPerBlockCumulativeWithSums::forced_import(db, "tx_v3", version, indexes, cached_starts)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredU64;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::ComputedPerBlockCumulativeSum;
|
||||
use crate::internal::ComputedPerBlockCumulativeWithSums;
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub v1: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub v2: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub v3: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub v1: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub v2: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub v3: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
}
|
||||
|
||||
@@ -22,11 +22,8 @@ impl Vecs {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
let window_starts = blocks.lookback.window_starts();
|
||||
|
||||
self.sent_sum.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
prices,
|
||||
exit,
|
||||
|sats_vec| {
|
||||
@@ -43,7 +40,6 @@ impl Vecs {
|
||||
|
||||
self.received_sum.compute(
|
||||
starting_indexes.height,
|
||||
&window_starts,
|
||||
prices,
|
||||
exit,
|
||||
|sats_vec| {
|
||||
@@ -57,16 +53,6 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
// Annualized volume: rolling 1y sum of per-block sent volume
|
||||
self.annualized.sats.height.compute_rolling_sum(
|
||||
starting_indexes.height,
|
||||
&blocks.lookback._1y,
|
||||
&self.sent_sum.sats,
|
||||
exit,
|
||||
)?;
|
||||
self.annualized
|
||||
.compute(prices, starting_indexes.height, exit)?;
|
||||
|
||||
self.tx_per_sec
|
||||
.height
|
||||
.compute_binary::<_, Timestamp, PerSec>(
|
||||
|
||||
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{AmountPerBlock, AmountPerBlockRolling, ComputedPerBlock},
|
||||
internal::{AmountPerBlockCumulativeWithSums, CachedWindowStarts, ComputedPerBlock},
|
||||
};
|
||||
|
||||
impl Vecs {
|
||||
@@ -13,21 +13,23 @@ impl Vecs {
|
||||
db: &Database,
|
||||
version: Version,
|
||||
indexes: &indexes::Vecs,
|
||||
cached_starts: &CachedWindowStarts,
|
||||
) -> Result<Self> {
|
||||
let v2 = Version::TWO;
|
||||
Ok(Self {
|
||||
sent_sum: AmountPerBlockRolling::forced_import(db, "sent_sum", version, indexes)?,
|
||||
received_sum: AmountPerBlockRolling::forced_import(
|
||||
sent_sum: AmountPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"sent_sum",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
received_sum: AmountPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"received_sum",
|
||||
version,
|
||||
indexes,
|
||||
)?,
|
||||
annualized: AmountPerBlock::forced_import(
|
||||
db,
|
||||
"annualized_volume",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
tx_per_sec: ComputedPerBlock::forced_import(db, "tx_per_sec", version + v2, indexes)?,
|
||||
outputs_per_sec: ComputedPerBlock::forced_import(
|
||||
|
||||
@@ -2,13 +2,12 @@ use brk_traversable::Traversable;
|
||||
use brk_types::StoredF32;
|
||||
use vecdb::{Rw, StorageMode};
|
||||
|
||||
use crate::internal::{AmountPerBlock, AmountPerBlockRolling, ComputedPerBlock};
|
||||
use crate::internal::{AmountPerBlockCumulativeWithSums, ComputedPerBlock};
|
||||
|
||||
#[derive(Traversable)]
|
||||
pub struct Vecs<M: StorageMode = Rw> {
|
||||
pub sent_sum: AmountPerBlockRolling<M>,
|
||||
pub received_sum: AmountPerBlockRolling<M>,
|
||||
pub annualized: AmountPerBlock<M>,
|
||||
pub sent_sum: AmountPerBlockCumulativeWithSums<M>,
|
||||
pub received_sum: AmountPerBlockCumulativeWithSums<M>,
|
||||
pub tx_per_sec: ComputedPerBlock<StoredF32, M>,
|
||||
pub outputs_per_sec: ComputedPerBlock<StoredF32, M>,
|
||||
pub inputs_per_sec: ComputedPerBlock<StoredF32, M>,
|
||||
|
||||
Reference in New Issue
Block a user