mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
Fast sync child trie support. (#9239)
* state machine proofs. * initial implementation * Remove todo. * Extend test and fix import. * fix no proof, with proof ko. * fix start at logic. * Restore response size. * Rework comments. * Add explicit ref * Use compact proof. * ref change * elaborato on empty change set condition. * KeyValueState renaming. * Do not add two time child trie with same root to sync reply. * rust format * Fix merge. * fix warnings and fmt * fmt * update protocol id to V2
This commit is contained in:
@@ -42,7 +42,7 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
pub use sp_state_machine::Backend as StateBackend;
|
||||
pub use sp_state_machine::{Backend as StateBackend, KeyValueStates};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// Extracts the state backend type for the given backend.
|
||||
|
||||
@@ -39,7 +39,7 @@ pub use proof_provider::*;
|
||||
pub use sp_blockchain as blockchain;
|
||||
pub use sp_blockchain::HeaderBackend;
|
||||
|
||||
pub use sp_state_machine::{ExecutionStrategy, StorageProof};
|
||||
pub use sp_state_machine::{CompactProof, ExecutionStrategy, StorageProof};
|
||||
pub use sp_storage::{ChildInfo, PrefixedStorageKey, StorageData, StorageKey};
|
||||
|
||||
/// Usage Information Provider interface
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
//! Proof utilities
|
||||
use crate::{ChangesProof, StorageProof};
|
||||
use crate::{ChangesProof, CompactProof, StorageProof};
|
||||
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
|
||||
use sp_state_machine::{KeyValueStates, KeyValueStorageLevel};
|
||||
use sp_storage::{ChildInfo, PrefixedStorageKey, StorageKey};
|
||||
|
||||
/// Interface for providing block proving utilities.
|
||||
@@ -71,31 +72,43 @@ pub trait ProofProvider<Block: BlockT> {
|
||||
key: &StorageKey,
|
||||
) -> sp_blockchain::Result<ChangesProof<Block::Header>>;
|
||||
|
||||
/// Given a `BlockId` iterate over all storage values starting at `start_key` exclusively,
|
||||
/// building proofs until size limit is reached. Returns combined proof and the number of
|
||||
/// collected keys.
|
||||
/// Given a `BlockId` iterate over all storage values starting at `start_keys`.
|
||||
/// Last `start_keys` element contains last accessed key value.
|
||||
/// With multiple `start_keys`, first `start_keys` element is
|
||||
/// the current storage key of of the last accessed child trie.
|
||||
/// at last level the value to start at exclusively.
|
||||
/// Proofs is build until size limit is reached and always include at
|
||||
/// least one key following `start_keys`.
|
||||
/// Returns combined proof and the numbers of collected keys.
|
||||
fn read_proof_collection(
|
||||
&self,
|
||||
id: &BlockId<Block>,
|
||||
start_key: &[u8],
|
||||
start_keys: &[Vec<u8>],
|
||||
size_limit: usize,
|
||||
) -> sp_blockchain::Result<(StorageProof, u32)>;
|
||||
) -> sp_blockchain::Result<(CompactProof, u32)>;
|
||||
|
||||
/// Given a `BlockId` iterate over all storage values starting at `start_key`.
|
||||
/// Returns collected keys and values.
|
||||
/// Returns the collected keys values content of the top trie followed by the
|
||||
/// collected keys values of child tries.
|
||||
/// Only child tries with their root part of the collected content or
|
||||
/// related to `start_key` are attached.
|
||||
/// For each collected state a boolean indicates if state reach
|
||||
/// end.
|
||||
fn storage_collection(
|
||||
&self,
|
||||
id: &BlockId<Block>,
|
||||
start_key: &[u8],
|
||||
start_key: &[Vec<u8>],
|
||||
size_limit: usize,
|
||||
) -> sp_blockchain::Result<Vec<(Vec<u8>, Vec<u8>)>>;
|
||||
) -> sp_blockchain::Result<Vec<(KeyValueStorageLevel, bool)>>;
|
||||
|
||||
/// Verify read storage proof for a set of keys.
|
||||
/// Returns collected key-value pairs and a flag indicating if iteration is complete.
|
||||
/// Returns collected key-value pairs and a the nested state
|
||||
/// depth of current iteration or 0 if completed.
|
||||
fn verify_range_proof(
|
||||
&self,
|
||||
root: Block::Hash,
|
||||
proof: StorageProof,
|
||||
start_key: &[u8],
|
||||
) -> sp_blockchain::Result<(Vec<(Vec<u8>, Vec<u8>)>, bool)>;
|
||||
proof: CompactProof,
|
||||
start_keys: &[Vec<u8>],
|
||||
) -> sp_blockchain::Result<(KeyValueStates, usize)>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user