call zip_read fro within the txhashet lock for a consistent view on the files (#3142)

This commit is contained in:
Antioch Peverell 2019-11-26 21:17:28 +00:00 committed by GitHub
parent 11ac7d827a
commit e2795b1593
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 17 deletions

View file

@ -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,

View file

@ -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())?;