parser: fix utxo panic after soft reset

This commit is contained in:
k
2024-07-18 12:27:24 +02:00
parent 4d23fdef61
commit 1f9d1542f1
9 changed files with 135 additions and 99 deletions

View File

@@ -12,60 +12,29 @@ pub use cohorts_states::*;
use counters::*;
use date_data_vec::*;
use crate::{databases::AddressIndexToAddressData, datasets::AllDatasets, utils::log};
use crate::utils::log;
#[derive(Default, Allocative)]
pub struct States {
pub address_counters: Counters,
pub date_data_vec: DateDataVec,
pub address_cohorts_durable_states: AddressCohortsDurableStates,
pub utxo_cohorts_durable_states: UTXOCohortsDurableStates,
pub address_cohorts_durable_states: Option<AddressCohortsDurableStates>,
pub utxo_cohorts_durable_states: Option<UTXOCohortsDurableStates>,
}
impl States {
pub fn import(
address_index_to_address_data: &mut AddressIndexToAddressData,
datasets: &AllDatasets,
) -> color_eyre::Result<Self> {
pub fn import() -> color_eyre::Result<Self> {
let date_data_vec_handle = thread::spawn(DateDataVec::import);
let address_counters = Counters::import()?;
let date_data_vec = date_data_vec_handle.join().unwrap()?;
// TODO:
// For both address and utxo check if any of these datasets have a None min
// If so use default state otherwise init
// unrealized
// price_paid
// capitalization
// supply
// utxo
let mut address_cohorts_durable_states = AddressCohortsDurableStates::default();
let mut utxo_cohorts_durable_states = UTXOCohortsDurableStates::default();
if let Some(first_date_data) = date_data_vec.first() {
if let Some(first_block_data) = first_date_data.blocks.first() {
let first_height = first_block_data.height as usize;
let first_date = first_date_data.date;
// TODO: Do the same for addresses
address_cohorts_durable_states =
AddressCohortsDurableStates::init(address_index_to_address_data);
if !datasets.utxo.needs_durable_states(first_height, first_date) {
utxo_cohorts_durable_states = UTXOCohortsDurableStates::init(&date_data_vec);
}
}
}
Ok(Self {
address_cohorts_durable_states,
address_cohorts_durable_states: None,
address_counters,
date_data_vec,
utxo_cohorts_durable_states,
utxo_cohorts_durable_states: None,
})
}
@@ -74,13 +43,13 @@ impl States {
let _ = self.date_data_vec.reset();
self.utxo_cohorts_durable_states = UTXOCohortsDurableStates::default();
self.utxo_cohorts_durable_states = None;
// TODO: Check that they are ONLY computed in an `if include_addresses`
if include_addresses {
let _ = self.address_counters.reset();
self.address_cohorts_durable_states = AddressCohortsDurableStates::default();
self.address_cohorts_durable_states = None;
}
}