mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-19 23:18:10 -07:00
global: fixes + snapshot + packages
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use brk_core::{CheckedSub, Height, StoredU32, StoredU64, StoredUsize, Timestamp, Weight};
|
||||
use brk_core::{
|
||||
CheckedSub, DifficultyEpoch, HalvingEpoch, Height, StoredU32, StoredU64, StoredUsize,
|
||||
Timestamp, Weight,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_parser::bitcoin;
|
||||
@@ -8,19 +11,22 @@ use brk_vec::{Compressed, Version};
|
||||
|
||||
use super::{
|
||||
EagerVec, Indexes,
|
||||
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
grouped::{ComputedVecsFromDateindex, ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub height_to_interval: EagerVec<Height, Timestamp>,
|
||||
pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>,
|
||||
pub indexes_to_block_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_block_weight: ComputedVecsFromHeight<Weight>,
|
||||
pub height_to_vbytes: EagerVec<Height, StoredU64>,
|
||||
pub indexes_to_block_vbytes: ComputedVecsFromHeight<StoredU64>,
|
||||
pub difficultyepoch_to_timestamp: EagerVec<DifficultyEpoch, Timestamp>,
|
||||
pub halvingepoch_to_timestamp: EagerVec<HalvingEpoch, Timestamp>,
|
||||
pub timeindexes_to_timestamp: ComputedVecsFromDateindex<Timestamp>,
|
||||
pub indexes_to_block_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>,
|
||||
pub indexes_to_block_size: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_block_vbytes: ComputedVecsFromHeight<StoredU64>,
|
||||
pub indexes_to_block_weight: ComputedVecsFromHeight<Weight>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -33,6 +39,13 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
timeindexes_to_timestamp: ComputedVecsFromDateindex::forced_import(
|
||||
path,
|
||||
"timestamp",
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_first(),
|
||||
)?,
|
||||
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"block_interval",
|
||||
@@ -81,6 +94,16 @@ impl Vecs {
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_sum().add_total(),
|
||||
)?,
|
||||
difficultyepoch_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("difficultyepoch_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
halvingepoch_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("halvingepoch_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -91,9 +114,43 @@ impl Vecs {
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> color_eyre::Result<()> {
|
||||
self.timeindexes_to_timestamp.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_date.mut_vec(),
|
||||
|(di, d, ..)| (di, Timestamp::from(d)),
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_count.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v, indexer, _, starting_indexes, exit| {
|
||||
let indexer_vecs = indexer.mut_vecs();
|
||||
|
||||
v.compute_range(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_weight.mut_vec(),
|
||||
|h| (h, StoredU32::from(1_u32)),
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
let indexer_vecs = indexer.mut_vecs();
|
||||
|
||||
self.height_to_interval.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer.mut_vecs().height_to_timestamp.mut_vec(),
|
||||
indexer_vecs.height_to_timestamp.mut_vec(),
|
||||
|(height, timestamp, _, height_to_timestamp)| {
|
||||
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
|
||||
let prev_timestamp = height_to_timestamp.double_unwrap_cached_get(prev_h);
|
||||
@@ -113,38 +170,23 @@ impl Vecs {
|
||||
Some(self.height_to_interval.mut_vec()),
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_count.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|v, indexer, _, starting_indexes, exit| {
|
||||
v.compute_range(
|
||||
starting_indexes.height,
|
||||
indexer.mut_vecs().height_to_weight.mut_vec(),
|
||||
|h| (h, StoredU32::from(1_u32)),
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_weight.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(indexer.mut_vecs().height_to_weight.mut_vec()),
|
||||
Some(indexer_vecs.height_to_weight.mut_vec()),
|
||||
)?;
|
||||
|
||||
self.indexes_to_block_size.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(indexer.mut_vecs().height_to_total_size.mut_vec()),
|
||||
Some(indexer_vecs.height_to_total_size.mut_vec()),
|
||||
)?;
|
||||
|
||||
self.height_to_vbytes.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer.mut_vecs().height_to_weight.mut_vec(),
|
||||
indexer_vecs.height_to_weight.mut_vec(),
|
||||
|(h, w, ..)| {
|
||||
(
|
||||
h,
|
||||
@@ -161,6 +203,30 @@ impl Vecs {
|
||||
Some(self.height_to_vbytes.mut_vec()),
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_timestamp.compute_transform(
|
||||
starting_indexes.difficultyepoch,
|
||||
indexes.difficultyepoch_to_first_height.mut_vec(),
|
||||
|(i, h, ..)| {
|
||||
(
|
||||
i,
|
||||
indexer_vecs.height_to_timestamp.double_unwrap_cached_get(h),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.halvingepoch_to_timestamp.compute_transform(
|
||||
starting_indexes.halvingepoch,
|
||||
indexes.halvingepoch_to_first_height.mut_vec(),
|
||||
|(i, h, ..)| {
|
||||
(
|
||||
i,
|
||||
indexer_vecs.height_to_timestamp.double_unwrap_cached_get(h),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -169,12 +235,15 @@ impl Vecs {
|
||||
vec![
|
||||
self.height_to_interval.any_vec(),
|
||||
self.height_to_vbytes.any_vec(),
|
||||
self.difficultyepoch_to_timestamp.any_vec(),
|
||||
self.halvingepoch_to_timestamp.any_vec(),
|
||||
],
|
||||
self.indexes_to_block_interval.any_vecs(),
|
||||
self.timeindexes_to_timestamp.any_vecs(),
|
||||
self.indexes_to_block_count.any_vecs(),
|
||||
self.indexes_to_block_weight.any_vecs(),
|
||||
self.indexes_to_block_interval.any_vecs(),
|
||||
self.indexes_to_block_size.any_vecs(),
|
||||
self.indexes_to_block_vbytes.any_vecs(),
|
||||
self.indexes_to_block_weight.any_vecs(),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
||||
@@ -19,21 +19,17 @@ pub struct Vecs {
|
||||
pub dateindex_to_first_height: EagerVec<DateIndex, Height>,
|
||||
pub dateindex_to_last_height: EagerVec<DateIndex, Height>,
|
||||
pub dateindex_to_monthindex: EagerVec<DateIndex, MonthIndex>,
|
||||
pub dateindex_to_timestamp: EagerVec<DateIndex, Timestamp>,
|
||||
pub dateindex_to_weekindex: EagerVec<DateIndex, WeekIndex>,
|
||||
pub decadeindex_to_decadeindex: EagerVec<DecadeIndex, DecadeIndex>,
|
||||
pub decadeindex_to_first_yearindex: EagerVec<DecadeIndex, YearIndex>,
|
||||
pub decadeindex_to_last_yearindex: EagerVec<DecadeIndex, YearIndex>,
|
||||
pub decadeindex_to_timestamp: EagerVec<DecadeIndex, Timestamp>,
|
||||
pub difficultyepoch_to_difficultyepoch: EagerVec<DifficultyEpoch, DifficultyEpoch>,
|
||||
pub difficultyepoch_to_first_height: EagerVec<DifficultyEpoch, Height>,
|
||||
pub difficultyepoch_to_last_height: EagerVec<DifficultyEpoch, Height>,
|
||||
pub difficultyepoch_to_timestamp: EagerVec<DifficultyEpoch, Timestamp>,
|
||||
pub emptyoutputindex_to_emptyoutputindex: EagerVec<EmptyOutputIndex, EmptyOutputIndex>,
|
||||
pub halvingepoch_to_first_height: EagerVec<HalvingEpoch, Height>,
|
||||
pub halvingepoch_to_halvingepoch: EagerVec<HalvingEpoch, HalvingEpoch>,
|
||||
pub halvingepoch_to_last_height: EagerVec<HalvingEpoch, Height>,
|
||||
pub halvingepoch_to_timestamp: EagerVec<HalvingEpoch, Timestamp>,
|
||||
pub height_to_date: EagerVec<Height, Date>,
|
||||
pub height_to_date_fixed: EagerVec<Height, Date>,
|
||||
pub height_to_dateindex: EagerVec<Height, DateIndex>,
|
||||
@@ -47,7 +43,6 @@ pub struct Vecs {
|
||||
pub monthindex_to_last_dateindex: EagerVec<MonthIndex, DateIndex>,
|
||||
pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>,
|
||||
pub monthindex_to_quarterindex: EagerVec<MonthIndex, QuarterIndex>,
|
||||
pub monthindex_to_timestamp: EagerVec<MonthIndex, Timestamp>,
|
||||
pub monthindex_to_yearindex: EagerVec<MonthIndex, YearIndex>,
|
||||
pub opreturnindex_to_opreturnindex: EagerVec<OpReturnIndex, OpReturnIndex>,
|
||||
pub outputindex_to_outputindex: EagerVec<OutputIndex, OutputIndex>,
|
||||
@@ -63,7 +58,6 @@ pub struct Vecs {
|
||||
pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>,
|
||||
pub quarterindex_to_last_monthindex: EagerVec<QuarterIndex, MonthIndex>,
|
||||
pub quarterindex_to_quarterindex: EagerVec<QuarterIndex, QuarterIndex>,
|
||||
pub quarterindex_to_timestamp: EagerVec<QuarterIndex, Timestamp>,
|
||||
pub txindex_to_height: EagerVec<TxIndex, Height>,
|
||||
pub txindex_to_last_inputindex: EagerVec<TxIndex, InputIndex>,
|
||||
pub txindex_to_last_outputindex: EagerVec<TxIndex, OutputIndex>,
|
||||
@@ -71,12 +65,10 @@ pub struct Vecs {
|
||||
pub unknownoutputindex_to_unknownoutputindex: EagerVec<UnknownOutputIndex, UnknownOutputIndex>,
|
||||
pub weekindex_to_first_dateindex: EagerVec<WeekIndex, DateIndex>,
|
||||
pub weekindex_to_last_dateindex: EagerVec<WeekIndex, DateIndex>,
|
||||
pub weekindex_to_timestamp: EagerVec<WeekIndex, Timestamp>,
|
||||
pub weekindex_to_weekindex: EagerVec<WeekIndex, WeekIndex>,
|
||||
pub yearindex_to_decadeindex: EagerVec<YearIndex, DecadeIndex>,
|
||||
pub yearindex_to_first_monthindex: EagerVec<YearIndex, MonthIndex>,
|
||||
pub yearindex_to_last_monthindex: EagerVec<YearIndex, MonthIndex>,
|
||||
pub yearindex_to_timestamp: EagerVec<YearIndex, Timestamp>,
|
||||
pub yearindex_to_yearindex: EagerVec<YearIndex, YearIndex>,
|
||||
}
|
||||
|
||||
@@ -265,41 +257,6 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
dateindex_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("dateindex_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
decadeindex_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("decadeindex_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
difficultyepoch_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("difficultyepoch_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
halvingepoch_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("halvingepoch_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
monthindex_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("monthindex_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
weekindex_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("weekindex_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
yearindex_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("yearindex_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_timestamp_fixed: EagerVec::forced_import(
|
||||
&path.join("height_to_timestamp_fixed"),
|
||||
Version::ZERO,
|
||||
@@ -325,11 +282,6 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_timestamp: EagerVec::forced_import(
|
||||
&path.join("quarterindex_to_timestamp"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
p2pk33index_to_p2pk33index: EagerVec::forced_import(
|
||||
&path.join("p2pk33index_to_p2pk33index"),
|
||||
Version::ZERO,
|
||||
@@ -421,6 +373,158 @@ impl Vecs {
|
||||
let inputindexes_count = indexer_vecs.inputindex_to_outputindex.len();
|
||||
let outputindexes_count = indexer_vecs.outputindex_to_value.len();
|
||||
|
||||
// ---
|
||||
// OutputIndex
|
||||
// ---
|
||||
|
||||
self.outputindex_to_outputindex.compute_range(
|
||||
starting_indexes.outputindex,
|
||||
indexer_vecs.outputindex_to_value.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2pk33index_to_p2pk33index.compute_range(
|
||||
starting_indexes.p2pk33index,
|
||||
indexer_vecs.p2pk33index_to_p2pk33bytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2pk65index_to_p2pk65index.compute_range(
|
||||
starting_indexes.p2pk65index,
|
||||
indexer_vecs.p2pk65index_to_p2pk65bytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2pkhindex_to_p2pkhindex.compute_range(
|
||||
starting_indexes.p2pkhindex,
|
||||
indexer_vecs.p2pkhindex_to_p2pkhbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2shindex_to_p2shindex.compute_range(
|
||||
starting_indexes.p2shindex,
|
||||
indexer_vecs.p2shindex_to_p2shbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2trindex_to_p2trindex.compute_range(
|
||||
starting_indexes.p2trindex,
|
||||
indexer_vecs.p2trindex_to_p2trbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2wpkhindex_to_p2wpkhindex.compute_range(
|
||||
starting_indexes.p2wpkhindex,
|
||||
indexer_vecs.p2wpkhindex_to_p2wpkhbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2wshindex_to_p2wshindex.compute_range(
|
||||
starting_indexes.p2wshindex,
|
||||
indexer_vecs.p2wshindex_to_p2wshbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.emptyoutputindex_to_emptyoutputindex.compute_range(
|
||||
starting_indexes.emptyoutputindex,
|
||||
indexer_vecs.emptyoutputindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2msindex_to_p2msindex.compute_range(
|
||||
starting_indexes.p2msindex,
|
||||
indexer_vecs.p2msindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.opreturnindex_to_opreturnindex.compute_range(
|
||||
starting_indexes.opreturnindex,
|
||||
indexer_vecs.opreturnindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.p2aindex_to_p2aindex.compute_range(
|
||||
starting_indexes.p2aindex,
|
||||
indexer_vecs.p2aindex_to_p2abytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.unknownoutputindex_to_unknownoutputindex
|
||||
.compute_range(
|
||||
starting_indexes.unknownoutputindex,
|
||||
indexer_vecs.unknownoutputindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// InputIndex
|
||||
// ---
|
||||
|
||||
self.inputindex_to_inputindex.compute_range(
|
||||
starting_indexes.inputindex,
|
||||
indexer_vecs.inputindex_to_outputindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// TxIndex
|
||||
// ---
|
||||
|
||||
self.txindex_to_last_inputindex
|
||||
.compute_last_index_from_first(
|
||||
starting_indexes.txindex,
|
||||
indexer_vecs.txindex_to_first_inputindex.mut_vec(),
|
||||
inputindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_last_outputindex
|
||||
.compute_last_index_from_first(
|
||||
starting_indexes.txindex,
|
||||
indexer_vecs.txindex_to_first_outputindex.mut_vec(),
|
||||
outputindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_txindex.compute_range(
|
||||
starting_indexes.txindex,
|
||||
self.txindex_to_last_inputindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.height_to_last_txindex.compute_last_index_from_first(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_first_txindex.mut_vec(),
|
||||
txindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_height.compute_inverse_less_to_more(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_first_txindex.mut_vec(),
|
||||
self.height_to_last_txindex.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// Height
|
||||
// ---
|
||||
|
||||
self.height_to_height.compute_range(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.mut_vec(),
|
||||
@@ -457,6 +561,10 @@ impl Vecs {
|
||||
|
||||
let decremented_starting_height = starting_indexes.height.decremented().unwrap_or_default();
|
||||
|
||||
// ---
|
||||
// DateIndex
|
||||
// ---
|
||||
|
||||
let starting_dateindex = self
|
||||
.height_to_dateindex
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
@@ -509,36 +617,8 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.dateindex_to_timestamp.compute_transform(
|
||||
starting_dateindex,
|
||||
self.dateindex_to_date.mut_vec(),
|
||||
|(di, d, ..)| (di, Timestamp::from(d)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_last_inputindex
|
||||
.compute_last_index_from_first(
|
||||
starting_indexes.txindex,
|
||||
indexer_vecs.txindex_to_first_inputindex.mut_vec(),
|
||||
inputindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_last_outputindex
|
||||
.compute_last_index_from_first(
|
||||
starting_indexes.txindex,
|
||||
indexer_vecs.txindex_to_first_outputindex.mut_vec(),
|
||||
outputindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.height_to_last_txindex.compute_last_index_from_first(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_first_txindex.mut_vec(),
|
||||
txindexes_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// WeekIndex
|
||||
// ---
|
||||
|
||||
let starting_weekindex = self
|
||||
@@ -575,13 +655,46 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.weekindex_to_timestamp.compute_transform(
|
||||
starting_weekindex,
|
||||
self.weekindex_to_first_dateindex.mut_vec(),
|
||||
|(i, d, ..)| (i, self.dateindex_to_timestamp.double_unwrap_cached_get(d)),
|
||||
// ---
|
||||
// DifficultyEpoch
|
||||
// ---
|
||||
|
||||
let starting_difficultyepoch = self
|
||||
.height_to_difficultyepoch
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height_to_difficultyepoch.compute_range(
|
||||
starting_indexes.height,
|
||||
self.height_to_height.mut_vec(),
|
||||
|h| (h, DifficultyEpoch::from(h)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_first_height
|
||||
.compute_inverse_more_to_less(
|
||||
starting_indexes.height,
|
||||
self.height_to_difficultyepoch.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_last_height
|
||||
.compute_last_index_from_first(
|
||||
starting_difficultyepoch,
|
||||
self.difficultyepoch_to_first_height.mut_vec(),
|
||||
height_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_difficultyepoch.compute_range(
|
||||
starting_difficultyepoch,
|
||||
self.difficultyepoch_to_first_height.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// MonthIndex
|
||||
// ---
|
||||
|
||||
let starting_monthindex = self
|
||||
@@ -620,13 +733,8 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex_to_timestamp.compute_transform(
|
||||
starting_monthindex,
|
||||
self.monthindex_to_first_dateindex.mut_vec(),
|
||||
|(i, d, ..)| (i, self.dateindex_to_timestamp.double_unwrap_cached_get(d)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// QuarterIndex
|
||||
// ---
|
||||
|
||||
let starting_quarterindex = self
|
||||
@@ -665,13 +773,8 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex_to_timestamp.compute_transform(
|
||||
starting_quarterindex,
|
||||
self.quarterindex_to_first_monthindex.mut_vec(),
|
||||
|(i, m, ..)| (i, self.monthindex_to_timestamp.double_unwrap_cached_get(m)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// YearIndex
|
||||
// ---
|
||||
|
||||
let starting_yearindex = self
|
||||
@@ -710,104 +813,8 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex_to_timestamp.compute_transform(
|
||||
starting_yearindex,
|
||||
self.yearindex_to_first_monthindex.mut_vec(),
|
||||
|(i, m, ..)| (i, self.monthindex_to_timestamp.double_unwrap_cached_get(m)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
|
||||
let starting_decadeindex = self
|
||||
.yearindex_to_decadeindex
|
||||
.unwrap_cached_get(starting_yearindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.yearindex_to_decadeindex.compute_range(
|
||||
starting_yearindex,
|
||||
self.yearindex_to_yearindex.mut_vec(),
|
||||
|i| (i, DecadeIndex::from(i)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_first_yearindex
|
||||
.compute_inverse_more_to_less(
|
||||
starting_yearindex,
|
||||
self.yearindex_to_decadeindex.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_last_yearindex
|
||||
.compute_last_index_from_first(
|
||||
starting_decadeindex,
|
||||
self.decadeindex_to_first_yearindex.mut_vec(),
|
||||
year_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_decadeindex.compute_range(
|
||||
starting_decadeindex,
|
||||
self.decadeindex_to_first_yearindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_timestamp.compute_transform(
|
||||
starting_decadeindex,
|
||||
self.decadeindex_to_first_yearindex.mut_vec(),
|
||||
|(i, y, ..)| (i, self.yearindex_to_timestamp.double_unwrap_cached_get(y)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
|
||||
let starting_difficultyepoch = self
|
||||
.height_to_difficultyepoch
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height_to_difficultyepoch.compute_range(
|
||||
starting_indexes.height,
|
||||
self.height_to_height.mut_vec(),
|
||||
|h| (h, DifficultyEpoch::from(h)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_first_height
|
||||
.compute_inverse_more_to_less(
|
||||
starting_indexes.height,
|
||||
self.height_to_difficultyepoch.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_last_height
|
||||
.compute_last_index_from_first(
|
||||
starting_difficultyepoch,
|
||||
self.difficultyepoch_to_first_height.mut_vec(),
|
||||
height_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_difficultyepoch.compute_range(
|
||||
starting_difficultyepoch,
|
||||
self.difficultyepoch_to_first_height.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_timestamp.compute_transform(
|
||||
starting_difficultyepoch,
|
||||
self.difficultyepoch_to_first_height.mut_vec(),
|
||||
|(i, h, ..)| {
|
||||
(
|
||||
i,
|
||||
indexer_vecs.height_to_timestamp.double_unwrap_cached_get(h),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// HalvingEpoch
|
||||
// ---
|
||||
|
||||
let starting_halvingepoch = self
|
||||
@@ -844,112 +851,44 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// self.difficultyepoch_to_timestamp.compute_transform(
|
||||
// starting_difficultyepoch,
|
||||
// self.difficultyepoch_to_first_height.mut_vec(),
|
||||
// |(i, h, ..)| {
|
||||
// (
|
||||
// i,
|
||||
// *indexer_vecs.height_to_timestamp.unwraped_cached_get(h).unwrap().unwrap(),
|
||||
// )
|
||||
// },
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
// ---
|
||||
// DecadeIndex
|
||||
// ---
|
||||
|
||||
self.outputindex_to_outputindex.compute_range(
|
||||
starting_indexes.outputindex,
|
||||
indexer_vecs.outputindex_to_value.mut_vec(),
|
||||
|i| (i, i),
|
||||
let starting_decadeindex = self
|
||||
.yearindex_to_decadeindex
|
||||
.unwrap_cached_get(starting_yearindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.yearindex_to_decadeindex.compute_range(
|
||||
starting_yearindex,
|
||||
self.yearindex_to_yearindex.mut_vec(),
|
||||
|i| (i, DecadeIndex::from(i)),
|
||||
exit,
|
||||
)?;
|
||||
self.p2pk33index_to_p2pk33index.compute_range(
|
||||
starting_indexes.p2pk33index,
|
||||
indexer_vecs.p2pk33index_to_p2pk33bytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2pk65index_to_p2pk65index.compute_range(
|
||||
starting_indexes.p2pk65index,
|
||||
indexer_vecs.p2pk65index_to_p2pk65bytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2pkhindex_to_p2pkhindex.compute_range(
|
||||
starting_indexes.p2pkhindex,
|
||||
indexer_vecs.p2pkhindex_to_p2pkhbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2shindex_to_p2shindex.compute_range(
|
||||
starting_indexes.p2shindex,
|
||||
indexer_vecs.p2shindex_to_p2shbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2trindex_to_p2trindex.compute_range(
|
||||
starting_indexes.p2trindex,
|
||||
indexer_vecs.p2trindex_to_p2trbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2wpkhindex_to_p2wpkhindex.compute_range(
|
||||
starting_indexes.p2wpkhindex,
|
||||
indexer_vecs.p2wpkhindex_to_p2wpkhbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2wshindex_to_p2wshindex.compute_range(
|
||||
starting_indexes.p2wshindex,
|
||||
indexer_vecs.p2wshindex_to_p2wshbytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.txindex_to_txindex.compute_range(
|
||||
starting_indexes.txindex,
|
||||
self.txindex_to_height.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.inputindex_to_inputindex.compute_range(
|
||||
starting_indexes.inputindex,
|
||||
indexer_vecs.inputindex_to_outputindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.emptyoutputindex_to_emptyoutputindex.compute_range(
|
||||
starting_indexes.emptyoutputindex,
|
||||
indexer_vecs.emptyoutputindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2msindex_to_p2msindex.compute_range(
|
||||
starting_indexes.p2msindex,
|
||||
indexer_vecs.p2msindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.opreturnindex_to_opreturnindex.compute_range(
|
||||
starting_indexes.opreturnindex,
|
||||
indexer_vecs.opreturnindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.p2aindex_to_p2aindex.compute_range(
|
||||
starting_indexes.p2aindex,
|
||||
indexer_vecs.p2aindex_to_p2abytes.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
self.unknownoutputindex_to_unknownoutputindex
|
||||
.compute_range(
|
||||
starting_indexes.unknownoutputindex,
|
||||
indexer_vecs.unknownoutputindex_to_txindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
|
||||
self.decadeindex_to_first_yearindex
|
||||
.compute_inverse_more_to_less(
|
||||
starting_yearindex,
|
||||
self.yearindex_to_decadeindex.mut_vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_last_yearindex
|
||||
.compute_last_index_from_first(
|
||||
starting_decadeindex,
|
||||
self.decadeindex_to_first_yearindex.mut_vec(),
|
||||
year_count,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_decadeindex.compute_range(
|
||||
starting_decadeindex,
|
||||
self.decadeindex_to_first_yearindex.mut_vec(),
|
||||
|i| (i, i),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(Indexes {
|
||||
indexes: starting_indexes,
|
||||
dateindex: starting_dateindex,
|
||||
@@ -1000,19 +939,11 @@ impl Vecs {
|
||||
self.decadeindex_to_decadeindex.any_vec(),
|
||||
self.difficultyepoch_to_difficultyepoch.any_vec(),
|
||||
self.halvingepoch_to_halvingepoch.any_vec(),
|
||||
self.dateindex_to_timestamp.any_vec(),
|
||||
self.decadeindex_to_timestamp.any_vec(),
|
||||
self.difficultyepoch_to_timestamp.any_vec(),
|
||||
self.halvingepoch_to_timestamp.any_vec(),
|
||||
self.monthindex_to_timestamp.any_vec(),
|
||||
self.weekindex_to_timestamp.any_vec(),
|
||||
self.yearindex_to_timestamp.any_vec(),
|
||||
self.height_to_timestamp_fixed.any_vec(),
|
||||
self.monthindex_to_quarterindex.any_vec(),
|
||||
self.quarterindex_to_first_monthindex.any_vec(),
|
||||
self.quarterindex_to_last_monthindex.any_vec(),
|
||||
self.quarterindex_to_quarterindex.any_vec(),
|
||||
self.quarterindex_to_timestamp.any_vec(),
|
||||
self.p2pk33index_to_p2pk33index.any_vec(),
|
||||
self.p2pk65index_to_p2pk65index.any_vec(),
|
||||
self.p2pkhindex_to_p2pkhindex.any_vec(),
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use brk_core::{DifficultyEpoch, HalvingEpoch, StoredF64};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_vec::{Compressed, DynamicVec, Version};
|
||||
|
||||
use super::{
|
||||
Indexes,
|
||||
grouped::{ComputedVecsFromDateindex, ComputedVecsFromHeight, StorableVecGeneatorOptions},
|
||||
indexes,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub indexes_to_difficulty: ComputedVecsFromHeight<StoredF64>,
|
||||
pub indexes_to_difficultyepoch: ComputedVecsFromDateindex<DifficultyEpoch>,
|
||||
pub indexes_to_halvingepoch: ComputedVecsFromDateindex<HalvingEpoch>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
pub fn forced_import(path: &Path, compressed: Compressed) -> color_eyre::Result<Self> {
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
Ok(Self {
|
||||
indexes_to_difficulty: ComputedVecsFromHeight::forced_import(
|
||||
path,
|
||||
"difficulty",
|
||||
false,
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_difficultyepoch: ComputedVecsFromDateindex::forced_import(
|
||||
path,
|
||||
"difficultyepoch",
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)?,
|
||||
indexes_to_halvingepoch: ComputedVecsFromDateindex::forced_import(
|
||||
path,
|
||||
"halvingepoch",
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
StorableVecGeneatorOptions::default().add_last(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
indexer: &mut Indexer,
|
||||
indexes: &mut indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
) -> color_eyre::Result<()> {
|
||||
self.indexes_to_difficultyepoch.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_last_height.mut_vec(),
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
indexes
|
||||
.height_to_difficultyepoch
|
||||
.mut_vec()
|
||||
.double_unwrap_cached_get(height),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_halvingepoch.compute(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_last_height.mut_vec(),
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
indexes
|
||||
.height_to_halvingepoch
|
||||
.mut_vec()
|
||||
.double_unwrap_cached_get(height),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
||||
self.indexes_to_difficulty.compute_rest(
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
Some(indexer.mut_vecs().height_to_difficulty.mut_vec()),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn as_any_vecs(&self) -> Vec<&dyn brk_vec::AnyStoredVec> {
|
||||
[
|
||||
self.indexes_to_difficulty.any_vecs(),
|
||||
self.indexes_to_difficultyepoch.any_vecs(),
|
||||
self.indexes_to_halvingepoch.any_vecs(),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ pub mod blocks;
|
||||
pub mod grouped;
|
||||
pub mod indexes;
|
||||
pub mod marketprice;
|
||||
pub mod mining;
|
||||
pub mod transactions;
|
||||
pub mod vec;
|
||||
|
||||
@@ -19,7 +20,8 @@ pub use vec::*;
|
||||
pub struct Vecs {
|
||||
pub blocks: blocks::Vecs,
|
||||
pub indexes: indexes::Vecs,
|
||||
pub transactions: transactions::Vecs,
|
||||
pub mining: mining::Vecs,
|
||||
// pub transactions: transactions::Vecs,
|
||||
pub marketprice: Option<marketprice::Vecs>,
|
||||
}
|
||||
|
||||
@@ -30,7 +32,8 @@ impl Vecs {
|
||||
Ok(Self {
|
||||
blocks: blocks::Vecs::forced_import(path, compressed)?,
|
||||
indexes: indexes::Vecs::forced_import(path, compressed)?,
|
||||
transactions: transactions::Vecs::forced_import(path, compressed, fetch)?,
|
||||
mining: mining::Vecs::forced_import(path, compressed)?,
|
||||
// transactions: transactions::Vecs::forced_import(path, compressed, fetch)?,
|
||||
marketprice: fetch.then(|| marketprice::Vecs::forced_import(path, compressed).unwrap()),
|
||||
})
|
||||
}
|
||||
@@ -47,6 +50,9 @@ impl Vecs {
|
||||
self.blocks
|
||||
.compute(indexer, &mut self.indexes, &starting_indexes, exit)?;
|
||||
|
||||
self.mining
|
||||
.compute(indexer, &mut self.indexes, &starting_indexes, exit)?;
|
||||
|
||||
if let Some(marketprice) = self.marketprice.as_mut() {
|
||||
marketprice.compute(
|
||||
indexer,
|
||||
@@ -57,13 +63,13 @@ impl Vecs {
|
||||
)?;
|
||||
}
|
||||
|
||||
self.transactions.compute(
|
||||
indexer,
|
||||
&mut self.indexes,
|
||||
&starting_indexes,
|
||||
&mut self.marketprice.as_mut(),
|
||||
exit,
|
||||
)?;
|
||||
// self.transactions.compute(
|
||||
// indexer,
|
||||
// &mut self.indexes,
|
||||
// &starting_indexes,
|
||||
// &mut self.marketprice.as_mut(),
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -72,7 +78,8 @@ impl Vecs {
|
||||
[
|
||||
self.indexes.as_any_vecs(),
|
||||
self.blocks.as_any_vecs(),
|
||||
self.transactions.as_any_vecs(),
|
||||
self.mining.as_any_vecs(),
|
||||
// self.transactions.as_any_vecs(),
|
||||
self.marketprice
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.as_any_vecs()),
|
||||
|
||||
@@ -25,11 +25,11 @@ pub struct Vecs {
|
||||
pub indexes_to_feerate: ComputedVecsFromTxindex<Feerate>,
|
||||
pub indexes_to_input_value: ComputedVecsFromTxindex<Sats>,
|
||||
pub indexes_to_output_value: ComputedVecsFromTxindex<Sats>,
|
||||
// pub txindex_to_is_v1: ComputedVec<Txindex, bool>,
|
||||
// pub txindex_to_is_v1: LazyVec<Txindex, bool>,
|
||||
pub indexes_to_tx_v1: ComputedVecsFromHeight<StoredU32>,
|
||||
// pub txindex_to_is_v2: ComputedVec<Txindex, bool>,
|
||||
// pub txindex_to_is_v2: LazyVec<Txindex, bool>,
|
||||
pub indexes_to_tx_v2: ComputedVecsFromHeight<StoredU32>,
|
||||
// pub txindex_to_is_v3: ComputedVec<Txindex, bool>,
|
||||
// pub txindex_to_is_v3: LazyVec<Txindex, bool>,
|
||||
pub indexes_to_tx_v3: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_tx_vsize: ComputedVecsFromTxindex<StoredUsize>,
|
||||
pub indexes_to_tx_weight: ComputedVecsFromTxindex<Weight>,
|
||||
|
||||
@@ -252,7 +252,7 @@ where
|
||||
first_indexes.iter_from(index, |(value, first_index, ..)| {
|
||||
let first_index = (first_index).to_usize()?;
|
||||
let last_index = (last_indexes.double_unwrap_cached_get(value)).to_usize()?;
|
||||
(first_index..last_index)
|
||||
(first_index..=last_index)
|
||||
.try_for_each(|index| self.forced_push_at(I::from(index), value, exit))
|
||||
})?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user