Skip to content

Commit

Permalink
[PIBD_IMPL] Finalize PIBD download and move state to chain validation (
Browse files Browse the repository at this point in the history
…#3692)

* investigations as to why a slight rewind is needed on startup during PIBD

* move validation code into desegmenter validation thread (for now)

* ensure genesis entries in pmmrs are removed if they're removed in the first segment

* validation all working except for verifying kernel sums

* remove unneeded pmmr rollbacks on resume now root cause was found

* updates to remove unpruned leaves from leaf set when rebuilding pmmr

* remove + 1 to segment traversal iter length
  • Loading branch information
yeastplume authored Feb 15, 2022
1 parent 169e106 commit 3ea233d
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 68 deletions.
14 changes: 10 additions & 4 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::{
core::core::hash::{Hash, Hashed},
store::Batch,
txhashset::{ExtensionPair, HeaderExtension},
SyncState,
};
use grin_store::Error::NotFoundErr;
use std::collections::HashMap;
Expand Down Expand Up @@ -870,6 +871,7 @@ impl Chain {
pub fn desegmenter(
&self,
archive_header: &BlockHeader,
sync_state: Arc<SyncState>,
) -> Result<Arc<RwLock<Option<Desegmenter>>>, Error> {
// Use our cached desegmenter if we have one and the associated header matches.
if let Some(d) = self.pibd_desegmenter.write().as_ref() {
Expand All @@ -884,7 +886,7 @@ impl Chain {
}
// TODO: (Check whether we can do this.. we *should* be able to modify this as the desegmenter
// is in flight and we cross a horizon boundary, but needs more thinking)
let desegmenter = self.init_desegmenter(archive_header)?;
let desegmenter = self.init_desegmenter(archive_header, sync_state)?;
let mut cache = self.pibd_desegmenter.write();
*cache = Some(desegmenter.clone());

Expand All @@ -894,7 +896,11 @@ impl Chain {
/// initialize a desegmenter, which is capable of extending the hashset by appending
/// PIBD segments of the three PMMR trees + Bitmap PMMR
/// header should be the same header as selected for the txhashset.zip archive
fn init_desegmenter(&self, header: &BlockHeader) -> Result<Desegmenter, Error> {
fn init_desegmenter(
&self,
header: &BlockHeader,
sync_state: Arc<SyncState>,
) -> Result<Desegmenter, Error> {
debug!(
"init_desegmenter: initializing new desegmenter for {} at {}",
header.hash(),
Expand All @@ -905,7 +911,9 @@ impl Chain {
self.txhashset(),
self.header_pmmr.clone(),
header.clone(),
self.genesis.clone(),
self.store.clone(),
sync_state,
))
}

Expand Down Expand Up @@ -1657,8 +1665,6 @@ fn setup_head(
header.height,
header.hash()
);
let extension = &mut ext.extension;
extension.rewind_mmrs_to_last_inserted_leaves()?;
return Ok(());
}

Expand Down
Loading

0 comments on commit 3ea233d

Please sign in to comment.