referrerpolicy=no-referrer-when-downgrade

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::{HashMap, HashSet};
22
23use parking_lot::RwLock;
24
25use sp_api::CallContext;
26use sp_consensus::BlockOrigin;
27use sp_core::{offchain::OffchainStorage, H256};
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/// Out-of-band indexed-transaction data attached by upstream block-import wrappers.
166#[derive(Default, Debug, Clone)]
167pub struct PrefetchedIndexedTransactions {
168	/// Ops applied when the runtime produced none.
169	pub ops: Vec<IndexOperation>,
170
171	/// Payload bytes for `IndexOperation::Renew` hashes not yet in `TRANSACTION`.
172	pub renew_payloads: HashMap<H256, Vec<u8>>,
173}
174
175/// Block insertion operation.
176///
177/// Keeps hold if the inserted block state and data.
178pub trait BlockImportOperation<Block: BlockT> {
179	/// Associated state backend type.
180	type State: StateBackend<HashingFor<Block>>;
181
182	/// Returns pending state.
183	///
184	/// Returns None for backends with locally-unavailable state data.
185	fn state(&self) -> sp_blockchain::Result<Option<&Self::State>>;
186
187	/// Append block data to the transaction.
188	///
189	/// - `header`: The block header.
190	/// - `body`: The block body (extrinsics), if available.
191	/// - `justifications`: Block justifications, e.g. finality proofs.
192	/// - `state`: Whether this is a normal block, the new best block, or a newly finalized block.
193	/// - `register_as_leaf`: Whether to add the block to the leaf set. Blocks imported during warp
194	///   sync are stored in the database but should not be registered as leaves, since they are
195	///   historical blocks and not candidates for chain progression.
196	fn set_block_data(
197		&mut self,
198		header: Block::Header,
199		body: Option<Vec<Block::Extrinsic>>,
200		justifications: Option<Justifications>,
201		state: NewBlockState,
202		register_as_leaf: bool,
203	) -> sp_blockchain::Result<()>;
204
205	/// Inject storage data into the database.
206	fn update_db_storage(
207		&mut self,
208		update: BackendTransaction<HashingFor<Block>>,
209	) -> sp_blockchain::Result<()>;
210
211	/// Set genesis state. If `commit` is `false` the state is saved in memory, but is not written
212	/// to the database.
213	fn set_genesis_state(
214		&mut self,
215		storage: Storage,
216		commit: bool,
217		state_version: StateVersion,
218	) -> sp_blockchain::Result<Block::Hash>;
219
220	/// Inject storage data into the database replacing any existing data.
221	fn reset_storage(
222		&mut self,
223		storage: Storage,
224		state_version: StateVersion,
225	) -> sp_blockchain::Result<Block::Hash>;
226
227	/// Set storage changes.
228	fn update_storage(
229		&mut self,
230		update: StorageCollection,
231		child_update: ChildStorageCollection,
232	) -> sp_blockchain::Result<()>;
233
234	/// Write offchain storage changes to the database.
235	fn update_offchain_storage(
236		&mut self,
237		_offchain_update: OffchainChangesCollection,
238	) -> sp_blockchain::Result<()> {
239		Ok(())
240	}
241
242	/// Insert auxiliary keys.
243	///
244	/// Values are `None` if should be deleted.
245	fn insert_aux<I>(&mut self, ops: I) -> sp_blockchain::Result<()>
246	where
247		I: IntoIterator<Item = (Vec<u8>, Option<Vec<u8>>)>;
248
249	/// Mark a block as finalized, if multiple blocks are finalized in the same operation then they
250	/// must be marked in ascending order.
251	fn mark_finalized(
252		&mut self,
253		hash: Block::Hash,
254		justification: Option<Justification>,
255	) -> sp_blockchain::Result<()>;
256
257	/// Mark a block as new head. If both block import and set head are specified, set head
258	/// overrides block import's best block rule.
259	fn mark_head(&mut self, hash: Block::Hash) -> sp_blockchain::Result<()>;
260
261	/// Add a transaction index operation.
262	fn update_transaction_index(&mut self, index: Vec<IndexOperation>)
263		-> sp_blockchain::Result<()>;
264
265	/// Provide payload bytes for `IndexOperation::Renew` hashes that are not yet present in the
266	/// `TRANSACTION` column.
267	fn set_renew_payloads(&mut self, payloads: HashMap<H256, Vec<u8>>)
268		-> sp_blockchain::Result<()>;
269
270	/// Configure whether to create a block gap if newly imported block is missing parent
271	fn set_create_gap(&mut self, create_gap: bool);
272}
273
274/// Interface for performing operations on the backend.
275pub trait LockImportRun<Block: BlockT, B: Backend<Block>> {
276	/// Lock the import lock, and run operations inside.
277	fn lock_import_and_run<R, Err, F>(&self, f: F) -> Result<R, Err>
278	where
279		F: FnOnce(&mut ClientImportOperation<Block, B>) -> Result<R, Err>,
280		Err: From<sp_blockchain::Error>;
281}
282
283/// Finalize Facilities
284pub trait Finalizer<Block: BlockT, B: Backend<Block>> {
285	/// Mark all blocks up to given as finalized in operation.
286	///
287	/// If `justification` is provided it is stored with the given finalized
288	/// block (any other finalized blocks are left unjustified).
289	///
290	/// If the block being finalized is on a different fork from the current
291	/// best block the finalized block is set as best, this might be slightly
292	/// inaccurate (i.e. outdated). Usages that require determining an accurate
293	/// best block should use `SelectChain` instead of the client.
294	fn apply_finality(
295		&self,
296		operation: &mut ClientImportOperation<Block, B>,
297		block: Block::Hash,
298		justification: Option<Justification>,
299		notify: bool,
300	) -> sp_blockchain::Result<()>;
301
302	/// Finalize a block.
303	///
304	/// This will implicitly finalize all blocks up to it and
305	/// fire finality notifications.
306	///
307	/// If the block being finalized is on a different fork from the current
308	/// best block, the finalized block is set as best. This might be slightly
309	/// inaccurate (i.e. outdated). Usages that require determining an accurate
310	/// best block should use `SelectChain` instead of the client.
311	///
312	/// Pass a flag to indicate whether finality notifications should be propagated.
313	/// This is usually tied to some synchronization state, where we don't send notifications
314	/// while performing major synchronization work.
315	fn finalize_block(
316		&self,
317		block: Block::Hash,
318		justification: Option<Justification>,
319		notify: bool,
320	) -> sp_blockchain::Result<()>;
321}
322
323/// Provides access to an auxiliary database.
324///
325/// This is a simple global database not aware of forks. Can be used for storing auxiliary
326/// information like total block weight/difficulty for fork resolution purposes as a common use
327/// case.
328pub trait AuxStore {
329	/// Insert auxiliary data into key-value store.
330	///
331	/// Deletions occur after insertions.
332	fn insert_aux<
333		'a,
334		'b: 'a,
335		'c: 'a,
336		I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
337		D: IntoIterator<Item = &'a &'b [u8]>,
338	>(
339		&self,
340		insert: I,
341		delete: D,
342	) -> sp_blockchain::Result<()>;
343
344	/// Query auxiliary data from key-value store.
345	fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>>;
346}
347
348/// An `Iterator` that iterates keys in a given block under a prefix.
349pub struct KeysIter<State, Block>
350where
351	State: StateBackend<HashingFor<Block>>,
352	Block: BlockT,
353{
354	inner: <State as StateBackend<HashingFor<Block>>>::RawIter,
355	state: State,
356}
357
358impl<State, Block> KeysIter<State, Block>
359where
360	State: StateBackend<HashingFor<Block>>,
361	Block: BlockT,
362{
363	/// Create a new iterator over storage keys.
364	pub fn new(
365		state: State,
366		prefix: Option<&StorageKey>,
367		start_at: Option<&StorageKey>,
368	) -> Result<Self, State::Error> {
369		let mut args = IterArgs::default();
370		args.prefix = prefix.as_ref().map(|prefix| prefix.0.as_slice());
371		args.start_at = start_at.as_ref().map(|start_at| start_at.0.as_slice());
372		args.start_at_exclusive = true;
373
374		Ok(Self { inner: state.raw_iter(args)?, state })
375	}
376
377	/// Create a new iterator over a child storage's keys.
378	pub fn new_child(
379		state: State,
380		child_info: ChildInfo,
381		prefix: Option<&StorageKey>,
382		start_at: Option<&StorageKey>,
383	) -> Result<Self, State::Error> {
384		let mut args = IterArgs::default();
385		args.prefix = prefix.as_ref().map(|prefix| prefix.0.as_slice());
386		args.start_at = start_at.as_ref().map(|start_at| start_at.0.as_slice());
387		args.child_info = Some(child_info);
388		args.start_at_exclusive = true;
389
390		Ok(Self { inner: state.raw_iter(args)?, state })
391	}
392}
393
394impl<State, Block> Iterator for KeysIter<State, Block>
395where
396	Block: BlockT,
397	State: StateBackend<HashingFor<Block>>,
398{
399	type Item = StorageKey;
400
401	fn next(&mut self) -> Option<Self::Item> {
402		self.inner.next_key(&self.state)?.ok().map(StorageKey)
403	}
404}
405
406/// An `Iterator` that iterates keys and values in a given block under a prefix.
407pub struct PairsIter<State, Block>
408where
409	State: StateBackend<HashingFor<Block>>,
410	Block: BlockT,
411{
412	inner: <State as StateBackend<HashingFor<Block>>>::RawIter,
413	state: State,
414}
415
416impl<State, Block> Iterator for PairsIter<State, Block>
417where
418	Block: BlockT,
419	State: StateBackend<HashingFor<Block>>,
420{
421	type Item = (StorageKey, StorageData);
422
423	fn next(&mut self) -> Option<Self::Item> {
424		self.inner
425			.next_pair(&self.state)?
426			.ok()
427			.map(|(key, value)| (StorageKey(key), StorageData(value)))
428	}
429}
430
431impl<State, Block> PairsIter<State, Block>
432where
433	State: StateBackend<HashingFor<Block>>,
434	Block: BlockT,
435{
436	/// Create a new iterator over storage key and value pairs.
437	pub fn new(
438		state: State,
439		prefix: Option<&StorageKey>,
440		start_at: Option<&StorageKey>,
441	) -> Result<Self, State::Error> {
442		let mut args = IterArgs::default();
443		args.prefix = prefix.as_ref().map(|prefix| prefix.0.as_slice());
444		args.start_at = start_at.as_ref().map(|start_at| start_at.0.as_slice());
445		args.start_at_exclusive = true;
446
447		Ok(Self { inner: state.raw_iter(args)?, state })
448	}
449}
450
451/// Provides access to storage primitives
452pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
453	/// Given a block's `Hash` and a key, return the value under the key in that block.
454	fn storage(
455		&self,
456		hash: Block::Hash,
457		key: &StorageKey,
458	) -> sp_blockchain::Result<Option<StorageData>>;
459
460	/// Given a block's `Hash` and a key, return the value under the hash in that block.
461	fn storage_hash(
462		&self,
463		hash: Block::Hash,
464		key: &StorageKey,
465	) -> sp_blockchain::Result<Option<Block::Hash>>;
466
467	/// Given a block's `Hash` and a key prefix, returns a `KeysIter` iterates matching storage
468	/// keys in that block.
469	fn storage_keys(
470		&self,
471		hash: Block::Hash,
472		prefix: Option<&StorageKey>,
473		start_key: Option<&StorageKey>,
474	) -> sp_blockchain::Result<KeysIter<B::State, Block>>;
475
476	/// Given a block's `Hash` and a key prefix, returns an iterator over the storage keys and
477	/// values in that block.
478	fn storage_pairs(
479		&self,
480		hash: <Block as BlockT>::Hash,
481		prefix: Option<&StorageKey>,
482		start_key: Option<&StorageKey>,
483	) -> sp_blockchain::Result<PairsIter<B::State, Block>>;
484
485	/// Given a block's `Hash`, a key and a child storage key, return the value under the key in
486	/// that block.
487	fn child_storage(
488		&self,
489		hash: Block::Hash,
490		child_info: &ChildInfo,
491		key: &StorageKey,
492	) -> sp_blockchain::Result<Option<StorageData>>;
493
494	/// Given a block's `Hash` and a key `prefix` and a child storage key,
495	/// returns a `KeysIter` that iterates matching storage keys in that block.
496	fn child_storage_keys(
497		&self,
498		hash: Block::Hash,
499		child_info: ChildInfo,
500		prefix: Option<&StorageKey>,
501		start_key: Option<&StorageKey>,
502	) -> sp_blockchain::Result<KeysIter<B::State, Block>>;
503
504	/// Given a block's `Hash`, a key and a child storage key, return the hash under the key in that
505	/// block.
506	fn child_storage_hash(
507		&self,
508		hash: Block::Hash,
509		child_info: &ChildInfo,
510		key: &StorageKey,
511	) -> sp_blockchain::Result<Option<Block::Hash>>;
512
513	/// Given a block's `Hash` and a key, return the closest merkle value.
514	fn closest_merkle_value(
515		&self,
516		hash: Block::Hash,
517		key: &StorageKey,
518	) -> sp_blockchain::Result<Option<MerkleValue<Block::Hash>>>;
519
520	/// Given a block's `Hash`, a key and a child storage key, return the closest merkle value.
521	fn child_closest_merkle_value(
522		&self,
523		hash: Block::Hash,
524		child_info: &ChildInfo,
525		key: &StorageKey,
526	) -> sp_blockchain::Result<Option<MerkleValue<Block::Hash>>>;
527}
528
529/// Specify the desired trie cache context when calling [`Backend::state_at`].
530///
531/// This is used to determine the size of the local trie cache.
532#[derive(Debug, Clone, Copy)]
533pub enum TrieCacheContext {
534	/// This is used when calling [`Backend::state_at`] in a trusted context.
535	///
536	/// A trusted context is for example the building or importing of a block.
537	/// In this case the local trie cache can grow unlimited and all the cached data
538	/// will be propagated back to the shared trie cache. It is safe to let the local
539	/// cache grow to hold the entire data, because importing and building blocks is
540	/// bounded by the block size limit.
541	Trusted,
542	/// This is used when calling [`Backend::state_at`] in from untrusted context.
543	///
544	/// The local trie cache will be bounded by its preconfigured size.
545	Untrusted,
546}
547
548impl From<CallContext> for TrieCacheContext {
549	fn from(call_context: CallContext) -> Self {
550		match call_context {
551			CallContext::Onchain { .. } => TrieCacheContext::Trusted,
552			CallContext::Offchain => TrieCacheContext::Untrusted,
553		}
554	}
555}
556
557/// Client backend.
558///
559/// Manages the data layer.
560///
561/// # State Pruning
562///
563/// While an object from `state_at` is alive, the state
564/// should not be pruned. The backend should internally reference-count
565/// its state objects.
566///
567/// The same applies for live `BlockImportOperation`s: while an import operation building on a
568/// parent `P` is alive, the state for `P` should not be pruned.
569///
570/// # Block Pruning
571///
572/// Users can pin blocks in memory by calling `pin_block`. When
573/// a block would be pruned, its value is kept in an in-memory cache
574/// until it is unpinned via `unpin_block`.
575///
576/// While a block is pinned, its state is also preserved.
577///
578/// The backend should internally reference count the number of pin / unpin calls.
579pub trait Backend<Block: BlockT>: AuxStore + Send + Sync {
580	/// Associated block insertion operation type.
581	type BlockImportOperation: BlockImportOperation<Block, State = Self::State>;
582	/// Associated blockchain backend type.
583	type Blockchain: BlockchainBackend<Block>;
584	/// Associated state backend type.
585	type State: StateBackend<HashingFor<Block>>
586		+ Send
587		+ AsTrieBackend<
588			HashingFor<Block>,
589			TrieBackendStorage = <Self::State as StateBackend<HashingFor<Block>>>::TrieBackendStorage,
590		>;
591	/// Offchain workers local storage.
592	type OffchainStorage: OffchainStorage;
593
594	/// Begin a new block insertion transaction with given parent block id.
595	///
596	/// When constructing the genesis, this is called with all-zero hash.
597	fn begin_operation(&self) -> sp_blockchain::Result<Self::BlockImportOperation>;
598
599	/// Note an operation to contain state transition.
600	fn begin_state_operation(
601		&self,
602		operation: &mut Self::BlockImportOperation,
603		block: Block::Hash,
604	) -> sp_blockchain::Result<()>;
605
606	/// Commit block insertion.
607	fn commit_operation(
608		&self,
609		transaction: Self::BlockImportOperation,
610	) -> sp_blockchain::Result<()>;
611
612	/// Finalize block with given `hash`.
613	///
614	/// This should only be called if the parent of the given block has been finalized.
615	fn finalize_block(
616		&self,
617		hash: Block::Hash,
618		justification: Option<Justification>,
619	) -> sp_blockchain::Result<()>;
620
621	/// Append justification to the block with the given `hash`.
622	///
623	/// This should only be called for blocks that are already finalized.
624	fn append_justification(
625		&self,
626		hash: Block::Hash,
627		justification: Justification,
628	) -> sp_blockchain::Result<()>;
629
630	/// Returns reference to blockchain backend.
631	fn blockchain(&self) -> &Self::Blockchain;
632
633	/// Returns current usage statistics.
634	fn usage_info(&self) -> Option<UsageInfo>;
635
636	/// Returns a handle to offchain storage.
637	fn offchain_storage(&self) -> Option<Self::OffchainStorage>;
638
639	/// Pin the block to keep body, justification and state available after pruning.
640	/// Number of pins are reference counted. Users need to make sure to perform
641	/// one call to [`Self::unpin_block`] per call to [`Self::pin_block`].
642	fn pin_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()>;
643
644	/// Unpin the block to allow pruning.
645	fn unpin_block(&self, hash: Block::Hash);
646
647	/// Returns true if state for given block is available.
648	fn have_state_at(&self, hash: Block::Hash, _number: NumberFor<Block>) -> bool {
649		self.state_at(hash, TrieCacheContext::Untrusted).is_ok()
650	}
651
652	/// Returns state backend with post-state of given block.
653	fn state_at(
654		&self,
655		hash: Block::Hash,
656		trie_cache_context: TrieCacheContext,
657	) -> sp_blockchain::Result<Self::State>;
658
659	/// Attempts to revert the chain by `n` blocks. If `revert_finalized` is set it will attempt to
660	/// revert past any finalized block, this is unsafe and can potentially leave the node in an
661	/// inconsistent state. All blocks higher than the best block are also reverted and not counting
662	/// towards `n`.
663	///
664	/// Returns the number of blocks that were successfully reverted and the list of finalized
665	/// blocks that has been reverted.
666	fn revert(
667		&self,
668		n: NumberFor<Block>,
669		revert_finalized: bool,
670	) -> sp_blockchain::Result<(NumberFor<Block>, HashSet<Block::Hash>)>;
671
672	/// Discard non-best, unfinalized leaf block.
673	fn remove_leaf_block(&self, hash: Block::Hash) -> sp_blockchain::Result<()>;
674
675	/// Insert auxiliary data into key-value store.
676	fn insert_aux<
677		'a,
678		'b: 'a,
679		'c: 'a,
680		I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
681		D: IntoIterator<Item = &'a &'b [u8]>,
682	>(
683		&self,
684		insert: I,
685		delete: D,
686	) -> sp_blockchain::Result<()> {
687		AuxStore::insert_aux(self, insert, delete)
688	}
689	/// Query auxiliary data from key-value store.
690	fn get_aux(&self, key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
691		AuxStore::get_aux(self, key)
692	}
693
694	/// Gain access to the import lock around this backend.
695	///
696	/// _Note_ Backend isn't expected to acquire the lock by itself ever. Rather
697	/// the using components should acquire and hold the lock whenever they do
698	/// something that the import of a block would interfere with, e.g. importing
699	/// a new block or calculating the best head.
700	fn get_import_lock(&self) -> &RwLock<()>;
701
702	/// Tells whether the backend requires full-sync mode.
703	fn requires_full_sync(&self) -> bool;
704}
705
706/// Mark for all Backend implementations, that are making use of state data, stored locally.
707pub trait LocalBackend<Block: BlockT>: Backend<Block> {}