Skip to content

Commit

Permalink
Don't send back empty proofs if light request fails (paritytech#12372)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka authored and ark0f committed Feb 27, 2023
1 parent cc03d6a commit d0786fc
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions client/network/light/src/light_client_requests/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use futures::{channel::mpsc, prelude::*};
use libp2p::PeerId;
use log::{debug, trace};
use prost::Message;
use sc_client_api::{BlockBackend, ProofProvider, StorageProof};
use sc_client_api::{BlockBackend, ProofProvider};
use sc_network_common::{
config::ProtocolId,
request_responses::{IncomingRequest, OutgoingResponse, ProtocolConfig},
Expand Down Expand Up @@ -176,12 +176,15 @@ where

let block = Decode::decode(&mut request.block.as_ref())?;

let proof =
let response =
match self
.client
.execution_proof(&BlockId::Hash(block), &request.method, &request.data)
{
Ok((_, proof)) => proof,
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: {}",
Expand All @@ -190,16 +193,11 @@ where
request.block,
e,
);
StorageProof::empty()
None
},
};

let response = {
let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
schema::v1::light::response::Response::RemoteCallResponse(r)
};

Ok(schema::v1::light::Response { response: Some(response) })
Ok(schema::v1::light::Response { response })
}

fn on_remote_read_request(
Expand All @@ -221,11 +219,14 @@ where

let block = Decode::decode(&mut request.block.as_ref())?;

let proof = match self
let response = match self
.client
.read_proof(&BlockId::Hash(block), &mut request.keys.iter().map(AsRef::as_ref))
{
Ok(proof) => proof,
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: {}",
Expand All @@ -234,16 +235,11 @@ where
request.block,
error,
);
StorageProof::empty()
None
},
};

let response = {
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
schema::v1::light::response::Response::RemoteReadResponse(r)
};

Ok(schema::v1::light::Response { response: Some(response) })
Ok(schema::v1::light::Response { response })
}

fn on_remote_read_child_request(
Expand Down Expand Up @@ -271,14 +267,17 @@ where
Some((ChildType::ParentKeyId, storage_key)) => Ok(ChildInfo::new_default(storage_key)),
None => Err(sp_blockchain::Error::InvalidChildStorageKey),
};
let proof = match child_info.and_then(|child_info| {
let response = match child_info.and_then(|child_info| {
self.client.read_child_proof(
&BlockId::Hash(block),
&child_info,
&mut request.keys.iter().map(AsRef::as_ref),
)
}) {
Ok(proof) => proof,
Ok(proof) => {
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
Some(schema::v1::light::response::Response::RemoteReadResponse(r))
},
Err(error) => {
trace!(
"remote read child request from {} ({} {} at {:?}) failed with: {}",
Expand All @@ -288,16 +287,11 @@ where
request.block,
error,
);
StorageProof::empty()
None
},
};

let response = {
let r = schema::v1::light::RemoteReadResponse { proof: proof.encode() };
schema::v1::light::response::Response::RemoteReadResponse(r)
};

Ok(schema::v1::light::Response { response: Some(response) })
Ok(schema::v1::light::Response { response })
}
}

Expand Down

0 comments on commit d0786fc

Please sign in to comment.