Remove Backend::destroy_state (#5068)

* Remove `Backend::destroy_state`

This removes the `destroy_state` function of `Backend` and instead moves
the functionality into the `Drop` implementation of the state. This
makes it much easier to work with the state, as the user no longer needs
to call` destroy_state` manually. However, it requires that we switch
from `RwLock` to `ReentrantMutex` as while importing a block we maybe
need to lock again in `drop`.

* Bring back the `RwLock` and some other clean ups

* Fix compilation
This commit is contained in:
Gavin Wood
2020-03-05 17:01:52 +01:00
committed by GitHub
parent 26fc97f635
commit a8441ff968
7 changed files with 318 additions and 100 deletions
+4 -10
View File
@@ -830,15 +830,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
&state,
changes_trie_state.as_ref(),
*parent_hash,
);
{
let _lock = self.backend.get_import_lock().read();
self.backend.destroy_state(state)?;
}
// Make sure to consume the error, only after we have destroyed the state.
let gen_storage_changes = gen_storage_changes?;
)?;
if import_block.header.state_root()
!= &gen_storage_changes.transaction_storage_root
@@ -1792,7 +1784,9 @@ where
fn best_block_header(&self) -> sp_blockchain::Result<<Block as BlockT>::Header> {
let info = self.backend.blockchain().info();
let import_lock = self.backend.get_import_lock();
let best_hash = self.backend.blockchain().best_containing(info.best_hash, None, import_lock)?
let best_hash = self.backend
.blockchain()
.best_containing(info.best_hash, None, import_lock)?
.unwrap_or(info.best_hash);
Ok(self.backend.blockchain().header(BlockId::Hash(best_hash))?