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

Commit

Permalink
jsonrpsee v0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasad1 committed Apr 21, 2022
2 parents b8e5749 + 08bc38d commit 8426607
Show file tree
Hide file tree
Showing 16 changed files with 622 additions and 365 deletions.
672 changes: 377 additions & 295 deletions Cargo.lock

Large diffs are not rendered by default.

34 changes: 20 additions & 14 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use cumulus_primitives_core::{relay_chain::v2::Hash as PHash, PersistedValidatio
use futures::lock::Mutex;
use sc_client_api::{backend::AuxStore, BlockOf};
use sc_consensus::BlockImport;
use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, SlotInfo};
use sc_consensus_slots::{BackoffAuthoringBlocksStrategy, SimpleSlotWorker, SlotInfo};
use sc_telemetry::TelemetryHandle;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
Expand All @@ -42,7 +42,7 @@ use sp_core::crypto::Pair;
use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider};
use sp_keystore::SyncCryptoStorePtr;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member, NumberFor};
use std::{convert::TryFrom, hash::Hash, sync::Arc};
use std::{convert::TryFrom, hash::Hash, marker::PhantomData, sync::Arc};

mod import_queue;

Expand All @@ -53,29 +53,25 @@ pub use sc_consensus_slots::InherentDataProviderExt;
const LOG_TARGET: &str = "aura::cumulus";

/// The implementation of the AURA consensus for parachains.
pub struct AuraConsensus<B, CIDP> {
pub struct AuraConsensus<B, CIDP, W> {
create_inherent_data_providers: Arc<CIDP>,
aura_worker: Arc<
Mutex<
dyn sc_consensus_slots::SlotWorker<B, <EnableProofRecording as ProofRecording>::Proof>
+ Send
+ 'static,
>,
>,
aura_worker: Arc<Mutex<W>>,
slot_duration: SlotDuration,
_phantom: PhantomData<B>,
}

impl<B, CIDP> Clone for AuraConsensus<B, CIDP> {
impl<B, CIDP, W> Clone for AuraConsensus<B, CIDP, W> {
fn clone(&self) -> Self {
Self {
create_inherent_data_providers: self.create_inherent_data_providers.clone(),
aura_worker: self.aura_worker.clone(),
slot_duration: self.slot_duration,
_phantom: PhantomData,
}
}
}

impl<B, CIDP> AuraConsensus<B, CIDP>
impl<B, CIDP> AuraConsensus<B, CIDP, ()>
where
B: BlockT,
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + 'static,
Expand Down Expand Up @@ -134,13 +130,21 @@ where
},
);

Box::new(Self {
Box::new(AuraConsensus {
create_inherent_data_providers: Arc::new(create_inherent_data_providers),
aura_worker: Arc::new(Mutex::new(worker)),
slot_duration,
_phantom: PhantomData,
})
}
}

impl<B, CIDP, W> AuraConsensus<B, CIDP, W>
where
B: BlockT,
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt,
{
/// Create the inherent data.
///
/// Returns the created inherent data and the inherent data providers used.
Expand Down Expand Up @@ -178,11 +182,13 @@ where
}

#[async_trait::async_trait]
impl<B, CIDP> ParachainConsensus<B> for AuraConsensus<B, CIDP>
impl<B, CIDP, W> ParachainConsensus<B> for AuraConsensus<B, CIDP, W>
where
B: BlockT,
CIDP: CreateInherentDataProviders<B, (PHash, PersistedValidationData)> + Send + Sync + 'static,
CIDP::InherentDataProviders: InherentDataProviderExt + Send,
W: SimpleSlotWorker<B> + Send + Sync,
W::Proposer: Proposer<B, Proof = <EnableProofRecording as ProofRecording>::Proof>,
{
async fn produce_candidate(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion client/relay-chain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ parking_lot = "0.12.0"
derive_more = "0.99.2"
async-trait = "0.1.53"
thiserror = "1.0.30"
jsonrpsee-core = "0.10.1"
jsonrpsee-core = "0.11.0"
parity-scale-codec = "3.1.2"
2 changes: 1 addition & 1 deletion client/relay-chain-rpc-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ futures = "0.3.21"
futures-timer = "3.0.2"
parity-scale-codec = "3.1.2"
parking_lot = "0.12.0"
jsonrpsee = { version = "0.10.1", features = ["client"] }
jsonrpsee = { version = "0.11.0", features = ["client"] }
tracing = "0.1.34"
async-trait = "0.1.53"
url = "2.2.2"
Expand Down
4 changes: 4 additions & 0 deletions pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ std = [
"sp-trie/std",
"xcm/std"
]

runtime-benchmarks = [
"sp-runtime/runtime-benchmarks"
]
7 changes: 7 additions & 0 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,4 +1047,11 @@ impl<T: Config> BlockNumberProvider for RelaychainBlockNumberProvider<T> {
.map(|d| d.relay_parent_number)
.unwrap_or_default()
}
#[cfg(feature = "runtime-benchmarks")]
fn set_block_number(block: Self::BlockNumber) {
if let Some(mut validation_data) = Pallet::<T>::validation_data() {
validation_data.relay_parent_number = block;
ValidationData::<T>::put(validation_data)
}
}
}
2 changes: 1 addition & 1 deletion parachain-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log = "0.4.16"
codec = { package = "parity-scale-codec", version = "3.0.0" }
serde = { version = "1.0.132", features = ["derive"] }
hex-literal = "0.3.4"
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.11.0", features = ["server"] }

# Local
parachain-template-runtime = { path = "../runtime" }
Expand Down
83 changes: 75 additions & 8 deletions parachain-template/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use super::{
AccountId, Balances, Call, Event, Origin, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime,
WeightToFee, XcmpQueue,
};
use core::marker::PhantomData;
use frame_support::{
match_types, parameter_types,
log, match_types, parameter_types,
traits::{Everything, Nothing},
weights::Weight,
};
Expand All @@ -18,7 +19,7 @@ use xcm_builder::{
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents,
};
use xcm_executor::XcmExecutor;
use xcm_executor::{traits::ShouldExecute, XcmExecutor};

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
Expand Down Expand Up @@ -87,12 +88,78 @@ match_types! {
};
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// ^^^ Parent and its exec plurality get free execution
);
//TODO: move DenyThenTry to polkadot's xcm module.
/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else.
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
where
Deny: ShouldExecute,
Allow: ShouldExecute;

impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
where
Deny: ShouldExecute,
Allow: ShouldExecute,
{
fn should_execute<Call>(
origin: &MultiLocation,
message: &mut Xcm<Call>,
max_weight: Weight,
weight_credit: &mut Weight,
) -> Result<(), ()> {
Deny::should_execute(origin, message, max_weight, weight_credit)?;
Allow::should_execute(origin, message, max_weight, weight_credit)
}
}

// See issue #5233
pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain {
fn should_execute<Call>(
origin: &MultiLocation,
message: &mut Xcm<Call>,
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
if message.0.iter().any(|inst| {
matches!(
inst,
InitiateReserveWithdraw {
reserve: MultiLocation { parents: 1, interior: Here },
..
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
TransferReserveAsset {
dest: MultiLocation { parents: 1, interior: Here },
..
}
)
}) {
return Err(()) // Deny
}

// allow reserve transfers to arrive from relay chain
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
{
log::warn!(
target: "xcm::barriers",
"Unexpected ReserveAssetDeposited from the relay chain",
);
}
// Permit everything else
Ok(())
}
}

pub type Barrier = DenyThenTry<
DenyReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// ^^^ Parent and its exec plurality get free execution
),
>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ statemint-runtime = { path = "statemint" }
statemine-runtime = { path = "statemine" }
westmint-runtime = { path = "westmint" }
canvas-kusama-runtime = { path = "canvas-kusama" }
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.11.0", features = ["server"] }
parachains-common = { path = "parachains-common" }

# Substrate
Expand Down
24 changes: 14 additions & 10 deletions polkadot-parachains/canvas-kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use frame_support::{
};
use frame_system::EnsureRoot;
use pallet_xcm::{EnsureXcm, IsMajorityOfBody, XcmPassthrough};
use parachains_common::xcm_config::{DenyReserveTransferToRelayChain, DenyThenTry};
use polkadot_parachain::primitives::Sibling;
use xcm::latest::prelude::*;
use xcm_builder::{
Expand Down Expand Up @@ -117,16 +118,19 @@ match_types! {
};
}

pub type Barrier = (
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
);
pub type Barrier = DenyThenTry<
DenyReserveTransferToRelayChain,
(
TakeWeightCredit,
AllowTopLevelPaidExecutionFrom<Everything>,
// Parent and its exec plurality get free execution
AllowUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
// Subscriptions for version tracking are OK.
AllowSubscriptionsFrom<ParentOrSiblings>,
),
>;

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
Expand Down
2 changes: 2 additions & 0 deletions polkadot-parachains/parachains-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod impls;
pub mod xcm_config;
pub use constants::*;
pub use opaque::*;
pub use types::*;

/// Common types of parachains.
mod types {
use sp_runtime::traits::{IdentifyAccount, Verify};
Expand Down
67 changes: 67 additions & 0 deletions polkadot-parachains/parachains-common/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use core::marker::PhantomData;
use frame_support::{log, weights::Weight};
use xcm::latest::prelude::*;
use xcm_executor::traits::ShouldExecute;

//TODO: move DenyThenTry to polkadot's xcm module.
/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.
/// If it passes the Deny, and matches one of the Allow cases then it is let through.
pub struct DenyThenTry<Deny, Allow>(PhantomData<Deny>, PhantomData<Allow>)
where
Deny: ShouldExecute,
Allow: ShouldExecute;

impl<Deny, Allow> ShouldExecute for DenyThenTry<Deny, Allow>
where
Deny: ShouldExecute,
Allow: ShouldExecute,
{
fn should_execute<Call>(
origin: &MultiLocation,
message: &mut Xcm<Call>,
max_weight: Weight,
weight_credit: &mut Weight,
) -> Result<(), ()> {
Deny::should_execute(origin, message, max_weight, weight_credit)?;
Allow::should_execute(origin, message, max_weight, weight_credit)
}
}

// See issue #5233
pub struct DenyReserveTransferToRelayChain;
impl ShouldExecute for DenyReserveTransferToRelayChain {
fn should_execute<Call>(
origin: &MultiLocation,
message: &mut Xcm<Call>,
_max_weight: Weight,
_weight_credit: &mut Weight,
) -> Result<(), ()> {
if message.0.iter().any(|inst| {
matches!(
inst,
InitiateReserveWithdraw {
reserve: MultiLocation { parents: 1, interior: Here },
..
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
TransferReserveAsset {
dest: MultiLocation { parents: 1, interior: Here },
..
}
)
}) {
return Err(()) // Deny
}

// allow reserve transfers to arrive from relay chain
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
{
log::info!(
target: "runtime::xcm-barier",
"Unexpected Reserve Assets Deposited on the relay chain",
);
}
// Permit everything else
Ok(())
}
}
Loading

0 comments on commit 8426607

Please sign in to comment.