From e2795b15933d2c69d7096c1dacfe0af0b078f072 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Tue, 26 Nov 2019 21:17:28 +0000 Subject: [PATCH] call zip_read fro within the txhashet lock for a consistent view on the files (#3142) --- chain/src/chain.rs | 27 ++++++++++----------------- chain/src/txhashset/txhashset.rs | 13 +++++++++++++ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index c529d05ea..b468c67c0 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -671,24 +671,17 @@ impl Chain { // The fast sync client does *not* have the necessary data // to rewind after receiving the txhashset zip. let header = self.get_block_header(&h)?; - { - let mut header_pmmr = self.header_pmmr.write(); - let mut txhashset = self.txhashset.write(); - txhashset::extending_readonly(&mut header_pmmr, &mut txhashset, |ext| { - pipe::rewind_and_apply_fork(&header, ext)?; - let ref mut extension = ext.extension; - extension.snapshot()?; - Ok(()) - })?; - } - // prepares the zip and return the corresponding Read - let txhashset_reader = txhashset::zip_read(self.db_root.clone(), &header)?; - Ok(( - header.output_mmr_size, - header.kernel_mmr_size, - txhashset_reader, - )) + let mut header_pmmr = self.header_pmmr.write(); + let mut txhashset = self.txhashset.write(); + txhashset::extending_readonly(&mut header_pmmr, &mut txhashset, |ext| { + pipe::rewind_and_apply_fork(&header, ext)?; + ext.extension.snapshot()?; + + // prepare the zip + txhashset::zip_read(self.db_root.clone(), &header) + .map(|file| (header.output_mmr_size, header.kernel_mmr_size, file)) + }) } /// To support the ability to download the txhashset from multiple peers in parallel, diff --git a/chain/src/txhashset/txhashset.rs b/chain/src/txhashset/txhashset.rs index ba2d3ef0f..ba14d9361 100644 --- a/chain/src/txhashset/txhashset.rs +++ b/chain/src/txhashset/txhashset.rs @@ -1423,6 +1423,12 @@ pub fn zip_read(root_dir: String, header: &BlockHeader) -> Result { // if file exist, just re-use it let zip_file = File::open(zip_path.clone()); if let Ok(zip) = zip_file { + debug!( + "zip_read: {} at {}: reusing existing zip file: {:?}", + header.hash(), + header.height, + zip_path + ); return Ok(zip); } else { // clean up old zips. @@ -1463,6 +1469,13 @@ pub fn zip_read(root_dir: String, header: &BlockHeader) -> Result { temp_txhashset_path }; + debug!( + "zip_read: {} at {}: created zip file: {:?}", + header.hash(), + header.height, + zip_path + ); + // open it again to read it back let zip_file = File::open(zip_path.clone())?;