// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
//! Substrate light client interfaces
use std::sync::Arc;
use std::collections::{BTreeMap, HashMap};
use std::future::Future;
use sp_runtime::{
traits::{
Block as BlockT, Header as HeaderT, NumberFor,
},
generic::BlockId
};
use sp_core::ChangesTrieConfiguration;
use sp_state_machine::StorageProof;
use sp_blockchain::{
HeaderMetadata, well_known_cache_keys, HeaderBackend, Cache as BlockchainCache,
Error as ClientError, Result as ClientResult,
};
use crate::backend::{ AuxStore, NewBlockState };
/// Remote call request.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteCallRequest {
/// Call at state of given block.
pub block: Header::Hash,
/// Header of block at which call is performed.
pub header: Header,
/// Method to call.
pub method: String,
/// Call data.
pub call_data: Vec,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option,
}
/// Remote canonical header request.
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct RemoteHeaderRequest {
/// The root of CHT this block is included in.
pub cht_root: Header::Hash,
/// Number of the header to query.
pub block: Header::Number,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option,
}
/// Remote storage read request.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteReadRequest {
/// Read at state of given block.
pub block: Header::Hash,
/// Header of block at which read is performed.
pub header: Header,
/// Storage key to read.
pub keys: Vec>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option,
}
/// Remote storage read child request.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteReadChildRequest {
/// Read at state of given block.
pub block: Header::Hash,
/// Header of block at which read is performed.
pub header: Header,
/// Storage key for child.
pub storage_key: Vec,
/// Child trie source information.
pub child_info: Vec,
/// Child type, its required to resolve `child_info`
/// content and choose child implementation.
pub child_type: u32,
/// Child storage key to read.
pub keys: Vec>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option,
}
/// Remote key changes read request.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RemoteChangesRequest {
/// Changes trie configuration.
pub changes_trie_config: ChangesTrieConfiguration,
/// Query changes from range of blocks, starting (and including) with this hash...
pub first_block: (Header::Number, Header::Hash),
/// ...ending (and including) with this hash. Should come after first_block and
/// be the part of the same fork.
pub last_block: (Header::Number, Header::Hash),
/// Only use digests from blocks up to this hash. Should be last_block OR come
/// after this block and be the part of the same fork.
pub max_block: (Header::Number, Header::Hash),
/// Known changes trie roots for the range of blocks [tries_roots.0..max_block].
/// Proofs for roots of ascendants of tries_roots.0 are provided by the remote node.
pub tries_roots: (Header::Number, Header::Hash, Vec),
/// Optional Child Storage key to read.
pub storage_key: Option>,
/// Storage key to read.
pub key: Vec,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option,
}
/// Key changes read proof.
#[derive(Debug, PartialEq, Eq)]
pub struct ChangesProof {
/// Max block that has been used in changes query.
pub max_block: Header::Number,
/// All touched nodes of all changes tries.
pub proof: Vec>,
/// All changes tries roots that have been touched AND are missing from
/// the requester' node. It is a map of block number => changes trie root.
pub roots: BTreeMap,
/// The proofs for all changes tries roots that have been touched AND are
/// missing from the requester' node. It is a map of CHT number => proof.
pub roots_proof: StorageProof,
}
/// Remote block body request
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
pub struct RemoteBodyRequest {
/// Header of the requested block body
pub header: Header,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option,
}
/// Light client data fetcher. Implementations of this trait must check if remote data
/// is correct (see FetchedDataChecker) and return already checked data.
pub trait Fetcher: Send + Sync {
/// Remote header future.
type RemoteHeaderResult: Future