mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
global: big snapshot
This commit is contained in:
@@ -3,7 +3,7 @@ use brk_indexer::Indexer;
|
||||
use brk_types::Indexes;
|
||||
use vecdb::Exit;
|
||||
|
||||
use crate::{blocks, outputs, prices};
|
||||
use crate::{outputs, prices};
|
||||
|
||||
use super::Vecs;
|
||||
|
||||
@@ -11,14 +11,13 @@ impl Vecs {
|
||||
pub(crate) fn compute(
|
||||
&mut self,
|
||||
indexer: &Indexer,
|
||||
blocks: &blocks::Vecs,
|
||||
outputs: &outputs::Vecs,
|
||||
prices: &prices::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
self.count
|
||||
.compute(indexer, &blocks.lookback, starting_indexes, exit)?;
|
||||
.compute(indexer, starting_indexes, exit)?;
|
||||
|
||||
self.value
|
||||
.compute(indexer, prices, starting_indexes, exit)?;
|
||||
|
||||
@@ -4,20 +4,16 @@ use brk_types::{Indexes, StoredU64};
|
||||
use vecdb::Exit;
|
||||
|
||||
use super::Vecs;
|
||||
use crate::blocks;
|
||||
|
||||
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();
|
||||
|
||||
self.p2a
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2a.first_index,
|
||||
@@ -27,7 +23,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2ms
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.p2ms.first_index,
|
||||
@@ -37,7 +33,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2pk33
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2pk33.first_index,
|
||||
@@ -47,7 +43,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2pk65
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2pk65.first_index,
|
||||
@@ -57,7 +53,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2pkh
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2pkh.first_index,
|
||||
@@ -67,7 +63,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2sh
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2sh.first_index,
|
||||
@@ -77,7 +73,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2tr
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2tr.first_index,
|
||||
@@ -87,7 +83,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2wpkh
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2wpkh.first_index,
|
||||
@@ -97,7 +93,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.p2wsh
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.addresses.p2wsh.first_index,
|
||||
@@ -107,7 +103,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.opreturn
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.opreturn.first_index,
|
||||
@@ -117,7 +113,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.unknownoutput
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.unknown.first_index,
|
||||
@@ -127,7 +123,7 @@ impl Vecs {
|
||||
})?;
|
||||
|
||||
self.emptyoutput
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
&indexer.vecs.scripts.empty.first_index,
|
||||
@@ -138,7 +134,7 @@ impl Vecs {
|
||||
|
||||
// Compute segwit = p2wpkh + p2wsh + p2tr
|
||||
self.segwit
|
||||
.compute(starting_indexes.height, &window_starts, exit, |v| {
|
||||
.compute(starting_indexes.height, exit, |v| {
|
||||
Ok(v.compute_transform3(
|
||||
starting_indexes.height,
|
||||
&self.p2wpkh.raw.height,
|
||||
|
||||
@@ -3,34 +3,38 @@ 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> {
|
||||
let p2a =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2a_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2a_count", version, indexes, cached_starts)?;
|
||||
let p2ms =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2ms_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2ms_count", version, indexes, cached_starts)?;
|
||||
let p2pk33 =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2pk33_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2pk33_count", version, indexes, cached_starts)?;
|
||||
let p2pk65 =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2pk65_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2pk65_count", version, indexes, cached_starts)?;
|
||||
let p2pkh =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2pkh_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2pkh_count", version, indexes, cached_starts)?;
|
||||
let p2sh =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2sh_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2sh_count", version, indexes, cached_starts)?;
|
||||
let p2tr =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2tr_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2tr_count", version, indexes, cached_starts)?;
|
||||
let p2wpkh =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2wpkh_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2wpkh_count", version, indexes, cached_starts)?;
|
||||
let p2wsh =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "p2wsh_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "p2wsh_count", version, indexes, cached_starts)?;
|
||||
let segwit =
|
||||
ComputedPerBlockCumulativeSum::forced_import(db, "segwit_count", version, indexes)?;
|
||||
ComputedPerBlockCumulativeWithSums::forced_import(db, "segwit_count", version, indexes, cached_starts)?;
|
||||
|
||||
Ok(Self {
|
||||
p2a,
|
||||
@@ -42,23 +46,26 @@ impl Vecs {
|
||||
p2tr,
|
||||
p2wpkh,
|
||||
p2wsh,
|
||||
opreturn: ComputedPerBlockCumulativeSum::forced_import(
|
||||
opreturn: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"opreturn_count",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
emptyoutput: ComputedPerBlockCumulativeSum::forced_import(
|
||||
emptyoutput: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"emptyoutput_count",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
unknownoutput: ComputedPerBlockCumulativeSum::forced_import(
|
||||
unknownoutput: ComputedPerBlockCumulativeWithSums::forced_import(
|
||||
db,
|
||||
"unknownoutput_count",
|
||||
version,
|
||||
indexes,
|
||||
cached_starts,
|
||||
)?,
|
||||
segwit,
|
||||
})
|
||||
|
||||
@@ -2,22 +2,22 @@ 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 p2a: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2ms: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2pk33: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2pk65: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2pkh: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2sh: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2tr: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2wpkh: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2wsh: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub opreturn: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub emptyoutput: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub unknownoutput: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub p2a: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2ms: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2pk33: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2pk65: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2pkh: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2sh: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2tr: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2wpkh: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub p2wsh: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub opreturn: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub emptyoutput: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
pub unknownoutput: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
|
||||
pub segwit: ComputedPerBlockCumulativeSum<StoredU64, M>,
|
||||
pub segwit: ComputedPerBlockCumulativeWithSums<StoredU64, StoredU64, M>,
|
||||
}
|
||||
|
||||
@@ -9,17 +9,19 @@ use crate::{
|
||||
};
|
||||
|
||||
use super::{AdoptionVecs, CountVecs, ValueVecs, Vecs};
|
||||
use crate::internal::CachedWindowStarts;
|
||||
|
||||
impl Vecs {
|
||||
pub(crate) fn forced_import(
|
||||
parent_path: &Path,
|
||||
parent_version: Version,
|
||||
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, indexes)?;
|
||||
let count = CountVecs::forced_import(&db, version, indexes, cached_starts)?;
|
||||
let value = ValueVecs::forced_import(&db, version, indexes)?;
|
||||
let adoption = AdoptionVecs::forced_import(&db, version, indexes)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user