lazy: done

This commit is contained in:
nym21
2025-05-08 11:15:47 +02:00
parent 3f62da879c
commit 96eeacbe2b
14 changed files with 690 additions and 371 deletions

View File

@@ -83,6 +83,7 @@ where
})
}
#[allow(unused)]
pub fn compute_all<F>(
&mut self,
indexer: &Indexer,

View File

@@ -1,10 +1,11 @@
use std::path::Path;
use brk_core::{Bitcoin, Dollars, Sats, TxIndex};
use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, CollectableVec, Compressed, EagerVec, Result, StoredVec, Version,
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Compressed,
Computation, ComputedVecFrom3, LazyVecFrom1, StoredIndex, StoredVec, Version,
};
use crate::storage::{
@@ -17,44 +18,113 @@ use super::{ComputedVecsFromTxindex, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct ComputedValueVecsFromTxindex {
pub sats: ComputedVecsFromTxindex<Sats>,
pub bitcoin_txindex: LazyVecFrom1<TxIndex, Bitcoin, TxIndex, Sats>,
pub bitcoin: ComputedVecsFromTxindex<Bitcoin>,
#[allow(clippy::type_complexity)]
pub dollars_txindex: Option<
ComputedVecFrom3<
TxIndex,
Dollars,
TxIndex,
Bitcoin,
TxIndex,
Height,
Height,
Close<Dollars>,
>,
>,
pub dollars: Option<ComputedVecsFromTxindex<Dollars>>,
}
const VERSION: Version = Version::ONE;
impl ComputedValueVecsFromTxindex {
#[allow(clippy::too_many_arguments)]
pub fn forced_import(
path: &Path,
name: &str,
compute_source: bool,
indexes: &indexes::Vecs,
source: Option<BoxedAnyIterableVec<TxIndex, Sats>>,
version: Version,
computation: Computation,
compressed: Compressed,
marketprices: Option<&marketprice::Vecs>,
options: StorableVecGeneatorOptions,
compute_dollars: bool,
) -> color_eyre::Result<Self> {
let compute_source = source.is_none();
let compute_dollars = marketprices.is_some();
let sats = ComputedVecsFromTxindex::forced_import(
path,
name,
compute_source,
VERSION + version,
compressed,
options,
)?;
let bitcoin_txindex = LazyVecFrom1::init(
"txindex_to_{name}_in_btc",
VERSION + version,
source.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
|txindex: TxIndex, iter| {
iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| {
let sats = value.into_inner();
Bitcoin::from(sats)
})
},
);
let bitcoin = ComputedVecsFromTxindex::forced_import(
path,
&format!("{name}_in_btc"),
false,
VERSION + version,
compressed,
options,
)?;
let dollars_txindex = marketprices.map(|marketprices| {
ComputedVecFrom3::forced_import_or_init_from_3(
computation,
path,
"txindex_to_{name}_in_usd",
VERSION + version,
compressed,
bitcoin_txindex.boxed_clone(),
indexes.txindex_to_height.boxed_clone(),
marketprices.chainindexes_to_close.height.boxed_clone(),
|txindex: TxIndex,
txindex_to_btc_iter,
txindex_to_height_iter,
height_to_close_iter| {
let txindex = txindex.unwrap_to_usize();
txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| {
let btc = value.into_inner();
txindex_to_height_iter
.next_at(txindex)
.and_then(|(_, value)| {
let height = value.into_inner();
height_to_close_iter
.next_at(height.unwrap_to_usize())
.map(|(_, close)| *close.into_inner() * btc)
})
})
},
)
.unwrap()
});
Ok(Self {
sats: ComputedVecsFromTxindex::forced_import(
path,
name,
compute_source,
VERSION + version,
compressed,
options,
)?,
bitcoin: ComputedVecsFromTxindex::forced_import(
path,
&format!("{name}_in_btc"),
true,
VERSION + version,
compressed,
options,
)?,
sats,
bitcoin_txindex,
bitcoin,
dollars_txindex,
dollars: compute_dollars.then(|| {
ComputedVecsFromTxindex::forced_import(
path,
&format!("{name}_in_usd"),
true,
false,
VERSION + version,
compressed,
options,
@@ -64,50 +134,49 @@ impl ComputedValueVecsFromTxindex {
})
}
pub fn compute_all<F>(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
marketprices: Option<&marketprice::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
mut compute: F,
) -> color_eyre::Result<()>
where
F: FnMut(
&mut EagerVec<TxIndex, Sats>,
&Indexer,
&indexes::Vecs,
&Indexes,
&Exit,
) -> Result<()>,
{
compute(
self.sats.txindex.as_mut().unwrap(),
indexer,
indexes,
starting_indexes,
exit,
)?;
// pub fn compute_all<F>(
// &mut self,
// indexer: &Indexer,
// indexes: &indexes::Vecs,
// marketprices: Option<&marketprice::Vecs>,
// starting_indexes: &Indexes,
// exit: &Exit,
// mut compute: F,
// ) -> color_eyre::Result<()>
// where
// F: FnMut(
// &mut EagerVec<TxIndex, Sats>,
// &Indexer,
// &indexes::Vecs,
// &Indexes,
// &Exit,
// ) -> Result<()>,
// {
// compute(
// self.sats.txindex.as_mut().unwrap(),
// indexer,
// indexes,
// starting_indexes,
// exit,
// )?;
let txindex: Option<&StoredVec<TxIndex, Sats>> = None;
self.compute_rest(
indexer,
indexes,
marketprices,
starting_indexes,
exit,
txindex,
)?;
// let txindex: Option<&StoredVec<TxIndex, Sats>> = None;
// self.compute_rest(
// indexer,
// indexes,
// marketprices,
// starting_indexes,
// exit,
// txindex,
// )?;
Ok(())
}
// Ok(())
// }
pub fn compute_rest(
&mut self,
indexer: &Indexer,
indexes: &indexes::Vecs,
marketprices: Option<&marketprice::Vecs>,
starting_indexes: &Indexes,
exit: &Exit,
txindex: Option<&impl CollectableVec<TxIndex, Sats>>,
@@ -115,55 +184,31 @@ impl ComputedValueVecsFromTxindex {
if let Some(txindex) = txindex {
self.sats
.compute_rest(indexer, indexes, starting_indexes, exit, Some(txindex))?;
self.bitcoin.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_from_sats(starting_indexes.txindex, txindex, exit)
},
)?;
} else {
let txindex: Option<&StoredVec<TxIndex, Sats>> = None;
self.sats
.compute_rest(indexer, indexes, starting_indexes, exit, txindex)?;
self.bitcoin.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|v, _, _, starting_indexes, exit| {
v.compute_from_sats(
starting_indexes.txindex,
self.sats.txindex.as_ref().unwrap(),
exit,
)
},
)?;
}
let txindex = self.bitcoin.txindex.as_mut().unwrap();
self.bitcoin.compute_rest(
indexer,
indexes,
starting_indexes,
exit,
Some(&self.bitcoin_txindex),
)?;
if let Some(dollars) = self.dollars.as_mut() {
let price = &marketprices.unwrap().chainindexes_to_close.height;
let dollars_txindex = self.dollars_txindex.as_mut().unwrap();
dollars.compute_all(
dollars_txindex.compute_if_necessary(starting_indexes.txindex, exit)?;
dollars.compute_rest(
indexer,
indexes,
starting_indexes,
exit,
|v, _, indexes, starting_indexes, exit| {
v.compute_from_bitcoin(
starting_indexes.txindex,
txindex,
&indexes.txindex_to_height,
price,
exit,
)
},
Some(dollars_txindex),
)?;
}

View File

@@ -33,19 +33,24 @@ impl Vecs {
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
let indexes = indexes::Vecs::forced_import(path, indexer, computation, compressed)?;
let marketprice =
fetch.then(|| marketprice::Vecs::forced_import(path, computation, compressed).unwrap());
Ok(Self {
blocks: blocks::Vecs::forced_import(path, computation, compressed)?,
indexes: indexes::Vecs::forced_import(path, indexer, computation, compressed)?,
mining: mining::Vecs::forced_import(path, computation, compressed)?,
transactions: transactions::Vecs::forced_import(
path,
indexer,
&indexes,
computation,
compressed,
fetch,
marketprice.as_ref(),
)?,
marketprice: fetch
.then(|| marketprice::Vecs::forced_import(path, computation, compressed).unwrap()),
indexes,
marketprice,
})
}

View File

@@ -1,14 +1,15 @@
use std::{fs, path::Path};
use brk_core::{
CheckedSub, Feerate, InputIndex, OutputIndex, Sats, StoredUsize, TxIndex, TxVersion, Weight,
CheckedSub, Feerate, Height, InputIndex, OutputIndex, Sats, StoredU32, StoredUsize, TxIndex,
TxVersion, Weight,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::bitcoin;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Compressed, Computation,
ComputedVec, ComputedVecFrom2, EagerVec, StoredIndex, Version,
ComputedVec, ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, StoredIndex, Version,
};
use super::{
@@ -30,9 +31,29 @@ pub struct Vecs {
pub indexes_to_fee: ComputedValueVecsFromTxindex,
pub indexes_to_feerate: ComputedVecsFromTxindex<Feerate>,
/// Value == 0 when Coinbase
pub indexes_to_input_value: ComputedVecsFromTxindex<Sats>,
pub txindex_to_input_value: ComputedVecFrom3<
TxIndex,
Sats,
TxIndex,
InputIndex,
TxIndex,
StoredUsize,
InputIndex,
Sats,
>,
// pub indexes_to_input_value: ComputedVecsFromTxindex<Sats>,
pub indexes_to_opreturn_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_output_value: ComputedVecsFromTxindex<Sats>,
pub txindex_to_output_value: ComputedVecFrom3<
TxIndex,
Sats,
TxIndex,
OutputIndex,
TxIndex,
StoredUsize,
OutputIndex,
Sats,
>,
// pub indexes_to_output_value: ComputedVecsFromTxindex<Sats>,
pub indexes_to_p2a_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_p2ms_count: ComputedVecsFromHeight<StoredUsize>,
pub indexes_to_p2pk33_count: ComputedVecsFromHeight<StoredUsize>,
@@ -51,25 +72,317 @@ pub struct Vecs {
pub indexes_to_tx_weight: ComputedVecsFromTxindex<Weight>,
pub indexes_to_unknownoutput_count: ComputedVecsFromHeight<StoredUsize>,
pub inputindex_to_value:
ComputedVecFrom2<InputIndex, Sats, OutputIndex, Sats, InputIndex, OutputIndex>,
// Bitcoin and dollar version too
ComputedVecFrom2<InputIndex, Sats, InputIndex, OutputIndex, OutputIndex, Sats>,
pub txindex_to_input_count:
ComputedVecFrom2<TxIndex, StoredUsize, TxIndex, InputIndex, InputIndex, OutputIndex>,
pub indexes_to_input_count: ComputedVecsFromTxindex<StoredUsize>,
pub txindex_to_is_coinbase: EagerVec<TxIndex, bool>,
pub txindex_to_is_coinbase: ComputedVecFrom2<TxIndex, bool, TxIndex, Height, Height, TxIndex>,
pub txindex_to_output_count:
ComputedVecFrom2<TxIndex, StoredUsize, TxIndex, OutputIndex, OutputIndex, Sats>,
pub indexes_to_output_count: ComputedVecsFromTxindex<StoredUsize>,
pub txindex_to_vsize: EagerVec<TxIndex, StoredUsize>,
pub txindex_to_weight: EagerVec<TxIndex, Weight>,
pub txindex_to_vsize: ComputedVecFrom1<TxIndex, StoredUsize, TxIndex, Weight>,
pub txindex_to_weight:
ComputedVecFrom2<TxIndex, Weight, TxIndex, StoredU32, TxIndex, StoredU32>,
pub txindex_to_fee: ComputedVecFrom2<TxIndex, Sats, TxIndex, Sats, TxIndex, Sats>,
pub txindex_to_feerate: ComputedVecFrom2<TxIndex, Feerate, TxIndex, Sats, TxIndex, StoredUsize>,
}
impl Vecs {
pub fn forced_import(
path: &Path,
indexer: &Indexer,
indexes: &indexes::Vecs,
computation: Computation,
compressed: Compressed,
compute_dollars: bool,
marketprices: Option<&marketprice::Vecs>,
) -> color_eyre::Result<Self> {
let compute_dollars = marketprices.is_some();
fs::create_dir_all(path)?;
let inputindex_to_value = ComputedVec::forced_import_or_init_from_2(
computation,
path,
"inputindex_to_value",
Version::ZERO,
compressed,
indexer.vecs().inputindex_to_outputindex.boxed_clone(),
indexer.vecs().outputindex_to_value.boxed_clone(),
|index: InputIndex, inputindex_to_outputindex_iter, outputindex_to_value_iter| {
inputindex_to_outputindex_iter
.next_at(index.unwrap_to_usize())
.map(|(inputindex, outputindex)| {
let outputindex = outputindex.into_inner();
if outputindex == OutputIndex::COINBASE {
Sats::ZERO
} else if let Some((_, value)) =
outputindex_to_value_iter.next_at(outputindex.unwrap_to_usize())
{
value.into_inner()
} else {
dbg!(inputindex, outputindex);
panic!()
}
})
},
)?;
let txindex_to_weight = ComputedVec::forced_import_or_init_from_2(
computation,
path,
"txindex_to_weight",
Version::ZERO,
compressed,
indexer.vecs().txindex_to_base_size.boxed_clone(),
indexer.vecs().txindex_to_total_size.boxed_clone(),
|index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| {
let index = index.unwrap_to_usize();
txindex_to_base_size_iter
.next_at(index)
.map(|(_, base_size)| {
let base_size = base_size.into_inner();
let total_size = txindex_to_total_size_iter
.next_at(index)
.unwrap()
.1
.into_inner();
// This is the exact definition of a weight unit, as defined by BIP-141 (quote above).
let wu = usize::from(base_size) * 3 + usize::from(total_size);
Weight::from(bitcoin::Weight::from_wu_usize(wu))
})
},
)?;
let txindex_to_vsize = ComputedVec::forced_import_or_init_from_1(
computation,
path,
"txindex_to_vsize",
Version::ZERO,
compressed,
txindex_to_weight.boxed_clone(),
|index: TxIndex, iter| {
let index = index.unwrap_to_usize();
iter.next_at(index).map(|(_, weight)| {
StoredUsize::from(
bitcoin::Weight::from(weight.into_inner()).to_vbytes_ceil() as usize
)
})
},
)?;
let txindex_to_is_coinbase = ComputedVec::forced_import_or_init_from_2(
computation,
path,
"txindex_to_is_coinbase",
Version::ZERO,
compressed,
indexes.txindex_to_height.boxed_clone(),
indexer.vecs().height_to_first_txindex.boxed_clone(),
|index: TxIndex, txindex_to_height_iter, height_to_first_txindex_iter| {
txindex_to_height_iter
.next_at(index.unwrap_to_usize())
.map(|(_, height)| {
let height = height.into_inner();
let txindex = height_to_first_txindex_iter
.next_at(height.unwrap_to_usize())
.unwrap()
.1
.into_inner();
index == txindex
})
},
)?;
let txindex_to_input_count = ComputedVec::forced_import_or_init_from_2(
computation,
path,
"txindex_to_input_count",
Version::ZERO,
compressed,
indexer.vecs().txindex_to_first_inputindex.boxed_clone(),
indexer.vecs().inputindex_to_outputindex.boxed_clone(),
|index: TxIndex, txindex_to_first_inputindex_iter, inputindex_to_outputindex_iter| {
let txindex = index.unwrap_to_usize();
txindex_to_first_inputindex_iter
.next_at(txindex)
.map(|(_, start)| {
let start = usize::from(start.into_inner());
let end = txindex_to_first_inputindex_iter
.next_at(txindex + 1)
.map(|(_, v)| usize::from(v.into_inner()))
.unwrap_or_else(|| inputindex_to_outputindex_iter.len());
StoredUsize::from((start..end).count())
})
},
)?;
let txindex_to_input_value = ComputedVec::forced_import_or_init_from_3(
computation,
path,
"txindex_to_input_value",
Version::ZERO,
compressed,
indexer.vecs().txindex_to_first_inputindex.boxed_clone(),
txindex_to_input_count.boxed_clone(),
inputindex_to_value.boxed_clone(),
|index: TxIndex,
txindex_to_first_inputindex_iter,
txindex_to_input_count_iter,
inputindex_to_value_iter| {
let txindex = index.unwrap_to_usize();
txindex_to_first_inputindex_iter
.next_at(txindex)
.map(|(_, first_index)| {
let first_index = usize::from(first_index.into_inner());
let count = *txindex_to_input_count_iter
.next_at(txindex)
.unwrap()
.1
.into_inner();
let range = first_index..first_index + count;
range.into_iter().fold(Sats::ZERO, |total, inputindex| {
total
+ inputindex_to_value_iter
.next_at(inputindex)
.unwrap()
.1
.into_inner()
})
})
},
)?;
// let indexes_to_input_value: ComputedVecsFromTxindex<Sats> =
// ComputedVecsFromTxindex::forced_import(
// path,
// "input_value",
// true,
// Version::ZERO,
// compressed,
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
// .add_total(),
// )?;
let txindex_to_output_count = ComputedVec::forced_import_or_init_from_2(
computation,
path,
"txindex_to_output_count",
Version::ZERO,
compressed,
indexer.vecs().txindex_to_first_outputindex.boxed_clone(),
indexer.vecs().outputindex_to_value.boxed_clone(),
|index: TxIndex, txindex_to_first_outputindex_iter, outputindex_to_value_iter| {
let txindex = index.unwrap_to_usize();
txindex_to_first_outputindex_iter
.next_at(txindex)
.map(|(_, start)| {
let start = usize::from(start.into_inner());
let end = txindex_to_first_outputindex_iter
.next_at(txindex + 1)
.map(|(_, v)| usize::from(v.into_inner()))
.unwrap_or_else(|| outputindex_to_value_iter.len());
StoredUsize::from((start..end).count())
})
},
)?;
let txindex_to_output_value = ComputedVec::forced_import_or_init_from_3(
computation,
path,
"txindex_to_output_value",
Version::ZERO,
compressed,
indexer.vecs().txindex_to_first_outputindex.boxed_clone(),
txindex_to_output_count.boxed_clone(),
indexer.vecs().outputindex_to_value.boxed_clone(),
|index: TxIndex,
txindex_to_first_outputindex_iter,
txindex_to_output_count_iter,
outputindex_to_value_iter| {
let txindex = index.unwrap_to_usize();
txindex_to_first_outputindex_iter
.next_at(txindex)
.map(|(_, first_index)| {
let first_index = usize::from(first_index.into_inner());
let count = *txindex_to_output_count_iter
.next_at(txindex)
.unwrap()
.1
.into_inner();
let range = first_index..first_index + count;
range.into_iter().fold(Sats::ZERO, |total, outputindex| {
total
+ outputindex_to_value_iter
.next_at(outputindex)
.unwrap()
.1
.into_inner()
})
})
},
)?;
// let indexes_to_output_value: ComputedVecsFromTxindex<Sats> =
// ComputedVecsFromTxindex::forced_import(
// path,
// "output_value",
// true,
// Version::ZERO,
// compressed,
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
// .add_total(),
// )?;
let txindex_to_fee = ComputedVecFrom2::forced_import_or_init_from_2(
computation,
path,
"txindex_to_fee",
Version::ZERO,
compressed,
txindex_to_input_value.boxed_clone(),
txindex_to_output_value.boxed_clone(),
|txindex: TxIndex, input_iter, output_iter| {
let txindex = txindex.unwrap_to_usize();
input_iter.next_at(txindex).and_then(|(_, value)| {
let input = value.into_inner();
if input.is_zero() {
return Some(Sats::ZERO);
}
output_iter.next_at(txindex).map(|(_, value)| {
let output = value.into_inner();
input.checked_sub(output).unwrap()
})
})
},
)?;
let txindex_to_feerate = ComputedVecFrom2::forced_import_or_init_from_2(
computation,
path,
"txindex_to_feerate",
Version::ZERO,
compressed,
txindex_to_fee.boxed_clone(),
txindex_to_vsize.boxed_clone(),
|txindex: TxIndex, fee_iter, vsize_iter| {
let txindex = txindex.unwrap_to_usize();
fee_iter.next_at(txindex).and_then(|(_, value)| {
let fee = value.into_inner();
vsize_iter.next_at(txindex).map(|(_, value)| {
let vsize = value.into_inner();
Feerate::from((fee, vsize))
})
})
},
)?;
Ok(Self {
indexes_to_tx_count: ComputedVecsFromHeight::forced_import(
path,
@@ -84,15 +397,10 @@ impl Vecs {
.add_sum()
.add_total(),
)?,
txindex_to_is_coinbase: EagerVec::forced_import(
&path.join("txindex_to_is_coinbase"),
Version::ZERO,
compressed,
)?,
indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
path,
"input_count",
true,
false,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
@@ -105,7 +413,7 @@ impl Vecs {
indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
path,
"output_count",
true,
false,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
@@ -115,32 +423,6 @@ impl Vecs {
.add_sum()
.add_total(),
)?,
inputindex_to_value: ComputedVec::forced_import_or_init_from_2(
computation,
path,
"inputindex_to_value",
Version::ZERO,
compressed,
indexer.vecs().outputindex_to_value.boxed_clone(),
indexer.vecs().inputindex_to_outputindex.boxed_clone(),
|index: InputIndex, outputindex_to_value_iter, inputindex_to_outputindex_iter| {
inputindex_to_outputindex_iter
.next_at(index.unwrap_to_usize())
.map(|(inputindex, outputindex)| {
let outputindex = outputindex.into_inner();
if outputindex == OutputIndex::COINBASE {
Sats::ZERO
} else if let Some((_, value)) =
outputindex_to_value_iter.next_at(outputindex.unwrap_to_usize())
{
value.into_inner()
} else {
dbg!(inputindex, outputindex);
panic!()
}
})
},
)?,
indexes_to_tx_v1: ComputedVecsFromHeight::forced_import(
path,
"tx_v1",
@@ -165,46 +447,26 @@ impl Vecs {
compressed,
StorableVecGeneatorOptions::default().add_sum().add_total(),
)?,
indexes_to_input_value: ComputedVecsFromTxindex::forced_import(
path,
"input_value",
true,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
.add_average()
.add_sum()
.add_total(),
)?,
indexes_to_output_value: ComputedVecsFromTxindex::forced_import(
path,
"output_value",
true,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
.add_average()
.add_sum()
.add_total(),
)?,
indexes_to_fee: ComputedValueVecsFromTxindex::forced_import(
path,
"fee",
true,
indexes,
Some(txindex_to_fee.boxed_clone()),
Version::ZERO,
computation,
compressed,
marketprices,
StorableVecGeneatorOptions::default()
.add_sum()
.add_total()
.add_percentiles()
.add_minmax()
.add_average(),
compute_dollars,
)?,
indexes_to_feerate: ComputedVecsFromTxindex::forced_import(
path,
"feerate",
true,
false,
Version::ZERO,
compressed,
StorableVecGeneatorOptions::default()
@@ -212,16 +474,6 @@ impl Vecs {
.add_minmax()
.add_average(),
)?,
txindex_to_weight: EagerVec::forced_import(
&path.join("txindex_to_weight"),
Version::ZERO,
compressed,
)?,
txindex_to_vsize: EagerVec::forced_import(
&path.join("txindex_to_vsize"),
Version::ZERO,
compressed,
)?,
indexes_to_tx_vsize: ComputedVecsFromTxindex::forced_import(
path,
"tx_vsize",
@@ -428,6 +680,18 @@ impl Vecs {
.add_sum()
.add_total(),
)?,
txindex_to_is_coinbase,
inputindex_to_value,
// indexes_to_input_value,
// indexes_to_output_value,
txindex_to_input_value,
txindex_to_output_value,
txindex_to_fee,
txindex_to_feerate,
txindex_to_vsize,
txindex_to_weight,
txindex_to_input_count,
txindex_to_output_count,
})
}
@@ -454,34 +718,20 @@ impl Vecs {
},
)?;
self.indexes_to_input_count.compute_all(
self.indexes_to_input_count.compute_rest(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
&indexer.vecs().txindex_to_first_inputindex,
&indexer.vecs().inputindex_to_outputindex,
exit,
)
},
Some(&self.txindex_to_input_count),
)?;
self.indexes_to_output_count.compute_all(
self.indexes_to_output_count.compute_rest(
indexer,
indexes,
starting_indexes,
exit,
|v, indexer, _, starting_indexes, exit| {
v.compute_count_from_indexes(
starting_indexes.txindex,
&indexer.vecs().txindex_to_first_outputindex,
&indexer.vecs().outputindex_to_value,
exit,
)
},
Some(&self.txindex_to_output_count),
)?;
let compute_indexes_to_tx_vany =
@@ -510,122 +760,70 @@ impl Vecs {
compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v2, TxVersion::TWO)?;
compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v3, TxVersion::THREE)?;
self.txindex_to_is_coinbase.compute_is_first_ordered(
starting_indexes.txindex,
&indexes.txindex_to_height,
&indexer.vecs().height_to_first_txindex,
exit,
)?;
self.txindex_to_is_coinbase
.compute_if_necessary(starting_indexes.txindex, exit)?;
let mut txindex_to_total_size_iter = indexer.vecs().txindex_to_total_size.iter();
self.txindex_to_weight.compute_transform(
starting_indexes.txindex,
&indexer.vecs().txindex_to_base_size,
|(txindex, base_size, ..)| {
let total_size = txindex_to_total_size_iter.unwrap_get_inner(txindex);
self.txindex_to_weight
.compute_if_necessary(starting_indexes.txindex, exit)?;
// This is the exact definition of a weight unit, as defined by BIP-141 (quote above).
let wu = usize::from(base_size) * 3 + usize::from(total_size);
let weight = Weight::from(bitcoin::Weight::from_wu_usize(wu));
(txindex, weight)
},
exit,
)?;
self.txindex_to_vsize.compute_transform(
starting_indexes.txindex,
&self.txindex_to_weight,
|(txindex, weight, ..)| {
let vbytes =
StoredUsize::from(bitcoin::Weight::from(weight).to_vbytes_ceil() as usize);
(txindex, vbytes)
},
exit,
)?;
self.txindex_to_vsize
.compute_if_necessary(starting_indexes.txindex, exit)?;
self.inputindex_to_value
.compute_if_necessary(starting_indexes.inputindex, exit)?;
self.indexes_to_output_value.compute_all(
self.txindex_to_output_value
.compute_if_necessary(starting_indexes.txindex, exit)?;
// self.indexes_to_output_value.compute_all(
// indexer,
// indexes,
// starting_indexes,
// exit,
// |vec, indexer, _, starting_indexes, exit| {
// vec.compute_sum_from_indexes(
// starting_indexes.txindex,
// &indexer.vecs().txindex_to_first_outputindex,
// self.indexes_to_output_count.txindex.as_ref().unwrap(),
// &indexer.vecs().outputindex_to_value,
// exit,
// )
// },
// )?;
self.txindex_to_input_value
.compute_if_necessary(starting_indexes.txindex, exit)?;
// self.indexes_to_input_value.compute_all(
// indexer,
// indexes,
// starting_indexes,
// exit,
// |vec, indexer, _, starting_indexes, exit| {
// vec.compute_sum_from_indexes(
// starting_indexes.txindex,
// &indexer.vecs().txindex_to_first_inputindex,
// self.indexes_to_input_count.txindex.as_ref().unwrap(),
// &self.inputindex_to_value,
// exit,
// )
// },
// )?;
self.indexes_to_fee.compute_rest(
indexer,
indexes,
starting_indexes,
exit,
|vec, indexer, _, starting_indexes, exit| {
vec.compute_sum_from_indexes(
starting_indexes.txindex,
&indexer.vecs().txindex_to_first_outputindex,
self.indexes_to_output_count.txindex.as_ref().unwrap(),
&indexer.vecs().outputindex_to_value,
exit,
)
},
Some(&self.txindex_to_fee),
)?;
self.indexes_to_input_value.compute_all(
self.indexes_to_feerate.compute_rest(
indexer,
indexes,
starting_indexes,
exit,
|vec, indexer, _, starting_indexes, exit| {
vec.compute_sum_from_indexes(
starting_indexes.txindex,
&indexer.vecs().txindex_to_first_inputindex,
self.indexes_to_input_count.txindex.as_ref().unwrap(),
&self.inputindex_to_value,
exit,
)
},
)?;
self.indexes_to_fee.compute_all(
indexer,
indexes,
marketprices,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
let mut txindex_to_output_value_iter = self
.indexes_to_output_value
.txindex
.as_ref()
.unwrap()
.iter();
vec.compute_transform(
starting_indexes.txindex,
self.indexes_to_input_value.txindex.as_ref().unwrap(),
|(txindex, input_value, ..)| {
if input_value.is_zero() {
(txindex, input_value)
} else {
let output_value =
txindex_to_output_value_iter.unwrap_get_inner(txindex);
(txindex, input_value.checked_sub(output_value).unwrap())
}
},
exit,
)
},
)?;
self.indexes_to_feerate.compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
let mut txindex_to_vsize_iter = self.txindex_to_vsize.iter();
vec.compute_transform(
starting_indexes.txindex,
self.indexes_to_fee.sats.txindex.as_ref().unwrap(),
|(txindex, fee, ..)| {
let vsize = txindex_to_vsize_iter.unwrap_get_inner(txindex);
(txindex, Feerate::from((fee, vsize)))
},
exit,
)
},
Some(&self.txindex_to_feerate),
)?;
self.indexes_to_tx_weight.compute_rest(
@@ -653,12 +851,7 @@ impl Vecs {
|vec, indexer, _, starting_indexes, exit| {
let mut txindex_to_first_outputindex_iter =
indexer.vecs().txindex_to_first_outputindex.iter();
let mut txindex_to_output_count_iter = self
.indexes_to_output_count
.txindex
.as_ref()
.unwrap()
.iter();
let mut txindex_to_output_count_iter = self.txindex_to_output_count.iter();
let mut outputindex_to_value_iter = indexer.vecs().outputindex_to_value.iter();
vec.compute_transform(
starting_indexes.height,
@@ -890,23 +1083,22 @@ impl Vecs {
[
vec![
&self.inputindex_to_value as &dyn AnyCollectableVec,
&self.txindex_to_fee,
&self.txindex_to_feerate,
&self.txindex_to_input_count,
&self.txindex_to_input_value,
&self.txindex_to_is_coinbase,
&self.txindex_to_output_count,
&self.txindex_to_output_value,
&self.txindex_to_vsize,
&self.txindex_to_weight,
],
self.indexes_to_tx_count.vecs(),
self.indexes_to_coinbase.vecs(),
self.indexes_to_emptyoutput_count.vecs(),
self.indexes_to_fee.vecs(),
self.indexes_to_feerate.vecs(),
self.indexes_to_input_value.vecs(),
self.indexes_to_output_value.vecs(),
self.indexes_to_subsidy.vecs(),
self.indexes_to_tx_v1.vecs(),
self.indexes_to_tx_v2.vecs(),
self.indexes_to_tx_v3.vecs(),
self.indexes_to_tx_vsize.vecs(),
self.indexes_to_tx_weight.vecs(),
self.indexes_to_input_count.vecs(),
self.indexes_to_opreturn_count.vecs(),
self.indexes_to_output_count.vecs(),
self.indexes_to_p2a_count.vecs(),
self.indexes_to_p2ms_count.vecs(),
@@ -917,9 +1109,14 @@ impl Vecs {
self.indexes_to_p2tr_count.vecs(),
self.indexes_to_p2wpkh_count.vecs(),
self.indexes_to_p2wsh_count.vecs(),
self.indexes_to_opreturn_count.vecs(),
self.indexes_to_subsidy.vecs(),
self.indexes_to_tx_count.vecs(),
self.indexes_to_tx_v1.vecs(),
self.indexes_to_tx_v2.vecs(),
self.indexes_to_tx_v3.vecs(),
self.indexes_to_tx_vsize.vecs(),
self.indexes_to_tx_weight.vecs(),
self.indexes_to_unknownoutput_count.vecs(),
self.indexes_to_emptyoutput_count.vecs(),
]
.concat()
}