Fixed shared cache race on import (#4194)

* Fixed is_best race on import

* Take import lock outside of backend

* Actually take the lock
This commit is contained in:
Arkadiy Paronyan
2019-11-25 13:38:37 +01:00
committed by Gavin Wood
parent 50b84a6438
commit d56d6163ef
8 changed files with 56 additions and 48 deletions
+3 -3
View File
@@ -19,7 +19,7 @@
use std::collections::HashMap;
use std::sync::Arc;
use parking_lot::{RwLock, Mutex};
use parking_lot::RwLock;
use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState, ChangesTrieTransaction};
use primitives::offchain::storage::InMemOffchainStorage;
@@ -49,7 +49,7 @@ const IN_MEMORY_EXPECT_PROOF: &str = "InMemory state backend has Void error type
pub struct Backend<S, H: Hasher> {
blockchain: Arc<Blockchain<S>>,
genesis_state: RwLock<Option<InMemoryState<H>>>,
import_lock: Mutex<()>,
import_lock: RwLock<()>,
}
/// Light block (header and justification) import operation.
@@ -216,7 +216,7 @@ impl<S, Block, H> ClientBackend<Block, H> for Backend<S, H> where
Err(ClientError::NotAvailableOnLightClient)
}
fn get_import_lock(&self) -> &Mutex<()> {
fn get_import_lock(&self) -> &RwLock<()> {
&self.import_lock
}
}