Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call zip_read() from within the txhashet lock for a consistent view on the files #3142

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,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.
Expand Down Expand Up @@ -1410,6 +1416,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())?;

Expand Down