mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
Removed From<H256> bound (#790)
This commit is contained in:
committed by
Robert Habermeier
parent
f71200ee3c
commit
da991efd5f
@@ -65,16 +65,15 @@ pub fn compute_root<Header, Hasher, I>(
|
||||
cht_size: u64,
|
||||
cht_num: Header::Number,
|
||||
hashes: I,
|
||||
) -> Option<Header::Hash>
|
||||
) -> Option<Hasher::Out>
|
||||
where
|
||||
Header: HeaderT,
|
||||
Header::Hash: From<Hasher::Out>,
|
||||
Hasher: hashdb::Hasher,
|
||||
Hasher::Out: Ord + Encodable,
|
||||
I: IntoIterator<Item=Option<Header::Hash>>,
|
||||
{
|
||||
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.
|
||||
@@ -113,17 +112,19 @@ pub fn check_proof<Header, Hasher, Codec>(
|
||||
) -> ClientResult<()>
|
||||
where
|
||||
Header: HeaderT,
|
||||
Header::Hash: From<H256>,
|
||||
Header::Hash: AsRef<[u8]>,
|
||||
Hasher: hashdb::Hasher,
|
||||
Hasher::Out: Ord + Encodable + HeapSizeOf + From<Header::Hash>,
|
||||
Hasher::Out: Ord + Encodable + HeapSizeOf,
|
||||
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_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))?;
|
||||
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)?;
|
||||
match local_hash == remote_hash {
|
||||
let local_hash = decode_cht_value(&local_cht_value).ok_or_else(|| ClientErrorKind::InvalidHeaderProof)?;
|
||||
match &local_hash[..] == remote_hash.as_ref() {
|
||||
true => Ok(()),
|
||||
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.
|
||||
pub fn decode_cht_value<Hash: From<H256>>(value: &[u8]) -> Option<Hash> {
|
||||
pub fn decode_cht_value(value: &[u8]) -> Option<H256> {
|
||||
match value.len() {
|
||||
32 => Some(H256::from_slice(&value[0..32]).into()),
|
||||
32 => Some(H256::from_slice(&value[0..32])),
|
||||
_ => None,
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ use runtime_primitives::generic::BlockId;
|
||||
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
|
||||
use state_machine::{Backend as StateBackend, CodeExecutor, OverlayedChanges,
|
||||
execution_proof_check, ExecutionManager};
|
||||
use primitives::H256;
|
||||
use patricia_trie::NodeCodec;
|
||||
use hashdb::Hasher;
|
||||
use rlp::Encodable;
|
||||
@@ -138,14 +137,16 @@ pub fn check_execution_proof<Header, E, H, C>(
|
||||
Header: HeaderT,
|
||||
E: CodeExecutor<H>,
|
||||
H: Hasher,
|
||||
H::Out: Ord + Encodable + HeapSizeOf + From<H256>,
|
||||
H::Out: Ord + Encodable + HeapSizeOf,
|
||||
C: NodeCodec<H>,
|
||||
{
|
||||
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 local_result = execution_proof_check::<H, C, _>(
|
||||
H256::from_slice(local_state_root.as_ref()).into(),
|
||||
root,
|
||||
remote_proof,
|
||||
&mut changes,
|
||||
executor,
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
use futures::IntoFuture;
|
||||
|
||||
use primitives::H256;
|
||||
use hashdb::Hasher;
|
||||
use patricia_trie::NodeCodec;
|
||||
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>
|
||||
where
|
||||
Block: BlockT,
|
||||
Block::Hash: Into<H::Out> + From<H256>,
|
||||
E: CodeExecutor<H>,
|
||||
H: Hasher,
|
||||
C: NodeCodec<H> + Sync + Send,
|
||||
H::Out: Ord + Encodable + HeapSizeOf + From<Block::Hash> + From<H256>,
|
||||
H::Out: Ord + Encodable + HeapSizeOf,
|
||||
{
|
||||
fn check_header_proof(
|
||||
&self,
|
||||
@@ -162,8 +160,9 @@ impl<E, Block, H, C> FetchChecker<Block> for LightDataChecker<E, H, C>
|
||||
request: &RemoteReadRequest<Block::Header>,
|
||||
remote_proof: Vec<Vec<u8>>
|
||||
) -> ClientResult<Option<Vec<u8>>> {
|
||||
let local_state_root = request.header.state_root().clone();
|
||||
read_proof_check::<H, C>(local_state_root.into(), remote_proof, &request.key).map_err(Into::into)
|
||||
let mut root: H::Out = Default::default();
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user