Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
redunant return_value removed
  • Loading branch information
svyatonik committed Jun 18, 2018
commit 508055a519e1dc81db72ef7aeed118444acb6f2c
12 changes: 3 additions & 9 deletions substrate/client/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<B, F, Block> CallExecutor<Block> for RemoteCallExecutor<B, F>
}

/// Check remote execution proof using given backend.
pub fn check_execution_proof<B, E, Block>(backend: &B, executor: &E, request: &RemoteCallRequest<Block::Hash>, remote_proof: (Vec<u8>, Vec<Vec<u8>>)) -> Result<CallResult, error::Error>
pub fn check_execution_proof<B, E, Block>(backend: &B, executor: &E, request: &RemoteCallRequest<Block::Hash>, remote_proof: Vec<Vec<u8>>) -> Result<CallResult, error::Error>
where
B: backend::RemoteBackend<Block>,
E: CodeExecutor,
Expand All @@ -178,13 +178,11 @@ pub fn check_execution_proof<B, E, Block>(backend: &B, executor: &E, request: &R
}

/// Check remote execution proof using given state root.
fn do_check_execution_proof<E, H>(local_state_root: H, executor: &E, request: &RemoteCallRequest<H>, remote_proof: (Vec<u8>, Vec<Vec<u8>>)) -> Result<CallResult, error::Error>
fn do_check_execution_proof<E, H>(local_state_root: H, executor: &E, request: &RemoteCallRequest<H>, remote_proof: Vec<Vec<u8>>) -> Result<CallResult, error::Error>
where
E: CodeExecutor,
H: Into<[u8; 32]>, // TODO: remove when patricia_trie generic.
{
let (remote_result, remote_proof) = remote_proof;

let mut changes = OverlayedChanges::default();
let (local_result, _) = state_machine::proof_check(
local_state_root.into(),
Expand All @@ -194,10 +192,6 @@ fn do_check_execution_proof<E, H>(local_state_root: H, executor: &E, request: &R
&request.method,
&request.call_data)?;

if local_result != remote_result {
return Err(error::ErrorKind::InvalidExecutionProof.into());
}

Ok(CallResult { return_data: local_result, changes })
}

Expand All @@ -218,7 +212,7 @@ mod tests {
.unwrap().storage_root(::std::iter::empty()).0;

// 'fetch' execution proof from remote node
let remote_execution_proof = remote_client.execution_proof(&remote_block_id, "authorities", &[]).unwrap();
let remote_execution_proof = remote_client.execution_proof(&remote_block_id, "authorities", &[]).unwrap().1;

// check remote execution proof locally
let local_executor = test_client::NativeExecutor::new();
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait Fetcher<B: BlockT>: Send + Sync {
/// Light client remote data checker.
pub trait FetchChecker<B: BlockT>: Send + Sync {
/// Check remote method execution proof.
fn check_execution_proof(&self, request: &RemoteCallRequest<B::Hash>, remote_proof: (Vec<u8>, Vec<Vec<u8>>)) -> error::Result<CallResult>;
fn check_execution_proof(&self, request: &RemoteCallRequest<B::Hash>, remote_proof: Vec<Vec<u8>>) -> error::Result<CallResult>;
}

/// Light client backend.
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<E, B> FetchChecker<B> for LightDataChecker<E, B>
B: BlockT,
<<B as BlockT>::Header as HeaderT>::Hash: Into<[u8; 32]>, // TODO: remove when patricia_trie generic.
{
fn check_execution_proof(&self, request: &RemoteCallRequest<B::Hash>, remote_proof: (Vec<u8>, Vec<Vec<u8>>)) -> error::Result<CallResult> {
fn check_execution_proof(&self, request: &RemoteCallRequest<B::Hash>, remote_proof: Vec<Vec<u8>>) -> error::Result<CallResult> {
check_execution_proof(&*self.backend, &self.executor, request, remote_proof)
}
}
Expand Down
2 changes: 0 additions & 2 deletions substrate/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ pub enum Direction {
pub struct RemoteCallResponse {
/// Id of a request this response was made for.
pub id: RequestId,
/// Method return value.
pub value: Vec<u8>,
/// Execution proof.
pub proof: Vec<Vec<u8>>,
}
Expand Down
9 changes: 4 additions & 5 deletions substrate/network/src/on_demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<B, E> OnDemandService for OnDemand<B, E> where
fn on_remote_response(&self, io: &mut SyncIo, peer: PeerId, response: message::RemoteCallResponse) {
let mut core = self.core.lock();
match core.remove(peer, response.id) {
Some(request) => match self.checker.check_execution_proof(&request.request, (response.value, response.proof)) {
Some(request) => match self.checker.check_execution_proof(&request.request, response.proof) {
Ok(response) => {
// we do not bother if receiver has been dropped already
let _ = request.sender.send(response);
Expand Down Expand Up @@ -312,10 +312,10 @@ mod tests {
}

impl FetchChecker<Block> for DummyFetchChecker {
fn check_execution_proof(&self, _request: &RemoteCallRequest<Hash>, remote_proof: (Vec<u8>, Vec<Vec<u8>>)) -> client::error::Result<client::CallResult> {
fn check_execution_proof(&self, _request: &RemoteCallRequest<Hash>, _remote_proof: Vec<Vec<u8>>) -> client::error::Result<client::CallResult> {
match self.ok {
true => Ok(client::CallResult {
return_data: remote_proof.0,
return_data: vec![42],
changes: Default::default(),
}),
false => Err(client::error::ErrorKind::Backend("Test error".into()).into()),
Expand All @@ -338,7 +338,6 @@ mod tests {
fn receive_response(on_demand: &OnDemand<Block, DummyExecutor>, network: &mut TestIo, peer: PeerId, id: message::RequestId) {
on_demand.on_remote_response(network, peer, message::RemoteCallResponse {
id: id,
value: vec![1],
proof: vec![vec![2]],
});
}
Expand Down Expand Up @@ -431,7 +430,7 @@ mod tests {
let response = on_demand.remote_call(RemoteCallRequest { block: Default::default(), method: "test".into(), call_data: vec![] });
let thread = ::std::thread::spawn(move || {
let result = response.wait().unwrap();
assert_eq!(result.return_data, vec![1]);
assert_eq!(result.return_data, vec![42]);
});

receive_response(&*on_demand, &mut network, 0, 0);
Expand Down
8 changes: 4 additions & 4 deletions substrate/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,17 @@ impl<B: BlockT> Protocol<B> where

fn on_remote_call_request(&self, io: &mut SyncIo, peer_id: PeerId, request: message::RemoteCallRequest<B::Hash>) {
trace!(target: "sync", "Remote request {} from {} ({} at {})", request.id, peer_id, request.method, request.block);
let (value, proof) = match self.chain.execution_proof(&request.block, &request.method, &request.data) {
Ok((value, proof)) => (value, proof),
let proof = match self.chain.execution_proof(&request.block, &request.method, &request.data) {
Ok((_, proof)) => proof,
Err(error) => {
trace!(target: "sync", "Remote request {} from {} ({} at {}) failed with: {}",
request.id, peer_id, request.method, request.block, error);
(Default::default(), Default::default())
Default::default()
},
};

self.send_message(io, peer_id, GenericMessage::RemoteCallResponse(message::RemoteCallResponse {
id: request.id, value, proof,
id: request.id, proof,
}));
}

Expand Down