computer: simplified a bunch of things

This commit is contained in:
nym21
2026-02-26 19:37:22 +01:00
parent 9e4fe62de2
commit cccaf6b206
252 changed files with 3788 additions and 7279 deletions

View File

@@ -2,7 +2,7 @@ use brk_error::Result;
use brk_indexer::Indexer;
use vecdb::Exit;
use crate::{blocks, outputs, ComputeIndexes};
use crate::{blocks, outputs, prices, ComputeIndexes};
use super::Vecs;
@@ -12,6 +12,7 @@ impl Vecs {
indexer: &Indexer,
blocks: &blocks::Vecs,
outputs: &outputs::Vecs,
prices: &prices::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
@@ -19,7 +20,7 @@ impl Vecs {
.compute(indexer, &blocks.count, &outputs.count, starting_indexes, exit)?;
self.value
.compute(indexer, starting_indexes, exit)?;
.compute(indexer, &blocks.count, prices, starting_indexes, exit)?;
let _lock = exit.lock();
self.db.compact()?;

View File

@@ -130,9 +130,9 @@ impl Vecs {
self.segwit.compute(starting_indexes.height, &window_starts, exit, |v| {
Ok(v.compute_transform3(
starting_indexes.height,
&self.p2wpkh.last.height,
&self.p2wsh.last.height,
&self.p2tr.last.height,
&self.p2wpkh.height,
&self.p2wsh.height,
&self.p2tr.height,
|(h, p2wpkh, p2wsh, p2tr, ..)| {
(h, StoredU64::from(*p2wpkh + *p2wsh + *p2tr))
},
@@ -143,8 +143,8 @@ impl Vecs {
// Adoption ratios: per-block ratio of script type / total outputs
self.taproot_adoption.height.compute_transform2(
starting_indexes.height,
&self.p2tr.last.height,
&outputs_count.total_count.sum_cum.sum.0,
&self.p2tr.height,
&outputs_count.total_count.sum_cumulative.sum.0,
|(h, p2tr, total, ..)| {
let ratio = if *total > 0 {
StoredF32::from(*p2tr as f64 / *total as f64)
@@ -158,8 +158,8 @@ impl Vecs {
self.segwit_adoption.height.compute_transform2(
starting_indexes.height,
&self.segwit.last.height,
&outputs_count.total_count.sum_cum.sum.0,
&self.segwit.height,
&outputs_count.total_count.sum_cumulative.sum.0,
|(h, segwit, total, ..)| {
let ratio = if *total > 0 {
StoredF32::from(*segwit as f64 / *total as f64)

View File

@@ -5,7 +5,7 @@ use vecdb::Database;
use super::Vecs;
use crate::{
indexes,
internal::{ComputedFromHeightCumSum, ComputedFromHeightLast},
internal::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast},
};
impl Vecs {
@@ -14,20 +14,20 @@ impl Vecs {
version: Version,
indexes: &indexes::Vecs,
) -> Result<Self> {
let p2a = ComputedFromHeightCumSum::forced_import(db, "p2a_count", version, indexes)?;
let p2ms = ComputedFromHeightCumSum::forced_import(db, "p2ms_count", version, indexes)?;
let p2a = ComputedFromHeightCumulativeSum::forced_import(db, "p2a_count", version, indexes)?;
let p2ms = ComputedFromHeightCumulativeSum::forced_import(db, "p2ms_count", version, indexes)?;
let p2pk33 =
ComputedFromHeightCumSum::forced_import(db, "p2pk33_count", version, indexes)?;
ComputedFromHeightCumulativeSum::forced_import(db, "p2pk33_count", version, indexes)?;
let p2pk65 =
ComputedFromHeightCumSum::forced_import(db, "p2pk65_count", version, indexes)?;
let p2pkh = ComputedFromHeightCumSum::forced_import(db, "p2pkh_count", version, indexes)?;
let p2sh = ComputedFromHeightCumSum::forced_import(db, "p2sh_count", version, indexes)?;
let p2tr = ComputedFromHeightCumSum::forced_import(db, "p2tr_count", version, indexes)?;
ComputedFromHeightCumulativeSum::forced_import(db, "p2pk65_count", version, indexes)?;
let p2pkh = ComputedFromHeightCumulativeSum::forced_import(db, "p2pkh_count", version, indexes)?;
let p2sh = ComputedFromHeightCumulativeSum::forced_import(db, "p2sh_count", version, indexes)?;
let p2tr = ComputedFromHeightCumulativeSum::forced_import(db, "p2tr_count", version, indexes)?;
let p2wpkh =
ComputedFromHeightCumSum::forced_import(db, "p2wpkh_count", version, indexes)?;
let p2wsh = ComputedFromHeightCumSum::forced_import(db, "p2wsh_count", version, indexes)?;
ComputedFromHeightCumulativeSum::forced_import(db, "p2wpkh_count", version, indexes)?;
let p2wsh = ComputedFromHeightCumulativeSum::forced_import(db, "p2wsh_count", version, indexes)?;
let segwit =
ComputedFromHeightCumSum::forced_import(db, "segwit_count", version, indexes)?;
ComputedFromHeightCumulativeSum::forced_import(db, "segwit_count", version, indexes)?;
Ok(Self {
p2a,
@@ -39,19 +39,19 @@ impl Vecs {
p2tr,
p2wpkh,
p2wsh,
opreturn: ComputedFromHeightCumSum::forced_import(
opreturn: ComputedFromHeightCumulativeSum::forced_import(
db,
"opreturn_count",
version,
indexes,
)?,
emptyoutput: ComputedFromHeightCumSum::forced_import(
emptyoutput: ComputedFromHeightCumulativeSum::forced_import(
db,
"emptyoutput_count",
version,
indexes,
)?,
unknownoutput: ComputedFromHeightCumSum::forced_import(
unknownoutput: ComputedFromHeightCumulativeSum::forced_import(
db,
"unknownoutput_count",
version,

View File

@@ -2,27 +2,27 @@ use brk_traversable::Traversable;
use brk_types::{StoredF32, StoredU64};
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedFromHeightCumSum, ComputedFromHeightLast};
use crate::internal::{ComputedFromHeightCumulativeSum, ComputedFromHeightLast};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
// Per-type output counts
pub p2a: ComputedFromHeightCumSum<StoredU64, M>,
pub p2ms: ComputedFromHeightCumSum<StoredU64, M>,
pub p2pk33: ComputedFromHeightCumSum<StoredU64, M>,
pub p2pk65: ComputedFromHeightCumSum<StoredU64, M>,
pub p2pkh: ComputedFromHeightCumSum<StoredU64, M>,
pub p2sh: ComputedFromHeightCumSum<StoredU64, M>,
pub p2tr: ComputedFromHeightCumSum<StoredU64, M>,
pub p2wpkh: ComputedFromHeightCumSum<StoredU64, M>,
pub p2wsh: ComputedFromHeightCumSum<StoredU64, M>,
pub opreturn: ComputedFromHeightCumSum<StoredU64, M>,
pub emptyoutput: ComputedFromHeightCumSum<StoredU64, M>,
pub unknownoutput: ComputedFromHeightCumSum<StoredU64, M>,
pub p2a: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2ms: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2pk33: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2pk65: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2pkh: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2sh: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2tr: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2wpkh: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub p2wsh: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub opreturn: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub emptyoutput: ComputedFromHeightCumulativeSum<StoredU64, M>,
pub unknownoutput: ComputedFromHeightCumulativeSum<StoredU64, M>,
// Aggregate counts
/// SegWit output count (p2wpkh + p2wsh + p2tr)
pub segwit: ComputedFromHeightCumSum<StoredU64, M>,
pub segwit: ComputedFromHeightCumulativeSum<StoredU64, M>,
// Adoption ratios (stored per-block, lazy period views)
pub taproot_adoption: ComputedFromHeightLast<StoredF32, M>,

View File

@@ -5,7 +5,7 @@ use brk_traversable::Traversable;
use brk_types::Version;
use vecdb::{Database, PAGE_SIZE};
use crate::{indexes, prices};
use crate::indexes;
use super::{CountVecs, ValueVecs, Vecs};
@@ -14,7 +14,6 @@ impl Vecs {
parent_path: &Path,
parent_version: Version,
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)?;
@@ -22,7 +21,7 @@ impl Vecs {
let version = parent_version;
let count = CountVecs::forced_import(&db, version, indexes)?;
let value = ValueVecs::forced_import(&db, version, indexes, prices)?;
let value = ValueVecs::forced_import(&db, version, indexes)?;
let this = Self { db, count, value };

View File

@@ -4,17 +4,22 @@ use brk_types::{Height, OutputType, Sats, TxOutIndex};
use vecdb::{AnyStoredVec, AnyVec, Exit, ReadableVec, WritableVec, VecIndex};
use super::Vecs;
use crate::ComputeIndexes;
use crate::{ComputeIndexes, blocks, prices};
impl Vecs {
pub(crate) fn compute(
&mut self,
indexer: &Indexer,
count_vecs: &blocks::CountVecs,
prices: &prices::Vecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
let window_starts = count_vecs.window_starts();
self.opreturn
.compute(starting_indexes, exit, |height_vec| {
.compute(starting_indexes.height, &window_starts, prices, exit, |height_vec| {
// Validate computed versions against dependencies
let dep_version = indexer.vecs.outputs.first_txoutindex.version()
+ indexer.vecs.outputs.outputtype.version()

View File

@@ -3,14 +3,13 @@ use brk_types::Version;
use vecdb::Database;
use super::Vecs;
use crate::{indexes, internal::ValueFromHeightFull, prices};
use crate::{indexes, internal::ValueFromHeightFull};
impl Vecs {
pub(crate) fn forced_import(
db: &Database,
version: Version,
indexes: &indexes::Vecs,
prices: &prices::Vecs,
) -> Result<Self> {
Ok(Self {
opreturn: ValueFromHeightFull::forced_import(
@@ -18,7 +17,6 @@ impl Vecs {
"opreturn_value",
version,
indexes,
prices,
)?,
})
}