mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-31 12:43:06 -07:00
global: fixes
This commit is contained in:
@@ -152,7 +152,7 @@ impl Vecs {
|
||||
self.height_to_interval.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.vec(),
|
||||
|(height, timestamp)| {
|
||||
|(height, timestamp, ..)| {
|
||||
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
|
||||
let prev_timestamp = height_to_timestamp_iter.unwrap_get_inner(prev_h);
|
||||
timestamp
|
||||
|
||||
@@ -196,8 +196,20 @@ where
|
||||
}
|
||||
|
||||
if let Some(last) = self.last.as_mut() {
|
||||
let last_index = first_index + *count_index;
|
||||
let v = source_iter.get(last_index).unwrap().1.into_inner();
|
||||
let count_index = *count_index;
|
||||
if count_index == 0 {
|
||||
panic!("should compute last if count can be 0")
|
||||
}
|
||||
let last_index = first_index + (count_index - 1);
|
||||
let v = source_iter
|
||||
.get(last_index)
|
||||
.context("to work")
|
||||
.inspect_err(|_| {
|
||||
dbg!(first_index, count_index, last_index);
|
||||
})
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner();
|
||||
last.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
|
||||
@@ -356,7 +368,11 @@ where
|
||||
}
|
||||
|
||||
if let Some(last) = self.last.as_mut() {
|
||||
let last_index = first_index + *count_index;
|
||||
let count_index = *count_index;
|
||||
if count_index == 0 {
|
||||
panic!("should compute last if count can be 0")
|
||||
}
|
||||
let last_index = first_index + (count_index - 1);
|
||||
let v = source_last_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
|
||||
@@ -500,16 +500,24 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut height_to_timestamp_iter = indexer_vecs.height_to_timestamp.iter();
|
||||
let mut prev_timestamp_fixed = None;
|
||||
self.height_to_timestamp_fixed.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.vec(),
|
||||
|(h, timestamp, ..)| {
|
||||
let timestamp = h
|
||||
.decremented()
|
||||
.map(|h| height_to_timestamp_iter.unwrap_get_inner(h))
|
||||
.map_or(timestamp, |prev_d| prev_d.max(timestamp));
|
||||
(h, timestamp)
|
||||
|(h, timestamp, height_to_timestamp_fixed_iter)| {
|
||||
if prev_timestamp_fixed.is_none() {
|
||||
if let Some(prev_h) = h.decremented() {
|
||||
prev_timestamp_fixed.replace(
|
||||
height_to_timestamp_fixed_iter
|
||||
.iter()
|
||||
.unwrap_get_inner(prev_h),
|
||||
);
|
||||
}
|
||||
}
|
||||
let timestamp_fixed =
|
||||
prev_timestamp_fixed.map_or(timestamp, |prev_d| prev_d.max(timestamp));
|
||||
prev_timestamp_fixed.replace(timestamp_fixed);
|
||||
(h, timestamp_fixed)
|
||||
},
|
||||
exit,
|
||||
)?;
|
||||
@@ -862,32 +870,36 @@ impl Vecs {
|
||||
self.dateindex_to_date.any_vec(),
|
||||
self.dateindex_to_dateindex.any_vec(),
|
||||
self.dateindex_to_first_height.any_vec(),
|
||||
self.height_to_dateindex.any_vec(),
|
||||
self.height_to_date_fixed.any_vec(),
|
||||
self.height_to_height.any_vec(),
|
||||
self.height_to_date.any_vec(),
|
||||
self.difficultyepoch_to_first_height.any_vec(),
|
||||
self.halvingepoch_to_first_height.any_vec(),
|
||||
self.weekindex_to_first_dateindex.any_vec(),
|
||||
self.monthindex_to_first_dateindex.any_vec(),
|
||||
self.yearindex_to_first_monthindex.any_vec(),
|
||||
self.decadeindex_to_first_yearindex.any_vec(),
|
||||
self.dateindex_to_weekindex.any_vec(),
|
||||
self.dateindex_to_height_count.any_vec(),
|
||||
self.dateindex_to_monthindex.any_vec(),
|
||||
self.monthindex_to_yearindex.any_vec(),
|
||||
self.yearindex_to_decadeindex.any_vec(),
|
||||
self.dateindex_to_weekindex.any_vec(),
|
||||
self.decadeindex_to_decadeindex.any_vec(),
|
||||
self.decadeindex_to_first_yearindex.any_vec(),
|
||||
self.decadeindex_to_yearindex_count.any_vec(),
|
||||
self.difficultyepoch_to_difficultyepoch.any_vec(),
|
||||
self.difficultyepoch_to_first_height.any_vec(),
|
||||
self.difficultyepoch_to_height_count.any_vec(),
|
||||
self.emptyoutputindex_to_emptyoutputindex.any_vec(),
|
||||
self.halvingepoch_to_first_height.any_vec(),
|
||||
self.halvingepoch_to_halvingepoch.any_vec(),
|
||||
self.height_to_date.any_vec(),
|
||||
self.height_to_date_fixed.any_vec(),
|
||||
self.height_to_dateindex.any_vec(),
|
||||
self.height_to_difficultyepoch.any_vec(),
|
||||
self.height_to_halvingepoch.any_vec(),
|
||||
self.weekindex_to_weekindex.any_vec(),
|
||||
self.monthindex_to_monthindex.any_vec(),
|
||||
self.yearindex_to_yearindex.any_vec(),
|
||||
self.decadeindex_to_decadeindex.any_vec(),
|
||||
self.difficultyepoch_to_difficultyepoch.any_vec(),
|
||||
self.halvingepoch_to_halvingepoch.any_vec(),
|
||||
self.height_to_height.any_vec(),
|
||||
self.height_to_timestamp_fixed.any_vec(),
|
||||
self.height_to_txindex_count.any_vec(),
|
||||
self.inputindex_to_inputindex.any_vec(),
|
||||
self.monthindex_to_dateindex_count.any_vec(),
|
||||
self.monthindex_to_first_dateindex.any_vec(),
|
||||
self.monthindex_to_monthindex.any_vec(),
|
||||
self.monthindex_to_quarterindex.any_vec(),
|
||||
self.quarterindex_to_first_monthindex.any_vec(),
|
||||
self.quarterindex_to_quarterindex.any_vec(),
|
||||
self.monthindex_to_yearindex.any_vec(),
|
||||
self.opreturnindex_to_opreturnindex.any_vec(),
|
||||
self.outputindex_to_outputindex.any_vec(),
|
||||
self.p2aindex_to_p2aindex.any_vec(),
|
||||
self.p2msindex_to_p2msindex.any_vec(),
|
||||
self.p2pk33index_to_p2pk33index.any_vec(),
|
||||
self.p2pk65index_to_p2pk65index.any_vec(),
|
||||
self.p2pkhindex_to_p2pkhindex.any_vec(),
|
||||
@@ -895,22 +907,19 @@ impl Vecs {
|
||||
self.p2trindex_to_p2trindex.any_vec(),
|
||||
self.p2wpkhindex_to_p2wpkhindex.any_vec(),
|
||||
self.p2wshindex_to_p2wshindex.any_vec(),
|
||||
self.txindex_to_txindex.any_vec(),
|
||||
self.inputindex_to_inputindex.any_vec(),
|
||||
self.emptyoutputindex_to_emptyoutputindex.any_vec(),
|
||||
self.p2msindex_to_p2msindex.any_vec(),
|
||||
self.opreturnindex_to_opreturnindex.any_vec(),
|
||||
self.p2aindex_to_p2aindex.any_vec(),
|
||||
self.unknownoutputindex_to_unknownoutputindex.any_vec(),
|
||||
self.outputindex_to_outputindex.any_vec(),
|
||||
self.height_to_txindex_count.any_vec(),
|
||||
self.dateindex_to_height_count.any_vec(),
|
||||
self.weekindex_to_dateindex_count.any_vec(),
|
||||
self.difficultyepoch_to_height_count.any_vec(),
|
||||
self.monthindex_to_dateindex_count.any_vec(),
|
||||
self.quarterindex_to_first_monthindex.any_vec(),
|
||||
self.quarterindex_to_monthindex_count.any_vec(),
|
||||
self.quarterindex_to_quarterindex.any_vec(),
|
||||
self.txindex_to_height.any_vec(),
|
||||
self.txindex_to_txindex.any_vec(),
|
||||
self.unknownoutputindex_to_unknownoutputindex.any_vec(),
|
||||
self.weekindex_to_dateindex_count.any_vec(),
|
||||
self.weekindex_to_first_dateindex.any_vec(),
|
||||
self.weekindex_to_weekindex.any_vec(),
|
||||
self.yearindex_to_decadeindex.any_vec(),
|
||||
self.yearindex_to_first_monthindex.any_vec(),
|
||||
self.yearindex_to_monthindex_count.any_vec(),
|
||||
self.decadeindex_to_yearindex_count.any_vec(),
|
||||
self.yearindex_to_yearindex.any_vec(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ impl Vecs {
|
||||
self.height_to_ohlc_in_cents.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.vec(),
|
||||
|(h, t)| {
|
||||
|(h, t, ..)| {
|
||||
let ohlc = fetcher
|
||||
.get_height(
|
||||
h,
|
||||
|
||||
@@ -62,17 +62,16 @@ impl Vecs {
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
let mut height_count_iter = indexes.dateindex_to_height_count.iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_first_height.vec(),
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
height_to_difficultyepoch_iter
|
||||
.get(height)
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner(),
|
||||
height_to_difficultyepoch_iter.unwrap_get_inner(
|
||||
height + (*height_count_iter.unwrap_get_inner(di) - 1),
|
||||
),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
@@ -87,10 +86,18 @@ impl Vecs {
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
let mut height_count_iter = indexes.dateindex_to_height_count.iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_first_height.vec(),
|
||||
|(di, height, ..)| (di, height_to_halvingepoch_iter.unwrap_get_inner(height)),
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
height_to_halvingepoch_iter.unwrap_get_inner(
|
||||
height + (*height_count_iter.unwrap_get_inner(di) - 1),
|
||||
),
|
||||
)
|
||||
},
|
||||
exit,
|
||||
)
|
||||
},
|
||||
|
||||
@@ -19,10 +19,10 @@ pub use vec::*;
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub indexes: indexes::Vecs,
|
||||
// pub blocks: blocks::Vecs,
|
||||
// pub mining: mining::Vecs,
|
||||
// pub transactions: transactions::Vecs,
|
||||
// pub marketprice: Option<marketprice::Vecs>,
|
||||
pub blocks: blocks::Vecs,
|
||||
pub mining: mining::Vecs,
|
||||
pub transactions: transactions::Vecs,
|
||||
pub marketprice: Option<marketprice::Vecs>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -30,11 +30,11 @@ impl Vecs {
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
Ok(Self {
|
||||
// blocks: blocks::Vecs::forced_import(path, compressed)?,
|
||||
blocks: blocks::Vecs::forced_import(path, compressed)?,
|
||||
indexes: indexes::Vecs::forced_import(path, compressed)?,
|
||||
// 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()),
|
||||
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,29 +47,29 @@ impl Vecs {
|
||||
) -> color_eyre::Result<()> {
|
||||
let starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?;
|
||||
|
||||
// self.blocks
|
||||
// .compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
self.blocks
|
||||
.compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
|
||||
// self.mining
|
||||
// .compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
self.mining
|
||||
.compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
|
||||
// if let Some(marketprice) = self.marketprice.as_mut() {
|
||||
// marketprice.compute(
|
||||
// indexer,
|
||||
// &self.indexes,
|
||||
// &starting_indexes,
|
||||
// fetcher.unwrap(),
|
||||
// exit,
|
||||
// )?;
|
||||
// }
|
||||
if let Some(marketprice) = self.marketprice.as_mut() {
|
||||
marketprice.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes,
|
||||
fetcher.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
|
||||
// self.transactions.compute(
|
||||
// indexer,
|
||||
// &self.indexes,
|
||||
// &starting_indexes,
|
||||
// self.marketprice.as_ref(),
|
||||
// exit,
|
||||
// )?;
|
||||
self.transactions.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes,
|
||||
self.marketprice.as_ref(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -77,12 +77,12 @@ impl Vecs {
|
||||
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStoredVec> {
|
||||
[
|
||||
self.indexes.as_any_vecs(),
|
||||
// self.blocks.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()),
|
||||
self.blocks.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()),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ impl Vecs {
|
||||
self.inputindex_to_value.compute_transform(
|
||||
starting_indexes.inputindex,
|
||||
indexer.vecs().inputindex_to_outputindex.vec(),
|
||||
|(inputindex, outputindex)| {
|
||||
|(inputindex, outputindex, ..)| {
|
||||
let value = if outputindex == OutputIndex::COINBASE {
|
||||
Sats::ZERO
|
||||
} else if let Some((_, value)) = outputindex_to_value_iter.get(outputindex) {
|
||||
|
||||
@@ -182,7 +182,7 @@ where
|
||||
where
|
||||
A: StoredIndex,
|
||||
B: StoredType,
|
||||
F: FnMut((A, B)) -> (I, T),
|
||||
F: FnMut((A, B, &Self)) -> (I, T),
|
||||
{
|
||||
self.validate_computed_version_or_reset_file(
|
||||
Version::ZERO + self.version() + other.version(),
|
||||
@@ -190,7 +190,7 @@ where
|
||||
|
||||
let index = max_from.min(A::from(self.len()));
|
||||
other.iter_at(index).try_for_each(|(a, b)| {
|
||||
let (i, v) = t((a, b.into_inner()));
|
||||
let (i, v) = t((a, b.into_inner(), self));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
@@ -217,9 +217,21 @@ where
|
||||
.last()
|
||||
.map_or_else(T::default, |(_, v)| v.into_inner()),
|
||||
);
|
||||
other.iter_at(index).try_for_each(|(v, i)| {
|
||||
let mut prev_i = None;
|
||||
other.iter_at(index).try_for_each(|(v, i)| -> Result<()> {
|
||||
let i = i.into_inner();
|
||||
self.forced_push_at(i, v, exit)
|
||||
if prev_i.is_some_and(|prev_i| prev_i == i) {
|
||||
return Ok(());
|
||||
}
|
||||
if self
|
||||
.inner
|
||||
.get(i)?
|
||||
.is_none_or(|old_v| old_v.into_inner() > v)
|
||||
{
|
||||
self.forced_push_at(i, v, exit)?;
|
||||
}
|
||||
prev_i.replace(i);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
|
||||
Reference in New Issue
Block a user