This commit is contained in:
nym21
2025-11-18 21:00:59 +01:00
parent e8f77ab2e5
commit 8467e218ae
28 changed files with 283 additions and 295 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ impl Vecs {
let height = block.height();
self.height_to_position
.forced_push(height, block.metadata().position(), exit)?;
.truncate_push(height, block.metadata().position())?;
let txindex = height_to_first_txindex_iter.get_unwrap(height);
@@ -105,7 +105,7 @@ impl Vecs {
|(index, metadata)| -> Result<()> {
let txindex = txindex + index;
self.txindex_to_position
.forced_push(txindex, metadata.position(), exit)?;
.truncate_push(txindex, metadata.position())?;
Ok(())
},
)?;
+2 -3
View File
@@ -85,12 +85,11 @@ impl Vecs {
.enumerate()
.skip(index.to_usize())
.try_for_each(|(i, v)| -> Result<()> {
self.height_to_price_ohlc_in_cents.forced_push_at(
self.height_to_price_ohlc_in_cents.truncate_push_at(
i,
self.fetcher
.get_height(i.into(), v, prev_timestamp)
.unwrap(),
exit,
)?;
prev_timestamp = Some(v);
Ok(())
@@ -127,7 +126,7 @@ impl Vecs {
prev.replace(ohlc.clone());
self.dateindex_to_price_ohlc_in_cents
.forced_push_at(i, ohlc, exit)?;
.truncate_push_at(i, ohlc)?;
Ok(())
})?;
@@ -226,7 +226,7 @@ where
.skip(index.to_usize())
.try_for_each(|(i, v)| -> Result<()> {
cumulative += v;
cumulative_vec.forced_push_at(i, cumulative, exit)?;
cumulative_vec.truncate_push_at(i, cumulative)?;
Ok(())
})?;
@@ -246,6 +246,10 @@ where
where
I2: VecIndex + VecValue + CheckedSub<I2>,
{
dbg!(source.len());
dbg!(first_indexes.len());
dbg!(count_indexes.len());
self.validate_computed_version_or_reset(
source.version() + first_indexes.version() + count_indexes.version(),
)?;
@@ -275,7 +279,7 @@ where
let f = source_iter
.get(first_index)
.unwrap_or_else(|| T::from(0_usize));
first.forced_push_at(index, f, exit)?;
first.truncate_push_at(index, f)?;
}
if let Some(last) = self.last.as_mut() {
@@ -291,7 +295,7 @@ where
// })
// .unwrap()
// ;
last.forced_push_at(index, v, exit)?;
last.truncate_push_at(index, v)?;
}
let needs_sum_or_cumulative = self.sum.is_some() || self.cumulative.is_some();
@@ -316,7 +320,7 @@ where
values.sort_unstable();
if let Some(max) = self.max.as_mut() {
max.forced_push_at(
max.truncate_push_at(
index,
*values
.last()
@@ -325,6 +329,7 @@ where
dbg!(
&values,
max.name(),
index,
first_indexes.name(),
first_index,
count_indexes.name(),
@@ -334,32 +339,31 @@ where
);
})
.unwrap(),
exit,
)?;
}
if let Some(pct90) = self.pct90.as_mut() {
pct90.forced_push_at(index, get_percentile(&values, 0.90), exit)?;
pct90.truncate_push_at(index, get_percentile(&values, 0.90))?;
}
if let Some(pct75) = self.pct75.as_mut() {
pct75.forced_push_at(index, get_percentile(&values, 0.75), exit)?;
pct75.truncate_push_at(index, get_percentile(&values, 0.75))?;
}
if let Some(median) = self.median.as_mut() {
median.forced_push_at(index, get_percentile(&values, 0.50), exit)?;
median.truncate_push_at(index, get_percentile(&values, 0.50))?;
}
if let Some(pct25) = self.pct25.as_mut() {
pct25.forced_push_at(index, get_percentile(&values, 0.25), exit)?;
pct25.truncate_push_at(index, get_percentile(&values, 0.25))?;
}
if let Some(pct10) = self.pct10.as_mut() {
pct10.forced_push_at(index, get_percentile(&values, 0.10), exit)?;
pct10.truncate_push_at(index, get_percentile(&values, 0.10))?;
}
if let Some(min) = self.min.as_mut() {
min.forced_push_at(index, *values.first().unwrap(), exit)?;
min.truncate_push_at(index, *values.first().unwrap())?;
}
}
@@ -369,18 +373,18 @@ where
if let Some(average) = self.average.as_mut() {
let avg = sum / len;
average.forced_push_at(index, avg, exit)?;
average.truncate_push_at(index, avg)?;
}
if needs_sum_or_cumulative {
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(index, sum, exit)?;
sum_vec.truncate_push_at(index, sum)?;
}
if let Some(cumulative_vec) = self.cumulative.as_mut() {
let t = cumulative.unwrap() + sum;
cumulative.replace(t);
cumulative_vec.forced_push_at(index, t, exit)?;
cumulative_vec.truncate_push_at(index, t)?;
}
}
}
@@ -445,7 +449,7 @@ where
if let Some(first) = self.first.as_mut() {
let v = source_first_iter.as_mut().unwrap().get_unwrap(first_index);
first.forced_push_at(index, v, exit)?;
first.truncate_push_at(index, v)?;
}
if let Some(last) = self.last.as_mut() {
@@ -455,7 +459,7 @@ where
}
let last_index = first_index + (count_index - 1);
let v = source_last_iter.as_mut().unwrap().get_unwrap(last_index);
last.forced_push_at(index, v, exit)?;
last.truncate_push_at(index, v)?;
}
let needs_sum_or_cumulative = self.sum.is_some() || self.cumulative.is_some();
@@ -473,7 +477,7 @@ where
.take(*count_index as usize)
.collect::<Vec<_>>();
values.sort_unstable();
max.forced_push_at(index, *values.last().unwrap(), exit)?;
max.truncate_push_at(index, *values.last().unwrap())?;
}
if let Some(min) = self.min.as_mut() {
@@ -483,7 +487,7 @@ where
.take(*count_index as usize)
.collect::<Vec<_>>();
values.sort_unstable();
min.forced_push_at(index, *values.first().unwrap(), exit)?;
min.truncate_push_at(index, *values.first().unwrap())?;
}
}
@@ -500,7 +504,7 @@ where
// TODO: Multiply by count then divide by cumulative
// Right now it's not 100% accurate as there could be more or less elements in the lower timeframe (28 days vs 31 days in a month for example)
let avg = cumulative / len;
average.forced_push_at(index, avg, exit)?;
average.truncate_push_at(index, avg)?;
}
if needs_sum_or_cumulative {
@@ -513,13 +517,13 @@ where
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(sum_vec) = self.sum.as_mut() {
sum_vec.forced_push_at(index, sum, exit)?;
sum_vec.truncate_push_at(index, sum)?;
}
if let Some(cumulative_vec) = self.cumulative.as_mut() {
let t = cumulative.unwrap() + sum;
cumulative.replace(t);
cumulative_vec.forced_push_at(index, t, exit)?;
cumulative_vec.truncate_push_at(index, t)?;
}
}
}
+24 -48
View File
@@ -252,84 +252,73 @@ impl ComputedVecsFromTxindex<Bitcoin> {
.map(Height::from)
.try_for_each(|height| -> Result<()> {
if let Some(first) = self.height.first.as_mut() {
first.forced_push(
first.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_first().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(average) = self.height.average.as_mut() {
average.forced_push(
average.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_average().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(sum) = self.height.sum.as_mut() {
sum.forced_push(
sum.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_sum().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(max) = self.height.max.as_mut() {
max.forced_push(
max.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_max().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(pct90) = self.height.pct90.as_mut() {
pct90.forced_push(
pct90.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_pct90().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(pct75) = self.height.pct75.as_mut() {
pct75.forced_push(
pct75.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_pct75().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(median) = self.height.median.as_mut() {
median.forced_push(
median.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_median().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(pct25) = self.height.pct25.as_mut() {
pct25.forced_push(
pct25.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_pct25().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(pct10) = self.height.pct10.as_mut() {
pct10.forced_push(
pct10.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_pct10().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(min) = self.height.min.as_mut() {
min.forced_push(
min.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_min().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(last) = self.height.last.as_mut() {
last.forced_push(
last.truncate_push(
height,
Bitcoin::from(sats.height.unwrap_last().into_iter().get_unwrap(height)),
exit,
)?;
}
if let Some(cumulative) = self.height.cumulative.as_mut() {
cumulative.forced_push(
cumulative.truncate_push(
height,
Bitcoin::from(
sats.height
@@ -337,7 +326,6 @@ impl ComputedVecsFromTxindex<Bitcoin> {
.into_iter()
.get_unwrap(height),
),
exit,
)?;
}
Ok(())
@@ -380,14 +368,13 @@ impl ComputedVecsFromTxindex<Dollars> {
let price = *close_iter.get_unwrap(height);
if let Some(first) = self.height.first.as_mut() {
first.forced_push(
first.truncate_push(
height,
price * bitcoin.height.unwrap_first().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(average) = self.height.average.as_mut() {
average.forced_push(
average.truncate_push(
height,
price
* bitcoin
@@ -395,39 +382,34 @@ impl ComputedVecsFromTxindex<Dollars> {
.unwrap_average()
.into_iter()
.get_unwrap(height),
exit,
)?;
}
if let Some(sum) = self.height.sum.as_mut() {
sum.forced_push(
sum.truncate_push(
height,
price * bitcoin.height.unwrap_sum().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(max) = self.height.max.as_mut() {
max.forced_push(
max.truncate_push(
height,
price * bitcoin.height.unwrap_max().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(pct90) = self.height.pct90.as_mut() {
pct90.forced_push(
pct90.truncate_push(
height,
price * bitcoin.height.unwrap_pct90().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(pct75) = self.height.pct75.as_mut() {
pct75.forced_push(
pct75.truncate_push(
height,
price * bitcoin.height.unwrap_pct75().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(median) = self.height.median.as_mut() {
median.forced_push(
median.truncate_push(
height,
price
* bitcoin
@@ -435,39 +417,34 @@ impl ComputedVecsFromTxindex<Dollars> {
.unwrap_median()
.into_iter()
.get_unwrap(height),
exit,
)?;
}
if let Some(pct25) = self.height.pct25.as_mut() {
pct25.forced_push(
pct25.truncate_push(
height,
price * bitcoin.height.unwrap_pct25().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(pct10) = self.height.pct10.as_mut() {
pct10.forced_push(
pct10.truncate_push(
height,
price * bitcoin.height.unwrap_pct10().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(min) = self.height.min.as_mut() {
min.forced_push(
min.truncate_push(
height,
price * bitcoin.height.unwrap_min().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(last) = self.height.last.as_mut() {
last.forced_push(
last.truncate_push(
height,
price * bitcoin.height.unwrap_last().into_iter().get_unwrap(height),
exit,
)?;
}
if let Some(cumulative) = self.height.cumulative.as_mut() {
cumulative.forced_push(
cumulative.truncate_push(
height,
price
* bitcoin
@@ -475,7 +452,6 @@ impl ComputedVecsFromTxindex<Dollars> {
.unwrap_cumulative()
.into_iter()
.get_unwrap(height),
exit,
)?;
}
Ok(())
@@ -407,42 +407,42 @@ impl ComputedRatioVecsFromDateIndex {
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
.truncate_push_at(index, StoredF32::NAN)?;
self.ratio_pct2
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
.truncate_push_at(index, StoredF32::NAN)?;
self.ratio_pct1
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
.truncate_push_at(index, StoredF32::NAN)?;
self.ratio_pct95
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
.truncate_push_at(index, StoredF32::NAN)?;
self.ratio_pct98
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
.truncate_push_at(index, StoredF32::NAN)?;
self.ratio_pct99
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
.truncate_push_at(index, StoredF32::NAN)?;
} else {
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
sorted.insert(pos, ratio);
@@ -453,42 +453,42 @@ impl ComputedRatioVecsFromDateIndex {
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.01), exit)?;
.truncate_push_at(index, get_percentile(&sorted, 0.01))?;
self.ratio_pct2
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.02), exit)?;
.truncate_push_at(index, get_percentile(&sorted, 0.02))?;
self.ratio_pct5
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.05), exit)?;
.truncate_push_at(index, get_percentile(&sorted, 0.05))?;
self.ratio_pct95
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.95), exit)?;
.truncate_push_at(index, get_percentile(&sorted, 0.95))?;
self.ratio_pct98
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.98), exit)?;
.truncate_push_at(index, get_percentile(&sorted, 0.98))?;
self.ratio_pct99
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.99), exit)?;
.truncate_push_at(index, get_percentile(&sorted, 0.99))?;
}
Ok(())
@@ -505,47 +505,47 @@ impl ComputedStandardDeviationVecsFromDateIndex {
.skip(starting_dateindex.to_usize())
.try_for_each(|(index, ratio)| -> Result<()> {
if index < min_date_usize {
self.sd.dateindex.as_mut().unwrap().forced_push_at(
index,
StoredF32::NAN,
exit,
)?;
self.sd
.dateindex
.as_mut()
.unwrap()
.truncate_push_at(index, StoredF32::NAN)?;
if let Some(v) = p0_5sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = p1sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = p1_5sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = p2sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = p2_5sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = p3sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = m0_5sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = m1sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = m1_5sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = m2sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = m2_5sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
if let Some(v) = m3sd.as_mut() {
v.forced_push_at(index, StoredF32::NAN, exit)?
v.truncate_push_at(index, StoredF32::NAN)?
}
// Advance iterator to stay in sync
sma_iter.next();
@@ -567,42 +567,42 @@ impl ComputedStandardDeviationVecsFromDateIndex {
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, sd, exit)?;
.truncate_push_at(index, sd)?;
if let Some(v) = p0_5sd.as_mut() {
v.forced_push_at(index, avg + StoredF32::from(0.5 * *sd), exit)?
v.truncate_push_at(index, avg + StoredF32::from(0.5 * *sd))?
}
if let Some(v) = p1sd.as_mut() {
v.forced_push_at(index, avg + sd, exit)?
v.truncate_push_at(index, avg + sd)?
}
if let Some(v) = p1_5sd.as_mut() {
v.forced_push_at(index, avg + StoredF32::from(1.5 * *sd), exit)?
v.truncate_push_at(index, avg + StoredF32::from(1.5 * *sd))?
}
if let Some(v) = p2sd.as_mut() {
v.forced_push_at(index, avg + 2 * sd, exit)?
v.truncate_push_at(index, avg + 2 * sd)?
}
if let Some(v) = p2_5sd.as_mut() {
v.forced_push_at(index, avg + StoredF32::from(2.5 * *sd), exit)?
v.truncate_push_at(index, avg + StoredF32::from(2.5 * *sd))?
}
if let Some(v) = p3sd.as_mut() {
v.forced_push_at(index, avg + 3 * sd, exit)?
v.truncate_push_at(index, avg + 3 * sd)?
}
if let Some(v) = m0_5sd.as_mut() {
v.forced_push_at(index, avg - StoredF32::from(0.5 * *sd), exit)?
v.truncate_push_at(index, avg - StoredF32::from(0.5 * *sd))?
}
if let Some(v) = m1sd.as_mut() {
v.forced_push_at(index, avg - sd, exit)?
v.truncate_push_at(index, avg - sd)?
}
if let Some(v) = m1_5sd.as_mut() {
v.forced_push_at(index, avg - StoredF32::from(1.5 * *sd), exit)?
v.truncate_push_at(index, avg - StoredF32::from(1.5 * *sd))?
}
if let Some(v) = m2sd.as_mut() {
v.forced_push_at(index, avg - 2 * sd, exit)?
v.truncate_push_at(index, avg - 2 * sd)?
}
if let Some(v) = m2_5sd.as_mut() {
v.forced_push_at(index, avg - StoredF32::from(2.5 * *sd), exit)?
v.truncate_push_at(index, avg - StoredF32::from(2.5 * *sd))?
}
if let Some(v) = m3sd.as_mut() {
v.forced_push_at(index, avg - 3 * sd, exit)?
v.truncate_push_at(index, avg - 3 * sd)?
}
}
+2 -2
View File
@@ -157,6 +157,8 @@ impl Computer {
info!("Computing indexes...");
let mut starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?;
return Ok(());
if let Some(fetched) = self.fetched.as_mut() {
info!("Computing fetched...");
fetched.compute(indexer, &self.indexes, &starting_indexes, exit)?;
@@ -213,8 +215,6 @@ impl Computer {
exit,
)?;
return Ok(());
info!("Computing stateful...");
self.stateful.compute(
indexer,
@@ -127,35 +127,30 @@ impl DynCohortVecs for Vecs {
self.inner.validate_computed_versions(base_version)
}
fn forced_pushed_at(&mut self, height: Height, exit: &Exit) -> Result<()> {
fn truncate_push(&mut self, height: Height) -> Result<()> {
if self.starting_height.unwrap() > height {
return Ok(());
}
self.height_to_addr_count.forced_push(
height,
self.state.as_ref().unwrap().addr_count.into(),
exit,
)?;
self.height_to_addr_count
.truncate_push(height, self.state.as_ref().unwrap().addr_count.into())?;
self.inner
.forced_pushed_at(height, exit, &self.state.as_ref().unwrap().inner)
.truncate_push(height, &self.state.as_ref().unwrap().inner)
}
fn compute_then_force_push_unrealized_states(
fn compute_then_truncate_push_unrealized_states(
&mut self,
height: Height,
height_price: Option<Dollars>,
dateindex: Option<DateIndex>,
date_price: Option<Option<Dollars>>,
exit: &Exit,
) -> Result<()> {
self.inner.compute_then_force_push_unrealized_states(
self.inner.compute_then_truncate_push_unrealized_states(
height,
height_price,
dateindex,
date_price,
exit,
&self.state.as_ref().unwrap().inner,
)
}
@@ -3,7 +3,7 @@ use brk_grouper::ByAddressType;
use brk_traversable::Traversable;
use brk_types::{Height, StoredU64};
use derive_deref::{Deref, DerefMut};
use vecdb::{EagerVec, Exit, GenericStoredVec};
use vecdb::{EagerVec, GenericStoredVec};
use super::AddressTypeToAddressCount;
@@ -18,28 +18,27 @@ impl From<ByAddressType<EagerVec<Height, StoredU64>>> for AddressTypeToHeightToA
}
impl AddressTypeToHeightToAddressCount {
pub fn forced_push(
pub fn truncate_push(
&mut self,
height: Height,
addresstype_to_usize: &AddressTypeToAddressCount,
exit: &Exit,
) -> Result<()> {
self.p2pk65
.forced_push(height, addresstype_to_usize.p2pk65.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2pk65.into())?;
self.p2pk33
.forced_push(height, addresstype_to_usize.p2pk33.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2pk33.into())?;
self.p2pkh
.forced_push(height, addresstype_to_usize.p2pkh.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2pkh.into())?;
self.p2sh
.forced_push(height, addresstype_to_usize.p2sh.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2sh.into())?;
self.p2wpkh
.forced_push(height, addresstype_to_usize.p2wpkh.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2wpkh.into())?;
self.p2wsh
.forced_push(height, addresstype_to_usize.p2wsh.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2wsh.into())?;
self.p2tr
.forced_push(height, addresstype_to_usize.p2tr.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2tr.into())?;
self.p2a
.forced_push(height, addresstype_to_usize.p2a.into(), exit)?;
.truncate_push(height, addresstype_to_usize.p2a.into())?;
Ok(())
}
+30 -43
View File
@@ -1564,26 +1564,18 @@ impl Vecs {
Ok(())
}
pub fn forced_pushed_at(
&mut self,
height: Height,
exit: &Exit,
state: &CohortState,
) -> Result<()> {
pub fn truncate_push(&mut self, height: Height, state: &CohortState) -> Result<()> {
self.height_to_supply
.forced_push(height, state.supply.value, exit)?;
.truncate_push(height, state.supply.value)?;
self.height_to_utxo_count.forced_push(
height,
StoredU64::from(state.supply.utxo_count),
exit,
)?;
self.height_to_utxo_count
.truncate_push(height, StoredU64::from(state.supply.utxo_count))?;
self.height_to_satblocks_destroyed
.forced_push(height, state.satblocks_destroyed, exit)?;
.truncate_push(height, state.satblocks_destroyed)?;
self.height_to_satdays_destroyed
.forced_push(height, state.satdays_destroyed, exit)?;
.truncate_push(height, state.satdays_destroyed)?;
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
let realized = state.realized.as_ref().unwrap_or_else(|| {
@@ -1591,72 +1583,67 @@ impl Vecs {
panic!();
});
height_to_realized_cap.forced_push(height, realized.cap, exit)?;
height_to_realized_cap.truncate_push(height, realized.cap)?;
self.height_to_realized_profit
.as_mut()
.unwrap()
.forced_push(height, realized.profit, exit)?;
self.height_to_realized_loss.as_mut().unwrap().forced_push(
height,
realized.loss,
exit,
)?;
self.height_to_value_created.as_mut().unwrap().forced_push(
height,
realized.value_created,
exit,
)?;
.truncate_push(height, realized.profit)?;
self.height_to_realized_loss
.as_mut()
.unwrap()
.truncate_push(height, realized.loss)?;
self.height_to_value_created
.as_mut()
.unwrap()
.truncate_push(height, realized.value_created)?;
self.height_to_value_destroyed
.as_mut()
.unwrap()
.forced_push(height, realized.value_destroyed, exit)?;
.truncate_push(height, realized.value_destroyed)?;
if self.height_to_adjusted_value_created.is_some() {
self.height_to_adjusted_value_created
.as_mut()
.unwrap()
.forced_push(height, realized.adj_value_created, exit)?;
.truncate_push(height, realized.adj_value_created)?;
self.height_to_adjusted_value_destroyed
.as_mut()
.unwrap()
.forced_push(height, realized.adj_value_destroyed, exit)?;
.truncate_push(height, realized.adj_value_destroyed)?;
}
}
Ok(())
}
pub fn compute_then_force_push_unrealized_states(
pub fn compute_then_truncate_push_unrealized_states(
&mut self,
height: Height,
height_price: Option<Dollars>,
dateindex: Option<DateIndex>,
date_price: Option<Option<Dollars>>,
exit: &Exit,
state: &CohortState,
) -> Result<()> {
if let Some(height_price) = height_price {
self.height_to_min_price_paid
.as_mut()
.unwrap()
.forced_push(
.truncate_push(
height,
state
.price_to_amount_first_key_value()
.map(|(&dollars, _)| dollars)
.unwrap_or(Dollars::NAN),
exit,
)?;
self.height_to_max_price_paid
.as_mut()
.unwrap()
.forced_push(
.truncate_push(
height,
state
.price_to_amount_last_key_value()
.map(|(&dollars, _)| dollars)
.unwrap_or(Dollars::NAN),
exit,
)?;
let (height_unrealized_state, date_unrealized_state) =
@@ -1665,19 +1652,19 @@ impl Vecs {
self.height_to_supply_in_profit
.as_mut()
.unwrap()
.forced_push(height, height_unrealized_state.supply_in_profit, exit)?;
.truncate_push(height, height_unrealized_state.supply_in_profit)?;
self.height_to_supply_in_loss
.as_mut()
.unwrap()
.forced_push(height, height_unrealized_state.supply_in_loss, exit)?;
.truncate_push(height, height_unrealized_state.supply_in_loss)?;
self.height_to_unrealized_profit
.as_mut()
.unwrap()
.forced_push(height, height_unrealized_state.unrealized_profit, exit)?;
.truncate_push(height, height_unrealized_state.unrealized_profit)?;
self.height_to_unrealized_loss
.as_mut()
.unwrap()
.forced_push(height, height_unrealized_state.unrealized_loss, exit)?;
.truncate_push(height, height_unrealized_state.unrealized_loss)?;
if let Some(date_unrealized_state) = date_unrealized_state {
let dateindex = dateindex.unwrap();
@@ -1685,19 +1672,19 @@ impl Vecs {
self.dateindex_to_supply_in_profit
.as_mut()
.unwrap()
.forced_push(dateindex, date_unrealized_state.supply_in_profit, exit)?;
.truncate_push(dateindex, date_unrealized_state.supply_in_profit)?;
self.dateindex_to_supply_in_loss
.as_mut()
.unwrap()
.forced_push(dateindex, date_unrealized_state.supply_in_loss, exit)?;
.truncate_push(dateindex, date_unrealized_state.supply_in_loss)?;
self.dateindex_to_unrealized_profit
.as_mut()
.unwrap()
.forced_push(dateindex, date_unrealized_state.unrealized_profit, exit)?;
.truncate_push(dateindex, date_unrealized_state.unrealized_profit)?;
self.dateindex_to_unrealized_loss
.as_mut()
.unwrap()
.forced_push(dateindex, date_unrealized_state.unrealized_loss, exit)?;
.truncate_push(dateindex, date_unrealized_state.unrealized_loss)?;
}
}
+9 -15
View File
@@ -1241,22 +1241,16 @@ impl Vecs {
});
self.height_to_unspendable_supply
.forced_push(height, unspendable_supply, exit)?;
.truncate_push(height, unspendable_supply)?;
self.height_to_opreturn_supply
.forced_push(height, opreturn_supply, exit)?;
.truncate_push(height, opreturn_supply)?;
self.addresstype_to_height_to_addr_count.forced_push(
height,
&addresstype_to_addr_count,
exit,
)?;
self.addresstype_to_height_to_addr_count
.truncate_push(height, &addresstype_to_addr_count)?;
self.addresstype_to_height_to_empty_addr_count.forced_push(
height,
&addresstype_to_empty_addr_count,
exit,
)?;
self.addresstype_to_height_to_empty_addr_count
.truncate_push(height, &addresstype_to_empty_addr_count)?;
let date = height_to_date_fixed_iter.get_unwrap(height);
let dateindex = DateIndex::try_from(date).unwrap();
@@ -1280,9 +1274,9 @@ impl Vecs {
.map(|Filtered(_, v)| v as &mut dyn DynCohortVecs),
)
.try_for_each(|v| {
v.forced_pushed_at(height, exit)?;
v.compute_then_force_push_unrealized_states(
height, price, dateindex, date_price, exit,
v.truncate_push(height)?;
v.compute_then_truncate_push_unrealized_states(
height, price, dateindex, date_price,
)
})?;
+2 -3
View File
@@ -12,15 +12,14 @@ pub trait DynCohortVecs: Send + Sync {
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()>;
fn forced_pushed_at(&mut self, height: Height, exit: &Exit) -> Result<()>;
fn truncate_push(&mut self, height: Height) -> Result<()>;
fn compute_then_force_push_unrealized_states(
fn compute_then_truncate_push_unrealized_states(
&mut self,
height: Height,
height_price: Option<Dollars>,
dateindex: Option<DateIndex>,
date_price: Option<Option<Dollars>>,
exit: &Exit,
) -> Result<()>;
fn safe_flush_stateful_vecs(&mut self, height: Height, exit: &Exit) -> Result<()>;
@@ -89,29 +89,27 @@ impl DynCohortVecs for Vecs {
self.inner.validate_computed_versions(base_version)
}
fn forced_pushed_at(&mut self, height: Height, exit: &Exit) -> Result<()> {
fn truncate_push(&mut self, height: Height) -> Result<()> {
if self.state_starting_height.unwrap() > height {
return Ok(());
}
self.inner
.forced_pushed_at(height, exit, self.state.as_ref().unwrap())
.truncate_push(height, self.state.as_ref().unwrap())
}
fn compute_then_force_push_unrealized_states(
fn compute_then_truncate_push_unrealized_states(
&mut self,
height: Height,
height_price: Option<Dollars>,
dateindex: Option<DateIndex>,
date_price: Option<Option<Dollars>>,
exit: &Exit,
) -> Result<()> {
self.inner.compute_then_force_push_unrealized_states(
self.inner.compute_then_truncate_push_unrealized_states(
height,
height_price,
dateindex,
date_price,
exit,
self.state.as_mut().unwrap(),
)
}
+4 -4
View File
@@ -71,7 +71,7 @@ impl ComputeDCAStackViaLen for EagerVec<DateIndex, Sats> {
prev = stack;
self.forced_push_at(i, stack, exit)
self.truncate_push_at(i, stack)
})?;
self.safe_flush(exit)?;
@@ -115,7 +115,7 @@ impl ComputeDCAStackViaLen for EagerVec<DateIndex, Sats> {
prev = stack;
self.forced_push_at(i, stack, exit)
self.truncate_push_at(i, stack)
})?;
self.safe_flush(exit)?;
@@ -173,7 +173,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec<DateIndex, Dollars> {
.min(i.checked_sub(first_price_date).unwrap().to_usize() + 1)
/ Bitcoin::from(stack);
}
self.forced_push_at(i, avg_price, exit)
self.truncate_push_at(i, avg_price)
})?;
self.safe_flush(exit)?;
@@ -205,7 +205,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec<DateIndex, Dollars> {
if i >= from {
avg_price = DCA_AMOUNT * (i.to_usize() + 1 - from) / Bitcoin::from(stack);
}
self.forced_push_at(i, avg_price, exit)
self.truncate_push_at(i, avg_price)
})?;
self.safe_flush(exit)?;