Skip to content

Commit

Permalink
roll the "fix invalid root" changes into this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Sep 4, 2019
1 parent c600304 commit dc70c86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 6 additions & 4 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl Chain {

let mut header_pmmr =
PMMRHandle::new(&db_root, "header", "header_head", false, true, None)?;
let sync_pmmr = PMMRHandle::new(&db_root, "header", "header_head", false, true, None)?;
let sync_pmmr = PMMRHandle::new(&db_root, "header", "sync_head", false, true, None)?;

setup_head(&genesis, &store, &mut header_pmmr, &mut txhashset)?;
Chain::log_heads(&store)?;
Expand Down Expand Up @@ -1332,7 +1332,7 @@ impl Chain {
min_height: Option<u64>,
max_height: Option<u64>,
) -> Result<BlockHeader, Error> {
let txhashset = self.txhashset.read();
let header_pmmr = self.header_pmmr.read();

let mut min = min_height.unwrap_or(0).saturating_sub(1);
let mut max = match max_height {
Expand All @@ -1342,11 +1342,13 @@ impl Chain {

loop {
let search_height = max - (max - min) / 2;
let h = txhashset.get_header_by_height(search_height)?;
let hash = header_pmmr.get_header_hash_by_height(search_height)?;
let h = self.get_block_header(&hash)?;
if search_height == 0 {
return Ok(h);
}
let h_prev = txhashset.get_header_by_height(search_height - 1)?;
let hash_prev = header_pmmr.get_header_hash_by_height(search_height - 1)?;
let h_prev = self.get_block_header(&hash_prev)?;
if kernel_mmr_index > h.kernel_mmr_size {
min = search_height;
} else if kernel_mmr_index < h_prev.kernel_mmr_size {
Expand Down
14 changes: 6 additions & 8 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,14 @@ where
let commit_index = trees.commit_index.clone();
let batch = commit_index.batch()?;

// We want to use the current head of the most work chain unless
// we explicitly rewind the extension.
let head = batch.head()?;

trace!("Starting new txhashset (readonly) extension.");

let head = batch.head()?;
let header_head = batch.header_head()?;

let res = {
let header_pmmr = PMMR::at(&mut handle.backend, handle.last_pos);
let mut header_extension = HeaderExtension::new(header_pmmr, &batch, head.clone());
let mut header_extension = HeaderExtension::new(header_pmmr, &batch, header_head);
let mut extension = Extension::new(trees, &batch, head);
let mut extension_pair = ExtensionPair {
header_extension: &mut header_extension,
Expand Down Expand Up @@ -431,9 +430,8 @@ where
let res: Result<T, Error>;
let rollback: bool;

// We want to use the current head of the most work chain unless
// we explicitly rewind the extension.
let head = batch.head()?;
let header_head = batch.header_head()?;

// create a child transaction so if the state is rolled back by itself, all
// index saving can be undone
Expand All @@ -442,7 +440,7 @@ where
trace!("Starting new txhashset extension.");

let pmmr = PMMR::at(&mut header_pmmr.backend, header_pmmr.last_pos);
let mut header_extension = HeaderExtension::new(pmmr, &child_batch, head.clone());
let mut header_extension = HeaderExtension::new(pmmr, &child_batch, header_head);
let mut extension = Extension::new(trees, &child_batch, head);
let mut extension_pair = ExtensionPair {
header_extension: &mut header_extension,
Expand Down

0 comments on commit dc70c86

Please sign in to comment.