BlockId removal: refactor: ProofProvider (#12519)

* BlockId removal: refactor: ProofProvider

It changes the arguments of methods of `ProofProvider` trait from:
block: `BlockId<Block>` to: hash: `&Block::Hash`

This PR is part of BlockId::Number refactoring analysis (paritytech/substrate#11292)

* LightClientRequestHandler: excessive BlockIdTo bound removed

* imports cleanup

* formatting

* args tyeps cleanup
This commit is contained in:
Michal Kucharczyk
2022-10-19 12:13:57 +02:00
committed by GitHub
parent e3b269ab0f
commit 1d5aa47bee
5 changed files with 57 additions and 67 deletions
@@ -38,7 +38,7 @@ use sp_core::{
hexdisplay::HexDisplay,
storage::{ChildInfo, ChildType, PrefixedStorageKey},
};
use sp_runtime::{generic::BlockId, traits::Block};
use sp_runtime::traits::Block;
use std::{marker::PhantomData, sync::Arc};
const LOG_TARGET: &str = "light-client-request-handler";
@@ -172,26 +172,22 @@ where
let block = Decode::decode(&mut request.block.as_ref())?;
let response =
match self
.client
.execution_proof(&BlockId::Hash(block), &request.method, &request.data)
{
Ok((_, proof)) => {
let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
Some(schema::v1::light::response::Response::RemoteCallResponse(r))
},
Err(e) => {
trace!(
"remote call request from {} ({} at {:?}) failed with: {}",
peer,
request.method,
request.block,
e,
);
None
},
};
let response = match self.client.execution_proof(&block, &request.method, &request.data) {
Ok((_, proof)) => {
let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
Some(schema::v1::light::response::Response::RemoteCallResponse(r))
},
Err(e) => {
trace!(
"remote call request from {} ({} at {:?}) failed with: {}",
peer,
request.method,
request.block,
e,
);
None
},
};
Ok(schema::v1::light::Response { response })
}
@@ -215,25 +211,23 @@ where
let block = Decode::decode(&mut request.block.as_ref())?;
let response = match self
.client
.read_proof(&BlockId::Hash(block), &mut request.keys.iter().map(AsRef::as_ref))
{
Ok(proof) => {
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
Some(schema::v1::light::response::Response::RemoteReadResponse(r))
},
Err(error) => {
trace!(
"remote read request from {} ({} at {:?}) failed with: {}",
peer,
fmt_keys(request.keys.first(), request.keys.last()),
request.block,
error,
);
None
},
};
let response =
match self.client.read_proof(&block, &mut request.keys.iter().map(AsRef::as_ref)) {
Ok(proof) => {
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
Some(schema::v1::light::response::Response::RemoteReadResponse(r))
},
Err(error) => {
trace!(
"remote read request from {} ({} at {:?}) failed with: {}",
peer,
fmt_keys(request.keys.first(), request.keys.last()),
request.block,
error,
);
None
},
};
Ok(schema::v1::light::Response { response })
}
@@ -265,7 +259,7 @@ where
};
let response = match child_info.and_then(|child_info| {
self.client.read_child_proof(
&BlockId::Hash(block),
&block,
&child_info,
&mut request.keys.iter().map(AsRef::as_ref),
)