sc_client_api/proof_provider.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//! Proof utilities
20use crate::{CompactProof, StorageProof};
21use sp_runtime::traits::Block as BlockT;
22use sp_state_machine::{KeyValueStates, KeyValueStorageLevel};
23use sp_storage::ChildInfo;
24use std::time::Duration;
25
26/// Interface for providing block proving utilities.
27pub trait ProofProvider<Block: BlockT> {
28 /// Reads storage value at a given block + key, returning read proof.
29 fn read_proof(
30 &self,
31 hash: Block::Hash,
32 keys: &mut dyn Iterator<Item = &[u8]>,
33 ) -> sp_blockchain::Result<StorageProof>;
34
35 /// Reads child storage value at a given block + storage_key + key, returning
36 /// read proof.
37 fn read_child_proof(
38 &self,
39 hash: Block::Hash,
40 child_info: &ChildInfo,
41 keys: &mut dyn Iterator<Item = &[u8]>,
42 ) -> sp_blockchain::Result<StorageProof>;
43
44 /// Execute a call to a contract on top of state in a block of given hash
45 /// AND returning execution proof.
46 ///
47 /// `timeout` bounds the wall-clock execution time of the runtime call if `Some`.
48 ///
49 /// No changes are made.
50 fn execution_proof(
51 &self,
52 hash: Block::Hash,
53 method: &str,
54 call_data: &[u8],
55 timeout: Option<Duration>,
56 ) -> sp_blockchain::Result<(Vec<u8>, StorageProof)>;
57
58 /// Given a `Hash` iterate over all storage values starting at `start_keys`.
59 /// Last `start_keys` element contains last accessed key value.
60 /// With multiple `start_keys`, first `start_keys` element is
61 /// the current storage key of of the last accessed child trie.
62 /// at last level the value to start at exclusively.
63 /// Proofs is build until size limit is reached and always include at
64 /// least one key following `start_keys`.
65 /// Returns combined proof and the numbers of collected keys.
66 fn read_proof_collection(
67 &self,
68 hash: Block::Hash,
69 start_keys: &[Vec<u8>],
70 size_limit: usize,
71 ) -> sp_blockchain::Result<(CompactProof, u32)>;
72
73 /// Given a `Hash` iterate over all storage values starting at `start_key`.
74 /// Returns collected keys and values.
75 /// Returns the collected keys values content of the top trie followed by the
76 /// collected keys values of child tries.
77 /// Only child tries with their root part of the collected content or
78 /// related to `start_key` are attached.
79 /// For each collected state a boolean indicates if state reach
80 /// end.
81 fn storage_collection(
82 &self,
83 hash: Block::Hash,
84 start_key: &[Vec<u8>],
85 size_limit: usize,
86 ) -> sp_blockchain::Result<Vec<(KeyValueStorageLevel, bool)>>;
87
88 /// Verify read storage proof for a set of keys.
89 /// Returns collected key-value pairs and the nested state
90 /// depth of current iteration or 0 if completed.
91 fn verify_range_proof(
92 &self,
93 root: Block::Hash,
94 proof: CompactProof,
95 start_keys: &[Vec<u8>],
96 ) -> sp_blockchain::Result<(KeyValueStates, usize)>;
97}