mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11: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
|
||||
// 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,
|
||||
|
|
|
@ -1423,6 +1423,12 @@ pub fn zip_read(root_dir: String, header: &BlockHeader) -> Result<File, Error> {
|
|||
// 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<File, Error> {
|
|||
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())?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue