mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 08:09:58 -07:00
parser: fix utxo panic after soft reset
This commit is contained in:
@@ -12,7 +12,7 @@ pub struct AddressCohortDurableStates {
|
||||
pub price_to_split_amount: PriceToValue<SplitByLiquidity<WAmount>>,
|
||||
}
|
||||
|
||||
const ONE_THIRD: f64 = 0.33333333333;
|
||||
const ONE_THIRD: f64 = 1.0 / 3.0;
|
||||
|
||||
// TODO: Clean that mess, move to a generic liquidity split and somehow support rest for non floats
|
||||
impl AddressCohortDurableStates {
|
||||
|
||||
@@ -118,7 +118,7 @@ impl AddressCohortsDurableStates {
|
||||
}
|
||||
|
||||
pub fn compute_one_shot_states(
|
||||
&mut self,
|
||||
&self,
|
||||
block_price: Price,
|
||||
date_price: Option<Price>,
|
||||
) -> AddressCohortsOneShotStates {
|
||||
|
||||
@@ -20,7 +20,10 @@ impl UTXOCohortsDurableStates {
|
||||
let mut s = Self::default();
|
||||
|
||||
if let Some(last_date_data) = date_data_vec.last() {
|
||||
let last_block_data = last_date_data.blocks.last().unwrap();
|
||||
let last_block_data = last_date_data.blocks.last().unwrap_or_else(|| {
|
||||
dbg!(&last_date_data);
|
||||
panic!()
|
||||
});
|
||||
|
||||
date_data_vec.iter().for_each(|date_data| {
|
||||
let year = date_data.date.year() as u32;
|
||||
@@ -137,7 +140,7 @@ impl UTXOCohortsDurableStates {
|
||||
}
|
||||
|
||||
pub fn compute_one_shot_states(
|
||||
&mut self,
|
||||
&self,
|
||||
block_price: Price,
|
||||
date_price: Option<Price>,
|
||||
) -> UTXOCohortsOneShotStates {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user