mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 02:21:03 +00:00
Removed From<H256> bound (#790)
This commit is contained in:
committed by
Robert Habermeier
parent
f71200ee3c
commit
da991efd5f
@@ -28,7 +28,7 @@ use client::cht;
|
|||||||
use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
|
use client::error::{ErrorKind as ClientErrorKind, Result as ClientResult};
|
||||||
use client::light::blockchain::Storage as LightBlockchainStorage;
|
use client::light::blockchain::Storage as LightBlockchainStorage;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use primitives::{AuthorityId, H256, Blake2Hasher};
|
use primitives::{AuthorityId, Blake2Hasher};
|
||||||
use runtime_primitives::generic::BlockId;
|
use runtime_primitives::generic::BlockId;
|
||||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT,
|
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT,
|
||||||
Zero, One, As, NumberFor};
|
Zero, One, As, NumberFor};
|
||||||
@@ -183,7 +183,7 @@ impl<Block> BlockchainHeaderBackend<Block> for LightStorage<Block>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Block: BlockT> LightStorage<Block> where Block::Hash: From<H256> {
|
impl<Block: BlockT> LightStorage<Block> {
|
||||||
// note that a block is finalized. ensure that best chain contains the finalized
|
// note that a block is finalized. ensure that best chain contains the finalized
|
||||||
// block number first.
|
// block number first.
|
||||||
fn note_finalized(&self, transaction: &mut DBTransaction, header: &Block::Header, hash: Block::Hash) -> ClientResult<()> {
|
fn note_finalized(&self, transaction: &mut DBTransaction, header: &Block::Header, hash: Block::Hash) -> ClientResult<()> {
|
||||||
@@ -212,7 +212,7 @@ impl<Block: BlockT> LightStorage<Block> where Block::Hash: From<H256> {
|
|||||||
let mut build_cht = |header: &Block::Header| -> ClientResult<()> {
|
let mut build_cht = |header: &Block::Header| -> ClientResult<()> {
|
||||||
if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) {
|
if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) {
|
||||||
let new_cht_start: NumberFor<Block> = cht::start_number(cht::SIZE, new_cht_number);
|
let new_cht_start: NumberFor<Block> = cht::start_number(cht::SIZE, new_cht_number);
|
||||||
let new_cht_root: Option<Block::Hash> = cht::compute_root::<Block::Header, Blake2Hasher, _>(
|
let new_cht_root = cht::compute_root::<Block::Header, Blake2Hasher, _>(
|
||||||
cht::SIZE, new_cht_number, (new_cht_start.as_()..)
|
cht::SIZE, new_cht_number, (new_cht_start.as_()..)
|
||||||
.map(|num| self.hash(As::sa(num)).unwrap_or_default())
|
.map(|num| self.hash(As::sa(num)).unwrap_or_default())
|
||||||
);
|
);
|
||||||
@@ -262,7 +262,6 @@ impl<Block: BlockT> LightStorage<Block> where Block::Hash: From<H256> {
|
|||||||
impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
|
||||||
where
|
where
|
||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
Block::Hash: From<H256>,
|
|
||||||
{
|
{
|
||||||
fn import_header(
|
fn import_header(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -65,16 +65,15 @@ pub fn compute_root<Header, Hasher, I>(
|
|||||||
cht_size: u64,
|
cht_size: u64,
|
||||||
cht_num: Header::Number,
|
cht_num: Header::Number,
|
||||||
hashes: I,
|
hashes: I,
|
||||||
) -> Option<Header::Hash>
|
) -> Option<Hasher::Out>
|
||||||
where
|
where
|
||||||
Header: HeaderT,
|
Header: HeaderT,
|
||||||
Header::Hash: From<Hasher::Out>,
|
|
||||||
Hasher: hashdb::Hasher,
|
Hasher: hashdb::Hasher,
|
||||||
Hasher::Out: Ord + Encodable,
|
Hasher::Out: Ord + Encodable,
|
||||||
I: IntoIterator<Item=Option<Header::Hash>>,
|
I: IntoIterator<Item=Option<Header::Hash>>,
|
||||||
{
|
{
|
||||||
build_pairs::<Header, I>(cht_size, cht_num, hashes)
|
build_pairs::<Header, I>(cht_size, cht_num, hashes)
|
||||||
.map(|pairs| triehash::trie_root::<Hasher, _, _, _>(pairs).into())
|
.map(|pairs| triehash::trie_root::<Hasher, _, _, _>(pairs))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build CHT-based header proof.
|
/// Build CHT-based header proof.
|
||||||
@@ -113,17 +112,19 @@ pub fn check_proof<Header, Hasher, Codec>(
|
|||||||
) -> ClientResult<()>
|
) -> ClientResult<()>
|
||||||
where
|
where
|
||||||
Header: HeaderT,
|
Header: HeaderT,
|
||||||
Header::Hash: From<H256>,
|
Header::Hash: AsRef<[u8]>,
|
||||||
Hasher: hashdb::Hasher,
|
Hasher: hashdb::Hasher,
|
||||||
Hasher::Out: Ord + Encodable + HeapSizeOf + From<Header::Hash>,
|
Hasher::Out: Ord + Encodable + HeapSizeOf,
|
||||||
Codec: NodeCodec<Hasher>,
|
Codec: NodeCodec<Hasher>,
|
||||||
{
|
{
|
||||||
|
let mut root: Hasher::Out = Default::default();
|
||||||
|
root.as_mut().copy_from_slice(local_root.as_ref());
|
||||||
let local_cht_key = encode_cht_key(local_number);
|
let local_cht_key = encode_cht_key(local_number);
|
||||||
let local_cht_value = read_proof_check::<Hasher, Codec>(local_root.into(), remote_proof,
|
let local_cht_value = read_proof_check::<Hasher, Codec>(root, remote_proof,
|
||||||
&local_cht_key).map_err(|e| ClientError::from(e))?;
|
&local_cht_key).map_err(|e| ClientError::from(e))?;
|
||||||
let local_cht_value = local_cht_value.ok_or_else(|| ClientErrorKind::InvalidHeaderProof)?;
|
let local_cht_value = local_cht_value.ok_or_else(|| ClientErrorKind::InvalidHeaderProof)?;
|
||||||
let local_hash: Header::Hash = decode_cht_value(&local_cht_value).ok_or_else(|| ClientErrorKind::InvalidHeaderProof)?;
|
let local_hash = decode_cht_value(&local_cht_value).ok_or_else(|| ClientErrorKind::InvalidHeaderProof)?;
|
||||||
match local_hash == remote_hash {
|
match &local_hash[..] == remote_hash.as_ref() {
|
||||||
true => Ok(()),
|
true => Ok(()),
|
||||||
false => Err(ClientErrorKind::InvalidHeaderProof.into()),
|
false => Err(ClientErrorKind::InvalidHeaderProof.into()),
|
||||||
}
|
}
|
||||||
@@ -203,9 +204,9 @@ fn encode_cht_value<Hash: AsRef<[u8]>>(hash: Hash) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert CHT value into block header hash.
|
/// Convert CHT value into block header hash.
|
||||||
pub fn decode_cht_value<Hash: From<H256>>(value: &[u8]) -> Option<Hash> {
|
pub fn decode_cht_value(value: &[u8]) -> Option<H256> {
|
||||||
match value.len() {
|
match value.len() {
|
||||||
32 => Some(H256::from_slice(&value[0..32]).into()),
|
32 => Some(H256::from_slice(&value[0..32])),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ use runtime_primitives::generic::BlockId;
|
|||||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
|
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
|
||||||
use state_machine::{Backend as StateBackend, CodeExecutor, OverlayedChanges,
|
use state_machine::{Backend as StateBackend, CodeExecutor, OverlayedChanges,
|
||||||
execution_proof_check, ExecutionManager};
|
execution_proof_check, ExecutionManager};
|
||||||
use primitives::H256;
|
|
||||||
use patricia_trie::NodeCodec;
|
use patricia_trie::NodeCodec;
|
||||||
use hashdb::Hasher;
|
use hashdb::Hasher;
|
||||||
use rlp::Encodable;
|
use rlp::Encodable;
|
||||||
@@ -138,14 +137,16 @@ pub fn check_execution_proof<Header, E, H, C>(
|
|||||||
Header: HeaderT,
|
Header: HeaderT,
|
||||||
E: CodeExecutor<H>,
|
E: CodeExecutor<H>,
|
||||||
H: Hasher,
|
H: Hasher,
|
||||||
H::Out: Ord + Encodable + HeapSizeOf + From<H256>,
|
H::Out: Ord + Encodable + HeapSizeOf,
|
||||||
C: NodeCodec<H>,
|
C: NodeCodec<H>,
|
||||||
{
|
{
|
||||||
let local_state_root = request.header.state_root();
|
let local_state_root = request.header.state_root();
|
||||||
|
let mut root: H::Out = Default::default();
|
||||||
|
root.as_mut().copy_from_slice(local_state_root.as_ref());
|
||||||
|
|
||||||
let mut changes = OverlayedChanges::default();
|
let mut changes = OverlayedChanges::default();
|
||||||
let local_result = execution_proof_check::<H, C, _>(
|
let local_result = execution_proof_check::<H, C, _>(
|
||||||
H256::from_slice(local_state_root.as_ref()).into(),
|
root,
|
||||||
remote_proof,
|
remote_proof,
|
||||||
&mut changes,
|
&mut changes,
|
||||||
executor,
|
executor,
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
use futures::IntoFuture;
|
use futures::IntoFuture;
|
||||||
|
|
||||||
use primitives::H256;
|
|
||||||
use hashdb::Hasher;
|
use hashdb::Hasher;
|
||||||
use patricia_trie::NodeCodec;
|
use patricia_trie::NodeCodec;
|
||||||
use rlp::Encodable;
|
use rlp::Encodable;
|
||||||
@@ -134,11 +133,10 @@ impl<E, H, C> LightDataChecker<E, H, C> {
|
|||||||
impl<E, Block, H, C> FetchChecker<Block> for LightDataChecker<E, H, C>
|
impl<E, Block, H, C> FetchChecker<Block> for LightDataChecker<E, H, C>
|
||||||
where
|
where
|
||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
Block::Hash: Into<H::Out> + From<H256>,
|
|
||||||
E: CodeExecutor<H>,
|
E: CodeExecutor<H>,
|
||||||
H: Hasher,
|
H: Hasher,
|
||||||
C: NodeCodec<H> + Sync + Send,
|
C: NodeCodec<H> + Sync + Send,
|
||||||
H::Out: Ord + Encodable + HeapSizeOf + From<Block::Hash> + From<H256>,
|
H::Out: Ord + Encodable + HeapSizeOf,
|
||||||
{
|
{
|
||||||
fn check_header_proof(
|
fn check_header_proof(
|
||||||
&self,
|
&self,
|
||||||
@@ -162,8 +160,9 @@ impl<E, Block, H, C> FetchChecker<Block> for LightDataChecker<E, H, C>
|
|||||||
request: &RemoteReadRequest<Block::Header>,
|
request: &RemoteReadRequest<Block::Header>,
|
||||||
remote_proof: Vec<Vec<u8>>
|
remote_proof: Vec<Vec<u8>>
|
||||||
) -> ClientResult<Option<Vec<u8>>> {
|
) -> ClientResult<Option<Vec<u8>>> {
|
||||||
let local_state_root = request.header.state_root().clone();
|
let mut root: H::Out = Default::default();
|
||||||
read_proof_check::<H, C>(local_state_root.into(), remote_proof, &request.key).map_err(Into::into)
|
root.as_mut().copy_from_slice(request.header.state_root().as_ref());
|
||||||
|
read_proof_check::<H, C>(root, remote_proof, &request.key).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_execution_proof(
|
fn check_execution_proof(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ use substrate_executor::{NativeExecutor, NativeExecutionDispatch};
|
|||||||
use transaction_pool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
|
use transaction_pool::{self, Options as TransactionPoolOptions, Pool as TransactionPool};
|
||||||
use runtime_primitives::{traits::Block as BlockT, traits::Header as HeaderT, BuildStorage};
|
use runtime_primitives::{traits::Block as BlockT, traits::Header as HeaderT, BuildStorage};
|
||||||
use config::Configuration;
|
use config::Configuration;
|
||||||
use primitives::{Blake2Hasher, RlpCodec, H256};
|
use primitives::{Blake2Hasher, RlpCodec};
|
||||||
|
|
||||||
// Type aliases.
|
// Type aliases.
|
||||||
// These exist mainly to avoid typing `<F as Factory>::Foo` all over the code.
|
// These exist mainly to avoid typing `<F as Factory>::Foo` all over the code.
|
||||||
@@ -214,11 +214,7 @@ pub struct LightComponents<Factory: ServiceFactory> {
|
|||||||
_factory: PhantomData<Factory>,
|
_factory: PhantomData<Factory>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Factory: ServiceFactory> Components for LightComponents<Factory>
|
impl<Factory: ServiceFactory> Components for LightComponents<Factory> {
|
||||||
where
|
|
||||||
<<Factory as ServiceFactory>::Block as BlockT>::Hash: From<H256>,
|
|
||||||
H256: From<<<Factory as ServiceFactory>::Block as BlockT>::Hash>,
|
|
||||||
{
|
|
||||||
type Factory = Factory;
|
type Factory = Factory;
|
||||||
type Executor = LightExecutor<Factory>;
|
type Executor = LightExecutor<Factory>;
|
||||||
type Backend = LightBackend<Factory>;
|
type Backend = LightBackend<Factory>;
|
||||||
|
|||||||
Reference in New Issue
Block a user