computer: stateful: reset when reorg detected

This commit is contained in:
nym21
2025-06-13 18:03:09 +02:00
parent f477bd66f3
commit 2f74748cea
5 changed files with 23 additions and 27 deletions

View File

@@ -1289,7 +1289,7 @@ impl Vecs {
base_version + self.height_to_opreturn_supply.inner_version(), base_version + self.height_to_opreturn_supply.inner_version(),
)?; )?;
let mut chain_state: Vec<BlockState>; let mut chain_state: Vec<BlockState> = vec![];
let mut chain_state_starting_height = Height::from(self.chain_state.len()); let mut chain_state_starting_height = Height::from(self.chain_state.len());
let stateful_starting_height = match separate_utxo_vecs let stateful_starting_height = match separate_utxo_vecs
@@ -1322,25 +1322,27 @@ impl Vecs {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
chain_state_starting_height chain_state_starting_height
} }
Ordering::Less => { Ordering::Less => Height::ZERO,
// todo!("rollback instead");
chain_state = vec![];
chain_state_starting_height = Height::ZERO;
Height::ZERO
}
}; };
if stateful_starting_height.is_zero() {
info!("Starting processing utxos from the start");
separate_utxo_vecs
.par_iter_mut()
.try_for_each(|(_, v)| v.state.price_to_amount.reset())?;
}
let starting_height = starting_indexes let starting_height = starting_indexes
.height .height
.min(stateful_starting_height) .min(stateful_starting_height)
.min(Height::from(self.height_to_unspendable_supply.len())) .min(Height::from(self.height_to_unspendable_supply.len()))
.min(Height::from(self.height_to_opreturn_supply.len())); .min(Height::from(self.height_to_opreturn_supply.len()));
if starting_height.is_zero() {
info!("Starting processing utxos from the start");
// todo!("rollback instead");
chain_state = vec![];
chain_state_starting_height = Height::ZERO;
separate_utxo_vecs
.par_iter_mut()
.try_for_each(|(_, v)| v.state.price_to_amount.reset())?;
}
if starting_height == Height::from(height_to_date_fixed.len()) { if starting_height == Height::from(height_to_date_fixed.len()) {
return Ok(()); return Ok(());
} }

View File

@@ -14,16 +14,16 @@ fn main() -> color_eyre::Result<()> {
Binance::fetch_1d().map(|b| { Binance::fetch_1d().map(|b| {
dbg!(b.last_key_value()); dbg!(b.last_key_value());
}); })?;
Kraken::fetch_1d().map(|b| { Kraken::fetch_1d().map(|b| {
dbg!(b.last_key_value()); dbg!(b.last_key_value());
}); })?;
Binance::fetch_1mn().map(|b| { Binance::fetch_1mn().map(|b| {
dbg!(b.last_key_value()); dbg!(b.last_key_value());
}); })?;
Kraken::fetch_1mn().map(|b| { Kraken::fetch_1mn().map(|b| {
dbg!(b.last_key_value()); dbg!(b.last_key_value());
}); })?;
dbg!(fetcher.get_date(Date::new(2025, 6, 5))?); dbg!(fetcher.get_date(Date::new(2025, 6, 5))?);
dbg!(fetcher.get_height( dbg!(fetcher.get_height(

View File

@@ -110,13 +110,7 @@ impl TryFrom<(&mut Vecs, &Stores, &Client)> for Indexes {
vecs.height_to_blockhash vecs.height_to_blockhash
.iter() .iter()
.get(*height) .get(*height)
.is_none_or(|saved_blockhash| { .is_none_or(|saved_blockhash| &rpc_blockhash != saved_blockhash.as_ref())
let b = &rpc_blockhash != saved_blockhash.as_ref();
if b {
dbg!(rpc_blockhash, saved_blockhash.as_ref());
}
b
})
}) })
.unwrap_or(starting_height); .unwrap_or(starting_height);

View File

@@ -1,6 +1,6 @@
{ {
"name": "kibo.money", "name": "brk",
"short_name": "kibo", "short_name": "brk",
"description": "A better, FOSS, Bitcoin-only, self-hostable Glassnode", "description": "A better, FOSS, Bitcoin-only, self-hostable Glassnode",
"categories": [ "categories": [
"bitcoin", "bitcoin",

View File

@@ -2,7 +2,7 @@
// File auto-generated, any modifications will be overwritten // File auto-generated, any modifications will be overwritten
// //
export const VERSION = "v0.0.54"; export const VERSION = "v0.0.55";
/** @typedef {0} DateIndex */ /** @typedef {0} DateIndex */
/** @typedef {1} DecadeIndex */ /** @typedef {1} DecadeIndex */