lock chain.head() for less time (scope it in a block) (#1625)

* lock the chain.head for less tieme (scope it in a block)

* actually scope it to that block...
This commit is contained in:
Antioch Peverell 2018-10-01 22:12:56 +01:00 committed by GitHub
parent c9c829514b
commit f15bfbd35b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -685,19 +685,24 @@ impl Chain {
); );
status.on_save(); status.on_save();
// replace the chain txhashset with the newly built one // Replace the chain txhashset with the newly built one.
{ {
let mut txhashset_ref = self.txhashset.write().unwrap(); let mut txhashset_ref = self.txhashset.write().unwrap();
*txhashset_ref = txhashset; *txhashset_ref = txhashset;
} }
// setup new head // Setup new head.
{ let head = {
let mut head = self.head.lock().unwrap(); let mut head = self.head.lock().unwrap();
*head = Tip::from_block(&header); *head = Tip::from_block(&header);
head.clone()
};
// Save the new head to the db and rebuild the header by height index.
{
batch.save_body_head(&head)?; batch.save_body_head(&head)?;
batch.save_header_height(&header)?; batch.save_header_height(&header)?;
batch.build_by_height_index(&header, true)?; batch.build_by_height_index(&header, true)?;
} }
// Commit all the changes to the db.
batch.commit()?; batch.commit()?;
debug!( debug!(
@ -705,6 +710,7 @@ impl Chain {
"chain: txhashset_write: finished committing the batch (head etc.)" "chain: txhashset_write: finished committing the batch (head etc.)"
); );
// Check for any orphan blocks and process them based on the new chain state.
self.check_orphans(header.height + 1); self.check_orphans(header.height + 1);
status.on_done(); status.on_done();