global: snapshot

This commit is contained in:
nym21
2026-03-04 17:10:15 +01:00
parent 891f0dad9e
commit 9e23de4ba1
313 changed files with 9087 additions and 4918 deletions

View File

@@ -33,14 +33,8 @@ impl Vecs {
.compute(indexer, indexes, starting_indexes, exit)?;
// Fees depends on size
self.fees.compute(
indexer,
indexes,
inputs,
&self.size,
starting_indexes,
exit,
)?;
self.fees
.compute(indexer, indexes, inputs, &self.size, starting_indexes, exit)?;
// Volume depends on fees, counts, and blocks (lookback vecs, interval)
self.volume.compute(

View File

@@ -15,19 +15,15 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
let window_starts = count_vecs.window_starts();
self.tx_count.compute(
starting_indexes.height,
&window_starts,
exit,
|height| {
self.tx_count
.compute(starting_indexes.height, &window_starts, exit, |height| {
Ok(height.compute_count_from_indexes(
starting_indexes.height,
&indexer.vecs.transactions.first_txindex,
&indexer.vecs.transactions.txid,
exit,
)?)
},
)?;
})?;
Ok(())
}

View File

@@ -17,16 +17,16 @@ impl Vecs {
"is_coinbase",
version,
indexer.vecs.transactions.height.read_only_boxed_clone(),
indexer.vecs.transactions.first_txindex.read_only_boxed_clone(),
|index: TxIndex, _height, first_txindex| {
StoredBool::from(index == first_txindex)
},
indexer
.vecs
.transactions
.first_txindex
.read_only_boxed_clone(),
|index: TxIndex, _height, first_txindex| StoredBool::from(index == first_txindex),
);
Ok(Self {
tx_count: ComputedFromHeightFull::forced_import(
db, "tx_count", version, indexes,
)?,
tx_count: ComputedFromHeightFull::forced_import(db, "tx_count", version, indexes)?,
is_coinbase: txindex_to_is_coinbase,
})
}

View File

@@ -58,22 +58,12 @@ impl Vecs {
)?;
// Skip coinbase (first tx per block) since it has fee=0
self.fee.derive_from_with_skip(
indexer,
indexes,
starting_indexes,
exit,
1,
)?;
self.fee
.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_with_skip(
indexer,
indexes,
starting_indexes,
exit,
1,
)?;
self.fee_rate
.derive_from_with_skip(indexer, indexes, starting_indexes, exit, 1)?;
Ok(())
}

View File

@@ -2,11 +2,12 @@ use std::path::Path;
use brk_error::Result;
use brk_indexer::Indexer;
use brk_traversable::Traversable;
use brk_types::Version;
use vecdb::{Database, PAGE_SIZE};
use crate::indexes;
use crate::{
indexes,
internal::{finalize_db, open_db},
};
use super::{CountVecs, FeesVecs, SizeVecs, Vecs, VersionsVecs, VolumeVecs};
@@ -17,9 +18,7 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
) -> Result<Self> {
let db = Database::open(&parent_path.join(super::DB_NAME))?;
db.set_min_len(PAGE_SIZE * 50_000_000)?;
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)?;
@@ -36,14 +35,7 @@ impl Vecs {
versions,
volume,
};
this.db.retain_regions(
this.iter_any_exportable()
.flat_map(|v| v.region_names())
.collect(),
)?;
this.db.compact()?;
finalize_db(&this.db, &this)?;
Ok(this)
}
}

View File

@@ -1,7 +1,7 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::{TxIndex, VSize, Version, Weight};
use vecdb::{Database, ReadableCloneableVec, LazyVecFrom2};
use vecdb::{Database, LazyVecFrom2, ReadableCloneableVec};
use super::Vecs;
use crate::internal::LazyFromTxDistribution;
@@ -17,9 +17,7 @@ impl Vecs {
version,
indexer.vecs.transactions.base_size.read_only_boxed_clone(),
indexer.vecs.transactions.total_size.read_only_boxed_clone(),
|_index: TxIndex, base_size, total_size| {
Weight::from_sizes(*base_size, *total_size)
},
|_index: TxIndex, base_size, total_size| Weight::from_sizes(*base_size, *total_size),
);
let txindex_to_vsize = LazyVecFrom2::init(

View File

@@ -16,7 +16,8 @@ impl Vecs {
) -> Result<()> {
let window_starts = count_vecs.window_starts();
let tx_vany = |tx_vany: &mut ComputedFromHeightCumulativeSum<StoredU64>, txversion: TxVersion| {
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.

View File

@@ -6,7 +6,11 @@ use super::Vecs;
use crate::{indexes, internal::ComputedFromHeightCumulativeSum};
impl Vecs {
pub(crate) fn forced_import(db: &Database, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
v1: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v1", version, indexes)?,
v2: ComputedFromHeightCumulativeSum::forced_import(db, "tx_v2", version, indexes)?,

View File

@@ -67,24 +67,30 @@ impl Vecs {
self.annualized_volume
.compute(prices, starting_indexes.height, exit)?;
self.tx_per_sec.height.compute_binary::<_, Timestamp, PerSec>(
starting_indexes.height,
&count_vecs.tx_count.height,
&blocks.interval.height,
exit,
)?;
self.inputs_per_sec.height.compute_binary::<_, Timestamp, PerSec>(
starting_indexes.height,
&inputs_count.full.sum,
&blocks.interval.height,
exit,
)?;
self.outputs_per_sec.height.compute_binary::<_, Timestamp, PerSec>(
starting_indexes.height,
&outputs_count.total_count.full.sum,
&blocks.interval.height,
exit,
)?;
self.tx_per_sec
.height
.compute_binary::<_, Timestamp, PerSec>(
starting_indexes.height,
&count_vecs.tx_count.height,
&blocks.interval.height,
exit,
)?;
self.inputs_per_sec
.height
.compute_binary::<_, Timestamp, PerSec>(
starting_indexes.height,
&inputs_count.full.sum,
&blocks.interval.height,
exit,
)?;
self.outputs_per_sec
.height
.compute_binary::<_, Timestamp, PerSec>(
starting_indexes.height,
&outputs_count.total_count.full.sum,
&blocks.interval.height,
exit,
)?;
Ok(())
}

View File

@@ -16,11 +16,12 @@ impl Vecs {
) -> Result<Self> {
let v2 = Version::TWO;
Ok(Self {
sent_sum: ValueFromHeightRolling::forced_import(
db, "sent_sum", version, indexes,
)?,
sent_sum: ValueFromHeightRolling::forced_import(db, "sent_sum", version, indexes)?,
received_sum: ValueFromHeightRolling::forced_import(
db, "received_sum", version, indexes,
db,
"received_sum",
version,
indexes,
)?,
annualized_volume: ValueFromHeight::forced_import(
db,
@@ -28,12 +29,7 @@ impl Vecs {
version,
indexes,
)?,
tx_per_sec: ComputedFromHeight::forced_import(
db,
"tx_per_sec",
version + v2,
indexes,
)?,
tx_per_sec: ComputedFromHeight::forced_import(db, "tx_per_sec", version + v2, indexes)?,
outputs_per_sec: ComputedFromHeight::forced_import(
db,
"outputs_per_sec",

View File

@@ -2,11 +2,8 @@ use brk_traversable::Traversable;
use brk_types::StoredF32;
use vecdb::{Rw, StorageMode};
use crate::internal::{
ComputedFromHeight, ValueFromHeight, ValueFromHeightRolling,
};
use crate::internal::{ComputedFromHeight, ValueFromHeight, ValueFromHeightRolling};
/// Volume metrics
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub sent_sum: ValueFromHeightRolling<M>,