From dc70c86d21c2a38ba154435738ef0013d60d7bd3 Mon Sep 17 00:00:00 2001 From: antiochp <30642645+antiochp@users.noreply.github.com> Date: Thu, 29 Aug 2019 13:06:48 +0100 Subject: [PATCH] roll the "fix invalid root" changes into this PR --- chain/src/chain.rs | 10 ++++++---- chain/src/txhashset/txhashset.rs | 14 ++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 20642bab94..4c66660888 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -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)?; @@ -1332,7 +1332,7 @@ impl Chain { min_height: Option, max_height: Option, ) -> Result { - 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 { @@ -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 { diff --git a/chain/src/txhashset/txhashset.rs b/chain/src/txhashset/txhashset.rs index b9ced277d3..ea7638af0a 100644 --- a/chain/src/txhashset/txhashset.rs +++ b/chain/src/txhashset/txhashset.rs @@ -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, @@ -431,9 +430,8 @@ where let res: Result; 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 @@ -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,