Skip to main content

sc_client_api/
backend.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Substrate Client data backend
20
21use std::collections::HashSet;
22
23use parking_lot::RwLock;
24
25use sp_api::CallContext;
26use sp_consensus::BlockOrigin;
27use sp_core::offchain::OffchainStorage;
28use sp_runtime::{
29	traits::{Block as BlockT, HashingFor, NumberFor},
30	Justification, Justifications, StateVersion, Storage,
31};
32use sp_state_machine::{
33	backend::AsTrieBackend, ChildStorageCollection, IndexOperation, IterArgs,
34	OffchainChangesCollection, StorageCollection, StorageIterator,
35};
36use sp_storage::{ChildInfo, StorageData, StorageKey};
37pub use sp_trie::MerkleValue;
38
39use crate::{blockchain::Backend as BlockchainBackend, UsageInfo};
40
41pub use sp_state_machine::{Backend as StateBackend, BackendTransaction, KeyValueStates};
42
43/// Extracts the state backend type for the given backend.
44pub type StateBackendFor<B, Block> = <B as Backend<Block>>::State;
45
46/// Describes which block import notification stream should be notified.
47#[derive(Debug, Clone, Copy)]
48pub enum ImportNotificationAction {
49	/// Notify only when the node has synced to the tip or there is a re-org.
50	RecentBlock,
51	/// Notify for every single block no matter what the sync state is.
52	EveryBlock,
53	/// Both block import notifications above should be fired.
54	Both,
55	/// No block import notification should be fired.
56	None,
57}
58
59/// Import operation summary.
60///
61/// Contains information about the block that just got imported,
62/// including storage changes, reorged blocks, etc.
63pub struct ImportSummary<Block: BlockT> {
64	/// Block hash of the imported block.
65	pub hash: Block::Hash,
66	/// Import origin.
67	pub origin: BlockOrigin,
68	/// Header of the imported block.
69	pub header: Block::Header,
70	/// Is this block a new best block.
71	pub is_new_best: bool,
72	/// Optional storage changes.
73	pub storage_changes: Option<(StorageCollection, ChildStorageCollection)>,
74	/// Tree route from old best to new best.
75	///
76	/// If `None`, there was no re-org while importing.
77	pub tree_route: Option<sp_blockchain::TreeRoute<Block>>,
78	/// What notify action to take for this import.
79	pub import_notification_action: ImportNotificationAction,
80}
81
82/// A stale block.
83#[derive(Clone, Debug)]
84pub struct StaleBlock<Block: BlockT> {
85	/// The hash of this block.
86	pub hash: Block::Hash,
87	/// Is this a head?
88	pub is_head: bool,
89}
90
91/// Finalization operation summary.
92///
93/// Contains information about the block that just got finalized,
94/// including tree heads that became stale at the moment of finalization.
95pub struct FinalizeSummary<Block: BlockT> {
96	/// Last finalized block header.
97	pub header: Block::Header,
98	/// Blocks that were finalized.
99	///
100	/// The last entry is the one that has been explicitly finalized.
101	pub finalized: Vec<Block::Hash>,
102	/// Blocks that became stale during this finalization operation.
103	pub stale_blocks: Vec<StaleBlock<Block>>,
104}
105
106/// Import operation wrapper.
107pub struct ClientImportOperation<Block: BlockT, B: Backend<Block>> {
108	/// DB Operation.
109	pub op: B::BlockImportOperation,
110	/// Summary of imported block.
111	pub notify_imported: Option<ImportSummary<Block>>,
112	/// Summary of finalized block.
113	pub notify_finalized: Option<FinalizeSummary<Block>>,
114}
115
116/// Helper function to apply auxiliary data insertion into an operation.
117pub fn apply_aux<'a, 'b: 'a, 'c: 'a, B, Block, D, I>(
118	operation: &mut ClientImportOperation<Block, B>,
119	insert: I,
120	delete: D,
121) -> sp_blockchain::Result<()>
122where
123	Block: BlockT,
124	B: Backend<Block>,
125	I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
126	D: IntoIterator<Item = &'a &'b [u8]>,
127{
128	operation.op.insert_aux(
129		insert
130			.into_iter()
131			.map(|(k, v)| (k.to_vec(), Some(v.to_vec())))
132			.chain(delete.into_iter().map(|k| (k.to_vec(), None))),
133	)
134}
135
136/// State of a new block.
137#[derive(Debug, Clone, Copy, PartialEq, Eq)]
138pub enum NewBlockState {
139	/// Normal block.
140	Normal,
141	/// New best block.
142	Best,
143	/// Newly finalized block (implicitly best).
144	Final,
145}
146
147impl NewBlockState {
148	/// Whether this block is the new best block.
149	pub fn is_best(self) -> bool {
150		match self {
151			NewBlockState::Best | NewBlockState::Final => true,
152			NewBlockState::Normal => false,
153		}
154	}
155
156	/// Whether this block is considered final.
157	pub fn is_final(self) -> bool {
158		match self {
159			NewBlockState::Final => true,
160			NewBlockState::Best | NewBlockState::Normal => false,
161		}
162	}
163}
164
165/// Block insertion operation.
166///
167/// Keeps hold if the inserted block state and data.
168pub trait BlockImportOperation<Block: BlockT> {
169	/// Associated state backend type.
170	type State: StateBackend<HashingFor<Block>>;
171
172	/// Returns pending state.
173	///
174	/// Returns None for backends with locally-unavailable state data.
175	fn state(&self) -> sp_blockchain::Result<Option<&Self::State>>;
176
177	/// Append block data to the transaction.
178	///
179	/// - `header`: The block header.
180	/// - `body`: The block body (extrinsics), if available.
181	/// - `indexed_body`: Raw extrinsic data to be stored in the transaction index, keyed by their
182	///   hash.
183	/// - `justifications`: Block justifications, e.g. finality proofs.
184	/// - `state`: Whether this is a normal block, the new best block, or a newly finalized block.
185	/// - `register_as_leaf`: Whether to add the block to the leaf set. Blocks imported during warp
186	///   sync are stored in the database but should not be registered as leaves, since they are
187	///   historical blocks and not candidates for chain progression.
188	fn set_block_data(
189		&mut self,
190		header: Block::Header,
191		body: Option<Vec<Block::Extrinsic>>,
192		indexed_body: Option<Vec<Vec<u8>>>,
193		justifications: Option<Justifications>,
194		state: NewBlockState,
195		register_as_leaf: bool,
196	) -> sp_blockchain::Result<()>;
197
198	/// Inject storage data into the database.
199	fn update_db_storage(
200		&mut self,
201		update: BackendTransaction<HashingFor<Block>>,
202	) -> sp_blockchain::Result<()>;
203
204	/// Set genesis state. If `commit` is `false` the state is saved in memory, but is not written
205	/// to the database.
206	fn set_genesis_state(
207		&mut self,
208		storage: Storage,
209		commit: bool,
210		state_version: StateVersion,
211	) -> sp_blockchain::Result<Block::Hash>;
212
213	/// Inject storage data into the database replacing any existing data.
214	fn reset_storage(
215		&mut self,
216		storage: Storage,
217		state_version: StateVersion,
218	) -> sp_blockchain::Result<Block::Hash>;
219
220	/// Set storage changes.
221	fn update_storage(
222		&mut self,
223		update: StorageCollection,
224		child_update: ChildStorageCollection,
225	) -> sp_blockchain::Result<()>;
226
227	/// Write offchain storage changes to the database.
228	fn update_offchain_storage(
229		&mut self,
230		_offchain_update: OffchainChangesCollection,
231	) -> sp_blockchain::Result<()> {
232		Ok(())
233	}
234
235	/// Insert auxiliary keys.
236	///
237	/// Values are `None` if should be deleted.
238	fn insert_aux<I>(&mut self, ops: I) -> sp_blockchain::Result<()>
239	where
240		I: IntoIterator<Item = (Vec<u8>, Option<Vec<u8>>)>;
241
242	/// Mark a block as finalized, if multiple blocks are finalized in the same operation then they
243	/// must be marked in ascending order.
244	fn mark_finalized(
245		&mut self,
246		hash: Block::Hash,
247		justification: Option<Justification>,
248	) -> sp_blockchain::Result<()>;
249
250	/// Mark a block as new head. If both block import and set head are specified, set head
251	/// overrides block import's best block rule.
252	fn mark_head(&mut self, hash: Block::Hash) -> sp_blockchain::Result<()>;
253
254	/// Add a transaction index operation.
255	fn update_transaction_index(&mut self, index: Vec<IndexOperation>)
256		-> sp_blockchain::Result<()>;
257
258	/// Configure whether to create a block gap if newly imported block is missing parent
259	fn set_create_gap(&mut self, create_gap: bool);
260}
261
262/// Interface for performing operations on the backend.
263pub trait LockImportRun<Block: BlockT, B: Backend<Block>> {
264	/// Lock the import lock, and run operations inside.
265	fn lock_import_and_run<R, Err, F>(&self, f: F) -> Result<R, Err>
266	where
267		F: FnOnce(&mut ClientImportOperation<Block, B>) -> Result<R, Err>,
268		Err: From<sp_blockchain::Error>;
269}
270
271/// Finalize Facilities
272pub trait Finalizer<Block: BlockT, B: Backend<Block>> {
273	/// Mark all blocks up to given as finalized in operation.
274	///
275	/// If `justification` is provided it is stored with the given finalized
276	/// block (any other finalized blocks are left unjustified).
277	///
278	/// If the block being finalized is on a different fork from the current
279	/// best block the finalized block is set as best, this might be slightly
280	/// inaccurate (i.e. outdated). Usages that require determining an accurate
281	/// best block should use `SelectChain` instead of the client.
282	fn apply_finality(
283		&self,
284		operation: &mut ClientImportOperation<Block, B>,
285		block: Block::Hash,
286		justification: Option<Justification>,
287		notify: bool,
288	) -> sp_blockchain::Result<()>;
289
290	/// Finalize a block.
291	///
292	/// This will implicitly finalize all blocks up to it and
293	/// fire finality notifications.
294	///
295	/// If the block being finalized is on a different fork from the current
296	/// best block, the finalized block is set as best. This might be slightly
297	/// inaccurate (i.e. outdated). Usages that require determining an accurate
298	/// best block should use `SelectChain` instead of the client.
299	///
300	/// Pass a flag to indicate whether finality notifications should be propagated.
301	/// This is usually tied to some synchronization state, where we don't send notifications
302	/// while performing major synchronization work.
303	fn finalize_block(
304		&self,
305		block: Block::Hash,
306		justification: Option<Justification>,
307		notify: bool,
308	) -> sp_blockchain::Result<()>;
309}
310
311/// Provides access to an auxiliary database.
312///
313/// This is a simple global database not aware of forks. Can be used for storing auxiliary
314/// information like total block weight/difficulty for fork resolution purposes as a common use
315/// case.
316pub trait AuxStore {
317	/// Insert auxiliary data into key-value store.
318	///
319	/// Deletions occur after insertions.
320	fn insert_aux<
321		'a,
322		'b: 'a,
323		'c: 'a,
324		I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
325		D: IntoIterator<Item = &'a &'b [u8]>,
326	>(
327		&self,
328		insert: I,
329		delete: D,
330	) -> sp_blockchain::Result<()>;
331
332	/// Query auxiliary data from key-value store.
333	fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>>;
334}
335
336/// An `Iterator` that iterates keys in a given block under a prefix.
337pub struct KeysIter<State, Block>
338where
339	State: StateBackend<HashingFor<Block>>,
340	Block: BlockT,
341{
342	inner: <State as StateBackend<HashingFor<Block>>>::RawIter,
343	state: State,
344}
345
346impl<State, Block> KeysIter<State, Block>
347where
348	State: StateBackend<HashingFor<Block>>,
349	Block: BlockT,
350{
351	/// Create a new iterator over storage keys.
352	pub fn new(
353		state: State,
354		prefix: Option<&StorageKey>,
355		start_at: Option<&StorageKey>,
356	) -> Result<Self, State::Error> {
357		let mut args = IterArgs::default();
358		args.prefix = prefix.as_ref().map(|prefix| prefix.0.as_slice());
359		args.start_at = start_at.as_ref().map(|start_at| start_at.0.as_slice());
360		args.start_at_exclusive = true;
361
362		Ok(Self { inner: state.raw_iter(args)?, state })
363	}
364
365	/// Create a new iterator over a child storage's keys.
366	pub fn new_child(
367		state: State,
368		child_info: ChildInfo,
369		prefix: Option<&StorageKey>,
370		start_at: Option<&StorageKey>,
371	) -> Result<Self, State::Error> {
372		let mut args = IterArgs::default();
373		args.prefix = prefix.as_ref().map(|prefix| prefix.0.as_slice());
374		args.start_at = start_at.as_ref().map(|start_at| start_at.0.as_slice());
375		args.child_info = Some(child_info);
376		args.start_at_exclusive = true;
377
378		Ok(Self { inner: state.raw_iter(args)?, state })
379	}
380}
381
382impl<State, Block> Iterator for KeysIter<State, Block>
383where
384	Block: BlockT,
385	State: StateBackend<HashingFor<Block>>,
386{
387	type Item = StorageKey;
388
389	fn next(&mut self) -> Option<Self::Item> {
390		self.inner.next_key(&self.state)?.ok().map(StorageKey)
391	}
392}
393
394/// An `Iterator` that iterates keys and values in a given block under a prefix.
395pub struct PairsIter<State, Block>
396where
397	State: StateBackend<HashingFor<Block>>,
398	Block: BlockT,
399{
400	inner: <State as StateBackend<HashingFor<Block>>>::RawIter,
401	state: State,
402}
403
404impl<State, Block> Iterator for PairsIter<State, Block>
405where
406	Block: BlockT,
407	State: StateBackend<HashingFor<Block>>,
408{
409	type Item = (StorageKey, StorageData);
410
411	fn next(&mut self) -> Option<Self::Item> {
412		self.inner
413			.next_pair(&self.state)?
414			.ok()
415			.map(|(key, value)| (StorageKey(key), StorageData(value)))
416	}
417}
418
419impl<State, Block> PairsIter<State, Block>
420where
421	State: StateBackend<HashingFor<Block>>,
422	Block: BlockT,
423{
424	/// Create a new iterator over storage key and value pairs.
425	pub fn new(
426		state: State,
427		prefix: Option<&StorageKey>,
428		start_at: Option<&StorageKey>,
429	) -> Result<Self, State::Error> {
430		let mut args = IterArgs::default();
431		args.prefix = prefix.as_ref().map(|prefix| prefix.0.as_slice());
432		args.start_at = start_at.as_ref().map(|start_at| start_at.0.as_slice());
433		args.start_at_exclusive = true;
434
435		Ok(Self { inner: state.raw_iter(args)?, state })
436	}
437}
438
439/// Provides access to storage primitives
440pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
441	/// Given a block's `Hash` and a key, return the value under the key in that block.
442	fn storage(
443		&self,
444		hash: Block::Hash,
445		key: &StorageKey,
446	) -> sp_blockchain::Result<Option<StorageData>>;
447
448	/// Given a block's `Hash` and a key, return the value under the hash in that block.
449	fn storage_hash(
450		&self,
451		hash: Block::Hash,
452		key: &StorageKey,
453	) -> sp_blockchain::Result<Option<Block::Hash>>;
454
455	/// Given a block's `Hash` and a key prefix, returns a `KeysIter` iterates matching storage
456	/// keys in that block.
457	fn storage_keys(
458		&self,
459		hash: Block::Hash,
460		prefix: Option<&StorageKey>,
461		start_key: Option<&StorageKey>,
462	) -> sp_blockchain::Result<KeysIter<B::State, Block>>;
463
464	/// Given a block's `Hash` and a key prefix, returns an iterator over the storage keys and
465	/// values in that block.
466	fn storage_pairs(
467		&self,
468		hash: <Block as BlockT>::Hash,
469		prefix: Option<&StorageKey>,
470		start_key: Option<&StorageKey>,
471	) -> sp_blockchain::Result<PairsIter<B::State, Block>>;
472
473	/// Given a block's `Hash`, a key and a child storage key, return the value under the key in
474	/// that block.
475	fn child_storage(
476		&self,
477		hash: Block::Hash,
478		child_info: &ChildInfo,
479		key: &StorageKey,
480	) -> sp_blockchain::Result<Option<StorageData>>;
481
482	/// Given a block's `Hash` and a key `prefix` and a child storage key,
483	/// returns a `KeysIter` that iterates matching storage keys in that block.
484	fn child_storage_keys(
485		&self,
486		hash: Block::Hash,
487		child_info: ChildInfo,
488		prefix: Option<&StorageKey>,
489		start_key: Option<&StorageKey>,
490	) -> sp_blockchain::Result<KeysIter<B::State, Block>>;
491
492	/// Given a block's `Hash`, a key and a child storage key, return the hash under the key in that
493	/// block.
494	fn child_storage_hash(
495		&self,
496		hash: Block::Hash,
497		child_info: &ChildInfo,
498		key: &StorageKey,
499	) -> sp_blockchain::Result<Option<Block::Hash>>;
500
501	/// Given a block's `Hash` and a key, return the closest merkle value.
502	fn closest_merkle_value(
503		&self,
504		hash: Block::Hash,
505		key: &StorageKey,
506	) -> sp_blockchain::Result<Option<MerkleValue<Block::Hash>>>;
507
508	/// Given a block's `Hash`, a key and a child storage key, return the closest merkle value.
509	fn child_closest_merkle_value(
510		&self,
511		hash: Block::Hash,
512		child_info: &ChildInfo,
513		key: &StorageKey,
514	) -> sp_blockchain::Result<Option<MerkleValue<Block::Hash>>>;
515}
516
517/// Specify the desired trie cache context when calling [`Backend::state_at`].
518///
519/// This is used to determine the size of the local trie cache.
520#[derive(Debug, Clone, Copy)]
521pub enum TrieCacheContext {
522	/// This is used when calling [`Backend::state_at`] in a trusted context.
523	///
524	/// A trusted context is for example the building or importing of a block.
525	/// In this case the local trie cache can grow unlimited and all the cached data
526	/// will be propagated back to the shared trie cache. It is safe to let the local
527	/// cache grow to hold the entire data, because importing and building blocks is
528	/// bounded by the block size limit.
529	Trusted,
530	/// This is used when calling [`Backend::state_at`] in from untrusted context.
531	///
532	/// The local trie cache will be bounded by its preconfigured size.
533	Untrusted,
534}
535
536impl From<CallContext> for TrieCacheContext {
537	fn from(call_context: CallContext) -> Self {
538		match call_context {
539			CallContext::Onchain => TrieCacheContext::Trusted,
540			CallContext::Offchain => TrieCacheContext::Untrusted,
541		}
542	}
543}
544
545/// Client backend.
546///
547/// Manages the data layer.
548///
549/// # State Pruning
550///
551/// While an object from `state_at` is alive, the state
552/// should not be pruned. The backend should internally reference-count
553/// its state objects.
554///
555/// The same applies for live `BlockImportOperation`s: while an import operation building on a
556/// parent `P` is alive, the state for `P` should not be pruned.
557///
558/// # Block Pruning
559///
560/// Users can pin blocks in memory by calling `pin_block`. When
561/// a block would be pruned, its value is kept in an in-memory cache
562/// until it is unpinned via `unpin_block`.
563///
564/// While a block is pinned, its state is also preserved.
565///
566/// The backend should internally reference count the number of pin / unpin calls.
567pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
568	/// Associated block insertion operation type.
569	type BlockImportOperation: BlockImportOperation<Block, State = Self::State>;
570	/// Associated blockchain backend type.
571	type Blockchain: BlockchainBackend<Block>;
572	/// Associated state backend type.
573	type State: StateBackend<HashingFor<Block>>
574		+ Send
575		+ AsTrieBackend<
576			HashingFor<Block>,
577			TrieBackendStorage = <Self::State as StateBackend<HashingFor<Block>>>::TrieBackendStorage,
578		>;
579	/// Offchain workers local storage.
580	type OffchainStorage: OffchainStorage;
581
582	/// Begin a new block insertion transaction with given parent block id.
583	///
584	/// When constructing the genesis, this is called with all-zero hash.
585	fn begin_operation(&self) -> sp_blockchain::Result<Self::BlockImportOperation>;
586
587	/// Note an operation to contain state transition.
588	fn begin_state_operation(
589		&self,
590		operation: &mut Self::BlockImportOperation,
591		block: Block::Hash,
592	) -> sp_blockchain::Result<()>;
593
594	/// Commit block insertion.
595	fn commit_operation(
596		&self,
597		transaction: Self::BlockImportOperation,
598	) -> sp_blockchain::Result<()>;
599
600	/// Finalize block with given `hash`.
601	///
602	/// This should only be called if the parent of the given block has been finalized.
603	fn finalize_block(
604		&self,
605		hash: Block::Hash,
606		justification: Option<Justification>,
607	) -> sp_blockchain::Result<()>;
608
609	/// Append justification to the block with the given `hash`.
610	///
611	/// This should only be called for blocks that are already finalized.
612	fn append_justification(
613		&self,
614		hash: Block::Hash,
615		justification: Justification,
616	) -> sp_blockchain::Result<()>;
617
618	/// Returns reference to blockchain backend.
619	fn blockchain(&self) -> &Self::Blockchain;
620
621	/// Returns current usage statistics.
622	fn usage_info(&self) -> Option<UsageInfo>;
623
624	/// Returns a handle to offchain storage.
625	fn offchain_storage(&self) -> Option<Self::OffchainStorage>;
626
627	/// Pin the block to keep body, justification and state available after pruning.
628	/// Number of pins are reference counted. Users need to make sure to perform
629	/// one call to [`Self::unpin_block`] per call to [`Self::pin_block`].
630	fn pin_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()>;
631
632	/// Unpin the block to allow pruning.
633	fn unpin_block(&self, hash: Block::Hash);
634
635	/// Returns true if state for given block is available.
636	fn have_state_at(&self, hash: Block::Hash, _number: NumberFor<Block>) -> bool {
637		self.state_at(hash, TrieCacheContext::Untrusted).is_ok()
638	}
639
640	/// Returns state backend with post-state of given block.
641	fn state_at(
642		&self,
643		hash: Block::Hash,
644		trie_cache_context: TrieCacheContext,
645	) -> sp_blockchain::Result<Self::State>;
646
647	/// Attempts to revert the chain by `n` blocks. If `revert_finalized` is set it will attempt to
648	/// revert past any finalized block, this is unsafe and can potentially leave the node in an
649	/// inconsistent state. All blocks higher than the best block are also reverted and not counting
650	/// towards `n`.
651	///
652	/// Returns the number of blocks that were successfully reverted and the list of finalized
653	/// blocks that has been reverted.
654	fn revert(
655		&self,
656		n: NumberFor<Block>,
657		revert_finalized: bool,
658	) -> sp_blockchain::Result<(NumberFor<Block>, HashSet<Block::Hash>)>;
659
660	/// Discard non-best, unfinalized leaf block.
661	fn remove_leaf_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()>;
662
663	/// Insert auxiliary data into key-value store.
664	fn insert_aux<
665		'a,
666		'b: 'a,
667		'c: 'a,
668		I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
669		D: IntoIterator<Item = &'a &'b [u8]>,
670	>(
671		&self,
672		insert: I,
673		delete: D,
674	) -> sp_blockchain::Result<()> {
675		AuxStore::insert_aux(self, insert, delete)
676	}
677	/// Query auxiliary data from key-value store.
678	fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
679		AuxStore::get_aux(self, key)
680	}
681
682	/// Gain access to the import lock around this backend.
683	///
684	/// _Note_ Backend isn't expected to acquire the lock by itself ever. Rather
685	/// the using components should acquire and hold the lock whenever they do
686	/// something that the import of a block would interfere with, e.g. importing
687	/// a new block or calculating the best head.
688	fn get_import_lock(&self) -> &RwLock<()>;
689
690	/// Tells whether the backend requires full-sync mode.
691	fn requires_full_sync(&self) -> bool;
692}
693
694/// Mark for all Backend implementations, that are making use of state data, stored locally.
695pub trait LocalBackend<Block: BlockT>: Backend<Block> {}