global: utxos part 8

This commit is contained in:
nym21
2025-05-25 00:27:18 +02:00
parent 4ab10670c9
commit 4217c22ff6
14 changed files with 1863 additions and 814 deletions
@@ -36,7 +36,7 @@ use super::{BlockState, Transacted};
pub struct Outputs<T> {
pub all: T,
pub by_term: OutputsByTerm<T>,
// pub by_up_to: OutputsByUpTo<T>,
pub by_up_to: OutputsByUpTo<T>,
pub by_from: OutputsByFrom<T>,
pub by_range: OutputsByRange<T>,
pub by_epoch: OutputsByEpoch<T>,
@@ -51,7 +51,7 @@ impl<T> Outputs<T> {
[&mut self.all]
.into_iter()
.chain(self.by_term.as_mut_vec())
// .chain(self.by_up_to.as_mut_vec())
.chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
.chain(self.by_range.as_mut_vec())
.chain(self.by_epoch.as_mut_vec())
@@ -73,7 +73,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
self.by_term
.as_mut_vec()
.into_par_iter()
// .chain(self.by_up_to.as_mut_vec())
.chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
.chain(self.by_range.as_mut_vec())
.for_each(|(filter, v)| {
@@ -126,7 +126,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
.by_term
.as_mut_vec()
.into_iter()
// .chain(self.by_up_to.as_mut_vec())
.chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
.chain(self.by_range.as_mut_vec())
.chain(self.by_epoch.as_mut_vec())
@@ -187,7 +187,7 @@ impl Outputs<(OutputFilter, vecs::utxos::cohort::Vecs)> {
// Skip from and range as can't receive in the past
]
.into_iter()
// .chain(self.by_up_to.as_mut_vec().map(|(_, v)| v))
.chain(self.by_up_to.as_mut_vec().map(|(_, v)| v))
.for_each(|v| {
v.state.increment(&supply_state, price);
});
@@ -222,7 +222,7 @@ impl<T> Outputs<(OutputFilter, T)> {
[&self.all.1]
.into_iter()
.chain(self.by_term.vecs())
// .chain(self.by_up_to.vecs())
.chain(self.by_up_to.vecs())
.chain(self.by_from.vecs())
.chain(self.by_range.vecs())
.chain(self.by_epoch.vecs())
@@ -238,7 +238,7 @@ impl<T> From<Outputs<T>> for Outputs<(OutputFilter, T)> {
Self {
all: (OutputFilter::All, value.all),
by_term: OutputsByTerm::from(value.by_term),
// by_up_to: OutputsByUpTo::from(value.by_up_to),
by_up_to: OutputsByUpTo::from(value.by_up_to),
by_from: OutputsByFrom::from(value.by_from),
by_range: OutputsByRange::from(value.by_range),
by_epoch: OutputsByEpoch::from(value.by_epoch),
+2 -2
View File
@@ -117,7 +117,7 @@ impl Vecs {
path,
&suffix("realized_price"),
true,
VERSION + Version::ZERO + version,
VERSION + Version::new(2) + version,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)
@@ -128,7 +128,7 @@ impl Vecs {
path,
&suffix("realized_price"),
false,
VERSION + Version::ZERO,
VERSION + Version::new(2) + version,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)
+155 -149
View File
@@ -12,7 +12,7 @@ use rayon::prelude::*;
use crate::states::{
BlockState, OutputFilter, Outputs, OutputsByEpoch, OutputsByFrom, OutputsByRange,
OutputsBySize, OutputsBySpendableType, OutputsByTerm, SupplyState, Transacted,
OutputsBySize, OutputsBySpendableType, OutputsByTerm, OutputsByUpTo, SupplyState, Transacted,
};
use super::{
@@ -101,152 +101,152 @@ impl Vecs {
fetched,
)?,
},
// by_up_to: OutputsByUpTo {
// _1d: cohort::Vecs::forced_import(
// path,
// Some("up_to_1d"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _1w: cohort::Vecs::forced_import(
// path,
// Some("up_to_1w"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _1m: cohort::Vecs::forced_import(
// path,
// Some("up_to_1m"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _2m: cohort::Vecs::forced_import(
// path,
// Some("up_to_2m"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _3m: cohort::Vecs::forced_import(
// path,
// Some("up_to_3m"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _4m: cohort::Vecs::forced_import(
// path,
// Some("up_to_4m"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _5m: cohort::Vecs::forced_import(
// path,
// Some("up_to_5m"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _6m: cohort::Vecs::forced_import(
// path,
// Some("up_to_6m"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _1y: cohort::Vecs::forced_import(
// path,
// Some("up_to_1y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _2y: cohort::Vecs::forced_import(
// path,
// Some("up_to_2y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _3y: cohort::Vecs::forced_import(
// path,
// Some("up_to_3y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _4y: cohort::Vecs::forced_import(
// path,
// Some("up_to_4y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _5y: cohort::Vecs::forced_import(
// path,
// Some("up_to_5y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _6y: cohort::Vecs::forced_import(
// path,
// Some("up_to_6y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _7y: cohort::Vecs::forced_import(
// path,
// Some("up_to_7y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _8y: cohort::Vecs::forced_import(
// path,
// Some("up_to_8y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _10y: cohort::Vecs::forced_import(
// path,
// Some("up_to_10y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// _15y: cohort::Vecs::forced_import(
// path,
// Some("up_to_15y"),
// _computation,
// compressed,
// VERSION + Version::ZERO,
// fetched,
// )?,
// },
by_up_to: OutputsByUpTo {
_1d: cohort::Vecs::forced_import(
path,
Some("up_to_1d"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_1w: cohort::Vecs::forced_import(
path,
Some("up_to_1w"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_1m: cohort::Vecs::forced_import(
path,
Some("up_to_1m"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_2m: cohort::Vecs::forced_import(
path,
Some("up_to_2m"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_3m: cohort::Vecs::forced_import(
path,
Some("up_to_3m"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_4m: cohort::Vecs::forced_import(
path,
Some("up_to_4m"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_5m: cohort::Vecs::forced_import(
path,
Some("up_to_5m"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_6m: cohort::Vecs::forced_import(
path,
Some("up_to_6m"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_1y: cohort::Vecs::forced_import(
path,
Some("up_to_1y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_2y: cohort::Vecs::forced_import(
path,
Some("up_to_2y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_3y: cohort::Vecs::forced_import(
path,
Some("up_to_3y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_4y: cohort::Vecs::forced_import(
path,
Some("up_to_4y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_5y: cohort::Vecs::forced_import(
path,
Some("up_to_5y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_6y: cohort::Vecs::forced_import(
path,
Some("up_to_6y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_7y: cohort::Vecs::forced_import(
path,
Some("up_to_7y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_8y: cohort::Vecs::forced_import(
path,
Some("up_to_8y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_10y: cohort::Vecs::forced_import(
path,
Some("up_to_10y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
_15y: cohort::Vecs::forced_import(
path,
Some("up_to_15y"),
_computation,
compressed,
VERSION + Version::ZERO,
fetched,
)?,
},
by_from: OutputsByFrom {
_1d: cohort::Vecs::forced_import(
path,
@@ -1191,14 +1191,18 @@ impl Vecs {
let mut flat_vecs_ = self.utxos_vecs.as_mut_vec();
info!("Flushing...");
// Flush rest of values
flat_vecs_
.iter_mut()
.par_iter_mut()
.try_for_each(|(_, v)| v.safe_flush_height_vecs(exit))?;
self.height_to_unspendable_supply.safe_flush(exit)?;
info!("Computing rest...");
// Compute other vecs from height vecs
flat_vecs_.iter_mut().try_for_each(|(_, v)| {
flat_vecs_.par_iter_mut().try_for_each(|(_, v)| {
v.compute_rest(indexer, indexes, fetched, starting_indexes, exit)
})?;
self.indexes_to_unspendable_supply.compute_rest(
@@ -1210,6 +1214,8 @@ impl Vecs {
Some(&self.height_to_unspendable_supply),
)?;
info!("Chain state...");
// Save chain state
self.chain_state.truncate_if_needed(Height::ZERO)?;
mem::take(&mut chain_state)
+53 -14
View File
@@ -1,4 +1,5 @@
use std::{
cmp::Ordering,
f64,
ops::{Add, AddAssign, Div, Mul},
};
@@ -88,35 +89,55 @@ impl Add for Dollars {
impl Div<Dollars> for Dollars {
type Output = StoredF64;
fn div(self, rhs: Dollars) -> Self::Output {
StoredF64::from(self.0 / rhs.0)
if self.is_nan() {
StoredF64::from(self.0)
} else {
StoredF64::from(self.0 / rhs.0)
}
}
}
impl Div<Close<Dollars>> for Dollars {
type Output = StoredF64;
fn div(self, rhs: Close<Dollars>) -> Self::Output {
StoredF64::from(self.0 / rhs.0)
if self.is_nan() {
StoredF64::from(self.0)
} else {
StoredF64::from(self.0 / rhs.0)
}
}
}
impl Div<Dollars> for Close<Dollars> {
type Output = StoredF64;
fn div(self, rhs: Dollars) -> Self::Output {
StoredF64::from(self.0 / rhs.0)
if self.is_nan() {
StoredF64::from(self.0)
} else {
StoredF64::from(self.0 / rhs.0)
}
}
}
impl Div<usize> for Dollars {
type Output = Self;
fn div(self, rhs: usize) -> Self::Output {
Self::from(Cents::from(self) / rhs)
if self.is_nan() {
self
} else {
Self::from(Cents::from(self) / rhs)
}
}
}
impl Div<Bitcoin> for Dollars {
type Output = Self;
fn div(self, rhs: Bitcoin) -> Self::Output {
Self(f64::from(self) / f64::from(rhs))
if self.is_nan() {
self
} else {
Self(f64::from(self) / f64::from(rhs))
}
}
}
@@ -125,16 +146,26 @@ impl Eq for Dollars {}
#[allow(clippy::derive_ord_xor_partial_ord)]
impl Ord for Dollars {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.partial_cmp(&other.0).unwrap()
match (self.0.is_nan(), other.0.is_nan()) {
(true, true) => Ordering::Equal,
(true, false) => Ordering::Less,
(false, true) => Ordering::Greater,
(false, false) => self.0.partial_cmp(&other.0).unwrap(),
}
}
}
impl Mul<Bitcoin> for Dollars {
type Output = Self;
fn mul(self, rhs: Bitcoin) -> Self::Output {
Self::from(Cents::from(
u128::from(Sats::from(rhs)) * u128::from(Cents::from(self)) / u128::from(Sats::ONE_BTC),
))
if self.is_nan() {
self
} else {
Self::from(Cents::from(
u128::from(Sats::from(rhs)) * u128::from(Cents::from(self))
/ u128::from(Sats::ONE_BTC),
))
}
}
}
@@ -142,7 +173,7 @@ impl Mul<StoredF32> for Dollars {
type Output = Self;
fn mul(self, rhs: StoredF32) -> Self::Output {
if rhs.is_nan() {
Self(f64::NAN)
self
} else {
Self::from(Cents::from(Self::from(self.0 * *rhs as f64)))
}
@@ -152,7 +183,11 @@ impl Mul<StoredF32> for Dollars {
impl Mul<usize> for Dollars {
type Output = Self;
fn mul(self, rhs: usize) -> Self::Output {
Self::from(Cents::from(self) * rhs)
if self.is_nan() {
self
} else {
Self::from(Cents::from(self) * rhs)
}
}
}
@@ -182,9 +217,13 @@ impl AddAssign for Dollars {
impl CheckedSub for Dollars {
fn checked_sub(self, rhs: Self) -> Option<Self> {
Cents::from(self)
.checked_sub(Cents::from(rhs))
.map(Dollars::from)
if self.is_nan() {
Some(self)
} else {
Cents::from(self)
.checked_sub(Cents::from(rhs))
.map(Dollars::from)
}
}
}
+10 -2
View File
@@ -1,4 +1,7 @@
use std::ops::{Add, Div, Mul, Sub};
use std::{
cmp::Ordering,
ops::{Add, Div, Mul, Sub},
};
use derive_deref::Deref;
use serde::Serialize;
@@ -79,7 +82,12 @@ impl Eq for StoredF32 {}
#[allow(clippy::derive_ord_xor_partial_ord)]
impl Ord for StoredF32 {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.partial_cmp(&other.0).unwrap()
match (self.0.is_nan(), other.0.is_nan()) {
(true, true) => Ordering::Equal,
(true, false) => Ordering::Less,
(false, true) => Ordering::Greater,
(false, false) => self.0.partial_cmp(&other.0).unwrap(),
}
}
}
+10 -2
View File
@@ -1,4 +1,7 @@
use std::ops::{Add, Div, Mul};
use std::{
cmp::Ordering,
ops::{Add, Div, Mul},
};
use derive_deref::Deref;
use serde::Serialize;
@@ -72,7 +75,12 @@ impl Eq for StoredF64 {}
#[allow(clippy::derive_ord_xor_partial_ord)]
impl Ord for StoredF64 {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.0.partial_cmp(&other.0).unwrap()
match (self.0.is_nan(), other.0.is_nan()) {
(true, true) => Ordering::Equal,
(true, false) => Ordering::Less,
(false, true) => Ordering::Greater,
(false, false) => self.0.partial_cmp(&other.0).unwrap(),
}
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ color-eyre = { workspace = true }
jiff = { workspace = true }
log = { workspace = true }
minreq = { workspace = true }
oxc = { version = "0.71.0", features = ["codegen", "minifier"] }
oxc = { version = "0.72.0", features = ["codegen", "minifier"] }
serde = { workspace = true }
tokio = { version = "1.45.0", features = ["full"] }
tower-http = { version = "0.6.4", features = ["compression-full", "trace"] }
+3 -1
View File
@@ -267,7 +267,9 @@ where
let mut divider_iter = divider.iter();
divided.iter_at(index).try_for_each(|(i, divided)| {
let v = (divided.into_inner() / divider_iter.unwrap_get_inner(i) * multiplier)
let divided = divided.into_inner();
let divider = divider_iter.unwrap_get_inner(i);
let v = (divided / divider * multiplier)
.checked_sub(subtract)
.unwrap();
self.forced_push_at(i, T::from(v), exit)