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