mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 02:21:14 +00:00
Move import lock onto backend (#2797)
* Drop import_lock from client, move it into backend, impl default version via static mutex * still need to allow depcretion because of client.backend * additional docs * Remove default impl of get_import_lock, impl on instances * Bump parking_lot to 0.8.0 accross the board
This commit is contained in:
committed by
Bastian Köcher
parent
4f888f34d3
commit
eaa0ab014a
@@ -8,7 +8,7 @@ edition = "2018"
|
||||
derive_more = { version = "0.14.0", optional = true }
|
||||
fnv = { version = "1.0", optional = true }
|
||||
log = { version = "0.4", optional = true }
|
||||
parking_lot = { version = "0.7.1", optional = true }
|
||||
parking_lot = { version = "0.8.0", optional = true }
|
||||
hex = { package = "hex-literal", version = "0.1", optional = true }
|
||||
futures = { version = "0.1.17", optional = true }
|
||||
consensus = { package = "substrate-consensus-common", path = "../consensus/common", optional = true }
|
||||
|
||||
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8"
|
||||
log = "0.4"
|
||||
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
|
||||
# FIXME replace with release as soon as our rocksdb changes are released upstream https://github.com/paritytech/parity-common/issues/88
|
||||
|
||||
@@ -656,6 +656,7 @@ pub struct Backend<Block: BlockT> {
|
||||
blockchain: BlockchainDb<Block>,
|
||||
canonicalization_delay: u64,
|
||||
shared_cache: SharedCache<Block, Blake2Hasher>,
|
||||
import_lock: Mutex<()>,
|
||||
}
|
||||
|
||||
impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
||||
@@ -722,6 +723,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
|
||||
blockchain,
|
||||
canonicalization_delay,
|
||||
shared_cache: new_shared_cache(state_cache_size),
|
||||
import_lock: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1350,6 +1352,10 @@ impl<Block> client::backend::Backend<Block, Blake2Hasher> for Backend<Block> whe
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_import_lock(&self) -> &Mutex<()> {
|
||||
&self.import_lock
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block> client::backend::LocalBackend<Block, Blake2Hasher> for Backend<Block>
|
||||
|
||||
@@ -26,6 +26,7 @@ use state_machine::ChangesTrieStorage as StateChangesTrieStorage;
|
||||
use consensus::well_known_cache_keys;
|
||||
use hash_db::Hasher;
|
||||
use trie::MemoryDB;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
/// State of a new block.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -174,6 +175,13 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
|
||||
fn get_aux(&self, key: &[u8]) -> error::Result<Option<Vec<u8>>> {
|
||||
AuxStore::get_aux(self, key)
|
||||
}
|
||||
|
||||
/// Gain access to the import lock around this backend.
|
||||
/// _Note_ Backend isn't expected to acquire the lock by itself ever. Rather
|
||||
/// the using components should acquire and hold the lock whenever they do
|
||||
/// something that the import of a block would interfere with, e.g. importing
|
||||
/// a new block or calculating the best head.
|
||||
fn get_import_lock(&self) -> &Mutex<()>;
|
||||
}
|
||||
|
||||
/// Changes trie storage that supports pruning.
|
||||
|
||||
@@ -124,7 +124,6 @@ pub struct Client<B, E, Block, RA> where Block: BlockT {
|
||||
storage_notifications: Mutex<StorageNotifications<Block>>,
|
||||
import_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<BlockImportNotification<Block>>>>,
|
||||
finality_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<FinalityNotification<Block>>>>,
|
||||
import_lock: Arc<Mutex<()>>,
|
||||
// holds the block hash currently being imported. TODO: replace this with block queue
|
||||
importing_block: RwLock<Option<Block::Hash>>,
|
||||
execution_strategies: ExecutionStrategies,
|
||||
@@ -318,7 +317,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
storage_notifications: Default::default(),
|
||||
import_notification_sinks: Default::default(),
|
||||
finality_notification_sinks: Default::default(),
|
||||
import_lock: Default::default(),
|
||||
importing_block: Default::default(),
|
||||
execution_strategies,
|
||||
_phantom: Default::default(),
|
||||
@@ -344,15 +342,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
&self.backend
|
||||
}
|
||||
|
||||
/// Expose reference to import lock
|
||||
#[doc(hidden)]
|
||||
#[deprecated(note="Rather than relying on `client` to provide this, access \
|
||||
to the backend should be handled at setup only - see #1134. This function \
|
||||
will be removed once that is in place.")]
|
||||
pub fn import_lock(&self) -> Arc<Mutex<()>> {
|
||||
self.import_lock.clone()
|
||||
}
|
||||
|
||||
/// Given a `BlockId` and a key prefix, return the matching child storage keys in that block.
|
||||
pub fn storage_keys(&self, id: &BlockId<Block>, key_prefix: &StorageKey) -> error::Result<Vec<StorageKey>> {
|
||||
let keys = self.state_at(id)?.keys(&key_prefix.0).into_iter().map(StorageKey).collect();
|
||||
@@ -744,7 +733,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
Err: From<error::Error>,
|
||||
{
|
||||
let inner = || {
|
||||
let _import_lock = self.import_lock.lock();
|
||||
let _import_lock = self.backend.get_import_lock().lock();
|
||||
|
||||
let mut op = ClientImportOperation {
|
||||
op: self.backend.begin_operation()?,
|
||||
@@ -1493,17 +1482,14 @@ where
|
||||
/// where 'longest' is defined as the highest number of blocks
|
||||
pub struct LongestChain<B, Block> {
|
||||
backend: Arc<B>,
|
||||
import_lock: Arc<Mutex<()>>,
|
||||
_phantom: PhantomData<Block>
|
||||
}
|
||||
|
||||
impl<B, Block> Clone for LongestChain<B, Block> {
|
||||
fn clone(&self) -> Self {
|
||||
let backend = self.backend.clone();
|
||||
let import_lock = self.import_lock.clone();
|
||||
LongestChain {
|
||||
backend,
|
||||
import_lock,
|
||||
_phantom: Default::default()
|
||||
}
|
||||
}
|
||||
@@ -1515,10 +1501,9 @@ where
|
||||
Block: BlockT<Hash=H256>,
|
||||
{
|
||||
/// Instantiate a new LongestChain for Backend B
|
||||
pub fn new(backend: Arc<B>, import_lock: Arc<Mutex<()>>) -> Self {
|
||||
pub fn new(backend: Arc<B>) -> Self {
|
||||
LongestChain {
|
||||
backend,
|
||||
import_lock,
|
||||
_phantom: Default::default()
|
||||
}
|
||||
}
|
||||
@@ -1564,7 +1549,7 @@ where
|
||||
// ensure no blocks are imported during this code block.
|
||||
// an import could trigger a reorg which could change the canonical chain.
|
||||
// we depend on the canonical chain staying the same during this code block.
|
||||
let _import_lock = self.import_lock.lock();
|
||||
let _import_lock = self.backend.get_import_lock().lock();
|
||||
|
||||
let info = self.backend.blockchain().info();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
use primitives::{ChangesTrieConfiguration, storage::well_known_keys};
|
||||
use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{
|
||||
@@ -541,6 +541,7 @@ where
|
||||
states: RwLock<HashMap<Block::Hash, InMemory<H>>>,
|
||||
changes_trie_storage: ChangesTrieStorage<Block, H>,
|
||||
blockchain: Blockchain<Block>,
|
||||
import_lock: Mutex<()>,
|
||||
}
|
||||
|
||||
impl<Block, H> Backend<Block, H>
|
||||
@@ -555,6 +556,7 @@ where
|
||||
states: RwLock::new(HashMap::new()),
|
||||
changes_trie_storage: ChangesTrieStorage(InMemoryChangesTrieStorage::new()),
|
||||
blockchain: Blockchain::new(),
|
||||
import_lock: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -684,6 +686,10 @@ where
|
||||
fn revert(&self, _n: NumberFor<Block>) -> error::Result<NumberFor<Block>> {
|
||||
Ok(Zero::zero())
|
||||
}
|
||||
|
||||
fn get_import_lock(&self) -> &Mutex<()> {
|
||||
&self.import_lock
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, H> backend::LocalBackend<Block, H> for Backend<Block, H>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, Weak};
|
||||
use futures::{Future, IntoFuture};
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
|
||||
use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
|
||||
use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState};
|
||||
@@ -41,6 +41,7 @@ const IN_MEMORY_EXPECT_PROOF: &str = "InMemory state backend has Void error type
|
||||
pub struct Backend<S, F, H: Hasher> {
|
||||
blockchain: Arc<Blockchain<S, F>>,
|
||||
genesis_state: RwLock<Option<InMemoryState<H>>>,
|
||||
import_lock: Mutex<()>,
|
||||
}
|
||||
|
||||
/// Light block (header and justification) import operation.
|
||||
@@ -77,6 +78,7 @@ impl<S, F, H: Hasher> Backend<S, F, H> {
|
||||
Self {
|
||||
blockchain,
|
||||
genesis_state: RwLock::new(None),
|
||||
import_lock: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +215,10 @@ impl<S, F, Block, H> ClientBackend<Block, H> for Backend<S, F, H> where
|
||||
fn revert(&self, _n: NumberFor<Block>) -> ClientResult<NumberFor<Block>> {
|
||||
Err(ClientError::NotAvailableOnLightClient.into())
|
||||
}
|
||||
|
||||
fn get_import_lock(&self) -> &Mutex<()> {
|
||||
&self.import_lock
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, F, Block, H> RemoteBackend<Block, H> for Backend<S, F, H>
|
||||
|
||||
@@ -23,7 +23,7 @@ authorities = { package = "substrate-consensus-authorities", path = "../authorit
|
||||
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
|
||||
futures = "0.1.17"
|
||||
tokio = "0.1.7"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -886,7 +886,6 @@ mod tests {
|
||||
#[allow(deprecated)]
|
||||
let select_chain = LongestChain::new(
|
||||
client.backend().clone(),
|
||||
client.import_lock().clone(),
|
||||
);
|
||||
let environ = Arc::new(DummyFactory(client.clone()));
|
||||
import_notifications.push(
|
||||
|
||||
@@ -24,7 +24,7 @@ slots = { package = "substrate-consensus-slots", path = "../slots" }
|
||||
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
|
||||
futures = "0.1.26"
|
||||
tokio = "0.1.18"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4.6"
|
||||
schnorrkel = "0.1.1"
|
||||
rand = "0.6.5"
|
||||
|
||||
@@ -975,7 +975,7 @@ mod tests {
|
||||
|
||||
|
||||
#[allow(deprecated)]
|
||||
let select_chain = LongestChain::new(client.backend().clone(), client.import_lock().clone());
|
||||
let select_chain = LongestChain::new(client.backend().clone());
|
||||
|
||||
let babe = start_babe(BabeParams {
|
||||
config,
|
||||
|
||||
@@ -18,7 +18,7 @@ runtime_version = { package = "sr-version", path = "../../sr-version" }
|
||||
runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
|
||||
tokio-timer = "0.2"
|
||||
parity-codec = { version = "3.3", features = ["derive"] }
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
|
||||
[dev-dependencies]
|
||||
test_client = { package = "substrate-test-client", path = "../../test-client" }
|
||||
|
||||
@@ -20,7 +20,7 @@ runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" }
|
||||
runtime_version = { package = "sr-version", path = "../../sr-version" }
|
||||
runtime_io = { package = "sr-io", path = "../../sr-io" }
|
||||
tokio = "0.1.7"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4"
|
||||
rhododendron = { version = "0.5.0", features = ["codec"] }
|
||||
exit-future = "0.1"
|
||||
|
||||
@@ -14,7 +14,7 @@ consensus_common = { package = "substrate-consensus-common", path = "../common"
|
||||
inherents = { package = "substrate-inherents", path = "../../inherents" }
|
||||
futures = "0.1.17"
|
||||
tokio = "0.1.7"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -17,7 +17,7 @@ panic-handler = { package = "substrate-panic-handler", path = "../panic-handler"
|
||||
wasmi = { version = "0.4.3" }
|
||||
byteorder = "1.1"
|
||||
lazy_static = "1.0"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4"
|
||||
libsecp256k1 = "0.2.1"
|
||||
tiny-keccak = "1.4.2"
|
||||
|
||||
@@ -8,7 +8,7 @@ edition = "2018"
|
||||
fork-tree = { path = "../../core/util/fork-tree" }
|
||||
futures = "0.1"
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
tokio = "0.1.7"
|
||||
rand = "0.6"
|
||||
parity-codec = { version = "3.3", features = ["derive"] }
|
||||
|
||||
@@ -121,8 +121,7 @@ impl TestNetFactory for GrandpaTestNet {
|
||||
PeersClient::Full(ref client) => {
|
||||
#[allow(deprecated)]
|
||||
let select_chain = LongestChain::new(
|
||||
client.backend().clone(),
|
||||
client.import_lock().clone()
|
||||
client.backend().clone()
|
||||
);
|
||||
let (import, link) = block_import(
|
||||
client.clone(),
|
||||
|
||||
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
parking_lot = { version = "0.7", optional = true }
|
||||
parking_lot = { version = "0.8.0", optional = true }
|
||||
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
|
||||
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
|
||||
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false }
|
||||
|
||||
@@ -13,7 +13,7 @@ bytes = "0.4"
|
||||
fnv = "1.0"
|
||||
futures = "0.1"
|
||||
libp2p = { version = "0.9.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
lazy_static = "1.2"
|
||||
log = "0.4"
|
||||
rand = "0.6"
|
||||
|
||||
@@ -11,7 +11,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
derive_more = "0.14.0"
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
bitflags = "1.0"
|
||||
futures = "0.1.17"
|
||||
linked-hash-map = "0.5"
|
||||
|
||||
@@ -13,7 +13,7 @@ futures = "0.1.25"
|
||||
log = "0.4"
|
||||
offchain-primitives = { package = "substrate-offchain-primitives", path = "./primitives" }
|
||||
parity-codec = { version = "3.3", features = ["derive"] }
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
|
||||
runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" }
|
||||
tokio = "0.1.7"
|
||||
|
||||
@@ -11,7 +11,7 @@ jsonrpc-core-client = "12.0.0"
|
||||
jsonrpc-pubsub = "12.0.0"
|
||||
jsonrpc-derive = "12.0.0"
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
parity-codec = "3.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
|
||||
@@ -7,7 +7,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
derive_more = "0.14.0"
|
||||
futures = "0.1.17"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
lazy_static = "1.0"
|
||||
log = "0.4"
|
||||
slog = {version = "^2", features = ["nested-values"]}
|
||||
|
||||
@@ -622,7 +622,8 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
|
||||
/// { |_, client| Ok(BasicQueue::new(Arc::new(MyVerifier), client, None, None, None)) },
|
||||
/// SelectChain = LongestChain<FullBackend<Self>, Self::Block>
|
||||
/// { |config: &FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
|
||||
/// Ok(LongestChain::new(client.backend().clone(), client.import_lock()))
|
||||
/// #[allow(deprecated)]
|
||||
/// Ok(LongestChain::new(client.backend().clone()))
|
||||
/// }},
|
||||
/// FinalityProofProvider = { |client: Arc<FullClient<Self>>| {
|
||||
/// Ok(Some(Arc::new(grandpa::FinalityProofProvider::new(client.clone(), client)) as _))
|
||||
|
||||
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
log = "0.4"
|
||||
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
|
||||
parity-codec = { version = "3.3", features = ["derive"] }
|
||||
|
||||
@@ -7,7 +7,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
hash-db = "0.12"
|
||||
trie-db = "0.12"
|
||||
trie-root = "0.12"
|
||||
|
||||
@@ -6,7 +6,7 @@ description = "Telemetry utils"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
lazy_static = "1.0"
|
||||
log = "0.4"
|
||||
rand = "0.6"
|
||||
|
||||
@@ -237,7 +237,7 @@ impl<E, B> TestClientBuilder<E, B> where
|
||||
).expect("Creates new client");
|
||||
|
||||
#[allow(deprecated)]
|
||||
let longest_chain = client::LongestChain::new(self.backend, client.import_lock());
|
||||
let longest_chain = client::LongestChain::new(self.backend);
|
||||
|
||||
(client, longest_chain)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ derive_more = "0.14.0"
|
||||
futures = "0.1"
|
||||
log = "0.4"
|
||||
parity-codec = "3.3"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
sr-primitives = { path = "../sr-primitives" }
|
||||
client = { package = "substrate-client", path = "../client" }
|
||||
substrate-primitives = { path = "../primitives" }
|
||||
|
||||
@@ -8,7 +8,7 @@ edition = "2018"
|
||||
derive_more = "0.14.0"
|
||||
futures = "0.1"
|
||||
log = "0.4"
|
||||
parking_lot = "0.7.1"
|
||||
parking_lot = "0.8.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
substrate-primitives = { path = "../../primitives" }
|
||||
sr-primitives = { path = "../../sr-primitives" }
|
||||
|
||||
Reference in New Issue
Block a user