mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
Remove requirement on Hash = H256, make Proposer return StorageChanges and Proof (#3860)
* Extend `Proposer` to optionally generate a proof of the proposal * Something * Refactor sr-api to not depend on client anymore * Fix benches * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Apply suggestions from code review * Introduce new `into_storage_changes` function * Switch to runtime api for `execute_block` and don't require `H256` anywhere in the code * Put the `StorageChanges` into the `Proposal` * Move the runtime api error to its own trait * Adds `StorageTransactionCache` to the runtime api This requires that we add `type NodeBlock = ` to the `impl_runtime_apis!` macro to work around some bugs in rustc :( * Remove `type NodeBlock` and switch to a "better" hack * Start using the transaction cache from the runtime api * Make it compile * Move `InMemory` to its own file * Make all tests work again * Return block, storage_changes and proof from Blockbuilder::bake() * Make sure that we use/set `storage_changes` when possible * Add test * Fix deadlock * Remove accidentally added folders * Introduce `RecordProof` as argument type to be more explicit * Update client/src/client.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update primitives/state-machine/src/ext.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Integrates review feedback * Remove `unsafe` usage * Update client/block-builder/src/lib.rs Co-Authored-By: Benjamin Kampmann <ben@gnunicorn.org> * Update client/src/call_executor.rs * Bump versions Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> Co-authored-by: Benjamin Kampmann <ben.kampmann@googlemail.com>
This commit is contained in:
@@ -24,12 +24,12 @@ use parking_lot::RwLock;
|
||||
use sp_core::storage::{ChildInfo, OwnedChildInfo};
|
||||
use sp_core::offchain::storage::InMemOffchainStorage;
|
||||
use sp_state_machine::{
|
||||
Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState, ChangesTrieTransaction
|
||||
Backend as StateBackend, TrieBackend, InMemoryBackend, ChangesTrieTransaction
|
||||
};
|
||||
use sp_runtime::{generic::BlockId, Justification, Storage};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero, Header};
|
||||
use sp_runtime::traits::{Block as BlockT, NumberFor, Zero, Header, HasherFor};
|
||||
use crate::in_mem::{self, check_genesis_storage};
|
||||
use sp_blockchain::{ Error as ClientError, Result as ClientResult };
|
||||
use sp_blockchain::{Error as ClientError, Result as ClientResult};
|
||||
use sc_client_api::{
|
||||
backend::{
|
||||
AuxStore, Backend as ClientBackend, BlockImportOperation, RemoteBackend, NewBlockState,
|
||||
@@ -43,33 +43,32 @@ use sc_client_api::{
|
||||
};
|
||||
use crate::light::blockchain::Blockchain;
|
||||
use hash_db::Hasher;
|
||||
use sp_trie::MemoryDB;
|
||||
|
||||
const IN_MEMORY_EXPECT_PROOF: &str = "InMemory state backend has Void error type and always succeeds; qed";
|
||||
|
||||
/// Light client backend.
|
||||
pub struct Backend<S, H: Hasher> {
|
||||
blockchain: Arc<Blockchain<S>>,
|
||||
genesis_state: RwLock<Option<InMemoryState<H>>>,
|
||||
genesis_state: RwLock<Option<InMemoryBackend<H>>>,
|
||||
import_lock: RwLock<()>,
|
||||
}
|
||||
|
||||
/// Light block (header and justification) import operation.
|
||||
pub struct ImportOperation<Block: BlockT, S, H: Hasher> {
|
||||
pub struct ImportOperation<Block: BlockT, S> {
|
||||
header: Option<Block::Header>,
|
||||
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
|
||||
leaf_state: NewBlockState,
|
||||
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
finalized_blocks: Vec<BlockId<Block>>,
|
||||
set_head: Option<BlockId<Block>>,
|
||||
storage_update: Option<InMemoryState<H>>,
|
||||
_phantom: ::std::marker::PhantomData<S>,
|
||||
storage_update: Option<InMemoryBackend<HasherFor<Block>>>,
|
||||
_phantom: std::marker::PhantomData<S>,
|
||||
}
|
||||
|
||||
/// Either in-memory genesis state, or locally-unavailable state.
|
||||
pub enum GenesisOrUnavailableState<H: Hasher> {
|
||||
/// Genesis state - storage values are stored in-memory.
|
||||
Genesis(InMemoryState<H>),
|
||||
Genesis(InMemoryBackend<H>),
|
||||
/// We know that state exists, but all calls will fail with error, because it
|
||||
/// isn't locally available.
|
||||
Unavailable,
|
||||
@@ -107,16 +106,16 @@ impl<S: AuxStore, H: Hasher> AuxStore for Backend<S, H> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, Block, H> ClientBackend<Block, H> for Backend<S, H> where
|
||||
Block: BlockT,
|
||||
S: BlockchainStorage<Block>,
|
||||
H: Hasher<Out=Block::Hash>,
|
||||
H::Out: Ord,
|
||||
impl<S, Block> ClientBackend<Block> for Backend<S, HasherFor<Block>>
|
||||
where
|
||||
Block: BlockT,
|
||||
S: BlockchainStorage<Block>,
|
||||
Block::Hash: Ord,
|
||||
{
|
||||
type BlockImportOperation = ImportOperation<Block, S, H>;
|
||||
type BlockImportOperation = ImportOperation<Block, S>;
|
||||
type Blockchain = Blockchain<S>;
|
||||
type State = GenesisOrUnavailableState<H>;
|
||||
type ChangesTrieStorage = in_mem::ChangesTrieStorage<Block, H>;
|
||||
type State = GenesisOrUnavailableState<HasherFor<Block>>;
|
||||
type ChangesTrieStorage = in_mem::ChangesTrieStorage<Block>;
|
||||
type OffchainStorage = InMemOffchainStorage;
|
||||
|
||||
fn begin_operation(&self) -> ClientResult<Self::BlockImportOperation> {
|
||||
@@ -179,7 +178,11 @@ impl<S, Block, H> ClientBackend<Block, H> for Backend<S, H> where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finalize_block(&self, block: BlockId<Block>, _justification: Option<Justification>) -> ClientResult<()> {
|
||||
fn finalize_block(
|
||||
&self,
|
||||
block: BlockId<Block>,
|
||||
_justification: Option<Justification>,
|
||||
) -> ClientResult<()> {
|
||||
self.blockchain.storage().finalize_header(block)
|
||||
}
|
||||
|
||||
@@ -227,12 +230,11 @@ impl<S, Block, H> ClientBackend<Block, H> for Backend<S, H> where
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, Block, H> RemoteBackend<Block, H> for Backend<S, H>
|
||||
impl<S, Block> RemoteBackend<Block> for Backend<S, HasherFor<Block>>
|
||||
where
|
||||
Block: BlockT,
|
||||
S: BlockchainStorage<Block> + 'static,
|
||||
H: Hasher<Out=Block::Hash>,
|
||||
H::Out: Ord,
|
||||
Block::Hash: Ord,
|
||||
{
|
||||
fn is_local_state_available(&self, block: &BlockId<Block>) -> bool {
|
||||
self.genesis_state.read().is_some()
|
||||
@@ -246,14 +248,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, Block, H> BlockImportOperation<Block, H> for ImportOperation<Block, S, H>
|
||||
where
|
||||
Block: BlockT,
|
||||
S: BlockchainStorage<Block>,
|
||||
H: Hasher<Out=Block::Hash>,
|
||||
H::Out: Ord,
|
||||
impl<S, Block> BlockImportOperation<Block> for ImportOperation<Block, S>
|
||||
where
|
||||
Block: BlockT,
|
||||
S: BlockchainStorage<Block>,
|
||||
Block::Hash: Ord,
|
||||
{
|
||||
type State = GenesisOrUnavailableState<H>;
|
||||
type State = GenesisOrUnavailableState<HasherFor<Block>>;
|
||||
|
||||
fn state(&self) -> ClientResult<Option<&Self::State>> {
|
||||
// None means 'locally-stateless' backend
|
||||
@@ -276,17 +277,23 @@ where
|
||||
self.cache = cache;
|
||||
}
|
||||
|
||||
fn update_db_storage(&mut self, _update: <Self::State as StateBackend<H>>::Transaction) -> ClientResult<()> {
|
||||
fn update_db_storage(
|
||||
&mut self,
|
||||
_update: <Self::State as StateBackend<HasherFor<Block>>>::Transaction,
|
||||
) -> ClientResult<()> {
|
||||
// we're not storing anything locally => ignore changes
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_changes_trie(&mut self, _update: ChangesTrieTransaction<H, NumberFor<Block>>) -> ClientResult<()> {
|
||||
fn update_changes_trie(
|
||||
&mut self,
|
||||
_update: ChangesTrieTransaction<HasherFor<Block>, NumberFor<Block>>,
|
||||
) -> ClientResult<()> {
|
||||
// we're not storing anything locally => ignore changes
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reset_storage(&mut self, input: Storage) -> ClientResult<H::Out> {
|
||||
fn reset_storage(&mut self, input: Storage) -> ClientResult<Block::Hash> {
|
||||
check_genesis_storage(&input)?;
|
||||
|
||||
// this is only called when genesis block is imported => shouldn't be performance bottleneck
|
||||
@@ -303,8 +310,8 @@ where
|
||||
storage.insert(Some((child_key, storage_child.child_info)), storage_child.data);
|
||||
}
|
||||
|
||||
let storage_update: InMemoryState<H> = storage.into();
|
||||
let (storage_root, _) = storage_update.full_storage_root(::std::iter::empty(), child_delta);
|
||||
let storage_update = InMemoryBackend::from(storage);
|
||||
let (storage_root, _) = storage_update.full_storage_root(std::iter::empty(), child_delta);
|
||||
self.storage_update = Some(storage_update);
|
||||
|
||||
Ok(storage_root)
|
||||
@@ -351,8 +358,8 @@ impl<H: Hasher> StateBackend<H> for GenesisOrUnavailableState<H>
|
||||
H::Out: Ord + codec::Codec,
|
||||
{
|
||||
type Error = ClientError;
|
||||
type Transaction = ();
|
||||
type TrieBackendStorage = MemoryDB<H>;
|
||||
type Transaction = <InMemoryBackend<H> as StateBackend<H>>::Transaction;
|
||||
type TrieBackendStorage = <InMemoryBackend<H> as StateBackend<H>>::TrieBackendStorage;
|
||||
|
||||
fn storage(&self, key: &[u8]) -> ClientResult<Option<Vec<u8>>> {
|
||||
match *self {
|
||||
@@ -445,8 +452,8 @@ impl<H: Hasher> StateBackend<H> for GenesisOrUnavailableState<H>
|
||||
{
|
||||
match *self {
|
||||
GenesisOrUnavailableState::Genesis(ref state) =>
|
||||
(state.storage_root(delta).0, ()),
|
||||
GenesisOrUnavailableState::Unavailable => (H::Out::default(), ()),
|
||||
state.storage_root(delta),
|
||||
GenesisOrUnavailableState::Unavailable => Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,9 +469,10 @@ impl<H: Hasher> StateBackend<H> for GenesisOrUnavailableState<H>
|
||||
match *self {
|
||||
GenesisOrUnavailableState::Genesis(ref state) => {
|
||||
let (root, is_equal, _) = state.child_storage_root(storage_key, child_info, delta);
|
||||
(root, is_equal, ())
|
||||
(root, is_equal, Default::default())
|
||||
},
|
||||
GenesisOrUnavailableState::Unavailable => (H::Out::default(), true, ()),
|
||||
GenesisOrUnavailableState::Unavailable =>
|
||||
(H::Out::default(), true, Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,9 +536,9 @@ mod tests {
|
||||
#[test]
|
||||
fn light_aux_store_is_updated_via_non_importing_op() {
|
||||
let backend = Backend::new(Arc::new(DummyBlockchain::new(DummyStorage::new())));
|
||||
let mut op = ClientBackend::<Block, Blake2Hasher>::begin_operation(&backend).unwrap();
|
||||
BlockImportOperation::<Block, Blake2Hasher>::insert_aux(&mut op, vec![(vec![1], Some(vec![2]))]).unwrap();
|
||||
ClientBackend::<Block, Blake2Hasher>::commit_operation(&backend, op).unwrap();
|
||||
let mut op = ClientBackend::<Block>::begin_operation(&backend).unwrap();
|
||||
BlockImportOperation::<Block>::insert_aux(&mut op, vec![(vec![1], Some(vec![2]))]).unwrap();
|
||||
ClientBackend::<Block>::commit_operation(&backend, op).unwrap();
|
||||
|
||||
assert_eq!(AuxStore::get_aux(&backend, &[1]).unwrap(), Some(vec![2]));
|
||||
}
|
||||
|
||||
@@ -21,22 +21,19 @@ use std::{
|
||||
};
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use sp_core::{
|
||||
H256, Blake2Hasher, convert_hash, NativeOrEncoded,
|
||||
traits::CodeExecutor,
|
||||
};
|
||||
use sp_core::{convert_hash, NativeOrEncoded, traits::CodeExecutor};
|
||||
use sp_runtime::{
|
||||
generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, NumberFor},
|
||||
generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, HasherFor},
|
||||
};
|
||||
use sp_externalities::Extensions;
|
||||
use sp_state_machine::{
|
||||
self, Backend as StateBackend, OverlayedChanges, ExecutionStrategy, create_proof_check_backend,
|
||||
execution_proof_check_on_trie_backend, ExecutionManager, ChangesTrieTransaction, StorageProof,
|
||||
execution_proof_check_on_trie_backend, ExecutionManager, StorageProof,
|
||||
merge_storage_proofs,
|
||||
};
|
||||
use hash_db::Hasher;
|
||||
|
||||
use sp_api::{ProofRecorder, InitializeBlock};
|
||||
use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache};
|
||||
|
||||
use sp_blockchain::{Error as ClientError, Result as ClientResult};
|
||||
|
||||
@@ -71,15 +68,17 @@ impl<B, L: Clone> Clone for GenesisCallExecutor<B, L> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
impl<Block, B, Local> CallExecutor<Block> for
|
||||
GenesisCallExecutor<B, Local>
|
||||
where
|
||||
Block: BlockT<Hash=H256>,
|
||||
B: RemoteBackend<Block, Blake2Hasher>,
|
||||
Local: CallExecutor<Block, Blake2Hasher>,
|
||||
Block: BlockT,
|
||||
B: RemoteBackend<Block>,
|
||||
Local: CallExecutor<Block>,
|
||||
{
|
||||
type Error = ClientError;
|
||||
|
||||
type Backend = B;
|
||||
|
||||
fn call(
|
||||
&self,
|
||||
id: &BlockId<Block>,
|
||||
@@ -110,6 +109,7 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
changes: &RefCell<OverlayedChanges>,
|
||||
_: Option<&RefCell<StorageTransactionCache<Block, B::State>>>,
|
||||
initialize_block: InitializeBlock<'a, Block>,
|
||||
_manager: ExecutionManager<EM>,
|
||||
native_call: Option<NC>,
|
||||
@@ -135,6 +135,7 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
method,
|
||||
call_data,
|
||||
changes,
|
||||
None,
|
||||
initialize_block,
|
||||
ExecutionManager::NativeWhenPossible,
|
||||
native_call,
|
||||
@@ -152,36 +153,12 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
}
|
||||
}
|
||||
|
||||
fn call_at_state<
|
||||
S: StateBackend<Blake2Hasher>,
|
||||
FF: FnOnce(
|
||||
Result<NativeOrEncoded<R>, Self::Error>,
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(&self,
|
||||
_state: &S,
|
||||
fn prove_at_trie_state<S: sp_state_machine::TrieBackendStorage<HasherFor<Block>>>(
|
||||
&self,
|
||||
_state: &sp_state_machine::TrieBackend<S, HasherFor<Block>>,
|
||||
_changes: &mut OverlayedChanges,
|
||||
_method: &str,
|
||||
_call_data: &[u8],
|
||||
_manager: ExecutionManager<FF>,
|
||||
_native_call: Option<NC>,
|
||||
_extensions: Option<Extensions>,
|
||||
) -> ClientResult<(
|
||||
NativeOrEncoded<R>,
|
||||
(S::Transaction, <Blake2Hasher as Hasher>::Out),
|
||||
Option<ChangesTrieTransaction<Blake2Hasher, NumberFor<Block>>>,
|
||||
)> {
|
||||
Err(ClientError::NotAvailableOnLightClient)
|
||||
}
|
||||
|
||||
fn prove_at_trie_state<S: sp_state_machine::TrieBackendStorage<Blake2Hasher>>(
|
||||
&self,
|
||||
_state: &sp_state_machine::TrieBackend<S, Blake2Hasher>,
|
||||
_changes: &mut OverlayedChanges,
|
||||
_method: &str,
|
||||
_call_data: &[u8]
|
||||
) -> ClientResult<(Vec<u8>, StorageProof)> {
|
||||
Err(ClientError::NotAvailableOnLightClient)
|
||||
}
|
||||
@@ -203,12 +180,15 @@ pub fn prove_execution<Block, S, E>(
|
||||
call_data: &[u8],
|
||||
) -> ClientResult<(Vec<u8>, StorageProof)>
|
||||
where
|
||||
Block: BlockT<Hash=H256>,
|
||||
S: StateBackend<Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
Block: BlockT,
|
||||
S: StateBackend<HasherFor<Block>>,
|
||||
E: CallExecutor<Block>,
|
||||
{
|
||||
let trie_state = state.as_trie_backend()
|
||||
.ok_or_else(|| Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as Box<dyn sp_state_machine::Error>)?;
|
||||
.ok_or_else(||
|
||||
Box::new(sp_state_machine::ExecutionError::UnableToGenerateProof) as
|
||||
Box<dyn sp_state_machine::Error>
|
||||
)?;
|
||||
|
||||
// prepare execution environment + record preparation proof
|
||||
let mut changes = Default::default();
|
||||
@@ -220,7 +200,12 @@ pub fn prove_execution<Block, S, E>(
|
||||
)?;
|
||||
|
||||
// execute method + record execution proof
|
||||
let (result, exec_proof) = executor.prove_at_trie_state(&trie_state, &mut changes, method, call_data)?;
|
||||
let (result, exec_proof) = executor.prove_at_trie_state(
|
||||
&trie_state,
|
||||
&mut changes,
|
||||
method,
|
||||
call_data,
|
||||
)?;
|
||||
let total_proof = merge_storage_proofs(vec![init_proof, exec_proof]);
|
||||
|
||||
Ok((result, total_proof))
|
||||
@@ -238,7 +223,8 @@ pub fn check_execution_proof<Header, E, H>(
|
||||
where
|
||||
Header: HeaderT,
|
||||
E: CodeExecutor,
|
||||
H: Hasher<Out=H256>,
|
||||
H: Hasher,
|
||||
H::Out: Ord + codec::Codec + 'static,
|
||||
{
|
||||
check_execution_proof_with_make_header::<Header, E, H, _>(
|
||||
executor,
|
||||
@@ -263,7 +249,8 @@ fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader: Fn(&Head
|
||||
where
|
||||
Header: HeaderT,
|
||||
E: CodeExecutor,
|
||||
H: Hasher<Out=H256>,
|
||||
H: Hasher,
|
||||
H::Out: Ord + codec::Codec + 'static,
|
||||
{
|
||||
let local_state_root = request.header.state_root();
|
||||
let root: H::Out = convert_hash(&local_state_root);
|
||||
@@ -294,17 +281,21 @@ fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader: Fn(&Head
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_consensus::BlockOrigin;
|
||||
use substrate_test_runtime_client::{self, runtime::{Header, Digest, Block}, ClientExt, TestClient};
|
||||
use substrate_test_runtime_client::{
|
||||
runtime::{Header, Digest, Block}, TestClient, ClientBlockImportExt,
|
||||
};
|
||||
use sc_executor::{NativeExecutor, WasmExecutionMethod};
|
||||
use sp_core::Blake2Hasher;
|
||||
use sp_core::{Blake2Hasher, H256};
|
||||
use sc_client_api::backend::{Backend, NewBlockState};
|
||||
use crate::in_mem::Backend as InMemBackend;
|
||||
|
||||
struct DummyCallExecutor;
|
||||
|
||||
impl CallExecutor<Block, Blake2Hasher> for DummyCallExecutor {
|
||||
impl CallExecutor<Block> for DummyCallExecutor {
|
||||
type Error = ClientError;
|
||||
|
||||
type Backend = substrate_test_runtime_client::Backend;
|
||||
|
||||
fn call(
|
||||
&self,
|
||||
_id: &BlockId<Block>,
|
||||
@@ -332,6 +323,12 @@ mod tests {
|
||||
_method: &str,
|
||||
_call_data: &[u8],
|
||||
_changes: &RefCell<OverlayedChanges>,
|
||||
_storage_transaction_cache: Option<&RefCell<
|
||||
StorageTransactionCache<
|
||||
Block,
|
||||
<Self::Backend as sc_client_api::backend::Backend<Block>>::State,
|
||||
>
|
||||
>>,
|
||||
_initialize_block: InitializeBlock<'a, Block>,
|
||||
_execution_manager: ExecutionManager<EM>,
|
||||
_native_call: Option<NC>,
|
||||
@@ -345,36 +342,9 @@ mod tests {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn call_at_state<
|
||||
S: sp_state_machine::Backend<Blake2Hasher>,
|
||||
F: FnOnce(
|
||||
Result<NativeOrEncoded<R>, Self::Error>,
|
||||
Result<NativeOrEncoded<R>, Self::Error>
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
>(&self,
|
||||
_state: &S,
|
||||
_overlay: &mut OverlayedChanges,
|
||||
_method: &str,
|
||||
_call_data: &[u8],
|
||||
_manager: ExecutionManager<F>,
|
||||
_native_call: Option<NC>,
|
||||
_extensions: Option<Extensions>,
|
||||
) -> Result<
|
||||
(
|
||||
NativeOrEncoded<R>,
|
||||
(S::Transaction, H256),
|
||||
Option<ChangesTrieTransaction<Blake2Hasher, NumberFor<Block>>>,
|
||||
),
|
||||
ClientError,
|
||||
> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn prove_at_trie_state<S: sp_state_machine::TrieBackendStorage<Blake2Hasher>>(
|
||||
fn prove_at_trie_state<S: sp_state_machine::TrieBackendStorage<HasherFor<Block>>>(
|
||||
&self,
|
||||
_trie_state: &sp_state_machine::TrieBackend<S, Blake2Hasher>,
|
||||
_trie_state: &sp_state_machine::TrieBackend<S, HasherFor<Block>>,
|
||||
_overlay: &mut OverlayedChanges,
|
||||
_method: &str,
|
||||
_call_data: &[u8]
|
||||
@@ -457,13 +427,13 @@ mod tests {
|
||||
}
|
||||
|
||||
// prepare remote client
|
||||
let remote_client = substrate_test_runtime_client::new();
|
||||
let mut remote_client = substrate_test_runtime_client::new();
|
||||
for i in 1u32..3u32 {
|
||||
let mut digest = Digest::default();
|
||||
digest.push(sp_runtime::generic::DigestItem::Other::<H256>(i.to_le_bytes().to_vec()));
|
||||
remote_client.import_justified(
|
||||
BlockOrigin::Own,
|
||||
remote_client.new_block(digest).unwrap().bake().unwrap(),
|
||||
remote_client.new_block(digest).unwrap().build().unwrap().block,
|
||||
Default::default(),
|
||||
).unwrap();
|
||||
}
|
||||
@@ -494,7 +464,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn code_is_executed_at_genesis_only() {
|
||||
let backend = Arc::new(InMemBackend::<Block, Blake2Hasher>::new());
|
||||
let backend = Arc::new(InMemBackend::<Block>::new());
|
||||
let def = H256::default();
|
||||
let header0 = substrate_test_runtime_client::runtime::Header::new(0, def, def, def, Default::default());
|
||||
let hash0 = header0.hash();
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::marker::PhantomData;
|
||||
|
||||
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
|
||||
use codec::{Decode, Encode};
|
||||
use sp_core::{convert_hash, traits::CodeExecutor, H256};
|
||||
use sp_core::{convert_hash, traits::CodeExecutor};
|
||||
use sp_runtime::traits::{
|
||||
Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor,
|
||||
SimpleArithmetic, CheckedConversion, Zero,
|
||||
@@ -198,7 +198,8 @@ impl<E, Block, H, S> FetchChecker<Block> for LightDataChecker<E, H, Block, S>
|
||||
where
|
||||
Block: BlockT,
|
||||
E: CodeExecutor,
|
||||
H: Hasher<Out=H256>,
|
||||
H: Hasher,
|
||||
H::Out: Ord + codec::Codec + 'static,
|
||||
S: BlockchainStorage<Block>,
|
||||
{
|
||||
fn check_header_proof(
|
||||
@@ -214,8 +215,8 @@ impl<E, Block, H, S> FetchChecker<Block> for LightDataChecker<E, H, Block, S>
|
||||
request.cht_root,
|
||||
request.block,
|
||||
remote_header_hash,
|
||||
remote_proof)
|
||||
.map(|_| remote_header)
|
||||
remote_proof,
|
||||
).map(|_| remote_header)
|
||||
}
|
||||
|
||||
fn check_read_proof(
|
||||
@@ -331,7 +332,7 @@ pub mod tests {
|
||||
use sp_blockchain::Error as ClientError;
|
||||
use sc_client_api::backend::NewBlockState;
|
||||
use substrate_test_runtime_client::{
|
||||
self, ClientExt, blockchain::HeaderBackend, AccountKeyring,
|
||||
blockchain::HeaderBackend, AccountKeyring, ClientBlockImportExt,
|
||||
runtime::{self, Hash, Block, Header, Extrinsic}
|
||||
};
|
||||
use sp_consensus::BlockOrigin;
|
||||
@@ -442,13 +443,15 @@ pub mod tests {
|
||||
|
||||
fn prepare_for_header_proof_check(insert_cht: bool) -> (TestChecker, Hash, Header, StorageProof) {
|
||||
// prepare remote client
|
||||
let remote_client = substrate_test_runtime_client::new();
|
||||
let mut remote_client = substrate_test_runtime_client::new();
|
||||
let mut local_headers_hashes = Vec::new();
|
||||
for i in 0..4 {
|
||||
let builder = remote_client.new_block(Default::default()).unwrap();
|
||||
remote_client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap();
|
||||
local_headers_hashes.push(remote_client.block_hash(i + 1)
|
||||
.map_err(|_| ClientError::Backend("TestError".into())));
|
||||
let block = remote_client.new_block(Default::default()).unwrap().build().unwrap().block;
|
||||
remote_client.import(BlockOrigin::Own, block).unwrap();
|
||||
local_headers_hashes.push(
|
||||
remote_client.block_hash(i + 1)
|
||||
.map_err(|_| ClientError::Backend("TestError".into()))
|
||||
);
|
||||
}
|
||||
|
||||
// 'fetch' header proof from remote node
|
||||
|
||||
@@ -24,9 +24,9 @@ pub mod fetcher;
|
||||
use std::sync::Arc;
|
||||
|
||||
use sc_executor::RuntimeInfo;
|
||||
use sp_core::{H256, Blake2Hasher, traits::CodeExecutor};
|
||||
use sp_core::traits::CodeExecutor;
|
||||
use sp_runtime::BuildStorage;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use sp_runtime::traits::{Block as BlockT, HasherFor};
|
||||
use sp_blockchain::Result as ClientResult;
|
||||
|
||||
use crate::call_executor::LocalCallExecutor;
|
||||
@@ -45,7 +45,7 @@ pub fn new_light_blockchain<B: BlockT, S: BlockchainStorage<B>>(storage: S) -> A
|
||||
}
|
||||
|
||||
/// Create an instance of light client backend.
|
||||
pub fn new_light_backend<B, S>(blockchain: Arc<Blockchain<S>>) -> Arc<Backend<S, Blake2Hasher>>
|
||||
pub fn new_light_backend<B, S>(blockchain: Arc<Blockchain<S>>) -> Arc<Backend<S, HasherFor<B>>>
|
||||
where
|
||||
B: BlockT,
|
||||
S: BlockchainStorage<B>,
|
||||
@@ -55,15 +55,22 @@ pub fn new_light_backend<B, S>(blockchain: Arc<Blockchain<S>>) -> Arc<Backend<S,
|
||||
|
||||
/// Create an instance of light client.
|
||||
pub fn new_light<B, S, GS, RA, E>(
|
||||
backend: Arc<Backend<S, Blake2Hasher>>,
|
||||
backend: Arc<Backend<S, HasherFor<B>>>,
|
||||
genesis_storage: GS,
|
||||
code_executor: E,
|
||||
) -> ClientResult<Client<Backend<S, Blake2Hasher>, GenesisCallExecutor<
|
||||
Backend<S, Blake2Hasher>,
|
||||
LocalCallExecutor<Backend<S, Blake2Hasher>, E>
|
||||
>, B, RA>>
|
||||
) -> ClientResult<
|
||||
Client<
|
||||
Backend<S, HasherFor<B>>,
|
||||
GenesisCallExecutor<
|
||||
Backend<S, HasherFor<B>>,
|
||||
LocalCallExecutor<Backend<S, HasherFor<B>>, E>
|
||||
>,
|
||||
B,
|
||||
RA
|
||||
>
|
||||
>
|
||||
where
|
||||
B: BlockT<Hash=H256>,
|
||||
B: BlockT,
|
||||
S: BlockchainStorage<B> + 'static,
|
||||
GS: BuildStorage,
|
||||
E: CodeExecutor + RuntimeInfo,
|
||||
@@ -84,7 +91,7 @@ pub fn new_light<B, S, GS, RA, E>(
|
||||
pub fn new_fetch_checker<E, B: BlockT, S: BlockchainStorage<B>>(
|
||||
blockchain: Arc<Blockchain<S>>,
|
||||
executor: E,
|
||||
) -> LightDataChecker<E, Blake2Hasher, B, S>
|
||||
) -> LightDataChecker<E, HasherFor<B>, B, S>
|
||||
where
|
||||
E: CodeExecutor,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user