global: snapshot

This commit is contained in:
nym21
2025-09-03 18:17:25 +02:00
parent 1c2afd14dd
commit 3359dfcc29
55 changed files with 3213 additions and 2769 deletions

View File

@@ -288,7 +288,7 @@ impl Vecs {
let txindex_to_fee_rate =
EagerVec::forced_import_compressed(&db, "fee_rate", version + VERSION + Version::ZERO)?;
Ok(Self {
let this = Self {
height_to_interval: EagerVec::forced_import_compressed(
&db,
"interval",
@@ -804,7 +804,16 @@ impl Vecs {
txindex_to_weight,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(

View File

@@ -43,7 +43,7 @@ pub struct Vecs {
pub indexes_to_cointime_price: ComputedVecsFromHeight<Dollars>,
pub indexes_to_cointime_cap: ComputedVecsFromHeight<Dollars>,
pub indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex,
// pub indexes_to_thermo_cap_relative_to_investor_cap: ComputedValueVecsFromHeight,
// pub indexes_to_thermo_cap_rel_to_investor_cap: ComputedValueVecsFromHeight,
}
impl Vecs {
@@ -58,7 +58,7 @@ impl Vecs {
let compute_dollars = price.is_some();
Ok(Self {
let this = Self {
indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import(
&db,
"coinblocks_created",
@@ -247,7 +247,16 @@ impl Vecs {
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
#[allow(clippy::too_many_arguments)]
@@ -597,7 +606,7 @@ impl Vecs {
// The price taken won't be correct for time based indexes
vec.compute_multiply(
starting_indexes.height,
&price.chainindexes_to_close.height,
&price.chainindexes_to_price_close.height,
indexes_to_coinblocks_destroyed.height.as_ref().unwrap(),
exit,
)?;
@@ -613,7 +622,7 @@ impl Vecs {
|vec, _, _, starting_indexes, exit| {
vec.compute_multiply(
starting_indexes.height,
&price.chainindexes_to_close.height,
&price.chainindexes_to_price_close.height,
self.indexes_to_coinblocks_created.height.as_ref().unwrap(),
exit,
)?;
@@ -629,7 +638,7 @@ impl Vecs {
|vec, _, _, starting_indexes, exit| {
vec.compute_multiply(
starting_indexes.height,
&price.chainindexes_to_close.height,
&price.chainindexes_to_price_close.height,
self.indexes_to_coinblocks_stored.height.as_ref().unwrap(),
exit,
)?;

View File

@@ -38,7 +38,7 @@ impl Vecs {
pub fn forced_import(parent: &Path, version: Version, indexes: &indexes::Vecs) -> Result<Self> {
let db = Database::open(&parent.join("constants"))?;
Ok(Self {
let this = Self {
constant_0: ComputedVecsFromHeight::forced_import(
&db,
"constant_0",
@@ -145,7 +145,16 @@ impl Vecs {
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(

View File

@@ -16,30 +16,39 @@ pub struct Vecs {
db: Database,
fetcher: Fetcher,
pub dateindex_to_ohlc_in_cents: RawVec<DateIndex, OHLCCents>,
pub height_to_ohlc_in_cents: RawVec<Height, OHLCCents>,
pub dateindex_to_price_ohlc_in_cents: RawVec<DateIndex, OHLCCents>,
pub height_to_price_ohlc_in_cents: RawVec<Height, OHLCCents>,
}
impl Vecs {
pub fn forced_import(parent: &Path, fetcher: Fetcher, version: Version) -> Result<Self> {
let db = Database::open(&parent.join("fetched"))?;
Ok(Self {
let this = Self {
fetcher,
dateindex_to_ohlc_in_cents: RawVec::forced_import(
dateindex_to_price_ohlc_in_cents: RawVec::forced_import(
&db,
"ohlc_in_cents",
"price_ohlc_in_cents",
version + Version::ZERO,
)?,
height_to_ohlc_in_cents: RawVec::forced_import(
height_to_price_ohlc_in_cents: RawVec::forced_import(
&db,
"ohlc_in_cents",
"price_ohlc_in_cents",
version + Version::ZERO,
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(
@@ -64,12 +73,12 @@ impl Vecs {
let height_to_timestamp = &indexer.vecs.height_to_timestamp;
let index = starting_indexes
.height
.min(Height::from(self.height_to_ohlc_in_cents.len()));
.min(Height::from(self.height_to_price_ohlc_in_cents.len()));
height_to_timestamp
.iter_at(index)
.try_for_each(|(i, v)| -> Result<()> {
let v = v.into_owned();
self.height_to_ohlc_in_cents.forced_push_at(
self.height_to_price_ohlc_in_cents.forced_push_at(
i,
self.fetcher
.get_height(
@@ -84,11 +93,11 @@ impl Vecs {
)?;
Ok(())
})?;
self.height_to_ohlc_in_cents.safe_flush(exit)?;
self.height_to_price_ohlc_in_cents.safe_flush(exit)?;
let index = starting_indexes
.dateindex
.min(DateIndex::from(self.dateindex_to_ohlc_in_cents.len()));
.min(DateIndex::from(self.dateindex_to_price_ohlc_in_cents.len()));
let mut prev = None;
indexes
.dateindex_to_date
@@ -98,7 +107,7 @@ impl Vecs {
if prev.is_none() {
let i = i.unwrap_to_usize();
prev.replace(if i > 0 {
self.dateindex_to_ohlc_in_cents
self.dateindex_to_price_ohlc_in_cents
.into_iter()
.unwrap_get_inner_(i - 1)
} else {
@@ -106,7 +115,8 @@ impl Vecs {
});
}
let ohlc = if i.unwrap_to_usize() + 100 >= self.dateindex_to_ohlc_in_cents.len()
let ohlc = if i.unwrap_to_usize() + 100
>= self.dateindex_to_price_ohlc_in_cents.len()
&& let Ok(mut ohlc) = self.fetcher.get_date(d)
{
let prev_open = *prev.as_ref().unwrap().close;
@@ -120,20 +130,20 @@ impl Vecs {
prev.replace(ohlc.clone());
self.dateindex_to_ohlc_in_cents
self.dateindex_to_price_ohlc_in_cents
.forced_push_at(i, ohlc, exit)?;
Ok(())
})?;
self.dateindex_to_ohlc_in_cents.safe_flush(exit)?;
self.dateindex_to_price_ohlc_in_cents.safe_flush(exit)?;
Ok(())
}
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
vec![
&self.dateindex_to_ohlc_in_cents as &dyn AnyCollectableVec,
&self.height_to_ohlc_in_cents,
&self.dateindex_to_price_ohlc_in_cents as &dyn AnyCollectableVec,
&self.height_to_price_ohlc_in_cents,
]
}
}

View File

@@ -144,7 +144,7 @@ where
Box::new(
EagerVec::forced_import(
db,
&suffix("cum"),
&suffix("cumulative"),
version + VERSION + Version::ZERO,
format,
)

View File

@@ -197,7 +197,7 @@ where
}),
cumulative: options.cumulative.then(|| {
Box::new(LazyVecFrom2::init(
&suffix("cum"),
&suffix("cumulative"),
version + VERSION + Version::ZERO,
source_extra.cumulative.as_ref().unwrap().boxed_clone(),
len_source.clone(),

View File

@@ -447,7 +447,7 @@ impl ComputedVecsFromTxindex<Dollars> {
let starting_index = self.height.starting_index(starting_indexes.height);
let mut close_iter = price.chainindexes_to_close.height.into_iter();
let mut close_iter = price.chainindexes_to_price_close.height.into_iter();
(starting_index.unwrap_to_usize()..indexer.vecs.height_to_weight.len())
.map(Height::from)

View File

@@ -22,18 +22,18 @@ pub struct ComputedRatioVecsFromDateIndex {
pub ratio: ComputedVecsFromDateIndex<StoredF32>,
pub ratio_1w_sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_1m_sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p99: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p98: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p95: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p5: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p2: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p1: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_p99_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p98_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p95_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p5_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p2_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_p1_as_price: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct99: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct98: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct95: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct5: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct2: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct1: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub ratio_pct99_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct98_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct95_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct5_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct2_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_pct1_in_usd: Option<ComputedVecsFromDateIndex<Dollars>>,
pub ratio_sd: Option<ComputedStandardDeviationVecsFromDateIndex>,
pub ratio_4y_sd: Option<ComputedStandardDeviationVecsFromDateIndex>,
@@ -141,10 +141,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p99: extended.then(|| {
ratio_pct99: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p99"),
&format!("{name}_ratio_pct99"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -152,10 +152,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p98: extended.then(|| {
ratio_pct98: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p98"),
&format!("{name}_ratio_pct98"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -163,10 +163,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p95: extended.then(|| {
ratio_pct95: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p95"),
&format!("{name}_ratio_pct95"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -174,10 +174,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p5: extended.then(|| {
ratio_pct5: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p5"),
&format!("{name}_ratio_pct5"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -185,10 +185,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p2: extended.then(|| {
ratio_pct2: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p2"),
&format!("{name}_ratio_pct2"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -196,10 +196,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p1: extended.then(|| {
ratio_pct1: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p1"),
&format!("{name}_ratio_pct1"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -207,10 +207,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p99_as_price: extended.then(|| {
ratio_pct99_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p99_as_price"),
&format!("{name}_ratio_pct99_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -218,10 +218,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p98_as_price: extended.then(|| {
ratio_pct98_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p98_as_price"),
&format!("{name}_ratio_pct98_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -229,10 +229,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p95_as_price: extended.then(|| {
ratio_pct95_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p95_as_price"),
&format!("{name}_ratio_pct95_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -240,10 +240,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p5_as_price: extended.then(|| {
ratio_pct5_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p5_as_price"),
&format!("{name}_ratio_pct5_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -251,10 +251,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p2_as_price: extended.then(|| {
ratio_pct2_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p2_as_price"),
&format!("{name}_ratio_pct2_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -262,10 +262,10 @@ impl ComputedRatioVecsFromDateIndex {
)
.unwrap()
}),
ratio_p1_as_price: extended.then(|| {
ratio_pct1_in_usd: extended.then(|| {
ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_ratio_p1_as_price"),
&format!("{name}_ratio_pct1_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -322,7 +322,7 @@ impl ComputedRatioVecsFromDateIndex {
exit: &Exit,
price_opt: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let closes = price.timeindexes_to_close.dateindex.as_ref().unwrap();
let closes = price.timeindexes_to_price_close.dateindex.as_ref().unwrap();
let price = price_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
@@ -423,42 +423,42 @@ impl ComputedRatioVecsFromDateIndex {
.iter_at(starting_dateindex)
.try_for_each(|(index, ratio)| -> Result<()> {
if index < min_ratio_date {
self.ratio_p5
self.ratio_pct5
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p2
self.ratio_pct2
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p1
self.ratio_pct1
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p95
self.ratio_pct95
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p98
self.ratio_pct98
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, StoredF32::NAN, exit)?;
self.ratio_p99
self.ratio_pct99
.as_mut()
.unwrap()
.dateindex
@@ -470,42 +470,42 @@ impl ComputedRatioVecsFromDateIndex {
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
sorted.insert(pos, ratio);
self.ratio_p1
self.ratio_pct1
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.01), exit)?;
self.ratio_p2
self.ratio_pct2
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.02), exit)?;
self.ratio_p5
self.ratio_pct5
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.05), exit)?;
self.ratio_p95
self.ratio_pct95
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.95), exit)?;
self.ratio_p98
self.ratio_pct98
.as_mut()
.unwrap()
.dateindex
.as_mut()
.unwrap()
.forced_push_at(index, get_percentile(&sorted, 0.98), exit)?;
self.ratio_p99
self.ratio_pct99
.as_mut()
.unwrap()
.dateindex
@@ -521,32 +521,32 @@ impl ComputedRatioVecsFromDateIndex {
.into_iter()
.try_for_each(|v| v.safe_flush(exit))?;
self.ratio_p1.as_mut().unwrap().compute_rest(
self.ratio_pct1.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p2.as_mut().unwrap().compute_rest(
self.ratio_pct2.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p5.as_mut().unwrap().compute_rest(
self.ratio_pct5.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p95.as_mut().unwrap().compute_rest(
self.ratio_pct95.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p98.as_mut().unwrap().compute_rest(
self.ratio_pct98.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
)?;
self.ratio_p99.as_mut().unwrap().compute_rest(
self.ratio_pct99.as_mut().unwrap().compute_rest(
starting_indexes,
exit,
None as Option<&EagerVec<_, _>>,
@@ -556,14 +556,14 @@ impl ComputedRatioVecsFromDateIndex {
std::mem::transmute(&self.price.as_ref().unwrap().dateindex)
});
self.ratio_p99_as_price.as_mut().unwrap().compute_all(
self.ratio_pct99_in_usd.as_mut().unwrap().compute_all(
indexer,
indexes,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
let mut iter = self
.ratio_p99
.ratio_pct99
.as_ref()
.unwrap()
.dateindex
@@ -583,10 +583,10 @@ impl ComputedRatioVecsFromDateIndex {
},
)?;
let compute_as_price =
|as_price: Option<&mut ComputedVecsFromDateIndex<Dollars>>,
let compute_in_usd =
|in_usd: Option<&mut ComputedVecsFromDateIndex<Dollars>>,
source: Option<&ComputedVecsFromDateIndex<StoredF32>>| {
as_price.unwrap().compute_all(
in_usd.unwrap().compute_all(
indexer,
indexes,
starting_indexes,
@@ -607,12 +607,12 @@ impl ComputedRatioVecsFromDateIndex {
)
};
compute_as_price(self.ratio_p1_as_price.as_mut(), self.ratio_p1.as_ref())?;
compute_as_price(self.ratio_p2_as_price.as_mut(), self.ratio_p2.as_ref())?;
compute_as_price(self.ratio_p5_as_price.as_mut(), self.ratio_p5.as_ref())?;
compute_as_price(self.ratio_p95_as_price.as_mut(), self.ratio_p95.as_ref())?;
compute_as_price(self.ratio_p98_as_price.as_mut(), self.ratio_p98.as_ref())?;
compute_as_price(self.ratio_p99_as_price.as_mut(), self.ratio_p99.as_ref())?;
compute_in_usd(self.ratio_pct1_in_usd.as_mut(), self.ratio_pct1.as_ref())?;
compute_in_usd(self.ratio_pct2_in_usd.as_mut(), self.ratio_pct2.as_ref())?;
compute_in_usd(self.ratio_pct5_in_usd.as_mut(), self.ratio_pct5.as_ref())?;
compute_in_usd(self.ratio_pct95_in_usd.as_mut(), self.ratio_pct95.as_ref())?;
compute_in_usd(self.ratio_pct98_in_usd.as_mut(), self.ratio_pct98.as_ref())?;
compute_in_usd(self.ratio_pct99_in_usd.as_mut(), self.ratio_pct99.as_ref())?;
self.ratio_sd.as_mut().unwrap().compute_all(
indexer,
@@ -652,22 +652,22 @@ impl ComputedRatioVecsFromDateIndex {
fn mut_ratio_vecs(&mut self) -> Vec<&mut EagerVec<DateIndex, StoredF32>> {
[
self.ratio_p1
self.ratio_pct1
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p2
self.ratio_pct2
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p5
self.ratio_pct5
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p95
self.ratio_pct95
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p98
self.ratio_pct98
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
self.ratio_p99
self.ratio_pct99
.as_mut()
.map_or(vec![], |v| vec![v.dateindex.as_mut().unwrap()]),
]
@@ -686,22 +686,22 @@ impl ComputedRatioVecsFromDateIndex {
self.ratio_1y_sd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_2y_sd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_4y_sd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p1.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p2.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p5.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p95.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p98.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p99.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p1_as_price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p2_as_price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p5_as_price.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_p95_as_price
self.ratio_pct1.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct2.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct5.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct95.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct98.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct99.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct1_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct2_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct5_in_usd.as_ref().map_or(vec![], |v| v.vecs()),
self.ratio_pct95_in_usd
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.ratio_p98_as_price
self.ratio_pct98_in_usd
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.ratio_p99_as_price
self.ratio_pct99_in_usd
.as_ref()
.map_or(vec![], |v| v.vecs()),
]

View File

@@ -16,7 +16,7 @@ pub struct ComputedStandardDeviationVecsFromDateIndex {
pub sma: Option<ComputedVecsFromDateIndex<StoredF32>>,
pub sd: ComputedVecsFromDateIndex<StoredF32>,
pub _0sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub _0sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p0_5sd: ComputedVecsFromDateIndex<StoredF32>,
pub p1sd: ComputedVecsFromDateIndex<StoredF32>,
pub p1_5sd: ComputedVecsFromDateIndex<StoredF32>,
@@ -29,18 +29,18 @@ pub struct ComputedStandardDeviationVecsFromDateIndex {
pub m2sd: ComputedVecsFromDateIndex<StoredF32>,
pub m2_5sd: ComputedVecsFromDateIndex<StoredF32>,
pub m3sd: ComputedVecsFromDateIndex<StoredF32>,
pub p0_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p1sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p1_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p2sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p2_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m0_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m1sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m1_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m2sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m2_5sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub m3sd_as_price: ComputedVecsFromDateIndex<Dollars>,
pub p0_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p1sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p1_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p2sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p2_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub p3sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m0_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m1sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m1_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m2sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m2_5sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub m3sd_in_usd: ComputedVecsFromDateIndex<Dollars>,
pub zscore: ComputedVecsFromDateIndex<StoredF32>,
}
@@ -175,105 +175,105 @@ impl ComputedStandardDeviationVecsFromDateIndex {
indexes,
options,
)?,
_0sd_as_price: ComputedVecsFromDateIndex::forced_import(
_0sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_0sd_as_price"),
&format!("{name}_0sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p0_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
p0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p0_5sd_as_price"),
&format!("{name}_p0_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p1sd_as_price: ComputedVecsFromDateIndex::forced_import(
p1sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p1sd_as_price"),
&format!("{name}_p1sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p1_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
p1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p1_5sd_as_price"),
&format!("{name}_p1_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p2sd_as_price: ComputedVecsFromDateIndex::forced_import(
p2sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p2sd_as_price"),
&format!("{name}_p2sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p2_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
p2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p2_5sd_as_price"),
&format!("{name}_p2_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
p3sd_as_price: ComputedVecsFromDateIndex::forced_import(
p3sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_p3sd_as_price"),
&format!("{name}_p3sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m0_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
m0_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m0_5sd_as_price"),
&format!("{name}_m0_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m1sd_as_price: ComputedVecsFromDateIndex::forced_import(
m1sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m1sd_as_price"),
&format!("{name}_m1sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m1_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
m1_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m1_5sd_as_price"),
&format!("{name}_m1_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m2sd_as_price: ComputedVecsFromDateIndex::forced_import(
m2sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m2sd_as_price"),
&format!("{name}_m2sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m2_5sd_as_price: ComputedVecsFromDateIndex::forced_import(
m2_5sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m2_5sd_as_price"),
&format!("{name}_m2_5sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
options,
)?,
m3sd_as_price: ComputedVecsFromDateIndex::forced_import(
m3sd_in_usd: ComputedVecsFromDateIndex::forced_import(
db,
&format!("{name}_m3sd_as_price"),
&format!("{name}_m3sd_in_usd"),
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -297,7 +297,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
starting_indexes: &Indexes,
exit: &Exit,
source: &impl CollectableVec<DateIndex, StoredF32>,
source_as_price: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
source_in_usd: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let min_date = DateIndex::try_from(Date::MIN_RATIO).unwrap();
@@ -326,7 +326,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
exit,
sma_opt,
source,
source_as_price,
source_in_usd,
)
}
@@ -339,7 +339,7 @@ impl ComputedStandardDeviationVecsFromDateIndex {
exit: &Exit,
sma_opt: Option<&impl AnyIterableVec<DateIndex, StoredF32>>,
source: &impl CollectableVec<DateIndex, StoredF32>,
source_as_price: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
source_in_usd: Option<&impl AnyIterableVec<DateIndex, Dollars>>,
) -> Result<()> {
let sma = sma_opt.unwrap_or_else(|| unsafe {
std::mem::transmute(&self.sma.as_ref().unwrap().dateindex)
@@ -571,14 +571,14 @@ impl ComputedStandardDeviationVecsFromDateIndex {
},
)?;
let Some(price) = source_as_price else {
let Some(price) = source_in_usd else {
return Ok(());
};
let compute_as_price =
|as_price: &mut ComputedVecsFromDateIndex<Dollars>,
let compute_in_usd =
|in_usd: &mut ComputedVecsFromDateIndex<Dollars>,
mut iter: BoxedVecIterator<DateIndex, StoredF32>| {
as_price.compute_all(
in_usd.compute_all(
indexer,
indexes,
starting_indexes,
@@ -598,53 +598,53 @@ impl ComputedStandardDeviationVecsFromDateIndex {
)
};
compute_as_price(&mut self._0sd_as_price, sma.iter())?;
compute_as_price(
&mut self.p0_5sd_as_price,
compute_in_usd(&mut self._0sd_in_usd, sma.iter())?;
compute_in_usd(
&mut self.p0_5sd_in_usd,
self.p0_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p1sd_as_price,
compute_in_usd(
&mut self.p1sd_in_usd,
self.p1sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p1_5sd_as_price,
compute_in_usd(
&mut self.p1_5sd_in_usd,
self.p1_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p2sd_as_price,
compute_in_usd(
&mut self.p2sd_in_usd,
self.p2sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p2_5sd_as_price,
compute_in_usd(
&mut self.p2_5sd_in_usd,
self.p2_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.p3sd_as_price,
compute_in_usd(
&mut self.p3sd_in_usd,
self.p3sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m0_5sd_as_price,
compute_in_usd(
&mut self.m0_5sd_in_usd,
self.m0_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m1sd_as_price,
compute_in_usd(
&mut self.m1sd_in_usd,
self.m1sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m1_5sd_as_price,
compute_in_usd(
&mut self.m1_5sd_in_usd,
self.m1_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m2sd_as_price,
compute_in_usd(
&mut self.m2sd_in_usd,
self.m2sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m2_5sd_as_price,
compute_in_usd(
&mut self.m2_5sd_in_usd,
self.m2_5sd.dateindex.as_ref().unwrap().iter(),
)?;
compute_as_price(
&mut self.m3sd_as_price,
compute_in_usd(
&mut self.m3sd_in_usd,
self.m3sd.dateindex.as_ref().unwrap().iter(),
)?;
@@ -685,19 +685,19 @@ impl ComputedStandardDeviationVecsFromDateIndex {
self.m2sd.vecs(),
self.m2_5sd.vecs(),
self.m3sd.vecs(),
self._0sd_as_price.vecs(),
self.p0_5sd_as_price.vecs(),
self.p1sd_as_price.vecs(),
self.p1_5sd_as_price.vecs(),
self.p2sd_as_price.vecs(),
self.p2_5sd_as_price.vecs(),
self.p3sd_as_price.vecs(),
self.m0_5sd_as_price.vecs(),
self.m1sd_as_price.vecs(),
self.m1_5sd_as_price.vecs(),
self.m2sd_as_price.vecs(),
self.m2_5sd_as_price.vecs(),
self.m3sd_as_price.vecs(),
self._0sd_in_usd.vecs(),
self.p0_5sd_in_usd.vecs(),
self.p1sd_in_usd.vecs(),
self.p1_5sd_in_usd.vecs(),
self.p2sd_in_usd.vecs(),
self.p2_5sd_in_usd.vecs(),
self.p3sd_in_usd.vecs(),
self.m0_5sd_in_usd.vecs(),
self.m1sd_in_usd.vecs(),
self.m1_5sd_in_usd.vecs(),
self.m2sd_in_usd.vecs(),
self.m2_5sd_in_usd.vecs(),
self.m3sd_in_usd.vecs(),
self.zscore.vecs(),
]
.into_iter()

View File

@@ -138,10 +138,10 @@ impl ComputedValueVecsFromDateIndex {
}
let dateindex_to_bitcoin = self.bitcoin.dateindex.as_ref().unwrap();
let dateindex_to_close = price
let dateindex_to_price_close = price
.as_ref()
.unwrap()
.timeindexes_to_close
.timeindexes_to_price_close
.dateindex
.as_ref()
.unwrap();
@@ -156,7 +156,7 @@ impl ComputedValueVecsFromDateIndex {
v.compute_from_bitcoin(
starting_indexes.dateindex,
dateindex_to_bitcoin,
dateindex_to_close,
dateindex_to_price_close,
exit,
)
},

View File

@@ -139,7 +139,7 @@ impl ComputedValueVecsFromHeight {
}
let height_to_bitcoin = self.bitcoin.height.as_ref().unwrap();
let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height;
let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height;
if let Some(dollars) = self.dollars.as_mut() {
dollars.compute_all(
@@ -151,7 +151,7 @@ impl ComputedValueVecsFromHeight {
v.compute_from_bitcoin(
starting_indexes.height,
height_to_bitcoin,
height_to_close,
height_to_price_close,
exit,
)
},

View File

@@ -78,23 +78,25 @@ impl ComputedValueVecsFromTxindex {
version + VERSION,
bitcoin_txindex.boxed_clone(),
indexes.txindex_to_height.boxed_clone(),
price.chainindexes_to_close.height.boxed_clone(),
price.chainindexes_to_price_close.height.boxed_clone(),
|txindex: TxIndex,
txindex_to_btc_iter,
txindex_to_in_btc_iter,
txindex_to_height_iter,
height_to_close_iter| {
height_to_price_close_iter| {
let txindex = txindex.unwrap_to_usize();
txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| {
let btc = value.into_owned();
txindex_to_height_iter
.next_at(txindex)
.and_then(|(_, value)| {
let height = value.into_owned();
height_to_close_iter
.next_at(height.unwrap_to_usize())
.map(|(_, close)| *close.into_owned() * btc)
})
})
txindex_to_in_btc_iter
.next_at(txindex)
.and_then(|(_, value)| {
let btc = value.into_owned();
txindex_to_height_iter
.next_at(txindex)
.and_then(|(_, value)| {
let height = value.into_owned();
height_to_price_close_iter
.next_at(height.unwrap_to_usize())
.map(|(_, close)| *close.into_owned() * btc)
})
})
},
)
});

View File

@@ -102,13 +102,13 @@ impl ComputedHeightValueVecs {
}
let height_to_bitcoin = &self.bitcoin;
let height_to_close = &price.as_ref().unwrap().chainindexes_to_close.height;
let height_to_price_close = &price.as_ref().unwrap().chainindexes_to_price_close.height;
if let Some(dollars) = self.dollars.as_mut() {
dollars.compute_from_bitcoin(
starting_indexes.height,
height_to_bitcoin,
height_to_close,
height_to_price_close,
exit,
)?;
}

View File

@@ -236,7 +236,7 @@ impl Vecs {
|index, _| Some(index),
);
Ok(Self {
let this = Self {
emptyoutputindex_to_emptyoutputindex,
inputindex_to_inputindex,
opreturnindex_to_opreturnindex,
@@ -472,7 +472,16 @@ impl Vecs {
)?,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
pub fn compute(

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -29,8 +29,8 @@ pub struct Vecs {
pub inner: common::Vecs,
pub height_to_address_count: EagerVec<Height, StoredU64>,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredU64>,
pub height_to_addr_count: EagerVec<Height, StoredU64>,
pub indexes_to_addr_count: ComputedVecsFromHeight<StoredU64>,
}
impl Vecs {
@@ -43,7 +43,7 @@ impl Vecs {
indexes: &indexes::Vecs,
price: Option<&price::Vecs>,
states_path: Option<&Path>,
compute_relative_to_all: bool,
compute_rel_to_all: bool,
) -> Result<Self> {
let compute_dollars = price.is_some();
@@ -58,15 +58,15 @@ impl Vecs {
compute_dollars,
)
}),
height_to_address_count: EagerVec::forced_import(
height_to_addr_count: EagerVec::forced_import(
db,
&suffix("address_count"),
&suffix("addr_count"),
version + VERSION + Version::ZERO,
format,
)?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
indexes_to_addr_count: ComputedVecsFromHeight::forced_import(
db,
&suffix("address_count"),
&suffix("addr_count"),
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -80,7 +80,7 @@ impl Vecs {
indexes,
price,
false,
compute_relative_to_all,
compute_rel_to_all,
false,
)?,
})
@@ -90,7 +90,7 @@ impl Vecs {
impl DynCohortVecs for Vecs {
fn min_height_vecs_len(&self) -> usize {
[
self.height_to_address_count.len(),
self.height_to_addr_count.len(),
self.inner.min_height_vecs_len(),
]
.into_iter()
@@ -110,8 +110,8 @@ impl DynCohortVecs for Vecs {
self.starting_height = Some(starting_height);
if let Some(prev_height) = starting_height.decremented() {
self.state.as_mut().unwrap().address_count = *self
.height_to_address_count
self.state.as_mut().unwrap().addr_count = *self
.height_to_addr_count
.into_iter()
.unwrap_get_inner(prev_height);
}
@@ -120,9 +120,9 @@ impl DynCohortVecs for Vecs {
}
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
self.height_to_address_count
self.height_to_addr_count
.validate_computed_version_or_reset(
base_version + self.height_to_address_count.inner_version(),
base_version + self.height_to_addr_count.inner_version(),
)?;
self.inner.validate_computed_versions(base_version)
@@ -133,9 +133,9 @@ impl DynCohortVecs for Vecs {
return Ok(());
}
self.height_to_address_count.forced_push_at(
self.height_to_addr_count.forced_push_at(
height,
self.state.as_ref().unwrap().address_count.into(),
self.state.as_ref().unwrap().addr_count.into(),
exit,
)?;
@@ -162,7 +162,7 @@ impl DynCohortVecs for Vecs {
}
fn safe_flush_stateful_vecs(&mut self, height: Height, exit: &Exit) -> Result<()> {
self.height_to_address_count.safe_flush(exit)?;
self.height_to_addr_count.safe_flush(exit)?;
self.inner
.safe_flush_stateful_vecs(height, exit, &mut self.state.as_mut().unwrap().inner)
@@ -177,11 +177,11 @@ impl DynCohortVecs for Vecs {
starting_indexes: &Indexes,
exit: &Exit,
) -> Result<()> {
self.indexes_to_address_count.compute_rest(
self.indexes_to_addr_count.compute_rest(
indexes,
starting_indexes,
exit,
Some(&self.height_to_address_count),
Some(&self.height_to_addr_count),
)?;
self.inner
@@ -191,8 +191,8 @@ impl DynCohortVecs for Vecs {
fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
[
self.inner.vecs(),
self.indexes_to_address_count.vecs(),
vec![&self.height_to_address_count],
self.indexes_to_addr_count.vecs(),
vec![&self.height_to_addr_count],
]
.concat()
}
@@ -205,11 +205,11 @@ impl CohortVecs for Vecs {
others: &[&Self],
exit: &Exit,
) -> Result<()> {
self.height_to_address_count.compute_sum_of_others(
self.height_to_addr_count.compute_sum_of_others(
starting_indexes.height,
others
.iter()
.map(|v| &v.height_to_address_count)
.map(|v| &v.height_to_addr_count)
.collect::<Vec<_>>()
.as_slice(),
exit,

File diff suppressed because it is too large Load Diff

View File

@@ -73,20 +73,24 @@ pub struct Vecs {
pub height_to_unspendable_supply: EagerVec<Height, Sats>,
pub height_to_opreturn_supply: EagerVec<Height, Sats>,
pub addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount,
pub addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount,
pub addresstype_to_height_to_addr_count: AddressTypeToHeightToAddressCount,
pub addresstype_to_height_to_empty_addr_count: AddressTypeToHeightToAddressCount,
// ---
// Computed
// ---
pub addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount,
pub addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount,
pub addresstype_to_indexes_to_addr_count: AddressTypeToIndexesToAddressCount,
pub addresstype_to_indexes_to_empty_addr_count: AddressTypeToIndexesToAddressCount,
pub indexes_to_unspendable_supply: ComputedValueVecsFromHeight,
pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight,
pub indexes_to_address_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_empty_address_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_addr_count: ComputedVecsFromHeight<StoredU64>,
pub indexes_to_empty_addr_count: ComputedVecsFromHeight<StoredU64>,
pub height_to_market_cap: Option<LazyVecFrom1<Height, Dollars, Height, Dollars>>,
pub indexes_to_market_cap: Option<ComputedVecsFromDateIndex<Dollars>>,
pub loadedaddressindex_to_loadedaddressindex:
LazyVecFrom1<LoadedAddressIndex, LoadedAddressIndex, LoadedAddressIndex, LoadedAddressData>,
pub emptyaddressindex_to_emptyaddressindex:
LazyVecFrom1<EmptyAddressIndex, EmptyAddressIndex, EmptyAddressIndex, EmptyAddressData>,
}
const SAVED_STAMPED_CHANGES: u16 = 10;
@@ -111,7 +115,28 @@ impl Vecs {
let utxo_cohorts =
utxo_cohorts::Vecs::forced_import(&db, version, format, indexes, price, &states_path)?;
Ok(Self {
let loadedaddressindex_to_loadedaddressdata = RawVec::forced_import_with(
ImportOptions::new(&db, "loadedaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?;
let emptyaddressindex_to_emptyaddressdata = RawVec::forced_import_with(
ImportOptions::new(&db, "emptyaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?;
let loadedaddressindex_to_loadedaddressindex = LazyVecFrom1::init(
"loadedaddressindex",
version + VERSION + Version::ZERO,
loadedaddressindex_to_loadedaddressdata.boxed_clone(),
|index, _| Some(index),
);
let emptyaddressindex_to_emptyaddressindex = LazyVecFrom1::init(
"emptyaddressindex",
version + VERSION + Version::ZERO,
emptyaddressindex_to_emptyaddressdata.boxed_clone(),
|index, _| Some(index),
);
let this = Self {
chain_state: RawVec::forced_import_with(
ImportOptions::new(&db, "chain", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
@@ -145,17 +170,17 @@ impl Vecs {
compute_dollars,
indexes,
)?,
indexes_to_address_count: ComputedVecsFromHeight::forced_import(
indexes_to_addr_count: ComputedVecsFromHeight::forced_import(
&db,
"address_count",
"addr_count",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
VecBuilderOptions::default().add_last(),
)?,
indexes_to_empty_address_count: ComputedVecsFromHeight::forced_import(
indexes_to_empty_addr_count: ComputedVecsFromHeight::forced_import(
&db,
"empty_address_count",
"empty_addr_count",
Source::Compute,
version + VERSION + Version::ZERO,
indexes,
@@ -192,99 +217,99 @@ impl Vecs {
)
.unwrap()
}),
addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount::from(
addresstype_to_height_to_addr_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
p2pk65: EagerVec::forced_import_compressed(
&db,
"p2pk65_address_count",
"p2pk65_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pk33: EagerVec::forced_import_compressed(
&db,
"p2pk33_address_count",
"p2pk33_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pkh: EagerVec::forced_import_compressed(
&db,
"p2pkh_address_count",
"p2pkh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2sh: EagerVec::forced_import_compressed(
&db,
"p2sh_address_count",
"p2sh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wpkh: EagerVec::forced_import_compressed(
&db,
"p2wpkh_address_count",
"p2wpkh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wsh: EagerVec::forced_import_compressed(
&db,
"p2wsh_address_count",
"p2wsh_addr_count",
version + VERSION + Version::ZERO,
)?,
p2tr: EagerVec::forced_import_compressed(
&db,
"p2tr_address_count",
"p2tr_addr_count",
version + VERSION + Version::ZERO,
)?,
p2a: EagerVec::forced_import_compressed(
&db,
"p2a_address_count",
"p2a_addr_count",
version + VERSION + Version::ZERO,
)?,
},
),
addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount::from(
addresstype_to_height_to_empty_addr_count: AddressTypeToHeightToAddressCount::from(
ByAddressType {
p2pk65: EagerVec::forced_import_compressed(
&db,
"p2pk65_empty_address_count",
"p2pk65_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pk33: EagerVec::forced_import_compressed(
&db,
"p2pk33_empty_address_count",
"p2pk33_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2pkh: EagerVec::forced_import_compressed(
&db,
"p2pkh_empty_address_count",
"p2pkh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2sh: EagerVec::forced_import_compressed(
&db,
"p2sh_empty_address_count",
"p2sh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wpkh: EagerVec::forced_import_compressed(
&db,
"p2wpkh_empty_address_count",
"p2wpkh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2wsh: EagerVec::forced_import_compressed(
&db,
"p2wsh_empty_address_count",
"p2wsh_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2tr: EagerVec::forced_import_compressed(
&db,
"p2tr_empty_address_count",
"p2tr_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
p2a: EagerVec::forced_import_compressed(
&db,
"p2a_empty_address_count",
"p2a_empty_addr_count",
version + VERSION + Version::ZERO,
)?,
},
),
addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount::from(
addresstype_to_indexes_to_addr_count: AddressTypeToIndexesToAddressCount::from(
ByAddressType {
p2pk65: ComputedVecsFromHeight::forced_import(
&db,
"p2pk65_address_count",
"p2pk65_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -292,7 +317,7 @@ impl Vecs {
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
&db,
"p2pk33_address_count",
"p2pk33_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -300,7 +325,7 @@ impl Vecs {
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
&db,
"p2pkh_address_count",
"p2pkh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -308,7 +333,7 @@ impl Vecs {
)?,
p2sh: ComputedVecsFromHeight::forced_import(
&db,
"p2sh_address_count",
"p2sh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -316,7 +341,7 @@ impl Vecs {
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
&db,
"p2wpkh_address_count",
"p2wpkh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -324,7 +349,7 @@ impl Vecs {
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
&db,
"p2wsh_address_count",
"p2wsh_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -332,7 +357,7 @@ impl Vecs {
)?,
p2tr: ComputedVecsFromHeight::forced_import(
&db,
"p2tr_address_count",
"p2tr_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -340,7 +365,7 @@ impl Vecs {
)?,
p2a: ComputedVecsFromHeight::forced_import(
&db,
"p2a_address_count",
"p2a_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -348,11 +373,11 @@ impl Vecs {
)?,
},
),
addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount::from(
addresstype_to_indexes_to_empty_addr_count: AddressTypeToIndexesToAddressCount::from(
ByAddressType {
p2pk65: ComputedVecsFromHeight::forced_import(
&db,
"p2pk65_empty_address_count",
"p2pk65_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -360,7 +385,7 @@ impl Vecs {
)?,
p2pk33: ComputedVecsFromHeight::forced_import(
&db,
"p2pk33_empty_address_count",
"p2pk33_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -368,7 +393,7 @@ impl Vecs {
)?,
p2pkh: ComputedVecsFromHeight::forced_import(
&db,
"p2pkh_empty_address_count",
"p2pkh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -376,7 +401,7 @@ impl Vecs {
)?,
p2sh: ComputedVecsFromHeight::forced_import(
&db,
"p2sh_empty_address_count",
"p2sh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -384,7 +409,7 @@ impl Vecs {
)?,
p2wpkh: ComputedVecsFromHeight::forced_import(
&db,
"p2wpkh_empty_address_count",
"p2wpkh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -392,7 +417,7 @@ impl Vecs {
)?,
p2wsh: ComputedVecsFromHeight::forced_import(
&db,
"p2wsh_empty_address_count",
"p2wsh_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -400,7 +425,7 @@ impl Vecs {
)?,
p2tr: ComputedVecsFromHeight::forced_import(
&db,
"p2tr_empty_address_count",
"p2tr_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -408,7 +433,7 @@ impl Vecs {
)?,
p2a: ComputedVecsFromHeight::forced_import(
&db,
"p2a_empty_address_count",
"p2a_empty_addr_count",
Source::None,
version + VERSION + Version::ZERO,
indexes,
@@ -459,17 +484,22 @@ impl Vecs {
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?,
loadedaddressindex_to_loadedaddressdata: RawVec::forced_import_with(
ImportOptions::new(&db, "loadedaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?,
emptyaddressindex_to_emptyaddressdata: RawVec::forced_import_with(
ImportOptions::new(&db, "emptyaddressdata", version + VERSION + Version::ZERO)
.with_saved_stamped_changes(SAVED_STAMPED_CHANGES),
)?,
loadedaddressindex_to_loadedaddressdata,
emptyaddressindex_to_emptyaddressdata,
loadedaddressindex_to_loadedaddressindex,
emptyaddressindex_to_emptyaddressindex,
db,
})
};
this.db.retain_regions(
this.vecs()
.into_iter()
.flat_map(|v| v.region_names())
.collect(),
)?;
Ok(this)
}
#[allow(clippy::too_many_arguments)]
@@ -524,17 +554,17 @@ impl Vecs {
.height
.as_ref()
.unwrap();
let height_to_close = price
let height_to_price_close = price
.as_ref()
.map(|price| &price.chainindexes_to_close.height);
let dateindex_to_close = price
.map(|price| &price.chainindexes_to_price_close.height);
let dateindex_to_price_close = price
.as_ref()
.map(|price| price.timeindexes_to_close.dateindex.as_ref().unwrap());
.map(|price| price.timeindexes_to_price_close.dateindex.as_ref().unwrap());
let height_to_date_fixed = &indexes.height_to_date_fixed;
let dateindex_to_first_height = &indexes.dateindex_to_first_height;
let dateindex_to_height_count = &indexes.dateindex_to_height_count;
let mut height_to_close_iter = height_to_close.as_ref().map(|v| v.into_iter());
let mut height_to_price_close_iter = height_to_price_close.as_ref().map(|v| v.into_iter());
let mut height_to_timestamp_fixed_iter = height_to_timestamp_fixed.into_iter();
let base_version = Version::ZERO
@@ -558,10 +588,10 @@ impl Vecs {
+ outputindex_to_outputtype.version()
+ outputindex_to_typeindex.version()
+ height_to_unclaimed_rewards.version()
+ height_to_close
+ height_to_price_close
.as_ref()
.map_or(Version::ZERO, |v| v.version())
+ dateindex_to_close
+ dateindex_to_price_close
.as_ref()
.map_or(Version::ZERO, |v| v.version())
+ height_to_date_fixed.version()
@@ -657,12 +687,14 @@ impl Vecs {
.rollback_before(starting_height.into())?,
]
.into_iter()
.enumerate()
.map(|(i, s)| {
let h = Height::from(s).incremented();
dbg!((i, s, h));
h
})
// .enumerate()
// .map(|(i, s)| {
// let h = Height::from(s).incremented();
// // dbg!((i, s, h));
// h
// })
.map(Height::from)
.map(Height::incremented)
.collect::<BTreeSet<Height>>();
if set.len() == 1 {
@@ -709,7 +741,7 @@ impl Vecs {
.map(|(height, supply)| {
let height = Height::from(height);
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
let price = height_to_close_iter
let price = height_to_price_close_iter
.as_mut()
.map(|i| *i.unwrap_get_inner(height));
BlockState {
@@ -780,13 +812,14 @@ impl Vecs {
let mut height_to_output_count_iter = height_to_output_count.into_iter();
let mut height_to_input_count_iter = height_to_input_count.into_iter();
let mut height_to_unclaimed_rewards_iter = height_to_unclaimed_rewards.into_iter();
let mut dateindex_to_close_iter = dateindex_to_close.as_ref().map(|v| v.into_iter());
let mut dateindex_to_price_close_iter =
dateindex_to_price_close.as_ref().map(|v| v.into_iter());
let mut height_to_date_fixed_iter = height_to_date_fixed.into_iter();
let mut dateindex_to_first_height_iter = dateindex_to_first_height.into_iter();
let mut dateindex_to_height_count_iter = dateindex_to_height_count.into_iter();
let height_to_close_vec =
height_to_close.map(|height_to_close| height_to_close.collect().unwrap());
let height_to_price_close_vec = height_to_price_close
.map(|height_to_price_close| height_to_price_close.collect().unwrap());
let height_to_timestamp_fixed_vec = height_to_timestamp_fixed.collect().unwrap();
let outputindex_range_to_height = RangeMap::from(height_to_first_outputindex);
@@ -805,12 +838,12 @@ impl Vecs {
} else {
Sats::ZERO
};
let mut addresstype_to_address_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_address_count,
let mut addresstype_to_addr_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_addr_count,
starting_height,
));
let mut addresstype_to_empty_address_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_empty_address_count,
let mut addresstype_to_empty_addr_count = AddressTypeToAddressCount::from((
&self.addresstype_to_height_to_empty_addr_count,
starting_height,
));
@@ -855,7 +888,7 @@ impl Vecs {
.for_each(|(_, v)| v.state.as_mut().unwrap().reset_single_iteration_values());
let timestamp = height_to_timestamp_fixed_iter.unwrap_get_inner(height);
let price = height_to_close_iter
let price = height_to_price_close_iter
.as_mut()
.map(|i| *i.unwrap_get_inner(height));
let first_outputindex = height_to_first_outputindex_iter
@@ -1123,8 +1156,8 @@ impl Vecs {
&mut addresstype_to_typeindex_to_loadedaddressdata,
&mut addresstype_to_typeindex_to_emptyaddressdata,
price,
&mut addresstype_to_address_count,
&mut addresstype_to_empty_address_count,
&mut addresstype_to_addr_count,
&mut addresstype_to_empty_addr_count,
&mut stored_or_new_addresstype_to_typeindex_to_addressdatawithsource,
);
@@ -1134,9 +1167,9 @@ impl Vecs {
&mut addresstype_to_typeindex_to_loadedaddressdata,
&mut addresstype_to_typeindex_to_emptyaddressdata,
price,
&mut addresstype_to_address_count,
&mut addresstype_to_empty_address_count,
height_to_close_vec.as_ref(),
&mut addresstype_to_addr_count,
&mut addresstype_to_empty_addr_count,
height_to_price_close_vec.as_ref(),
&height_to_timestamp_fixed_vec,
height,
timestamp,
@@ -1195,14 +1228,14 @@ impl Vecs {
self.height_to_opreturn_supply
.forced_push_at(height, opreturn_supply, exit)?;
self.addresstype_to_height_to_address_count.forced_push_at(
self.addresstype_to_height_to_addr_count.forced_push_at(
height,
&addresstype_to_address_count,
&addresstype_to_addr_count,
exit,
)?;
self.addresstype_to_height_to_empty_address_count
.forced_push_at(height, &addresstype_to_empty_address_count, exit)?;
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 dateindex = DateIndex::try_from(date).unwrap();
@@ -1213,7 +1246,7 @@ impl Vecs {
let is_date_last_height = date_first_height
+ Height::from(date_height_count).decremented().unwrap()
== height;
let date_price = dateindex_to_close_iter
let date_price = dateindex_to_price_close_iter
.as_mut()
.map(|v| is_date_last_height.then(|| *v.unwrap_get_inner(dateindex)));
@@ -1276,7 +1309,7 @@ impl Vecs {
info!("Computing rest part 1...");
self.indexes_to_address_count.compute_all(
self.indexes_to_addr_count.compute_all(
indexer,
indexes,
starting_indexes,
@@ -1285,7 +1318,7 @@ impl Vecs {
v.compute_sum_of_others(
starting_indexes.height,
&self
.addresstype_to_height_to_address_count
.addresstype_to_height_to_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v)
@@ -1296,7 +1329,7 @@ impl Vecs {
},
)?;
self.indexes_to_empty_address_count.compute_all(
self.indexes_to_empty_addr_count.compute_all(
indexer,
indexes,
starting_indexes,
@@ -1305,7 +1338,7 @@ impl Vecs {
v.compute_sum_of_others(
starting_indexes.height,
&self
.addresstype_to_height_to_empty_address_count
.addresstype_to_height_to_empty_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v)
@@ -1333,18 +1366,18 @@ impl Vecs {
Some(&self.height_to_opreturn_supply),
)?;
self.addresstype_to_indexes_to_address_count.compute(
self.addresstype_to_indexes_to_addr_count.compute(
indexes,
starting_indexes,
exit,
&self.addresstype_to_height_to_address_count,
&self.addresstype_to_height_to_addr_count,
)?;
self.addresstype_to_indexes_to_empty_address_count.compute(
self.addresstype_to_indexes_to_empty_addr_count.compute(
indexes,
starting_indexes,
exit,
&self.addresstype_to_height_to_empty_address_count,
&self.addresstype_to_height_to_empty_addr_count,
)?;
self.utxo_cohorts
@@ -1643,11 +1676,11 @@ impl Vecs {
.try_for_each(|(_, v)| v.safe_flush_stateful_vecs(height, exit))?;
self.height_to_unspendable_supply.safe_flush(exit)?;
self.height_to_opreturn_supply.safe_flush(exit)?;
self.addresstype_to_height_to_address_count
self.addresstype_to_height_to_addr_count
.as_mut_vec()
.into_iter()
.try_for_each(|v| v.safe_flush(exit))?;
self.addresstype_to_height_to_empty_address_count
self.addresstype_to_height_to_empty_addr_count
.as_mut_vec()
.into_iter()
.try_for_each(|v| v.safe_flush(exit))?;
@@ -1845,19 +1878,19 @@ impl Vecs {
.collect::<Vec<_>>(),
self.indexes_to_unspendable_supply.vecs(),
self.indexes_to_opreturn_supply.vecs(),
self.indexes_to_address_count.vecs(),
self.indexes_to_empty_address_count.vecs(),
self.addresstype_to_indexes_to_address_count.vecs(),
self.indexes_to_addr_count.vecs(),
self.indexes_to_empty_addr_count.vecs(),
self.addresstype_to_indexes_to_addr_count.vecs(),
self.indexes_to_market_cap
.as_ref()
.map_or(vec![], |v| v.vecs()),
self.addresstype_to_indexes_to_empty_address_count.vecs(),
self.addresstype_to_height_to_address_count
self.addresstype_to_indexes_to_empty_addr_count.vecs(),
self.addresstype_to_height_to_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v as &dyn AnyCollectableVec)
.collect::<Vec<_>>(),
self.addresstype_to_height_to_empty_address_count
self.addresstype_to_height_to_empty_addr_count
.as_typed_vec()
.into_iter()
.map(|(_, v)| v as &dyn AnyCollectableVec)
@@ -1868,6 +1901,19 @@ impl Vecs {
vec![
&self.height_to_unspendable_supply,
&self.height_to_opreturn_supply,
&self.chain_state,
&self.p2pk33addressindex_to_anyaddressindex,
&self.p2pk65addressindex_to_anyaddressindex,
&self.p2pkhaddressindex_to_anyaddressindex,
&self.p2shaddressindex_to_anyaddressindex,
&self.p2traddressindex_to_anyaddressindex,
&self.p2wpkhaddressindex_to_anyaddressindex,
&self.p2wshaddressindex_to_anyaddressindex,
&self.p2aaddressindex_to_anyaddressindex,
&self.loadedaddressindex_to_loadedaddressdata,
&self.emptyaddressindex_to_emptyaddressdata,
&self.loadedaddressindex_to_loadedaddressindex,
&self.emptyaddressindex_to_emptyaddressindex,
],
]
.into_iter()
@@ -1888,8 +1934,8 @@ impl AddressTypeToVec<(TypeIndex, Sats)> {
WithAddressDataSource<EmptyAddressData>,
>,
price: Option<Dollars>,
addresstype_to_address_count: &mut ByAddressType<u64>,
addresstype_to_empty_address_count: &mut ByAddressType<u64>,
addresstype_to_addr_count: &mut ByAddressType<u64>,
addresstype_to_empty_addr_count: &mut ByAddressType<u64>,
stored_or_new_addresstype_to_typeindex_to_addressdatawithsource: &mut AddressTypeToTypeIndexTree<
WithAddressDataSource<LoadedAddressData>,
>,
@@ -1926,9 +1972,9 @@ impl AddressTypeToVec<(TypeIndex, Sats)> {
});
if is_new || from_any_empty {
(*addresstype_to_address_count.get_mut(_type).unwrap()) += 1;
(*addresstype_to_addr_count.get_mut(_type).unwrap()) += 1;
if from_any_empty {
(*addresstype_to_empty_address_count.get_mut(_type).unwrap()) -= 1;
(*addresstype_to_empty_addr_count.get_mut(_type).unwrap()) -= 1;
}
}
@@ -1988,9 +2034,9 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
WithAddressDataSource<EmptyAddressData>,
>,
price: Option<Dollars>,
addresstype_to_address_count: &mut ByAddressType<u64>,
addresstype_to_empty_address_count: &mut ByAddressType<u64>,
height_to_close_vec: Option<&Vec<brk_structs::Close<Dollars>>>,
addresstype_to_addr_count: &mut ByAddressType<u64>,
addresstype_to_empty_addr_count: &mut ByAddressType<u64>,
height_to_price_close_vec: Option<&Vec<brk_structs::Close<Dollars>>>,
height_to_timestamp_fixed_vec: &[Timestamp],
height: Height,
timestamp: Timestamp,
@@ -1999,7 +2045,7 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
>,
) -> Result<()> {
self.0.into_iter().try_for_each(|(prev_height, mut v)| {
let prev_price = height_to_close_vec
let prev_price = height_to_price_close_vec
.as_ref()
.map(|v| **v.get(prev_height.unwrap_to_usize()).unwrap());
@@ -2039,7 +2085,7 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
let amount = prev_amount.checked_sub(value).unwrap();
let will_be_empty = addressdata.outputs_len - 1 == 0;
let will_be_empty = addressdata.utxos - 1 == 0;
if will_be_empty
|| vecs.amount_range.get_mut(amount).0.clone()
@@ -2060,8 +2106,8 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
unreachable!()
}
(*addresstype_to_address_count.get_mut(_type).unwrap()) -= 1;
(*addresstype_to_empty_address_count.get_mut(_type).unwrap()) += 1;
(*addresstype_to_addr_count.get_mut(_type).unwrap()) -= 1;
(*addresstype_to_empty_addr_count.get_mut(_type).unwrap()) += 1;
let addressdata =
typeindex_to_loadedaddressdata.remove(&type_index).unwrap();

View File

@@ -33,7 +33,7 @@ impl Vecs {
price: Option<&price::Vecs>,
states_path: Option<&Path>,
extended: bool,
compute_relative_to_all: bool,
compute_rel_to_all: bool,
compute_adjusted: bool,
) -> Result<Self> {
let compute_dollars = price.is_some();
@@ -57,7 +57,7 @@ impl Vecs {
indexes,
price,
extended,
compute_relative_to_all,
compute_rel_to_all,
compute_adjusted,
)?,
})

View File

@@ -49,7 +49,7 @@ impl Vecs {
term: ByTerm {
short: utxo_cohort::Vecs::forced_import(
db,
Some("short_term_holders"),
Some("sth"),
format,
version + VERSION + Version::ZERO,
indexes,
@@ -61,7 +61,7 @@ impl Vecs {
)?,
long: utxo_cohort::Vecs::forced_import(
db,
Some("long_term_holders"),
Some("lth"),
format,
version + VERSION + Version::ZERO,
indexes,

View File

@@ -9,14 +9,14 @@ use super::CohortState;
#[derive(Clone)]
pub struct AddressCohortState {
pub address_count: u64,
pub addr_count: u64,
pub inner: CohortState,
}
impl AddressCohortState {
pub fn new(path: &Path, name: &str, compute_dollars: bool) -> Self {
Self {
address_count: 0,
addr_count: 0,
inner: CohortState::new(path, name, compute_dollars),
}
}
@@ -44,14 +44,14 @@ impl AddressCohortState {
let prev_realized_price = compute_price.then(|| addressdata.realized_price());
let prev_supply_state = SupplyState {
utxos: addressdata.outputs_len as u64,
utxos: addressdata.utxos as u64,
value: addressdata.amount(),
};
addressdata.send(value, prev_price)?;
let supply_state = SupplyState {
utxos: addressdata.outputs_len as u64,
utxos: addressdata.utxos as u64,
value: addressdata.amount(),
};
@@ -79,14 +79,14 @@ impl AddressCohortState {
let prev_realized_price = compute_price.then(|| address_data.realized_price());
let prev_supply_state = SupplyState {
utxos: address_data.outputs_len as u64,
utxos: address_data.utxos as u64,
value: address_data.amount(),
};
address_data.receive(value, price);
let supply_state = SupplyState {
utxos: address_data.outputs_len as u64,
utxos: address_data.utxos as u64,
value: address_data.amount(),
};
@@ -99,7 +99,7 @@ impl AddressCohortState {
}
pub fn add(&mut self, addressdata: &LoadedAddressData) {
self.address_count += 1;
self.addr_count += 1;
self.inner.increment_(
&addressdata.into(),
addressdata.realized_cap,
@@ -108,7 +108,7 @@ impl AddressCohortState {
}
pub fn subtract(&mut self, addressdata: &LoadedAddressData) {
self.address_count = self.address_count.checked_sub(1).unwrap();
self.addr_count = self.addr_count.checked_sub(1).unwrap();
self.inner.decrement_(
&addressdata.into(),
addressdata.realized_cap,

View File

@@ -283,7 +283,7 @@ impl CohortState {
}
}
Ordering::Equal => {
state.supply_even += sats;
state.supply_breakeven += sats;
}
}
};

View File

@@ -43,7 +43,7 @@ impl SubAssign<&SupplyState> for SupplyState {
impl From<&LoadedAddressData> for SupplyState {
fn from(value: &LoadedAddressData) -> Self {
Self {
utxos: value.outputs_len as u64,
utxos: value.utxos as u64,
value: value.amount(),
}
}

View File

@@ -3,7 +3,7 @@ use brk_structs::{Dollars, Sats};
#[derive(Debug, Default, Clone)]
pub struct UnrealizedState {
pub supply_in_profit: Sats,
pub supply_even: Sats,
pub supply_breakeven: Sats,
pub supply_in_loss: Sats,
pub unrealized_profit: Dollars,
pub unrealized_loss: Dollars,
@@ -12,7 +12,7 @@ pub struct UnrealizedState {
impl UnrealizedState {
pub const NAN: Self = Self {
supply_in_profit: Sats::ZERO,
supply_even: Sats::ZERO,
supply_breakeven: Sats::ZERO,
supply_in_loss: Sats::ZERO,
unrealized_profit: Dollars::NAN,
unrealized_loss: Dollars::NAN,
@@ -20,7 +20,7 @@ impl UnrealizedState {
pub const ZERO: Self = Self {
supply_in_profit: Sats::ZERO,
supply_even: Sats::ZERO,
supply_breakeven: Sats::ZERO,
supply_in_loss: Sats::ZERO,
unrealized_profit: Dollars::ZERO,
unrealized_loss: Dollars::ZERO,