mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-26 02:08:10 -07:00
computer: rollback part 1
This commit is contained in:
@@ -45,7 +45,7 @@ pub struct Computer {
|
||||
pub cointime: cointime::Vecs,
|
||||
}
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
const VERSION: Version = Version::TWO;
|
||||
|
||||
impl Computer {
|
||||
/// Do NOT import multiple times or things will break !!!
|
||||
|
||||
@@ -53,12 +53,11 @@ impl Vecs {
|
||||
Ok(Self {
|
||||
starting_height: Height::ZERO,
|
||||
state: states_path.map(|states_path| {
|
||||
AddressCohortState::default_and_import(
|
||||
AddressCohortState::new(
|
||||
states_path,
|
||||
cohort_name.unwrap_or_default(),
|
||||
compute_dollars,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
height_to_address_count: EagerVec::forced_import(
|
||||
db,
|
||||
@@ -95,9 +94,6 @@ impl Vecs {
|
||||
impl DynCohortVecs for Vecs {
|
||||
fn starting_height(&self) -> Height {
|
||||
[
|
||||
self.state.as_ref().map_or(Height::MAX, |state| {
|
||||
state.height().map_or(Height::MAX, |h| h.incremented())
|
||||
}),
|
||||
self.height_to_address_count.len().into(),
|
||||
self.inner.starting_height(),
|
||||
]
|
||||
@@ -106,7 +102,7 @@ impl DynCohortVecs for Vecs {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn init(&mut self, starting_height: Height) {
|
||||
fn import_state_at(&mut self, starting_height: Height) -> Result<()> {
|
||||
if starting_height > self.starting_height() {
|
||||
unreachable!()
|
||||
}
|
||||
@@ -120,10 +116,10 @@ impl DynCohortVecs for Vecs {
|
||||
.unwrap_get_inner(prev_height);
|
||||
}
|
||||
|
||||
self.inner.init(
|
||||
self.inner.import_state_at(
|
||||
&mut self.starting_height,
|
||||
&mut self.state.as_mut().unwrap().inner,
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
|
||||
@@ -26,7 +26,7 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
@@ -38,7 +38,7 @@ impl Vecs {
|
||||
_0sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_with_0sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -49,7 +49,7 @@ impl Vecs {
|
||||
_1sat_to_10sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1sat_under_10sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -60,7 +60,7 @@ impl Vecs {
|
||||
_10sats_to_100sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10sats_under_100sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -71,7 +71,7 @@ impl Vecs {
|
||||
_100sats_to_1k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100sats_under_1k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -82,7 +82,7 @@ impl Vecs {
|
||||
_1k_sats_to_10k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1k_sats_under_10k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -93,7 +93,7 @@ impl Vecs {
|
||||
_10k_sats_to_100k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10k_sats_under_100k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -104,7 +104,7 @@ impl Vecs {
|
||||
_100k_sats_to_1m_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100k_sats_under_1m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -115,7 +115,7 @@ impl Vecs {
|
||||
_1m_sats_to_10m_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1m_sats_under_10m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -126,7 +126,7 @@ impl Vecs {
|
||||
_10m_sats_to_1btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10m_sats_under_1btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -137,7 +137,7 @@ impl Vecs {
|
||||
_1btc_to_10btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1btc_under_10btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -148,7 +148,7 @@ impl Vecs {
|
||||
_10btc_to_100btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10btc_under_100btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -159,7 +159,7 @@ impl Vecs {
|
||||
_100btc_to_1k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100btc_under_1k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -170,7 +170,7 @@ impl Vecs {
|
||||
_1k_btc_to_10k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1k_btc_under_10k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -181,7 +181,7 @@ impl Vecs {
|
||||
_10k_btc_to_100k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10k_btc_under_100k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -192,7 +192,7 @@ impl Vecs {
|
||||
_100k_btc_or_more: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -205,7 +205,7 @@ impl Vecs {
|
||||
_10sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_10sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -216,7 +216,7 @@ impl Vecs {
|
||||
_100sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_100sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -227,7 +227,7 @@ impl Vecs {
|
||||
_1k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_1k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -238,7 +238,7 @@ impl Vecs {
|
||||
_10k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_10k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -249,7 +249,7 @@ impl Vecs {
|
||||
_100k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_100k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -260,7 +260,7 @@ impl Vecs {
|
||||
_1m_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_1m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -271,7 +271,7 @@ impl Vecs {
|
||||
_10m_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_10m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -282,7 +282,7 @@ impl Vecs {
|
||||
_1btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_1btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -293,7 +293,7 @@ impl Vecs {
|
||||
_10btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_10btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -304,7 +304,7 @@ impl Vecs {
|
||||
_100btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_100btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -315,7 +315,7 @@ impl Vecs {
|
||||
_1k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_1k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -326,7 +326,7 @@ impl Vecs {
|
||||
_10k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_10k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -337,7 +337,7 @@ impl Vecs {
|
||||
_100k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_under_100k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -350,7 +350,7 @@ impl Vecs {
|
||||
_1sat: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1sat"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -361,7 +361,7 @@ impl Vecs {
|
||||
_10sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -372,7 +372,7 @@ impl Vecs {
|
||||
_100sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -383,7 +383,7 @@ impl Vecs {
|
||||
_1k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -394,7 +394,7 @@ impl Vecs {
|
||||
_10k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -405,7 +405,7 @@ impl Vecs {
|
||||
_100k_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -416,7 +416,7 @@ impl Vecs {
|
||||
_1m_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -427,7 +427,7 @@ impl Vecs {
|
||||
_10m_sats: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -438,7 +438,7 @@ impl Vecs {
|
||||
_1btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -449,7 +449,7 @@ impl Vecs {
|
||||
_10btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -460,7 +460,7 @@ impl Vecs {
|
||||
_100btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_100btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -471,7 +471,7 @@ impl Vecs {
|
||||
_1k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_1k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -482,7 +482,7 @@ impl Vecs {
|
||||
_10k_btc: address_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("addrs_above_10k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
|
||||
@@ -19,7 +19,6 @@ impl From<ByAddressType<ComputedVecsFromHeight<StoredU64>>> for AddressTypeToInd
|
||||
impl AddressTypeToIndexesToAddressCount {
|
||||
pub fn compute(
|
||||
&mut self,
|
||||
// height: Height,
|
||||
indexes: &indexes::Vecs,
|
||||
starting_indexes: &Indexes,
|
||||
exit: &Exit,
|
||||
@@ -75,7 +74,7 @@ impl AddressTypeToIndexesToAddressCount {
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
//
|
||||
|
||||
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
|
||||
self.0
|
||||
.as_typed_vec()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use brk_error::Result;
|
||||
use brk_error::{Error, Result};
|
||||
use brk_indexer::Indexer;
|
||||
use brk_structs::{
|
||||
Bitcoin, DateIndex, Dollars, Height, Sats, StoredF32, StoredF64, StoredU64, Version,
|
||||
@@ -1111,7 +1111,11 @@ impl Vecs {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn init(&mut self, starting_height: &mut Height, state: &mut CohortState) {
|
||||
pub fn import_state_at(
|
||||
&mut self,
|
||||
starting_height: &mut Height,
|
||||
state: &mut CohortState,
|
||||
) -> Result<()> {
|
||||
if let Some(prev_height) = starting_height.decremented() {
|
||||
state.supply.value = self
|
||||
.height_to_supply
|
||||
@@ -1126,7 +1130,12 @@ impl Vecs {
|
||||
state.realized.as_mut().unwrap().cap = height_to_realized_cap
|
||||
.into_iter()
|
||||
.unwrap_get_inner(prev_height);
|
||||
|
||||
state.import_at(prev_height)?;
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Str("Unset"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,19 +44,12 @@ const VERSION: Version = Version::new(21);
|
||||
pub struct Vecs {
|
||||
db: Database,
|
||||
|
||||
// ---
|
||||
// States
|
||||
// ---
|
||||
|
||||
// Rollback: diff on stamped_flush + add rollback to stamp
|
||||
pub chain_state: RawVec<Height, SupplyState>,
|
||||
|
||||
pub height_to_unspendable_supply: EagerVec<Height, Sats>,
|
||||
pub indexes_to_unspendable_supply: ComputedValueVecsFromHeight,
|
||||
pub height_to_opreturn_supply: EagerVec<Height, Sats>,
|
||||
pub indexes_to_opreturn_supply: ComputedValueVecsFromHeight,
|
||||
pub addresstype_to_height_to_address_count: AddressTypeToHeightToAddressCount,
|
||||
pub addresstype_to_height_to_empty_address_count: AddressTypeToHeightToAddressCount,
|
||||
pub addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount,
|
||||
pub addresstype_to_indexes_to_empty_address_count: AddressTypeToIndexesToAddressCount,
|
||||
pub utxo_cohorts: utxo_cohorts::Vecs,
|
||||
pub address_cohorts: address_cohorts::Vecs,
|
||||
|
||||
pub p2pk33addressindex_to_anyaddressindex: RawVec<P2PK33AddressIndex, AnyAddressIndex>,
|
||||
pub p2pk65addressindex_to_anyaddressindex: RawVec<P2PK65AddressIndex, AnyAddressIndex>,
|
||||
pub p2pkhaddressindex_to_anyaddressindex: RawVec<P2PKHAddressIndex, AnyAddressIndex>,
|
||||
@@ -68,6 +61,22 @@ pub struct Vecs {
|
||||
pub loadedaddressindex_to_loadedaddressdata: RawVec<LoadedAddressIndex, LoadedAddressData>,
|
||||
pub emptyaddressindex_to_emptyaddressdata: RawVec<EmptyAddressIndex, EmptyAddressData>,
|
||||
|
||||
// Rollback: inner state: save price_to_amount_STAMP instead of price_to_amount
|
||||
pub utxo_cohorts: utxo_cohorts::Vecs,
|
||||
pub address_cohorts: address_cohorts::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,
|
||||
|
||||
// ---
|
||||
// Computed
|
||||
// ---
|
||||
pub addresstype_to_indexes_to_address_count: AddressTypeToIndexesToAddressCount,
|
||||
pub addresstype_to_indexes_to_empty_address_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>,
|
||||
}
|
||||
@@ -678,43 +687,57 @@ impl Vecs {
|
||||
};
|
||||
|
||||
let starting_height = starting_indexes.height.min(stateful_starting_height);
|
||||
|
||||
if starting_height.is_zero() {
|
||||
info!("Starting processing utxos from the start");
|
||||
|
||||
// TODO: rollback instead
|
||||
|
||||
chain_state = vec![];
|
||||
chain_state_starting_height = Height::ZERO;
|
||||
|
||||
self.p2pk33addressindex_to_anyaddressindex.reset()?;
|
||||
self.p2pk65addressindex_to_anyaddressindex.reset()?;
|
||||
self.p2pkhaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2shaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2traddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2wpkhaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2wshaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2aaddressindex_to_anyaddressindex.reset()?;
|
||||
self.loadedaddressindex_to_loadedaddressdata.reset()?;
|
||||
self.emptyaddressindex_to_emptyaddressdata.reset()?;
|
||||
|
||||
info!("Resetting utxo price maps...");
|
||||
|
||||
separate_utxo_vecs
|
||||
.par_iter_mut()
|
||||
.flat_map(|(_, v)| v.state.as_mut())
|
||||
.try_for_each(|state| state.reset_price_to_amount())?;
|
||||
|
||||
info!("Resetting address price maps...");
|
||||
|
||||
separate_address_vecs
|
||||
.par_iter_mut()
|
||||
.try_for_each(|(_, v)| v.state.as_mut().unwrap().reset_price_to_amount())?;
|
||||
};
|
||||
|
||||
let last_height = Height::from(indexer.vecs.height_to_blockhash.stamp());
|
||||
|
||||
if starting_height <= last_height {
|
||||
let starting_height = if separate_utxo_vecs
|
||||
.par_iter_mut()
|
||||
.try_for_each(|(_, v)| v.import_state_at(starting_height))
|
||||
.is_err()
|
||||
|| separate_address_vecs
|
||||
.par_iter_mut()
|
||||
.try_for_each(|(_, v)| v.import_state_at(starting_height))
|
||||
.is_err()
|
||||
{
|
||||
Height::ZERO
|
||||
} else {
|
||||
starting_height
|
||||
};
|
||||
|
||||
if starting_height.is_zero() {
|
||||
info!("Starting processing utxos from the start");
|
||||
|
||||
chain_state = vec![];
|
||||
chain_state_starting_height = Height::ZERO;
|
||||
|
||||
self.p2pk33addressindex_to_anyaddressindex.reset()?;
|
||||
self.p2pk65addressindex_to_anyaddressindex.reset()?;
|
||||
self.p2pkhaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2shaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2traddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2wpkhaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2wshaddressindex_to_anyaddressindex.reset()?;
|
||||
self.p2aaddressindex_to_anyaddressindex.reset()?;
|
||||
self.loadedaddressindex_to_loadedaddressdata.reset()?;
|
||||
self.emptyaddressindex_to_emptyaddressdata.reset()?;
|
||||
|
||||
info!("Resetting utxo price maps...");
|
||||
|
||||
separate_utxo_vecs
|
||||
.par_iter_mut()
|
||||
.flat_map(|(_, v)| v.state.as_mut())
|
||||
.try_for_each(|state| state.reset_price_to_amount_if_needed())?;
|
||||
|
||||
info!("Resetting address price maps...");
|
||||
|
||||
separate_address_vecs
|
||||
.par_iter_mut()
|
||||
.try_for_each(|(_, v)| {
|
||||
v.state.as_mut().unwrap().reset_price_to_amount_if_needed()
|
||||
})?;
|
||||
}
|
||||
|
||||
starting_indexes.update_from_height(starting_height, indexes);
|
||||
|
||||
let inputindex_to_outputindex_reader = inputindex_to_outputindex.create_reader();
|
||||
let outputindex_to_value_reader = outputindex_to_value.create_reader();
|
||||
let outputindex_to_outputtype_reader = outputindex_to_outputtype.create_reader();
|
||||
@@ -746,16 +769,6 @@ impl Vecs {
|
||||
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();
|
||||
|
||||
starting_indexes.update_from_height(starting_height, indexes);
|
||||
|
||||
separate_utxo_vecs
|
||||
.par_iter_mut()
|
||||
.for_each(|(_, v)| v.init(starting_height));
|
||||
|
||||
separate_address_vecs
|
||||
.par_iter_mut()
|
||||
.for_each(|(_, v)| v.init(starting_height));
|
||||
|
||||
let height_to_close_vec =
|
||||
height_to_close.map(|height_to_close| height_to_close.collect().unwrap());
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{Indexes, indexes, market, price};
|
||||
pub trait DynCohortVecs: Send + Sync {
|
||||
fn starting_height(&self) -> Height;
|
||||
|
||||
fn init(&mut self, starting_height: Height);
|
||||
fn import_state_at(&mut self, starting_height: Height) -> Result<()>;
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()>;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::{
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
starting_height: Height,
|
||||
starting_height: Option<Height>,
|
||||
|
||||
pub state: Option<UTXOCohortState>,
|
||||
|
||||
@@ -40,15 +40,14 @@ impl Vecs {
|
||||
let compute_dollars = price.is_some();
|
||||
|
||||
Ok(Self {
|
||||
starting_height: Height::ZERO,
|
||||
starting_height: None,
|
||||
|
||||
state: states_path.map(|states_path| {
|
||||
UTXOCohortState::default_and_import(
|
||||
UTXOCohortState::new(
|
||||
states_path,
|
||||
cohort_name.unwrap_or_default(),
|
||||
compute_dollars,
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
|
||||
inner: common::Vecs::forced_import(
|
||||
@@ -69,26 +68,20 @@ impl Vecs {
|
||||
|
||||
impl DynCohortVecs for Vecs {
|
||||
fn starting_height(&self) -> Height {
|
||||
[
|
||||
self.state.as_ref().map_or(Height::MAX, |state| {
|
||||
state.height().map_or(Height::MAX, |h| h.incremented())
|
||||
}),
|
||||
self.inner.starting_height(),
|
||||
]
|
||||
.into_iter()
|
||||
.min()
|
||||
.unwrap()
|
||||
self.inner.starting_height()
|
||||
}
|
||||
|
||||
fn init(&mut self, starting_height: Height) {
|
||||
fn import_state_at(&mut self, starting_height: Height) -> Result<()> {
|
||||
if starting_height > self.starting_height() {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
self.starting_height = starting_height;
|
||||
self.starting_height = Some(starting_height);
|
||||
|
||||
self.inner
|
||||
.init(&mut self.starting_height, self.state.as_mut().unwrap());
|
||||
self.inner.import_state_at(
|
||||
self.starting_height.as_mut().unwrap(),
|
||||
self.state.as_mut().unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||
@@ -96,7 +89,7 @@ impl DynCohortVecs for Vecs {
|
||||
}
|
||||
|
||||
fn forced_pushed_at(&mut self, height: Height, exit: &Exit) -> Result<()> {
|
||||
if self.starting_height > height {
|
||||
if self.starting_height.unwrap() > height {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ impl Vecs {
|
||||
pub fn forced_import(
|
||||
db: &Database,
|
||||
version: Version,
|
||||
_computation: Computation,
|
||||
computation: Computation,
|
||||
format: Format,
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
@@ -38,7 +38,7 @@ impl Vecs {
|
||||
all: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
None,
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -52,7 +52,7 @@ impl Vecs {
|
||||
short: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("short_term_holders"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -65,7 +65,7 @@ impl Vecs {
|
||||
long: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("long_term_holders"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -80,7 +80,7 @@ impl Vecs {
|
||||
_0: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("epoch_0"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -93,7 +93,7 @@ impl Vecs {
|
||||
_1: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("epoch_1"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -106,7 +106,7 @@ impl Vecs {
|
||||
_2: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("epoch_2"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -119,7 +119,7 @@ impl Vecs {
|
||||
_3: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("epoch_3"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -132,7 +132,7 @@ impl Vecs {
|
||||
_4: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("epoch_4"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -147,7 +147,7 @@ impl Vecs {
|
||||
p2pk65: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2pk65"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -160,7 +160,7 @@ impl Vecs {
|
||||
p2pk33: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2pk33"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -173,7 +173,7 @@ impl Vecs {
|
||||
p2pkh: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2pkh"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -186,7 +186,7 @@ impl Vecs {
|
||||
p2sh: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2sh"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -199,7 +199,7 @@ impl Vecs {
|
||||
p2wpkh: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2wpkh"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -212,7 +212,7 @@ impl Vecs {
|
||||
p2wsh: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2wsh"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -225,7 +225,7 @@ impl Vecs {
|
||||
p2tr: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2tr"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -238,7 +238,7 @@ impl Vecs {
|
||||
p2a: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2a"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -251,7 +251,7 @@ impl Vecs {
|
||||
p2ms: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("p2ms_outputs"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -264,7 +264,7 @@ impl Vecs {
|
||||
empty: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("empty_outputs"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -277,7 +277,7 @@ impl Vecs {
|
||||
unknown: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("unknown_outputs"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -292,7 +292,7 @@ impl Vecs {
|
||||
_1w: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_1w_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -305,7 +305,7 @@ impl Vecs {
|
||||
_1m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_1m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -318,7 +318,7 @@ impl Vecs {
|
||||
_2m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_2m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -331,7 +331,7 @@ impl Vecs {
|
||||
_3m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_3m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -344,7 +344,7 @@ impl Vecs {
|
||||
_4m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_4m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -357,7 +357,7 @@ impl Vecs {
|
||||
_5m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_5m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -370,7 +370,7 @@ impl Vecs {
|
||||
_6m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_6m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -383,7 +383,7 @@ impl Vecs {
|
||||
_1y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_1y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -396,7 +396,7 @@ impl Vecs {
|
||||
_2y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_2y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -409,7 +409,7 @@ impl Vecs {
|
||||
_3y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_3y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -422,7 +422,7 @@ impl Vecs {
|
||||
_4y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_4y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -435,7 +435,7 @@ impl Vecs {
|
||||
_5y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_5y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -448,7 +448,7 @@ impl Vecs {
|
||||
_6y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_6y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -461,7 +461,7 @@ impl Vecs {
|
||||
_7y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_7y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -474,7 +474,7 @@ impl Vecs {
|
||||
_8y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_8y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -487,7 +487,7 @@ impl Vecs {
|
||||
_10y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_10y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -500,7 +500,7 @@ impl Vecs {
|
||||
_12y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_12y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -513,7 +513,7 @@ impl Vecs {
|
||||
_15y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_15y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -528,7 +528,7 @@ impl Vecs {
|
||||
_1d: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1d_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -541,7 +541,7 @@ impl Vecs {
|
||||
_1w: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1w_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -554,7 +554,7 @@ impl Vecs {
|
||||
_1m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -567,7 +567,7 @@ impl Vecs {
|
||||
_2m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_2m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -580,7 +580,7 @@ impl Vecs {
|
||||
_3m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_3m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -593,7 +593,7 @@ impl Vecs {
|
||||
_4m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_4m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -606,7 +606,7 @@ impl Vecs {
|
||||
_5m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_5m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -619,7 +619,7 @@ impl Vecs {
|
||||
_6m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_6m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -632,7 +632,7 @@ impl Vecs {
|
||||
_1y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -645,7 +645,7 @@ impl Vecs {
|
||||
_2y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_2y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -658,7 +658,7 @@ impl Vecs {
|
||||
_3y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_3y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -671,7 +671,7 @@ impl Vecs {
|
||||
_4y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_4y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -684,7 +684,7 @@ impl Vecs {
|
||||
_5y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_5y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -697,7 +697,7 @@ impl Vecs {
|
||||
_6y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_6y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -710,7 +710,7 @@ impl Vecs {
|
||||
_7y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_7y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -723,7 +723,7 @@ impl Vecs {
|
||||
_8y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_8y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -736,7 +736,7 @@ impl Vecs {
|
||||
_10y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_10y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -749,7 +749,7 @@ impl Vecs {
|
||||
_12y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_12y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -764,7 +764,7 @@ impl Vecs {
|
||||
up_to_1d: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_up_to_1d_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -777,7 +777,7 @@ impl Vecs {
|
||||
_1d_to_1w: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1d_up_to_1w_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -790,7 +790,7 @@ impl Vecs {
|
||||
_1w_to_1m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1w_up_to_1m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -803,7 +803,7 @@ impl Vecs {
|
||||
_1m_to_2m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1m_up_to_2m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -816,7 +816,7 @@ impl Vecs {
|
||||
_2m_to_3m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_2m_up_to_3m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -829,7 +829,7 @@ impl Vecs {
|
||||
_3m_to_4m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_3m_up_to_4m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -842,7 +842,7 @@ impl Vecs {
|
||||
_4m_to_5m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_4m_up_to_5m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -855,7 +855,7 @@ impl Vecs {
|
||||
_5m_to_6m: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_5m_up_to_6m_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -868,7 +868,7 @@ impl Vecs {
|
||||
_6m_to_1y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_6m_up_to_1y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -881,7 +881,7 @@ impl Vecs {
|
||||
_1y_to_2y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_1y_up_to_2y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -894,7 +894,7 @@ impl Vecs {
|
||||
_2y_to_3y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_2y_up_to_3y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -907,7 +907,7 @@ impl Vecs {
|
||||
_3y_to_4y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_3y_up_to_4y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -920,7 +920,7 @@ impl Vecs {
|
||||
_4y_to_5y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_4y_up_to_5y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -933,7 +933,7 @@ impl Vecs {
|
||||
_5y_to_6y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_5y_up_to_6y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -946,7 +946,7 @@ impl Vecs {
|
||||
_6y_to_7y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_6y_up_to_7y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -959,7 +959,7 @@ impl Vecs {
|
||||
_7y_to_8y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_7y_up_to_8y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -972,7 +972,7 @@ impl Vecs {
|
||||
_8y_to_10y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_8y_up_to_10y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -985,7 +985,7 @@ impl Vecs {
|
||||
_10y_to_12y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_10y_up_to_12y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -998,7 +998,7 @@ impl Vecs {
|
||||
_12y_to_15y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_12y_up_to_15y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1011,7 +1011,7 @@ impl Vecs {
|
||||
from_15y: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_at_least_15y_old"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1026,7 +1026,7 @@ impl Vecs {
|
||||
_0sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_with_0sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1039,7 +1039,7 @@ impl Vecs {
|
||||
_1sat_to_10sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1sat_under_10sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1052,7 +1052,7 @@ impl Vecs {
|
||||
_10sats_to_100sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10sats_under_100sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1065,7 +1065,7 @@ impl Vecs {
|
||||
_100sats_to_1k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100sats_under_1k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1078,7 +1078,7 @@ impl Vecs {
|
||||
_1k_sats_to_10k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1k_sats_under_10k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1091,7 +1091,7 @@ impl Vecs {
|
||||
_10k_sats_to_100k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10k_sats_under_100k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1104,7 +1104,7 @@ impl Vecs {
|
||||
_100k_sats_to_1m_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100k_sats_under_1m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1117,7 +1117,7 @@ impl Vecs {
|
||||
_1m_sats_to_10m_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1m_sats_under_10m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1130,7 +1130,7 @@ impl Vecs {
|
||||
_10m_sats_to_1btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10m_sats_under_1btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1143,7 +1143,7 @@ impl Vecs {
|
||||
_1btc_to_10btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1btc_under_10btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1156,7 +1156,7 @@ impl Vecs {
|
||||
_10btc_to_100btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10btc_under_100btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1169,7 +1169,7 @@ impl Vecs {
|
||||
_100btc_to_1k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100btc_under_1k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1182,7 +1182,7 @@ impl Vecs {
|
||||
_1k_btc_to_10k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1k_btc_under_10k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1195,7 +1195,7 @@ impl Vecs {
|
||||
_10k_btc_to_100k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10k_btc_under_100k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1208,7 +1208,7 @@ impl Vecs {
|
||||
_100k_btc_or_more: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1223,7 +1223,7 @@ impl Vecs {
|
||||
_10sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_10sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1236,7 +1236,7 @@ impl Vecs {
|
||||
_100sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_100sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1249,7 +1249,7 @@ impl Vecs {
|
||||
_1k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_1k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1262,7 +1262,7 @@ impl Vecs {
|
||||
_10k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_10k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1275,7 +1275,7 @@ impl Vecs {
|
||||
_100k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_100k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1288,7 +1288,7 @@ impl Vecs {
|
||||
_1m_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_1m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1301,7 +1301,7 @@ impl Vecs {
|
||||
_10m_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_10m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1314,7 +1314,7 @@ impl Vecs {
|
||||
_1btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_1btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1327,7 +1327,7 @@ impl Vecs {
|
||||
_10btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_10btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1340,7 +1340,7 @@ impl Vecs {
|
||||
_100btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_100btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1353,7 +1353,7 @@ impl Vecs {
|
||||
_1k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_1k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1366,7 +1366,7 @@ impl Vecs {
|
||||
_10k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_10k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1379,7 +1379,7 @@ impl Vecs {
|
||||
_100k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_under_100k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1394,7 +1394,7 @@ impl Vecs {
|
||||
_1sat: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1sat"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1407,7 +1407,7 @@ impl Vecs {
|
||||
_10sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1420,7 +1420,7 @@ impl Vecs {
|
||||
_100sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1433,7 +1433,7 @@ impl Vecs {
|
||||
_1k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1446,7 +1446,7 @@ impl Vecs {
|
||||
_10k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1459,7 +1459,7 @@ impl Vecs {
|
||||
_100k_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100k_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1472,7 +1472,7 @@ impl Vecs {
|
||||
_1m_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1485,7 +1485,7 @@ impl Vecs {
|
||||
_10m_sats: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10m_sats"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1498,7 +1498,7 @@ impl Vecs {
|
||||
_1btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1511,7 +1511,7 @@ impl Vecs {
|
||||
_10btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1524,7 +1524,7 @@ impl Vecs {
|
||||
_100btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_100btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1537,7 +1537,7 @@ impl Vecs {
|
||||
_1k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_1k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
@@ -1550,7 +1550,7 @@ impl Vecs {
|
||||
_10k_btc: utxo_cohort::Vecs::forced_import(
|
||||
db,
|
||||
Some("utxos_above_10k_btc"),
|
||||
_computation,
|
||||
computation,
|
||||
format,
|
||||
version + VERSION + Version::ZERO,
|
||||
indexes,
|
||||
|
||||
@@ -14,19 +14,15 @@ pub struct AddressCohortState {
|
||||
}
|
||||
|
||||
impl AddressCohortState {
|
||||
pub fn default_and_import(path: &Path, name: &str, compute_dollars: bool) -> Result<Self> {
|
||||
Ok(Self {
|
||||
pub fn new(path: &Path, name: &str, compute_dollars: bool) -> Self {
|
||||
Self {
|
||||
address_count: 0,
|
||||
inner: CohortState::default_and_import(path, name, compute_dollars)?,
|
||||
})
|
||||
inner: CohortState::new(path, name, compute_dollars),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn height(&self) -> Option<Height> {
|
||||
self.inner.height()
|
||||
}
|
||||
|
||||
pub fn reset_price_to_amount(&mut self) -> Result<()> {
|
||||
self.inner.reset_price_to_amount()
|
||||
pub fn reset_price_to_amount_if_needed(&mut self) -> Result<()> {
|
||||
self.inner.reset_price_to_amount_if_needed()
|
||||
}
|
||||
|
||||
pub fn reset_single_iteration_values(&mut self) {
|
||||
|
||||
@@ -8,38 +8,46 @@ use crate::{PriceToAmount, RealizedState, SupplyState, UnrealizedState};
|
||||
#[derive(Clone)]
|
||||
pub struct CohortState {
|
||||
pub supply: SupplyState,
|
||||
|
||||
pub realized: Option<RealizedState>,
|
||||
pub satblocks_destroyed: Sats,
|
||||
pub satdays_destroyed: Sats,
|
||||
|
||||
price_to_amount: PriceToAmount,
|
||||
price_to_amount: Option<PriceToAmount>,
|
||||
}
|
||||
|
||||
impl CohortState {
|
||||
pub fn default_and_import(path: &Path, name: &str, compute_dollars: bool) -> Result<Self> {
|
||||
Ok(Self {
|
||||
pub fn new(path: &Path, name: &str, compute_dollars: bool) -> Self {
|
||||
Self {
|
||||
supply: SupplyState::default(),
|
||||
realized: compute_dollars.then_some(RealizedState::NAN),
|
||||
satblocks_destroyed: Sats::ZERO,
|
||||
satdays_destroyed: Sats::ZERO,
|
||||
price_to_amount: PriceToAmount::forced_import(path, name),
|
||||
})
|
||||
price_to_amount: compute_dollars.then_some(PriceToAmount::create(path, name)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn height(&self) -> Option<Height> {
|
||||
self.price_to_amount.height()
|
||||
pub fn import_at(&mut self, height: Height) -> Result<()> {
|
||||
if let Some(price_to_amount) = self.price_to_amount.as_mut() {
|
||||
price_to_amount.import_at(height)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reset_price_to_amount(&mut self) -> Result<()> {
|
||||
self.price_to_amount.reset()
|
||||
pub fn reset_price_to_amount_if_needed(&mut self) -> Result<()> {
|
||||
if let Some(price_to_amount) = self.price_to_amount.as_mut() {
|
||||
price_to_amount.clean()?;
|
||||
price_to_amount.init();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn price_to_amount_first_key_value(&self) -> Option<(&Dollars, &Sats)> {
|
||||
self.price_to_amount.first_key_value()
|
||||
self.price_to_amount.as_ref().unwrap().first_key_value()
|
||||
}
|
||||
|
||||
pub fn price_to_amount_last_key_value(&self) -> Option<(&Dollars, &Sats)> {
|
||||
self.price_to_amount.last_key_value()
|
||||
self.price_to_amount.as_ref().unwrap().last_key_value()
|
||||
}
|
||||
|
||||
pub fn reset_single_iteration_values(&mut self) {
|
||||
@@ -58,7 +66,10 @@ impl CohortState {
|
||||
{
|
||||
let price = price.unwrap();
|
||||
realized.increment(supply_state, price);
|
||||
self.price_to_amount.increment(price, supply_state);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.increment(price, supply_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +85,10 @@ impl CohortState {
|
||||
&& let Some(realized) = self.realized.as_mut()
|
||||
{
|
||||
realized.increment_(realized_cap);
|
||||
self.price_to_amount.increment(realized_price, supply_state);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.increment(realized_price, supply_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +100,10 @@ impl CohortState {
|
||||
{
|
||||
let price = price.unwrap();
|
||||
realized.decrement(supply_state, price);
|
||||
self.price_to_amount.decrement(price, supply_state);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.decrement(price, supply_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +119,10 @@ impl CohortState {
|
||||
&& let Some(realized) = self.realized.as_mut()
|
||||
{
|
||||
realized.decrement_(realized_cap);
|
||||
self.price_to_amount.decrement(realized_price, supply_state);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.decrement(realized_price, supply_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,13 +153,19 @@ impl CohortState {
|
||||
if let Some((price, supply)) = price_to_amount_increment
|
||||
&& supply.value.is_not_zero()
|
||||
{
|
||||
self.price_to_amount.increment(price, supply);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.increment(price, supply);
|
||||
}
|
||||
|
||||
if let Some((price, supply)) = price_to_amount_decrement
|
||||
&& supply.value.is_not_zero()
|
||||
{
|
||||
self.price_to_amount.decrement(price, supply);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.decrement(price, supply);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,12 +222,18 @@ impl CohortState {
|
||||
if let Some((price, supply)) = price_to_amount_increment
|
||||
&& supply.value.is_not_zero()
|
||||
{
|
||||
self.price_to_amount.increment(price, supply);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.increment(price, supply);
|
||||
}
|
||||
if let Some((price, supply)) = price_to_amount_decrement
|
||||
&& supply.value.is_not_zero()
|
||||
{
|
||||
self.price_to_amount.decrement(price, supply);
|
||||
self.price_to_amount
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.decrement(price, supply);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,7 +244,7 @@ impl CohortState {
|
||||
height_price: Dollars,
|
||||
date_price: Option<Dollars>,
|
||||
) -> (UnrealizedState, Option<UnrealizedState>) {
|
||||
if self.price_to_amount.is_empty() {
|
||||
if self.price_to_amount.as_ref().unwrap().is_empty() {
|
||||
return (
|
||||
UnrealizedState::NAN,
|
||||
date_price.map(|_| UnrealizedState::NAN),
|
||||
@@ -255,23 +287,30 @@ impl CohortState {
|
||||
}
|
||||
};
|
||||
|
||||
self.price_to_amount.iter().for_each(|(&price, &sats)| {
|
||||
update_state(price, height_price, sats, &mut height_unrealized_state);
|
||||
self.price_to_amount
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.for_each(|(&price, &sats)| {
|
||||
update_state(price, height_price, sats, &mut height_unrealized_state);
|
||||
|
||||
if let Some(date_price) = date_price {
|
||||
update_state(
|
||||
price,
|
||||
date_price,
|
||||
sats,
|
||||
date_unrealized_state.as_mut().unwrap(),
|
||||
)
|
||||
}
|
||||
});
|
||||
if let Some(date_price) = date_price {
|
||||
update_state(
|
||||
price,
|
||||
date_price,
|
||||
sats,
|
||||
date_unrealized_state.as_mut().unwrap(),
|
||||
)
|
||||
}
|
||||
});
|
||||
|
||||
(height_unrealized_state, date_unrealized_state)
|
||||
}
|
||||
|
||||
pub fn commit(&mut self, height: Height) -> Result<()> {
|
||||
self.price_to_amount.flush(height)
|
||||
if let Some(price_to_amount) = self.price_to_amount.as_mut() {
|
||||
price_to_amount.flush(height)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_structs::Height;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use super::CohortState;
|
||||
@@ -10,19 +9,11 @@ use super::CohortState;
|
||||
pub struct UTXOCohortState(CohortState);
|
||||
|
||||
impl UTXOCohortState {
|
||||
pub fn default_and_import(path: &Path, name: &str, compute_dollars: bool) -> Result<Self> {
|
||||
Ok(Self(CohortState::default_and_import(
|
||||
path,
|
||||
name,
|
||||
compute_dollars,
|
||||
)?))
|
||||
pub fn new(path: &Path, name: &str, compute_dollars: bool) -> Self {
|
||||
Self(CohortState::new(path, name, compute_dollars))
|
||||
}
|
||||
|
||||
pub fn height(&self) -> Option<Height> {
|
||||
self.0.height()
|
||||
}
|
||||
|
||||
pub fn reset_price_to_amount(&mut self) -> Result<()> {
|
||||
self.0.reset_price_to_amount()
|
||||
pub fn reset_price_to_amount_if_needed(&mut self) -> Result<()> {
|
||||
self.0.reset_price_to_amount_if_needed()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +1,65 @@
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
fs,
|
||||
io::{Cursor, Read},
|
||||
path::{Path, PathBuf},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
use brk_error::{Error, Result};
|
||||
use brk_error::Result;
|
||||
use brk_structs::{Dollars, Height, Sats};
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use pco::standalone::{simple_decompress, simpler_compress};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy::{FromBytes, IntoBytes};
|
||||
|
||||
use crate::states::SupplyState;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PriceToAmount {
|
||||
pathbuf: PathBuf,
|
||||
height: Option<Height>,
|
||||
state: State,
|
||||
state: Option<State>,
|
||||
}
|
||||
|
||||
const STATE_AT_: &str = "state_at_";
|
||||
const STATE_TO_KEEP: usize = 10;
|
||||
|
||||
impl PriceToAmount {
|
||||
pub fn forced_import(path: &Path, name: &str) -> Self {
|
||||
Self::import(path, name).unwrap_or_else(|_| {
|
||||
// dbg!(e);
|
||||
Self {
|
||||
pathbuf: Self::path_(path, name),
|
||||
height: None,
|
||||
state: State::default(),
|
||||
}
|
||||
})
|
||||
pub fn create(path: &Path, name: &str) -> Self {
|
||||
Self {
|
||||
pathbuf: path.join(format!("{name}_price_to_amount")),
|
||||
state: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import(path: &Path, name: &str) -> Result<Self> {
|
||||
let path = Self::path_(path, name);
|
||||
fs::create_dir_all(&path)?;
|
||||
|
||||
let state = State::deserialize(&fs::read(Self::path_state_(&path))?)?;
|
||||
|
||||
Ok(Self {
|
||||
height: Height::try_from(Self::path_height_(&path).as_path()).ok(),
|
||||
pathbuf: path,
|
||||
state,
|
||||
})
|
||||
pub fn import_at(&mut self, height: Height) -> Result<()> {
|
||||
self.state = Some(State::deserialize(&fs::read(self.path_state(height))?)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&Dollars, &Sats)> {
|
||||
self.state.iter()
|
||||
self.state.as_ref().unwrap().iter()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.state.is_empty()
|
||||
self.state.as_ref().unwrap().is_empty()
|
||||
}
|
||||
|
||||
pub fn first_key_value(&self) -> Option<(&Dollars, &Sats)> {
|
||||
self.state.first_key_value()
|
||||
self.state.as_ref().unwrap().first_key_value()
|
||||
}
|
||||
|
||||
pub fn last_key_value(&self) -> Option<(&Dollars, &Sats)> {
|
||||
self.state.last_key_value()
|
||||
self.state.as_ref().unwrap().last_key_value()
|
||||
}
|
||||
|
||||
pub fn increment(&mut self, price: Dollars, supply_state: &SupplyState) {
|
||||
*self.state.entry(price).or_default() += supply_state.value;
|
||||
*self.state.as_mut().unwrap().entry(price).or_default() += supply_state.value;
|
||||
}
|
||||
|
||||
pub fn decrement(&mut self, price: Dollars, supply_state: &SupplyState) {
|
||||
if let Some(amount) = self.state.get_mut(&price) {
|
||||
if let Some(amount) = self.state.as_mut().unwrap().get_mut(&price) {
|
||||
*amount -= supply_state.value;
|
||||
if *amount == Sats::ZERO {
|
||||
self.state.remove(&price);
|
||||
self.state.as_mut().unwrap().remove(&price);
|
||||
}
|
||||
} else {
|
||||
dbg!(&self.state, price, &self.pathbuf);
|
||||
@@ -77,83 +67,89 @@ impl PriceToAmount {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) -> Result<()> {
|
||||
self.state.clear();
|
||||
self.height = None;
|
||||
fs::remove_dir_all(&self.pathbuf)?;
|
||||
pub fn init(&mut self) {
|
||||
self.state.replace(State::default());
|
||||
}
|
||||
|
||||
pub fn clean(&mut self) -> Result<()> {
|
||||
let _ = fs::remove_dir_all(&self.pathbuf);
|
||||
fs::create_dir_all(&self.pathbuf)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn flush(&mut self, height: Height) -> Result<()> {
|
||||
self.height = Some(height);
|
||||
height.write(&self.path_height())?;
|
||||
fs::write(self.path_state(), self.state.serialize())?;
|
||||
let mut files: Vec<(SystemTime, PathBuf)> = fs::read_dir(&self.pathbuf)?
|
||||
.filter_map(|entry| {
|
||||
let path = entry.ok()?.path();
|
||||
let name = path.file_name()?.to_str()?;
|
||||
if name.starts_with(STATE_AT_) && name[STATE_AT_.len() + 1..].parse::<u64>().is_ok()
|
||||
{
|
||||
let modified = fs::metadata(&path).ok()?.modified().ok()?;
|
||||
Some((modified, path))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
files.sort_unstable_by_key(|(time, _)| *time);
|
||||
|
||||
for (_, path) in files.iter().take(files.len().saturating_sub(STATE_TO_KEEP)) {
|
||||
fs::remove_file(path)?;
|
||||
}
|
||||
|
||||
fs::write(
|
||||
self.path_state(height),
|
||||
self.state.as_ref().unwrap().serialize()?,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn height(&self) -> Option<Height> {
|
||||
self.height
|
||||
fn path_state(&self, height: Height) -> PathBuf {
|
||||
Self::path_state_(&self.pathbuf, height)
|
||||
}
|
||||
|
||||
fn path_(path: &Path, name: &str) -> PathBuf {
|
||||
path.join(format!("{name}_price_to_amount"))
|
||||
}
|
||||
|
||||
fn path_state(&self) -> PathBuf {
|
||||
Self::path_state_(&self.pathbuf)
|
||||
}
|
||||
fn path_state_(path: &Path) -> PathBuf {
|
||||
path.join("state")
|
||||
}
|
||||
|
||||
fn path_height(&self) -> PathBuf {
|
||||
Self::path_height_(&self.pathbuf)
|
||||
}
|
||||
fn path_height_(path: &Path) -> PathBuf {
|
||||
path.join("height")
|
||||
fn path_state_(path: &Path, height: Height) -> PathBuf {
|
||||
path.join(format!("{STATE_AT_}{}", height))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default, Debug, Deref, DerefMut, Serialize, Deserialize)]
|
||||
struct State(BTreeMap<Dollars, Sats>);
|
||||
|
||||
const COMPRESSION_LEVEL: usize = 4;
|
||||
|
||||
impl State {
|
||||
fn serialize(&self) -> Vec<u8> {
|
||||
let len = self.len();
|
||||
fn serialize(&self) -> vecdb::Result<Vec<u8>> {
|
||||
let keys: Vec<f64> = self.keys().cloned().map(f64::from).collect();
|
||||
let values: Vec<u64> = self.values().cloned().map(u64::from).collect();
|
||||
|
||||
let mut buffer = Vec::with_capacity(8 + len * 16);
|
||||
let compressed_keys = simpler_compress(&keys, COMPRESSION_LEVEL)?;
|
||||
let compressed_values = simpler_compress(&values, COMPRESSION_LEVEL)?;
|
||||
|
||||
buffer.extend(len.as_bytes());
|
||||
let mut buffer = Vec::new();
|
||||
buffer.extend(&(keys.len() as u64).to_ne_bytes());
|
||||
buffer.extend(&(compressed_keys.len() as u64).to_ne_bytes());
|
||||
buffer.extend(compressed_keys);
|
||||
buffer.extend(compressed_values);
|
||||
|
||||
self.iter().for_each(|(key, value)| {
|
||||
buffer.extend(key.as_bytes());
|
||||
buffer.extend(value.as_bytes());
|
||||
});
|
||||
|
||||
buffer
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
fn deserialize(data: &[u8]) -> Result<Self> {
|
||||
let mut cursor = Cursor::new(data);
|
||||
let mut buffer = [0u8; 8];
|
||||
fn deserialize(data: &[u8]) -> vecdb::Result<Self> {
|
||||
let entry_count = u64::from_ne_bytes(data[0..8].try_into().unwrap()) as usize;
|
||||
let keys_len = u64::from_ne_bytes(data[8..16].try_into().unwrap()) as usize;
|
||||
|
||||
cursor
|
||||
.read_exact(&mut buffer)
|
||||
.map_err(|_| Error::Str("Failed to read entry count"))?;
|
||||
let entry_count = usize::read_from_bytes(&buffer)?;
|
||||
let keys: Vec<f64> = simple_decompress(&data[16..16 + keys_len])?;
|
||||
let values: Vec<u64> = simple_decompress(&data[16 + keys_len..])?;
|
||||
|
||||
let mut map = BTreeMap::new();
|
||||
let map: BTreeMap<Dollars, Sats> = keys
|
||||
.into_iter()
|
||||
.zip(values)
|
||||
.map(|(k, v)| (Dollars::from(k), Sats::from(v)))
|
||||
.collect();
|
||||
|
||||
for _ in 0..entry_count {
|
||||
cursor.read_exact(&mut buffer)?;
|
||||
let key = Dollars::read_from_bytes(&buffer)?;
|
||||
|
||||
cursor.read_exact(&mut buffer)?;
|
||||
let value = Sats::read_from_bytes(&buffer)?;
|
||||
|
||||
map.insert(key, value);
|
||||
}
|
||||
assert_eq!(map.len(), entry_count);
|
||||
|
||||
Ok(Self(map))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user