global: snapshot

This commit is contained in:
nym21
2025-11-06 13:07:07 +01:00
parent a2ba4d89f3
commit df577ca7f5
62 changed files with 1078 additions and 2291 deletions

View File

@@ -6,7 +6,8 @@ use brk_reader::Reader;
use brk_traversable::Traversable;
use brk_types::{BlkPosition, Height, TxIndex, Version};
use vecdb::{
AnyStoredVec, AnyVec, CompressedVec, Database, Exit, GenericStoredVec, PAGE_SIZE, VecIterator,
AnyStoredVec, AnyVec, CompressedVec, Database, Exit, GenericStoredVec, PAGE_SIZE,
VecIteratorExtended,
};
use super::Indexes;
@@ -58,7 +59,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexer, starting_indexes, reader, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -75,14 +76,14 @@ impl Vecs {
let Some(min_height) = indexer
.vecs
.txindex_to_height
.iter()
.get_inner(min_txindex)
.iter()?
.get(min_txindex)
.map(|h| h.min(starting_indexes.height))
else {
return Ok(());
};
let mut height_to_first_txindex_iter = indexer.vecs.height_to_first_txindex.iter();
let mut height_to_first_txindex_iter = indexer.vecs.height_to_first_txindex.iter()?;
parser
.read(
@@ -99,7 +100,7 @@ impl Vecs {
exit,
)?;
let txindex = height_to_first_txindex_iter.unwrap_get_inner(height);
let txindex = height_to_first_txindex_iter.get_unwrap(height);
block.tx_metadata().iter().enumerate().try_for_each(
|(index, metadata)| -> Result<()> {

View File

@@ -12,7 +12,7 @@ use brk_types::{
};
use vecdb::{
AnyCloneableIterableVec, AnyIterableVec, Database, EagerVec, Exit, LazyVecFrom1, LazyVecFrom2,
LazyVecFrom3, PAGE_SIZE, StoredIndex, VecIterator,
LazyVecFrom3, PAGE_SIZE, StoredIndex, VecIterator, VecIteratorExtended,
};
use crate::grouped::{
@@ -1123,7 +1123,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexer, indexes, starting_indexes, price, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -1152,9 +1152,8 @@ impl Vecs {
starting_indexes.height,
&indexes.height_to_timestamp_fixed,
|(h, t, ..)| {
while t.difference_in_days_between(
height_to_timestamp_fixed_iter.unwrap_get_inner(prev),
) > 0
while t.difference_in_days_between(height_to_timestamp_fixed_iter.unsafe_get(prev))
> 0
{
prev.increment();
if prev > h {
@@ -1216,7 +1215,7 @@ impl Vecs {
&indexer.vecs.height_to_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);
let prev_timestamp = height_to_timestamp_iter.unsafe_get(prev_h);
timestamp
.checked_sub(prev_timestamp)
.unwrap_or(Timestamp::ZERO)
@@ -1266,19 +1265,19 @@ impl Vecs {
Some(&self.height_to_vbytes),
)?;
let mut height_to_timestamp_iter = indexer.vecs.height_to_timestamp.iter();
let mut height_to_timestamp_iter = indexer.vecs.height_to_timestamp.iter()?;
self.difficultyepoch_to_timestamp.compute_transform(
starting_indexes.difficultyepoch,
&indexes.difficultyepoch_to_first_height,
|(i, h, ..)| (i, height_to_timestamp_iter.unwrap_get_inner(h)),
|(i, h, ..)| (i, height_to_timestamp_iter.unsafe_get(h)),
exit,
)?;
self.halvingepoch_to_timestamp.compute_transform(
starting_indexes.halvingepoch,
&indexes.halvingepoch_to_first_height,
|(i, h, ..)| (i, height_to_timestamp_iter.unwrap_get_inner(h)),
|(i, h, ..)| (i, height_to_timestamp_iter.unsafe_get(h)),
exit,
)?;
@@ -1292,9 +1291,8 @@ impl Vecs {
|(di, height, ..)| {
(
di,
height_to_difficultyepoch_iter.unwrap_get_inner(
height + (*height_count_iter.unwrap_get_inner(di) - 1),
),
height_to_difficultyepoch_iter
.unsafe_get(height + (*height_count_iter.unsafe_get(di) - 1)),
)
},
exit,
@@ -1312,9 +1310,8 @@ impl Vecs {
|(di, height, ..)| {
(
di,
height_to_halvingepoch_iter.unwrap_get_inner(
height + (*height_count_iter.unwrap_get_inner(di) - 1),
),
height_to_halvingepoch_iter
.unsafe_get(height + (*height_count_iter.unsafe_get(di) - 1)),
)
},
exit,
@@ -1365,7 +1362,7 @@ impl Vecs {
&indexer.vecs.height_to_first_txindex,
&indexer.vecs.txindex_to_txid,
|txindex| {
let v = txindex_to_txversion_iter.unwrap_get_inner(txindex);
let v = txindex_to_txversion_iter.unsafe_get(txindex);
v == txversion
},
exit,
@@ -1385,7 +1382,7 @@ impl Vecs {
let value = if txoutindex == TxOutIndex::COINBASE {
Sats::MAX
} else {
txoutindex_to_value_iter.unwrap_get_inner(txoutindex)
txoutindex_to_value_iter.unsafe_get(txoutindex)
};
(txinindex, value)
},
@@ -1525,14 +1522,14 @@ impl Vecs {
&indexer.vecs.height_to_first_txindex,
|(height, txindex, ..)| {
let first_txoutindex = txindex_to_first_txoutindex_iter
.unwrap_get_inner(txindex)
.unsafe_get(txindex)
.to_usize();
let output_count = txindex_to_output_count_iter.unwrap_get_inner(txindex);
let output_count = txindex_to_output_count_iter.unsafe_get(txindex);
let mut sats = Sats::ZERO;
(first_txoutindex..first_txoutindex + usize::from(output_count)).for_each(
|txoutindex| {
sats += txoutindex_to_value_iter
.unwrap_get_inner(TxOutIndex::from(txoutindex));
.unsafe_get(TxOutIndex::from(txoutindex));
},
);
(height, sats)
@@ -1556,7 +1553,7 @@ impl Vecs {
let range = *h - (*count - 1)..=*h;
let sum = range
.map(Height::from)
.map(|h| height_to_coinbase_iter.unwrap_get_inner(h))
.map(|h| height_to_coinbase_iter.unsafe_get(h))
.sum::<Sats>();
(h, sum)
},
@@ -1575,7 +1572,7 @@ impl Vecs {
let range = *h - (*count - 1)..=*h;
let sum = range
.map(Height::from)
.map(|h| height_to_coinbase_iter.unwrap_get_inner(h))
.map(|h| height_to_coinbase_iter.unsafe_get(h))
.sum::<Dollars>();
(h, sum)
},
@@ -1593,7 +1590,7 @@ impl Vecs {
starting_indexes.height,
self.indexes_to_coinbase.sats.height.as_ref().unwrap(),
|(height, coinbase, ..)| {
let fees = indexes_to_fee_sum_iter.unwrap_get_inner(height);
let fees = indexes_to_fee_sum_iter.unsafe_get(height);
(height, coinbase.checked_sub(fees).unwrap())
},
exit,
@@ -1787,8 +1784,8 @@ impl Vecs {
starting_indexes.height,
self.indexes_to_output_count.height.unwrap_cumulative(),
|(h, output_count, ..)| {
let input_count = input_count_iter.unwrap_get_inner(h);
let opreturn_count = opreturn_count_iter.unwrap_get_inner(h);
let input_count = input_count_iter.unsafe_get(h);
let opreturn_count = opreturn_count_iter.unsafe_get(h);
let block_count = u64::from(h + 1_usize);
// -1 > genesis output is unspendable
let mut utxo_count =

View File

@@ -298,7 +298,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexes, starting_indexes, price, chain, stateful, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -339,7 +339,7 @@ impl Vecs {
starting_indexes.height,
self.indexes_to_coinblocks_created.height.as_ref().unwrap(),
|(i, created, ..)| {
let destroyed = coinblocks_destroyed_iter.unwrap_get_inner(i);
let destroyed = coinblocks_destroyed_iter.unsafe_get(i);
(i, created.checked_sub(destroyed).unwrap())
},
exit,

View File

@@ -177,7 +177,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexes, starting_indexes, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}

View File

@@ -60,7 +60,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexer, indexes, starting_indexes, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -76,16 +76,18 @@ impl Vecs {
.height
.min(Height::from(self.height_to_price_ohlc_in_cents.len()));
height_to_timestamp
.iter_at(index)
.iter()?
.skip(index.to_usize())
.enumerate()
.try_for_each(|(i, v)| -> Result<()> {
self.height_to_price_ohlc_in_cents.forced_push_at(
i,
i.into(),
self.fetcher
.get_height(
i,
i.into(),
v,
i.decremented().map(|prev_i| {
height_to_timestamp.into_iter().unwrap_get_inner(prev_i)
height_to_timestamp.into_iter().get_unwrap_at(prev_i)
}),
)
.unwrap(),
@@ -101,14 +103,16 @@ impl Vecs {
let mut prev = None;
indexes
.dateindex_to_date
.iter_at(index)
.iter()
.skip(index.to_usize())
.enumerate()
.try_for_each(|(i, d)| -> Result<()> {
if prev.is_none() {
let i = i.to_usize();
prev.replace(if i > 0 {
self.dateindex_to_price_ohlc_in_cents
.into_iter()
.unwrap_get_inner_(i - 1)
.get_unwrap_at(i - 1)
} else {
OHLCCents::default()
});
@@ -129,7 +133,7 @@ impl Vecs {
prev.replace(ohlc.clone());
self.dateindex_to_price_ohlc_in_cents
.forced_push_at(i, ohlc, exit)?;
.forced_push_at_(i, ohlc, exit)?;
Ok(())
})?;

View File

@@ -219,13 +219,17 @@ where
let cumulative_vec = self.cumulative.as_mut().unwrap();
let mut cumulative = index.decremented().map_or(T::from(0_usize), |index| {
cumulative_vec.iter().unwrap_get_inner(index)
cumulative_vec.iter().unsafe_get(index)
});
source.iter_at(index).try_for_each(|(i, v)| -> Result<()> {
cumulative += v;
cumulative_vec.forced_push_at(i, cumulative, exit)?;
Ok(())
})?;
source
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, v)| -> Result<()> {
cumulative += v;
cumulative_vec.forced_push_at(i, cumulative, exit)?;
Ok(())
})?;
self.safe_flush(exit)?;
@@ -256,14 +260,13 @@ where
let mut cumulative = cumulative_vec.map(|cumulative_vec| {
index.decremented().map_or(T::from(0_usize), |index| {
cumulative_vec.iter().unwrap_get_inner(index)
cumulative_vec.iter().unsafe_get(index)
})
});
first_indexes
.iter_at(index)
.try_for_each(|(index, first_index)| -> Result<()> {
let count_index = count_indexes_iter.unwrap_get_inner(index);
first_indexes.iter().skip(index).enumerate().try_for_each(
|(index, first_index)| -> Result<()> {
let count_index = count_indexes_iter.unsafe_get(index);
if let Some(first) = self.first.as_mut() {
let f = source_iter
@@ -278,7 +281,7 @@ where
panic!("should compute last if count can be 0")
}
let last_index = first_index + (count_index - 1);
let v = source_iter.unwrap_get_inner(last_index);
let v = source_iter.unsafe_get(last_index);
// .context("to work")
// .inspect_err(|_| {
// dbg!(first_index, count_index, last_index);
@@ -382,7 +385,8 @@ where
}
Ok(())
})?;
},
)?;
self.safe_flush(exit)?;
@@ -427,20 +431,16 @@ where
let mut cumulative = self.cumulative.as_mut().map(|cumulative_vec| {
index.decremented().map_or(T::from(0_usize), |index| {
cumulative_vec.iter().unwrap_get_inner(index)
cumulative_vec.iter().unsafe_get(index)
})
});
first_indexes
.iter_at(index)
.try_for_each(|(index, first_index, ..)| -> Result<()> {
let count_index = count_indexes_iter.unwrap_get_inner(index);
first_indexes.iter().skip(index).enumerate().try_for_each(
|(index, first_index, ..)| -> Result<()> {
let count_index = count_indexes_iter.unsafe_get(index);
if let Some(first) = self.first.as_mut() {
let v = source_first_iter
.as_mut()
.unwrap()
.unwrap_get_inner(first_index);
let v = source_first_iter.as_mut().unwrap().unsafe_get(first_index);
first.forced_push_at(index, v, exit)?;
}
@@ -450,10 +450,7 @@ where
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()
.unwrap_get_inner(last_index);
let v = source_last_iter.as_mut().unwrap().unsafe_get(last_index);
last.forced_push_at(index, v, exit)?;
}
@@ -529,7 +526,8 @@ where
}
Ok(())
})?;
},
)?;
self.safe_flush(exit)?;

View File

@@ -255,132 +255,77 @@ impl ComputedVecsFromTxindex<Bitcoin> {
if let Some(first) = self.height.first.as_mut() {
first.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_first()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_first().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(average) = self.height.average.as_mut() {
average.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_average()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_average().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(sum) = self.height.sum.as_mut() {
sum.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_sum()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_sum().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(max) = self.height.max.as_mut() {
max.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_max()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_max().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(pct90) = self.height.pct90.as_mut() {
pct90.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_pct90()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_pct90().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(pct75) = self.height.pct75.as_mut() {
pct75.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_pct75()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_pct75().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(median) = self.height.median.as_mut() {
median.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_median()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_median().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(pct25) = self.height.pct25.as_mut() {
pct25.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_pct25()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_pct25().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(pct10) = self.height.pct10.as_mut() {
pct10.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_pct10()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_pct10().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(min) = self.height.min.as_mut() {
min.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_min()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_min().into_iter().unsafe_get(height)),
exit,
)?;
}
if let Some(last) = self.height.last.as_mut() {
last.forced_push_at(
height,
Bitcoin::from(
sats.height
.unwrap_last()
.into_iter()
.unwrap_get_inner(height),
),
Bitcoin::from(sats.height.unwrap_last().into_iter().unsafe_get(height)),
exit,
)?;
}
@@ -391,7 +336,7 @@ impl ComputedVecsFromTxindex<Bitcoin> {
sats.height
.unwrap_cumulative()
.into_iter()
.unwrap_get_inner(height),
.unsafe_get(height),
),
exit,
)?;
@@ -433,17 +378,12 @@ impl ComputedVecsFromTxindex<Dollars> {
(starting_index.to_usize()..indexer.vecs.height_to_weight.len())
.map(Height::from)
.try_for_each(|height| -> Result<()> {
let price = *close_iter.unwrap_get_inner(height);
let price = *close_iter.unsafe_get(height);
if let Some(first) = self.height.first.as_mut() {
first.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_first()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_first().into_iter().unsafe_get(height),
exit,
)?;
}
@@ -455,55 +395,35 @@ impl ComputedVecsFromTxindex<Dollars> {
.height
.unwrap_average()
.into_iter()
.unwrap_get_inner(height),
.unsafe_get(height),
exit,
)?;
}
if let Some(sum) = self.height.sum.as_mut() {
sum.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_sum()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_sum().into_iter().unsafe_get(height),
exit,
)?;
}
if let Some(max) = self.height.max.as_mut() {
max.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_max()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_max().into_iter().unsafe_get(height),
exit,
)?;
}
if let Some(pct90) = self.height.pct90.as_mut() {
pct90.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_pct90()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_pct90().into_iter().unsafe_get(height),
exit,
)?;
}
if let Some(pct75) = self.height.pct75.as_mut() {
pct75.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_pct75()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_pct75().into_iter().unsafe_get(height),
exit,
)?;
}
@@ -515,55 +435,35 @@ impl ComputedVecsFromTxindex<Dollars> {
.height
.unwrap_median()
.into_iter()
.unwrap_get_inner(height),
.unsafe_get(height),
exit,
)?;
}
if let Some(pct25) = self.height.pct25.as_mut() {
pct25.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_pct25()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_pct25().into_iter().unsafe_get(height),
exit,
)?;
}
if let Some(pct10) = self.height.pct10.as_mut() {
pct10.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_pct10()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_pct10().into_iter().unsafe_get(height),
exit,
)?;
}
if let Some(min) = self.height.min.as_mut() {
min.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_min()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_min().into_iter().unsafe_get(height),
exit,
)?;
}
if let Some(last) = self.height.last.as_mut() {
last.forced_push_at(
height,
price
* bitcoin
.height
.unwrap_last()
.into_iter()
.unwrap_get_inner(height),
price * bitcoin.height.unwrap_last().into_iter().unsafe_get(height),
exit,
)?;
}
@@ -575,7 +475,7 @@ impl ComputedVecsFromTxindex<Dollars> {
.height
.unwrap_cumulative()
.into_iter()
.unwrap_get_inner(height),
.unsafe_get(height),
exit,
)?;
}

View File

@@ -394,7 +394,9 @@ impl ComputedRatioVecsFromDateIndex {
.dateindex
.as_ref()
.unwrap()
.iter_at(starting_dateindex)
.iter()
.skip(starting_dateindex)
.enumerate()
.try_for_each(|(index, ratio)| -> Result<()> {
if index < min_ratio_date {
self.ratio_pct5
@@ -545,7 +547,7 @@ impl ComputedRatioVecsFromDateIndex {
starting_indexes.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
let multiplier = iter.unsafe_get(i);
(i, price * multiplier)
},
exit,
@@ -562,7 +564,7 @@ impl ComputedRatioVecsFromDateIndex {
starting_indexes.dateindex,
date_to_price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
let multiplier = iter.unsafe_get(i);
(i, price * multiplier)
},
exit,

View File

@@ -499,7 +499,9 @@ impl ComputedStandardDeviationVecsFromDateIndex {
let mut m3sd = self.m3sd.as_mut().map(|c| c.dateindex.as_mut().unwrap());
source
.iter_at(starting_dateindex)
.iter()
.skip(starting_dateindex)
.enumerate()
.try_for_each(|(index, ratio)| -> Result<()> {
if index < min_date {
self.sd.dateindex.as_mut().unwrap().forced_push_at(
@@ -548,7 +550,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
sorted.insert(pos, ratio);
let avg = sma_iter.unwrap_get_inner(index);
let avg = sma_iter.unsafe_get(index);
let population = index.checked_sub(min_date).unwrap().to_usize() as f32 + 1.0;
@@ -637,7 +639,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
starting_indexes.dateindex,
price,
|(i, price, ..)| {
let multiplier = iter.unwrap_get_inner(i);
let multiplier = iter.unsafe_get(i);
(i, price * multiplier)
},
exit,

View File

@@ -509,7 +509,7 @@ impl Vecs {
exit: &Exit,
) -> Result<Indexes> {
let idxs = self.compute_(indexer, starting_indexes, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(idxs)
}
@@ -558,7 +558,7 @@ impl Vecs {
prev_timestamp_fixed.replace(
height_to_timestamp_fixed_iter
.into_iter()
.unwrap_get_inner(prev_h),
.unsafe_get(prev_h),
);
}
let timestamp_fixed =
@@ -946,13 +946,9 @@ pub struct Indexes {
impl Indexes {
pub fn update_from_height(&mut self, height: Height, indexes: &Vecs) {
self.indexes.height = height;
self.dateindex = DateIndex::try_from(
indexes
.height_to_date_fixed
.into_iter()
.unwrap_get_inner(height),
)
.unwrap();
self.dateindex =
DateIndex::try_from(indexes.height_to_date_fixed.into_iter().unsafe_get(height))
.unwrap();
self.weekindex = WeekIndex::from(self.dateindex);
self.monthindex = MonthIndex::from(self.dateindex);
self.quarterindex = QuarterIndex::from(self.monthindex);

View File

@@ -12,38 +12,38 @@ use log::info;
use vecdb::{Exit, Format};
mod blks;
mod chain;
mod cointime;
mod constants;
// mod chain;
// mod cointime;
// mod constants;
mod fetched;
mod grouped;
// mod grouped;
mod indexes;
mod market;
mod pools;
mod price;
mod stateful;
// mod market;
// mod pools;
// mod price;
// mod stateful;
mod states;
mod traits;
mod utils;
use indexes::Indexes;
pub use pools::*;
// pub use pools::*;
pub use states::PriceToAmount;
use states::*;
#[derive(Clone, Traversable)]
pub struct Computer {
pub chain: chain::Vecs,
pub cointime: cointime::Vecs,
pub constants: constants::Vecs,
pub blks: blks::Vecs,
// pub chain: chain::Vecs,
// pub cointime: cointime::Vecs,
// pub constants: constants::Vecs,
pub fetched: Option<fetched::Vecs>,
pub indexes: indexes::Vecs,
pub market: market::Vecs,
pub pools: pools::Vecs,
pub blks: blks::Vecs,
pub price: Option<price::Vecs>,
pub stateful: stateful::Vecs,
// pub market: market::Vecs,
// pub pools: pools::Vecs,
// pub price: Option<price::Vecs>,
// pub stateful: stateful::Vecs,
}
const VERSION: Version = Version::new(4);
@@ -81,69 +81,69 @@ impl Computer {
Ok((indexes, fetched, blks))
})?;
let (price, constants, market) = thread::scope(|s| -> Result<_> {
let constants_handle = big_thread().spawn_scoped(s, || {
constants::Vecs::forced_import(&computed_path, VERSION, &indexes)
})?;
// let (price, constants, market) = thread::scope(|s| -> Result<_> {
// let constants_handle = big_thread().spawn_scoped(s, || {
// constants::Vecs::forced_import(&computed_path, VERSION, &indexes)
// })?;
let market_handle = big_thread().spawn_scoped(s, || {
market::Vecs::forced_import(&computed_path, VERSION, &indexes)
})?;
// let market_handle = big_thread().spawn_scoped(s, || {
// market::Vecs::forced_import(&computed_path, VERSION, &indexes)
// })?;
let price = fetched
.is_some()
.then(|| price::Vecs::forced_import(&computed_path, VERSION, &indexes).unwrap());
// let price = fetched
// .is_some()
// .then(|| price::Vecs::forced_import(&computed_path, VERSION, &indexes).unwrap());
let constants = constants_handle.join().unwrap()?;
let market = market_handle.join().unwrap()?;
// let constants = constants_handle.join().unwrap()?;
// let market = market_handle.join().unwrap()?;
Ok((price, constants, market))
})?;
// Ok((price, constants, market))
// })?;
let (chain, pools, cointime) = thread::scope(|s| -> Result<_> {
let chain_handle = big_thread().spawn_scoped(s, || {
chain::Vecs::forced_import(
&computed_path,
VERSION,
indexer,
&indexes,
price.as_ref(),
)
})?;
// let (chain, pools, cointime) = thread::scope(|s| -> Result<_> {
// let chain_handle = big_thread().spawn_scoped(s, || {
// chain::Vecs::forced_import(
// &computed_path,
// VERSION,
// indexer,
// &indexes,
// price.as_ref(),
// )
// })?;
let pools_handle = big_thread().spawn_scoped(s, || {
pools::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())
})?;
// let pools_handle = big_thread().spawn_scoped(s, || {
// pools::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())
// })?;
let cointime =
cointime::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())?;
// let cointime =
// cointime::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())?;
let chain = chain_handle.join().unwrap()?;
let pools = pools_handle.join().unwrap()?;
// let chain = chain_handle.join().unwrap()?;
// let pools = pools_handle.join().unwrap()?;
Ok((chain, pools, cointime))
})?;
// Ok((chain, pools, cointime))
// })?;
// Threads inside
let stateful = stateful::Vecs::forced_import(
&computed_path,
VERSION,
Format::Compressed,
&indexes,
price.as_ref(),
)?;
// // Threads inside
// let stateful = stateful::Vecs::forced_import(
// &computed_path,
// VERSION,
// Format::Compressed,
// &indexes,
// price.as_ref(),
// )?;
Ok(Self {
constants,
market,
stateful,
chain,
// constants,
// market,
// stateful,
// chain,
blks,
pools,
cointime,
// pools,
// cointime,
indexes,
fetched,
price,
// price,
})
}
@@ -182,13 +182,6 @@ impl Computer {
Ok(())
});
// let blks = scope.spawn(|| -> Result<()> {
// info!("Computing blks...");
// self.blks
// .compute(indexer, &self.indexes, &starting_indexes, parser, exit)?;
// Ok(())
// });
let chain = scope.spawn(|| -> Result<()> {
info!("Computing chain...");
self.chain.compute(
@@ -207,7 +200,6 @@ impl Computer {
}
constants.join().unwrap()?;
// blks.join().unwrap()?;
chain.join().unwrap()?;
Ok(())
})?;

View File

@@ -3,7 +3,10 @@ use std::{path::Path, thread};
use brk_error::Result;
use brk_traversable::Traversable;
use brk_types::{Date, DateIndex, Dollars, Height, Sats, StoredF32, StoredU16, Version};
use vecdb::{Database, EagerVec, Exit, PAGE_SIZE, StoredIndex, VecIterator};
use vecdb::{
Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE, StoredIndex, VecIterator,
VecIteratorExtended,
};
use crate::{
grouped::{ComputedStandardDeviationVecsFromDateIndex, Source, StandardDeviationVecsOptions},
@@ -1532,7 +1535,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(price, starting_indexes, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -1591,12 +1594,12 @@ impl Vecs {
if prev.is_none() {
let i = i.to_usize();
prev.replace(if i > 0 {
slf.into_iter().unwrap_get_inner_(i - 1)
slf.one_shot_get_any_or_read_(i - 1).unwrap().unwrap()
} else {
StoredU16::default()
});
}
let days = if *high_iter.unwrap_get_inner(i) == ath {
let days = if *high_iter.unsafe_get(i) == ath {
StoredU16::default()
} else {
prev.unwrap() + StoredU16::new(1)
@@ -1622,7 +1625,7 @@ impl Vecs {
if prev.is_none() {
let i = i.to_usize();
prev.replace(if i > 0 {
slf.into_iter().unwrap_get_inner_(i - 1)
slf.one_shot_get_any_or_read_(i - 1)
} else {
StoredU16::ZERO
});

View File

@@ -81,7 +81,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexer, indexes, starting_indexes, chain, price, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -155,47 +155,40 @@ impl Vecs {
.iter()
.skip(min)
.try_for_each(|(height, coinbase_tag)| -> Result<()> {
let txindex = height_to_first_txindex_iter.unwrap_get_inner(height);
let txoutindex = txindex_to_first_txoutindex_iter.unwrap_get_inner(txindex);
let outputcount = txindex_to_output_count_iter.unwrap_get_inner(txindex);
let txindex = height_to_first_txindex_iter.unsafe_get(height);
let txoutindex = txindex_to_first_txoutindex_iter.unsafe_get(txindex);
let outputcount = txindex_to_output_count_iter.unsafe_get(txindex);
let pool = (*txoutindex..(*txoutindex + *outputcount))
.map(TxOutIndex::from)
.find_map(|txoutindex| {
let outputtype = txoutindex_to_outputtype_iter.unwrap_get_inner(txoutindex);
let typeindex = txoutindex_to_typeindex_iter.unwrap_get_inner(txoutindex);
let outputtype = txoutindex_to_outputtype_iter.unsafe_get(txoutindex);
let typeindex = txoutindex_to_typeindex_iter.unsafe_get(txoutindex);
match outputtype {
OutputType::P2PK65 => Some(AddressBytes::from(
p2pk65addressindex_to_p2pk65bytes_iter
.unwrap_get_inner(typeindex.into()),
p2pk65addressindex_to_p2pk65bytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2PK33 => Some(AddressBytes::from(
p2pk33addressindex_to_p2pk33bytes_iter
.unwrap_get_inner(typeindex.into()),
p2pk33addressindex_to_p2pk33bytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2PKH => Some(AddressBytes::from(
p2pkhaddressindex_to_p2pkhbytes_iter
.unwrap_get_inner(typeindex.into()),
p2pkhaddressindex_to_p2pkhbytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2SH => Some(AddressBytes::from(
p2shaddressindex_to_p2shbytes_iter
.unwrap_get_inner(typeindex.into()),
p2shaddressindex_to_p2shbytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2WPKH => Some(AddressBytes::from(
p2wpkhaddressindex_to_p2wpkhbytes_iter
.unwrap_get_inner(typeindex.into()),
p2wpkhaddressindex_to_p2wpkhbytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2WSH => Some(AddressBytes::from(
p2wshaddressindex_to_p2wshbytes_iter
.unwrap_get_inner(typeindex.into()),
p2wshaddressindex_to_p2wshbytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2TR => Some(AddressBytes::from(
p2traddressindex_to_p2trbytes_iter
.unwrap_get_inner(typeindex.into()),
p2traddressindex_to_p2trbytes_iter.unsafe_get(typeindex.into()),
)),
OutputType::P2A => Some(AddressBytes::from(
p2aaddressindex_to_p2abytes_iter.unwrap_get_inner(typeindex.into()),
p2aaddressindex_to_p2abytes_iter.unsafe_get(typeindex.into()),
)),
_ => None,
}

View File

@@ -354,7 +354,7 @@ impl Vecs {
if prev.is_none() {
let i = i.to_usize();
prev.replace(if i > 0 {
slf.into_iter().unwrap_get_inner_(i - 1)
slf.one_shot_get_any_or_read_(i - 1)
} else {
StoredU16::ZERO
});

View File

@@ -8,7 +8,7 @@ use brk_types::{
};
use vecdb::{
AnyIterableVec, AnyStoredVec, AnyVec, Database, EagerVec, Exit, GenericStoredVec, PAGE_SIZE,
RawVec,
RawVec, StoredIndex,
};
use crate::{fetched, grouped::Source};
@@ -343,7 +343,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexes, starting_indexes, fetched, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -387,10 +387,15 @@ impl Vecs {
.min(Height::from(self.height_to_price_ohlc.len()));
fetched
.height_to_price_ohlc_in_cents
.iter_at(index)
.iter()?
.skip(index.to_usize())
.enumerate()
.try_for_each(|(i, v)| -> Result<()> {
self.height_to_price_ohlc
.forced_push_at(i, OHLCDollars::from(v), exit)?;
self.height_to_price_ohlc.forced_push_at(
Height::from(i),
OHLCDollars::from(v),
exit,
)?;
Ok(())
})?;
self.height_to_price_ohlc.safe_flush(exit)?;
@@ -428,10 +433,15 @@ impl Vecs {
.min(DateIndex::from(self.dateindex_to_price_ohlc.len()));
fetched
.dateindex_to_price_ohlc_in_cents
.iter_at(index)
.iter()?
.skip(index.to_usize())
.enumerate()
.try_for_each(|(i, v)| -> Result<()> {
self.dateindex_to_price_ohlc
.forced_push_at(i, OHLCDollars::from(v), exit)?;
self.dateindex_to_price_ohlc.forced_push_at(
DateIndex::from(i),
OHLCDollars::from(v),
exit,
)?;
Ok(())
})?;
self.dateindex_to_price_ohlc.safe_flush(exit)?;
@@ -537,13 +547,15 @@ impl Vecs {
self.timeindexes_to_price_close
.weekindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index.to_usize())
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = weekindex_first_iter.unwrap_get_inner(i);
let high = weekindex_max_iter.unwrap_get_inner(i);
let low = weekindex_min_iter.unwrap_get_inner(i);
let open = weekindex_first_iter.unsafe_get_(i);
let high = weekindex_max_iter.unsafe_get_(i);
let low = weekindex_min_iter.unsafe_get_(i);
self.weekindex_to_price_ohlc.forced_push_at(
i,
WeekIndex::from(i),
OHLCDollars {
open,
high,
@@ -577,11 +589,13 @@ impl Vecs {
self.chainindexes_to_price_close
.difficultyepoch
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = difficultyepoch_first_iter.unwrap_get_inner(i);
let high = difficultyepoch_max_iter.unwrap_get_inner(i);
let low = difficultyepoch_min_iter.unwrap_get_inner(i);
let open = difficultyepoch_first_iter.unsafe_get(i);
let high = difficultyepoch_max_iter.unsafe_get(i);
let low = difficultyepoch_min_iter.unsafe_get(i);
self.difficultyepoch_to_price_ohlc.forced_push_at(
i,
OHLCDollars {
@@ -613,11 +627,13 @@ impl Vecs {
self.timeindexes_to_price_close
.monthindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = monthindex_first_iter.unwrap_get_inner(i);
let high = monthindex_max_iter.unwrap_get_inner(i);
let low = monthindex_min_iter.unwrap_get_inner(i);
let open = monthindex_first_iter.unsafe_get(i);
let high = monthindex_max_iter.unsafe_get(i);
let low = monthindex_min_iter.unsafe_get(i);
self.monthindex_to_price_ohlc.forced_push_at(
i,
OHLCDollars {
@@ -653,11 +669,13 @@ impl Vecs {
self.timeindexes_to_price_close
.quarterindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = quarterindex_first_iter.unwrap_get_inner(i);
let high = quarterindex_max_iter.unwrap_get_inner(i);
let low = quarterindex_min_iter.unwrap_get_inner(i);
let open = quarterindex_first_iter.unsafe_get(i);
let high = quarterindex_max_iter.unsafe_get(i);
let low = quarterindex_min_iter.unsafe_get(i);
self.quarterindex_to_price_ohlc.forced_push_at(
i,
OHLCDollars {
@@ -693,11 +711,13 @@ impl Vecs {
self.timeindexes_to_price_close
.semesterindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = semesterindex_first_iter.unwrap_get_inner(i);
let high = semesterindex_max_iter.unwrap_get_inner(i);
let low = semesterindex_min_iter.unwrap_get_inner(i);
let open = semesterindex_first_iter.unsafe_get(i);
let high = semesterindex_max_iter.unsafe_get(i);
let low = semesterindex_min_iter.unsafe_get(i);
self.semesterindex_to_price_ohlc.forced_push_at(
i,
OHLCDollars {
@@ -725,11 +745,13 @@ impl Vecs {
self.timeindexes_to_price_close
.yearindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = yearindex_first_iter.unwrap_get_inner(i);
let high = yearindex_max_iter.unwrap_get_inner(i);
let low = yearindex_min_iter.unwrap_get_inner(i);
let open = yearindex_first_iter.unsafe_get(i);
let high = yearindex_max_iter.unsafe_get(i);
let low = yearindex_min_iter.unsafe_get(i);
self.yearindex_to_price_ohlc.forced_push_at(
i,
OHLCDollars {
@@ -768,11 +790,13 @@ impl Vecs {
self.timeindexes_to_price_close
.decadeindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
let open = decadeindex_first_iter.unwrap_get_inner(i);
let high = decadeindex_max_iter.unwrap_get_inner(i);
let low = decadeindex_min_iter.unwrap_get_inner(i);
let open = decadeindex_first_iter.unsafe_get(i);
let high = decadeindex_max_iter.unsafe_get(i);
let low = decadeindex_min_iter.unsafe_get(i);
self.decadeindex_to_price_ohlc.forced_push_at(
i,
OHLCDollars {
@@ -883,14 +907,16 @@ impl Vecs {
.min(Height::from(self.height_to_price_ohlc_in_sats.len()));
self.chainindexes_to_price_close_in_sats
.height
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.height_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: height_first_iter.unwrap_get_inner(i),
high: height_max_iter.unwrap_get_inner(i),
low: height_min_iter.unwrap_get_inner(i),
open: height_first_iter.unsafe_get(i),
high: height_max_iter.unsafe_get(i),
low: height_min_iter.unsafe_get(i),
close,
},
exit,
@@ -924,14 +950,16 @@ impl Vecs {
.dateindex
.as_ref()
.unwrap()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.dateindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: dateindex_first_iter.unwrap_get_inner(i),
high: dateindex_max_iter.unwrap_get_inner(i),
low: dateindex_min_iter.unwrap_get_inner(i),
open: dateindex_first_iter.unsafe_get(i),
high: dateindex_max_iter.unsafe_get(i),
low: dateindex_min_iter.unsafe_get(i),
close,
},
exit,
@@ -961,14 +989,16 @@ impl Vecs {
self.timeindexes_to_price_close_in_sats
.weekindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.weekindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: weekindex_first_iter.unwrap_get_inner(i),
high: weekindex_max_iter.unwrap_get_inner(i),
low: weekindex_min_iter.unwrap_get_inner(i),
open: weekindex_first_iter.unsafe_get(i),
high: weekindex_max_iter.unsafe_get(i),
low: weekindex_min_iter.unsafe_get(i),
close,
},
exit,
@@ -998,14 +1028,16 @@ impl Vecs {
self.chainindexes_to_price_close_in_sats
.difficultyepoch
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.difficultyepoch_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: difficultyepoch_first_iter.unwrap_get_inner(i),
high: difficultyepoch_max_iter.unwrap_get_inner(i),
low: difficultyepoch_min_iter.unwrap_get_inner(i),
open: difficultyepoch_first_iter.unsafe_get(i),
high: difficultyepoch_max_iter.unsafe_get(i),
low: difficultyepoch_min_iter.unsafe_get(i),
close,
},
exit,
@@ -1036,14 +1068,16 @@ impl Vecs {
self.timeindexes_to_price_close_in_sats
.monthindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.monthindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: monthindex_first_iter.unwrap_get_inner(i),
high: monthindex_max_iter.unwrap_get_inner(i),
low: monthindex_min_iter.unwrap_get_inner(i),
open: monthindex_first_iter.unsafe_get(i),
high: monthindex_max_iter.unsafe_get(i),
low: monthindex_min_iter.unsafe_get(i),
close,
},
exit,
@@ -1073,14 +1107,16 @@ impl Vecs {
self.timeindexes_to_price_close_in_sats
.quarterindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.quarterindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: quarterindex_first_iter.unwrap_get_inner(i),
high: quarterindex_max_iter.unwrap_get_inner(i),
low: quarterindex_min_iter.unwrap_get_inner(i),
open: quarterindex_first_iter.unsafe_get(i),
high: quarterindex_max_iter.unsafe_get(i),
low: quarterindex_min_iter.unsafe_get(i),
close,
},
exit,
@@ -1110,14 +1146,16 @@ impl Vecs {
self.timeindexes_to_price_close_in_sats
.semesterindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.semesterindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: semesterindex_first_iter.unwrap_get_inner(i),
high: semesterindex_max_iter.unwrap_get_inner(i),
low: semesterindex_min_iter.unwrap_get_inner(i),
open: semesterindex_first_iter.unsafe_get(i),
high: semesterindex_max_iter.unsafe_get(i),
low: semesterindex_min_iter.unsafe_get(i),
close,
},
exit,
@@ -1147,14 +1185,16 @@ impl Vecs {
self.timeindexes_to_price_close_in_sats
.yearindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.yearindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: yearindex_first_iter.unwrap_get_inner(i),
high: yearindex_max_iter.unwrap_get_inner(i),
low: yearindex_min_iter.unwrap_get_inner(i),
open: yearindex_first_iter.unsafe_get(i),
high: yearindex_max_iter.unsafe_get(i),
low: yearindex_min_iter.unsafe_get(i),
close,
},
exit,
@@ -1187,14 +1227,16 @@ impl Vecs {
self.timeindexes_to_price_close_in_sats
.decadeindex
.unwrap_last()
.iter_at(index)
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, close)| -> Result<()> {
self.decadeindex_to_price_ohlc_in_sats.forced_push_at(
i,
OHLCSats {
open: decadeindex_first_iter.unwrap_get_inner(i),
high: decadeindex_max_iter.unwrap_get_inner(i),
low: decadeindex_min_iter.unwrap_get_inner(i),
open: decadeindex_first_iter.unsafe_get(i),
high: decadeindex_max_iter.unsafe_get(i),
low: decadeindex_min_iter.unsafe_get(i),
close,
},
exit,

View File

@@ -112,7 +112,7 @@ impl DynCohortVecs for Vecs {
self.state.as_mut().unwrap().addr_count = *self
.height_to_addr_count
.into_iter()
.unwrap_get_inner(prev_height);
.unsafe_get(prev_height);
}
Ok(starting_height)

View File

@@ -13,34 +13,14 @@ impl From<(&AddressTypeToHeightToAddressCount, Height)> for AddressTypeToAddress
fn from((groups, starting_height): (&AddressTypeToHeightToAddressCount, Height)) -> Self {
if let Some(prev_height) = starting_height.decremented() {
Self(ByAddressType {
p2pk65: groups
.p2pk65
.into_iter()
.unwrap_get_inner(prev_height)
.into(),
p2pk33: groups
.p2pk33
.into_iter()
.unwrap_get_inner(prev_height)
.into(),
p2pkh: groups
.p2pkh
.into_iter()
.unwrap_get_inner(prev_height)
.into(),
p2sh: groups.p2sh.into_iter().unwrap_get_inner(prev_height).into(),
p2wpkh: groups
.p2wpkh
.into_iter()
.unwrap_get_inner(prev_height)
.into(),
p2wsh: groups
.p2wsh
.into_iter()
.unwrap_get_inner(prev_height)
.into(),
p2tr: groups.p2tr.into_iter().unwrap_get_inner(prev_height).into(),
p2a: groups.p2a.into_iter().unwrap_get_inner(prev_height).into(),
p2pk65: groups.p2pk65.into_iter().unsafe_get(prev_height).into(),
p2pk33: groups.p2pk33.into_iter().unsafe_get(prev_height).into(),
p2pkh: groups.p2pkh.into_iter().unsafe_get(prev_height).into(),
p2sh: groups.p2sh.into_iter().unsafe_get(prev_height).into(),
p2wpkh: groups.p2wpkh.into_iter().unsafe_get(prev_height).into(),
p2wsh: groups.p2wsh.into_iter().unsafe_get(prev_height).into(),
p2tr: groups.p2tr.into_iter().unsafe_get(prev_height).into(),
p2a: groups.p2a.into_iter().unsafe_get(prev_height).into(),
})
} else {
Default::default()

View File

@@ -1338,19 +1338,15 @@ impl Vecs {
prev_height = state.import_at_or_before(prev_height)?;
}
state.supply.value = self
.height_to_supply
.into_iter()
.unwrap_get_inner(prev_height);
state.supply.value = self.height_to_supply.into_iter().unsafe_get(prev_height);
state.supply.utxo_count = *self
.height_to_utxo_count
.into_iter()
.unwrap_get_inner(prev_height);
.unsafe_get(prev_height);
if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() {
state.realized.as_mut().unwrap().cap = height_to_realized_cap
.into_iter()
.unwrap_get_inner(prev_height);
state.realized.as_mut().unwrap().cap =
height_to_realized_cap.into_iter().unsafe_get(prev_height);
}
Ok(prev_height.incremented())
@@ -2106,11 +2102,11 @@ impl Vecs {
starting_indexes.dateindex,
&indexes.dateindex_to_first_height,
|(i, height, ..)| {
let count = dateindex_to_height_count_iter.unwrap_get_inner(i);
let count = dateindex_to_height_count_iter.unsafe_get(i);
if count == StoredU64::default() {
unreachable!()
}
let supply = height_to_supply_iter.unwrap_get_inner(height + (*count - 1));
let supply = height_to_supply_iter.unsafe_get(height + (*count - 1));
(i, supply)
},
exit,

View File

@@ -502,7 +502,7 @@ impl Vecs {
exit: &Exit,
) -> Result<()> {
self.compute_(indexer, indexes, chain, price, starting_indexes, exit)?;
self.db.flush_then_punch()?;
self.db.compact()?;
Ok(())
}
@@ -712,10 +712,10 @@ impl Vecs {
.enumerate()
.map(|(height, supply)| {
let height = Height::from(height);
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
let timestamp = height_to_timestamp_fixed_iter.unsafe_get(height);
let price = height_to_price_close_iter
.as_mut()
.map(|i| *i.unwrap_get_inner(height));
.map(|i| *i.unsafe_get(height));
BlockState {
timestamp,
price,
@@ -794,14 +794,14 @@ impl Vecs {
let mut unspendable_supply = if let Some(prev_height) = starting_height.decremented() {
self.height_to_unspendable_supply
.into_iter()
.unwrap_get_inner(prev_height)
.unsafe_get(prev_height)
} else {
Sats::ZERO
};
let mut opreturn_supply = if let Some(prev_height) = starting_height.decremented() {
self.height_to_opreturn_supply
.into_iter()
.unwrap_get_inner(prev_height)
.unsafe_get(prev_height)
} else {
Sats::ZERO
};
@@ -847,20 +847,18 @@ impl Vecs {
v.state.as_mut().unwrap().reset_single_iteration_values()
});
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
let timestamp = height_to_timestamp_fixed_iter.unsafe_get(height);
let price = height_to_price_close_iter
.as_mut()
.map(|i| *i.unwrap_get_inner(height));
let first_txindex = height_to_first_txindex_iter.unwrap_get_inner(height);
.map(|i| *i.unsafe_get(height));
let first_txindex = height_to_first_txindex_iter.unsafe_get(height);
let first_txoutindex = height_to_first_txoutindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.to_usize();
let first_txinindex = height_to_first_txinindex_iter
.unwrap_get_inner(height)
.to_usize();
let tx_count = height_to_tx_count_iter.unwrap_get_inner(height);
let output_count = height_to_output_count_iter.unwrap_get_inner(height);
let input_count = height_to_input_count_iter.unwrap_get_inner(height);
let first_txinindex = height_to_first_txinindex_iter.unsafe_get(height).to_usize();
let tx_count = height_to_tx_count_iter.unsafe_get(height);
let output_count = height_to_output_count_iter.unsafe_get(height);
let input_count = height_to_input_count_iter.unsafe_get(height);
let txoutindex_to_txindex = build_txoutindex_to_txindex(
first_txindex,
@@ -876,28 +874,28 @@ impl Vecs {
let first_addressindexes: ByAddressType<TypeIndex> = ByAddressType {
p2a: height_to_first_p2aaddressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2pk33: height_to_first_p2pk33addressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2pk65: height_to_first_p2pk65addressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2pkh: height_to_first_p2pkhaddressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2sh: height_to_first_p2shaddressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2tr: height_to_first_p2traddressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2wpkh: height_to_first_p2wpkhaddressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
p2wsh: height_to_first_p2wshaddressindex_iter
.unwrap_get_inner(height)
.unsafe_get(height)
.into(),
};
@@ -1211,7 +1209,7 @@ impl Vecs {
.into_iter()
.map(|state| state.value)
.sum::<Sats>()
+ height_to_unclaimed_rewards_iter.unwrap_get_inner(height);
+ height_to_unclaimed_rewards_iter.unsafe_get(height);
opreturn_supply += transacted.by_type.unspendable.opreturn.value;
@@ -1258,16 +1256,16 @@ impl Vecs {
self.addresstype_to_height_to_empty_addr_count
.forced_push_at(height, &addresstype_to_empty_addr_count, exit)?;
let date = height_to_date_fixed_iter.unwrap_get_inner(height);
let date = height_to_date_fixed_iter.unsafe_get(height);
let dateindex = DateIndex::try_from(date).unwrap();
let date_first_height = dateindex_to_first_height_iter.unwrap_get_inner(dateindex);
let date_height_count = dateindex_to_height_count_iter.unwrap_get_inner(dateindex);
let date_first_height = dateindex_to_first_height_iter.unsafe_get(dateindex);
let date_height_count = dateindex_to_height_count_iter.unsafe_get(dateindex);
let is_date_last_height = date_first_height
+ Height::from(date_height_count).decremented().unwrap()
== height;
let date_price = dateindex_to_price_close_iter
.as_mut()
.map(|v| is_date_last_height.then(|| *v.unwrap_get_inner(dateindex)));
.map(|v| is_date_last_height.then(|| *v.unsafe_get(dateindex)));
let dateindex = is_date_last_height.then_some(dateindex);
@@ -2137,7 +2135,7 @@ fn build_txoutindex_to_txindex<'a>(
let block_first_txindex = block_first_txindex.to_usize();
for tx_offset in 0..block_tx_count as usize {
let txindex = TxIndex::from(block_first_txindex + tx_offset);
let output_count = u64::from(txindex_to_output_count.unwrap_get_inner(txindex));
let output_count = u64::from(txindex_to_output_count.unsafe_get(txindex));
for _ in 0..output_count {
vec.push(txindex);
@@ -2157,7 +2155,7 @@ fn build_txinindex_to_txindex<'a>(
let block_first_txindex = block_first_txindex.to_usize();
for tx_offset in 0..block_tx_count as usize {
let txindex = TxIndex::from(block_first_txindex + tx_offset);
let input_count = u64::from(txindex_to_input_count.unwrap_get_inner(txindex));
let input_count = u64::from(txindex_to_input_count.unsafe_get(txindex));
for _ in 0..input_count {
vec.push(txindex);

View File

@@ -39,37 +39,41 @@ impl ComputeDCAStackViaLen for EagerVec<DateIndex, Sats> {
let mut other_iter = closes.iter();
let mut prev = None;
let index = max_from.min(DateIndex::from(self.len()));
closes.iter_at(index).try_for_each(|(i, closes)| {
let price = *closes;
let i_usize = i.to_usize();
if prev.is_none() {
if i_usize == 0 {
prev.replace(Sats::ZERO);
} else {
prev.replace(self.into_iter().unwrap_get_inner_(i_usize - 1));
}
}
let mut stack = Sats::ZERO;
if price != Dollars::ZERO {
stack = prev.unwrap() + Sats::from(Bitcoin::from(DCA_AMOUNT / price));
if i_usize >= len {
let prev_price = *other_iter.unwrap_get_inner_(i_usize - len);
if prev_price != Dollars::ZERO {
stack = stack
.checked_sub(Sats::from(Bitcoin::from(DCA_AMOUNT / prev_price)))
.unwrap();
let index = max_from.to_usize().min(self.len());
closes
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, closes)| {
let price = *closes;
let i_usize = i.to_usize();
if prev.is_none() {
if i_usize == 0 {
prev.replace(Sats::ZERO);
} else {
prev.replace(self.one_shot_get_any_or_read_(i_usize - 1));
}
}
}
prev.replace(stack);
let mut stack = Sats::ZERO;
self.forced_push_at(i, stack, exit)
})?;
if price != Dollars::ZERO {
stack = prev.unwrap() + Sats::from(Bitcoin::from(DCA_AMOUNT / price));
if i_usize >= len {
let prev_price = *other_iter.get_(i_usize - len);
if prev_price != Dollars::ZERO {
stack = stack
.checked_sub(Sats::from(Bitcoin::from(DCA_AMOUNT / prev_price)))
.unwrap();
}
}
}
prev.replace(stack);
self.forced_push_at(i, stack, exit)
})?;
self.safe_flush(exit)?;
@@ -90,27 +94,31 @@ impl ComputeDCAStackViaLen for EagerVec<DateIndex, Sats> {
let mut prev = None;
let index = max_from.min(DateIndex::from(self.len()));
closes.iter_at(index).try_for_each(|(i, closes)| {
let price = *closes;
let i_usize = i.to_usize();
if prev.is_none() {
if i_usize == 0 {
prev.replace(Sats::ZERO);
} else {
prev.replace(self.into_iter().unwrap_get_inner_(i_usize - 1));
closes
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, closes)| {
let price = *closes;
let i_usize = i.to_usize();
if prev.is_none() {
if i_usize == 0 {
prev.replace(Sats::ZERO);
} else {
prev.replace(self.one_shot_get_any_or_read_(i_usize - 1));
}
}
}
let mut stack = Sats::ZERO;
let mut stack = Sats::ZERO;
if price != Dollars::ZERO && i >= from {
stack = prev.unwrap() + Sats::from(Bitcoin::from(DCA_AMOUNT / price));
}
if price != Dollars::ZERO && i >= from {
stack = prev.unwrap() + Sats::from(Bitcoin::from(DCA_AMOUNT / price));
}
prev.replace(stack);
prev.replace(stack);
self.forced_push_at(i, stack, exit)
})?;
self.forced_push_at(i, stack, exit)
})?;
self.safe_flush(exit)?;
@@ -151,17 +159,21 @@ impl ComputeDCAAveragePriceViaLen for EagerVec<DateIndex, Dollars> {
let first_price_date = DateIndex::try_from(Date::new(2010, 7, 12)).unwrap();
stacks.iter_at(index).try_for_each(|(i, stack)| {
let mut avg_price = Dollars::from(f64::NAN);
if i > first_price_date {
avg_price = DCA_AMOUNT
* len
.min(i.to_usize() + 1)
.min(i.checked_sub(first_price_date).unwrap().to_usize() + 1)
/ Bitcoin::from(stack);
}
self.forced_push_at(i, avg_price, exit)
})?;
stacks
.iter()
.skip(index.to_usize())
.enumerate()
.try_for_each(|(i, stack)| {
let mut avg_price = Dollars::from(f64::NAN);
if i > first_price_date {
avg_price = DCA_AMOUNT
* len
.min(i.to_usize() + 1)
.min(i.checked_sub(first_price_date).unwrap().to_usize() + 1)
/ Bitcoin::from(stack);
}
self.forced_push_at(i, avg_price, exit)
})?;
self.safe_flush(exit)?;
@@ -183,13 +195,17 @@ impl ComputeDCAAveragePriceViaLen for EagerVec<DateIndex, Dollars> {
let from_usize = from.to_usize();
stacks.iter_at(index).try_for_each(|(i, stack)| {
let mut avg_price = Dollars::from(f64::NAN);
if i >= from {
avg_price = DCA_AMOUNT * (i.to_usize() + 1 - from_usize) / Bitcoin::from(stack);
}
self.forced_push_at(i, avg_price, exit)
})?;
stacks
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, stack)| {
let mut avg_price = Dollars::from(f64::NAN);
if i >= from {
avg_price = DCA_AMOUNT * (i.to_usize() + 1 - from_usize) / Bitcoin::from(stack);
}
self.forced_push_at(i, avg_price, exit)
})?;
self.safe_flush(exit)?;
@@ -220,10 +236,13 @@ where
)?;
let index = max_from.min(I::from(self.len()));
sats.iter_at(index).try_for_each(|(i, sats)| {
let (i, v) = (i, Bitcoin::from(sats));
self.forced_push_at(i, v, exit)
})?;
sats.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, sats)| {
let (i, v) = (i, Bitcoin::from(sats));
self.forced_push_at(i, v, exit)
})?;
self.safe_flush(exit)?;
@@ -257,11 +276,15 @@ where
let mut price_iter = price.iter();
let index = max_from.min(I::from(self.len()));
bitcoin.iter_at(index).try_for_each(|(i, bitcoin)| {
let dollars = price_iter.unwrap_get_inner(i);
let (i, v) = (i, *dollars * bitcoin);
self.forced_push_at(i, v, exit)
})?;
bitcoin
.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, bitcoin)| {
let dollars = price_iter.unsafe_get(i);
let (i, v) = (i, *dollars * bitcoin);
self.forced_push_at(i, v, exit)
})?;
self.safe_flush(exit)?;
@@ -295,15 +318,18 @@ where
let index = max_from.min(I::from(self.len()));
let mut close_iter = close.iter();
ath.iter_at(index).try_for_each(|(i, ath)| {
if ath == Dollars::ZERO {
self.forced_push_at(i, StoredF32::default(), exit)
} else {
let close = *close_iter.unwrap_get_inner(i);
let drawdown = StoredF32::from((*ath - *close) / *ath * -100.0);
self.forced_push_at(i, drawdown, exit)
}
})?;
ath.iter()
.skip(index)
.enumerate()
.try_for_each(|(i, ath)| {
if ath == Dollars::ZERO {
self.forced_push_at(i, StoredF32::default(), exit)
} else {
let close = *close_iter.unsafe_get(i);
let drawdown = StoredF32::from((*ath - *close) / *ath * -100.0);
self.forced_push_at(i, drawdown, exit)
}
})?;
self.safe_flush(exit)?;