Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into ao-update-kvdb-and-co
Browse files Browse the repository at this point in the history
* master:
  Implement `Clone` and `Default` for `Config` (#12397)
  Don't send back empty proofs if light request fails (#12372)
  MMR: impl `TypeInfo` for some structures (#12423)
  • Loading branch information
ordian committed Oct 5, 2022
2 parents bd29c35 + 87224cf commit d31a98d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/beefy/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl From<Error> for JsonRpseeError {
// Provides RPC methods for interacting with BEEFY.
#[rpc(client, server)]
pub trait BeefyApi<Notification, Hash> {
/// Returns the block most recently finalized by BEEFY, alongside side its justification.
/// Returns the block most recently finalized by BEEFY, alongside its justification.
#[subscription(
name = "beefy_subscribeJustifications" => "beefy_justifications",
unsubscribe = "beefy_unsubscribeJustifications",
Expand Down
2 changes: 1 addition & 1 deletion client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ where

if let Err(e) = self.backend.append_justification(
BlockId::Number(block_num),
(BEEFY_ENGINE_ID, finality_proof.clone().encode()),
(BEEFY_ENGINE_ID, finality_proof.encode()),
) {
error!(target: "beefy", "🥩 Error {:?} on appending justification: {:?}", e, finality_proof);
}
Expand Down
1 change: 1 addition & 0 deletions client/executor/wasmtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ pub struct Semantics {
pub max_memory_size: Option<usize>,
}

#[derive(Clone)]
pub struct Config {
/// The WebAssembly standard requires all imports of an instantiated module to be resolved,
/// otherwise, the instantiation fails. If this option is set to `true`, then this behavior is
Expand Down
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
4 changes: 2 additions & 2 deletions primitives/beefy/src/mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl BeefyDataProvider<Vec<u8>> for () {
}

/// A standard leaf that gets added every block to the MMR constructed by Substrate's `pallet_mmr`.
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode)]
#[derive(Debug, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)]
pub struct MmrLeaf<BlockNumber, Hash, MerkleRoot, ExtraData> {
/// Version of the leaf format.
///
Expand Down Expand Up @@ -73,7 +73,7 @@ pub struct MmrLeaf<BlockNumber, Hash, MerkleRoot, ExtraData> {
/// Given that adding new struct elements in SCALE is backward compatible (i.e. old format can be
/// still decoded, the new fields will simply be ignored). We expect the major version to be bumped
/// very rarely (hopefuly never).
#[derive(Debug, Default, PartialEq, Eq, Clone, Encode, Decode)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Encode, Decode, TypeInfo)]
pub struct MmrLeafVersion(u8);
impl MmrLeafVersion {
/// Create new version object from `major` and `minor` components.
Expand Down
1 change: 1 addition & 0 deletions primitives/merkle-mountain-range/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
log = { version = "0.4.17", default-features = false }
serde = { version = "1.0.136", features = ["derive"], optional = true }
sp-api = { version = "4.0.0-dev", default-features = false, path = "../api" }
Expand Down
5 changes: 3 additions & 2 deletions primitives/merkle-mountain-range/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]

use scale_info::TypeInfo;
use sp_debug_derive::RuntimeDebug;
use sp_runtime::traits;
#[cfg(not(feature = "std"))]
Expand Down Expand Up @@ -69,7 +70,7 @@ impl<Hash> OnNewRoot<Hash> for () {
}

/// A MMR proof data for one of the leaves.
#[derive(codec::Encode, codec::Decode, RuntimeDebug, Clone, PartialEq, Eq)]
#[derive(codec::Encode, codec::Decode, RuntimeDebug, Clone, PartialEq, Eq, TypeInfo)]
pub struct Proof<Hash> {
/// The index of the leaf the proof is for.
pub leaf_index: LeafIndex,
Expand Down Expand Up @@ -352,7 +353,7 @@ impl_leaf_data_for_tuple!(A:0, B:1, C:2, D:3);
impl_leaf_data_for_tuple!(A:0, B:1, C:2, D:3, E:4);

/// A MMR proof data for a group of leaves.
#[derive(codec::Encode, codec::Decode, RuntimeDebug, Clone, PartialEq, Eq)]
#[derive(codec::Encode, codec::Decode, RuntimeDebug, Clone, PartialEq, Eq, TypeInfo)]
pub struct BatchProof<Hash> {
/// The indices of the leaves the proof is for.
pub leaf_indices: Vec<LeafIndex>,
Expand Down

0 comments on commit d31a98d

Please sign in to comment.