mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
call zip_read fro within the txhashet lock for a consistent view on the files (#3142)
This commit is contained in:
parent
11ac7d827a
commit
e2795b1593
2 changed files with 23 additions and 17 deletions
|
@ -671,24 +671,17 @@ impl Chain {
|
||||||
// The fast sync client does *not* have the necessary data
|
// The fast sync client does *not* have the necessary data
|
||||||
// to rewind after receiving the txhashset zip.
|
// to rewind after receiving the txhashset zip.
|
||||||
let header = self.get_block_header(&h)?;
|
let header = self.get_block_header(&h)?;
|
||||||
{
|
|
||||||
let mut header_pmmr = self.header_pmmr.write();
|
let mut header_pmmr = self.header_pmmr.write();
|
||||||
let mut txhashset = self.txhashset.write();
|
let mut txhashset = self.txhashset.write();
|
||||||
txhashset::extending_readonly(&mut header_pmmr, &mut txhashset, |ext| {
|
txhashset::extending_readonly(&mut header_pmmr, &mut txhashset, |ext| {
|
||||||
pipe::rewind_and_apply_fork(&header, ext)?;
|
pipe::rewind_and_apply_fork(&header, ext)?;
|
||||||
let ref mut extension = ext.extension;
|
ext.extension.snapshot()?;
|
||||||
extension.snapshot()?;
|
|
||||||
Ok(())
|
|
||||||
})?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepares the zip and return the corresponding Read
|
// prepare the zip
|
||||||
let txhashset_reader = txhashset::zip_read(self.db_root.clone(), &header)?;
|
txhashset::zip_read(self.db_root.clone(), &header)
|
||||||
Ok((
|
.map(|file| (header.output_mmr_size, header.kernel_mmr_size, file))
|
||||||
header.output_mmr_size,
|
})
|
||||||
header.kernel_mmr_size,
|
|
||||||
txhashset_reader,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// To support the ability to download the txhashset from multiple peers in parallel,
|
/// To support the ability to download the txhashset from multiple peers in parallel,
|
||||||
|
|
|
@ -1423,6 +1423,12 @@ pub fn zip_read(root_dir: String, header: &BlockHeader) -> Result<File, Error> {
|
||||||
// if file exist, just re-use it
|
// if file exist, just re-use it
|
||||||
let zip_file = File::open(zip_path.clone());
|
let zip_file = File::open(zip_path.clone());
|
||||||
if let Ok(zip) = zip_file {
|
if let Ok(zip) = zip_file {
|
||||||
|
debug!(
|
||||||
|
"zip_read: {} at {}: reusing existing zip file: {:?}",
|
||||||
|
header.hash(),
|
||||||
|
header.height,
|
||||||
|
zip_path
|
||||||
|
);
|
||||||
return Ok(zip);
|
return Ok(zip);
|
||||||
} else {
|
} else {
|
||||||
// clean up old zips.
|
// clean up old zips.
|
||||||
|
@ -1463,6 +1469,13 @@ pub fn zip_read(root_dir: String, header: &BlockHeader) -> Result<File, Error> {
|
||||||
temp_txhashset_path
|
temp_txhashset_path
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"zip_read: {} at {}: created zip file: {:?}",
|
||||||
|
header.hash(),
|
||||||
|
header.height,
|
||||||
|
zip_path
|
||||||
|
);
|
||||||
|
|
||||||
// open it again to read it back
|
// open it again to read it back
|
||||||
let zip_file = File::open(zip_path.clone())?;
|
let zip_file = File::open(zip_path.clone())?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue