Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • parity/mirrors/polkadot-sdk
1 result
Show changes
Commits on Source (5)
Showing with 141 additions and 30 deletions
...@@ -20,7 +20,7 @@ use clap::Parser; ...@@ -20,7 +20,7 @@ use clap::Parser;
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use polkadot_node_primitives::{BlockData, PoV, POV_BOMB_LIMIT}; use polkadot_node_primitives::{BlockData, PoV, POV_BOMB_LIMIT};
use polkadot_parachain_primitives::primitives::ValidationParams; use polkadot_parachain_primitives::primitives::ValidationParams;
use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash, HeadData}; use polkadot_primitives::PersistedValidationData;
use sc_executor::WasmExecutor; use sc_executor::WasmExecutor;
use sp_core::traits::{CallContext, CodeExecutor, RuntimeCode, WrappedRuntimeCode}; use sp_core::traits::{CallContext, CodeExecutor, RuntimeCode, WrappedRuntimeCode};
use std::{fs, path::PathBuf, time::Instant}; use std::{fs, path::PathBuf, time::Instant};
...@@ -104,17 +104,10 @@ fn main() -> anyhow::Result<()> { ...@@ -104,17 +104,10 @@ fn main() -> anyhow::Result<()> {
tracing::error!(%error, "Failed to decode `PoV`"); tracing::error!(%error, "Failed to decode `PoV`");
anyhow::anyhow!("Failed to decode `PoV`") anyhow::anyhow!("Failed to decode `PoV`")
})?; })?;
let head_data = HeadData::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to `HeadData`"); let pvd = PersistedValidationData::decode(pov_file_ptr).map_err(|error| {
anyhow::anyhow!("Failed to decode `HeadData`") tracing::error!(%error, "Failed to `PersistedValidationData`");
})?; anyhow::anyhow!("Failed to decode `PersistedValidationData`")
let relay_parent_storage_root = RHash::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to relay storage root");
anyhow::anyhow!("Failed to decode relay storage root")
})?;
let relay_parent_number = RBlockNumber::decode(pov_file_ptr).map_err(|error| {
tracing::error!(%error, "Failed to relay block number");
anyhow::anyhow!("Failed to decode relay block number")
})?; })?;
let pov = sp_maybe_compressed_blob::decompress(&pov.block_data.0, POV_BOMB_LIMIT).map_err( let pov = sp_maybe_compressed_blob::decompress(&pov.block_data.0, POV_BOMB_LIMIT).map_err(
...@@ -125,9 +118,9 @@ fn main() -> anyhow::Result<()> { ...@@ -125,9 +118,9 @@ fn main() -> anyhow::Result<()> {
)?; )?;
let validation_params = ValidationParams { let validation_params = ValidationParams {
relay_parent_number, relay_parent_number: pvd.relay_parent_number,
relay_parent_storage_root, relay_parent_storage_root: pvd.relay_parent_storage_root,
parent_head: head_data, parent_head: pvd.parent_head,
block_data: BlockData(pov.into()), block_data: BlockData(pov.into()),
}; };
......
...@@ -409,6 +409,7 @@ where ...@@ -409,6 +409,7 @@ where
parent_header.clone(), parent_header.clone(),
*relay_parent_header.state_root(), *relay_parent_header.state_root(),
*relay_parent_header.number(), *relay_parent_header.number(),
validation_data.max_pov_size,
); );
} }
......
...@@ -375,6 +375,7 @@ where ...@@ -375,6 +375,7 @@ where
parachain_candidate: candidate, parachain_candidate: candidate,
validation_code_hash, validation_code_hash,
core_index: *core_index, core_index: *core_index,
max_pov_size: validation_data.max_pov_size,
}) { }) {
tracing::error!(target: crate::LOG_TARGET, ?err, "Unable to send block to collation task."); tracing::error!(target: crate::LOG_TARGET, ?err, "Unable to send block to collation task.");
return return
......
...@@ -126,6 +126,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface + ...@@ -126,6 +126,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
validation_code_hash, validation_code_hash,
relay_parent, relay_parent,
core_index, core_index,
max_pov_size,
} = message; } = message;
let hash = parachain_candidate.block.header().hash(); let hash = parachain_candidate.block.header().hash();
...@@ -160,6 +161,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface + ...@@ -160,6 +161,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
parent_header.clone(), parent_header.clone(),
relay_parent_header.state_root, relay_parent_header.state_root,
relay_parent_header.number, relay_parent_header.number,
max_pov_size,
); );
} else { } else {
tracing::error!(target: LOG_TARGET, "Failed to get relay parent header from hash: {relay_parent:?}"); tracing::error!(target: LOG_TARGET, "Failed to get relay parent header from hash: {relay_parent:?}");
......
...@@ -255,6 +255,8 @@ struct CollatorMessage<Block: BlockT> { ...@@ -255,6 +255,8 @@ struct CollatorMessage<Block: BlockT> {
pub validation_code_hash: ValidationCodeHash, pub validation_code_hash: ValidationCodeHash,
/// Core index that this block should be submitted on /// Core index that this block should be submitted on
pub core_index: CoreIndex, pub core_index: CoreIndex,
/// Maximum pov size. Currently needed only for exporting PoV.
pub max_pov_size: u32,
} }
/// Fetch the `CoreSelector` and `ClaimQueueOffset` for `parent_hash`. /// Fetch the `CoreSelector` and `ClaimQueueOffset` for `parent_hash`.
......
...@@ -273,6 +273,7 @@ pub(crate) fn export_pov_to_path<Block: BlockT>( ...@@ -273,6 +273,7 @@ pub(crate) fn export_pov_to_path<Block: BlockT>(
parent_header: Block::Header, parent_header: Block::Header,
relay_parent_storage_root: RHash, relay_parent_storage_root: RHash,
relay_parent_number: RBlockNumber, relay_parent_number: RBlockNumber,
max_pov_size: u32,
) { ) {
if let Err(error) = fs::create_dir_all(&path) { if let Err(error) = fs::create_dir_all(&path) {
tracing::error!(target: LOG_TARGET, %error, path = %path.display(), "Failed to create PoV export directory"); tracing::error!(target: LOG_TARGET, %error, path = %path.display(), "Failed to create PoV export directory");
...@@ -288,7 +289,11 @@ pub(crate) fn export_pov_to_path<Block: BlockT>( ...@@ -288,7 +289,11 @@ pub(crate) fn export_pov_to_path<Block: BlockT>(
}; };
pov.encode_to(&mut file); pov.encode_to(&mut file);
HeadData(parent_header.encode()).encode_to(&mut file); PersistedValidationData {
relay_parent_storage_root.encode_to(&mut file); parent_head: HeadData(parent_header.encode()),
relay_parent_number.encode_to(&mut file); relay_parent_number,
relay_parent_storage_root,
max_pov_size,
}
.encode_to(&mut file);
} }
...@@ -467,6 +467,10 @@ fn calling_payment_api_with_a_lower_version_works() { ...@@ -467,6 +467,10 @@ fn calling_payment_api_with_a_lower_version_works() {
#[test] #[test]
fn dry_run_error_event_check() { fn dry_run_error_event_check() {
use frame_support::{
dispatch::DispatchErrorWithPostInfo,
sp_runtime::{DispatchError, ModuleError},
};
use sp_tracing::{capture_test_logs, tracing::Level}; use sp_tracing::{capture_test_logs, tracing::Level};
let who = 1; let who = 1;
...@@ -491,7 +495,16 @@ fn dry_run_error_event_check() { ...@@ -491,7 +495,16 @@ fn dry_run_error_event_check() {
.dry_run_call(H256::zero(), origin, xcm_call, XCM_VERSION) .dry_run_call(H256::zero(), origin, xcm_call, XCM_VERSION)
.unwrap() .unwrap()
.unwrap(); .unwrap();
if let Err(DispatchErrorWithPostInfo {
error: DispatchError::Module(ModuleError { message: Some(err_msg), .. }),
..
}) = dry_run_effects.execution_result
{
assert_eq!(err_msg, "LocalExecutionIncomplete");
} else {
assert!(false, "Expected LocalExecutionIncomplete error");
}
println!("dry_run_effects.emitted_events={:?}", dry_run_effects.emitted_events);
assert!(dry_run_effects.emitted_events.is_empty()); assert!(dry_run_effects.emitted_events.is_empty());
}); });
assert!(log_capture.contains("xcm::pallet_xcm::execute_xcm_transfer: origin=Location")); assert!(log_capture.contains("xcm::pallet_xcm::execute_xcm_transfer: origin=Location"));
......
...@@ -40,7 +40,7 @@ use xcm_builder::{ ...@@ -40,7 +40,7 @@ use xcm_builder::{
MintLocation, NoChecking, TakeWeightCredit, MintLocation, NoChecking, TakeWeightCredit,
}; };
use xcm_executor::{ use xcm_executor::{
traits::{ConvertLocation, JustTry}, traits::{ConvertLocation, EventEmitter, JustTry},
XcmExecutor, XcmExecutor,
}; };
...@@ -296,11 +296,92 @@ pub type Barrier = ( ...@@ -296,11 +296,92 @@ pub type Barrier = (
pub type Trader = FixedRateOfFungible<NativeTokenPerSecondPerByte, ()>; pub type Trader = FixedRateOfFungible<NativeTokenPerSecondPerByte, ()>;
thread_local! {
static EMITTED_EVENTS: RefCell<Vec<<TestRuntime as frame_system::Config>::RuntimeEvent>> = RefCell::new(Vec::new());
}
pub struct TestEventEmitter {}
impl TestEventEmitter {
pub fn events() -> Vec<<TestRuntime as frame_system::Config>::RuntimeEvent> {
EMITTED_EVENTS.with(|events| events.borrow().clone())
}
pub fn reset_events() {
EMITTED_EVENTS.with(|events| events.borrow_mut().clear());
}
}
impl EventEmitter for TestEventEmitter {
fn emit_sent_event(
origin: Location,
destination: Location,
message: Option<Xcm<()>>,
message_id: XcmHash,
) {
sp_tracing::tracing::trace!(target: "xcm::mock",
?origin,
?destination,
?message,
?message_id,
"EventEmitter::emit_sent_event =>"
);
XcmPallet::emit_sent_event(origin, destination, message, message_id);
let events = frame_system::Pallet::<TestRuntime>::events();
if let Some(event) = events.last() {
EMITTED_EVENTS.with(|q| q.borrow_mut().push(event.event.clone()));
sp_tracing::tracing::trace!(target: "xcm::mock",
?event,
"EventEmitter::emit_sent_event <="
);
}
}
fn emit_send_failure_event(
origin: Location,
destination: Location,
error: SendError,
message_id: XcmHash,
) {
sp_tracing::tracing::debug!(target: "xcm::mock",
?origin,
?destination,
?error,
?message_id,
"EventEmitter::emit_send_failure_event =>"
);
XcmPallet::emit_send_failure_event(origin, destination, error, message_id);
let events = frame_system::Pallet::<TestRuntime>::events();
if let Some(event) = events.last() {
EMITTED_EVENTS.with(|q| q.borrow_mut().push(event.event.clone()));
sp_tracing::tracing::debug!(target: "xcm::mock",
?event,
"EventEmitter::emit_send_failure_event <="
);
}
}
fn emit_process_failure_event(origin: Location, error: XcmError, message_id: XcmHash) {
sp_tracing::tracing::debug!(target: "xcm::mock",
?origin,
?error,
?message_id,
"EventEmitter::emit_process_failure_event =>"
);
XcmPallet::emit_process_failure_event(origin, error, message_id);
let events = frame_system::Pallet::<TestRuntime>::events();
if let Some(event) = events.last() {
EMITTED_EVENTS.with(|q| q.borrow_mut().push(event.event.clone()));
sp_tracing::tracing::debug!(target: "xcm::mock",
?event,
"EventEmitter::emit_process_failure_event <="
);
}
}
}
pub struct XcmConfig; pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig { impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall; type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter; type XcmSender = XcmRouter;
type XcmEventEmitter = XcmPallet; type XcmEventEmitter = TestEventEmitter;
type AssetTransactor = AssetTransactors; type AssetTransactor = AssetTransactors;
type OriginConverter = (); type OriginConverter = ();
type IsReserve = RelayTokenToAssetHub; type IsReserve = RelayTokenToAssetHub;
......
title: 'sp-api: Support `mut` in `impl_runtime_apis!`'
doc:
- audience: Runtime Dev
description: |-
This brings support for declaring variables in parameters as `mut` inside of `impl_runtime_apis!`.
crates:
- name: sp-api-proc-macro
bump: patch
...@@ -74,10 +74,8 @@ pub fn replace_wild_card_parameter_names(input: &mut Signature) { ...@@ -74,10 +74,8 @@ pub fn replace_wild_card_parameter_names(input: &mut Signature) {
let mut generated_pattern_counter = 0; let mut generated_pattern_counter = 0;
input.inputs.iter_mut().for_each(|arg| { input.inputs.iter_mut().for_each(|arg| {
if let FnArg::Typed(arg) = arg { if let FnArg::Typed(arg) = arg {
arg.pat = Box::new(generate_unique_pattern( arg.pat =
(*arg.pat).clone(), Box::new(sanitize_pattern((*arg.pat).clone(), &mut generated_pattern_counter));
&mut generated_pattern_counter,
));
} }
}); });
} }
...@@ -101,8 +99,11 @@ pub fn fold_fn_decl_for_client_side( ...@@ -101,8 +99,11 @@ pub fn fold_fn_decl_for_client_side(
}; };
} }
/// Generate an unique pattern based on the given counter, if the given pattern is a `_`. /// Sanitize the given pattern.
pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat { ///
/// - `_` patterns are changed to a variable based on `counter`.
/// - `mut something` removes the `mut`.
pub fn sanitize_pattern(pat: Pat, counter: &mut u32) -> Pat {
match pat { match pat {
Pat::Wild(_) => { Pat::Wild(_) => {
let generated_name = let generated_name =
...@@ -111,6 +112,10 @@ pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat { ...@@ -111,6 +112,10 @@ pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat {
parse_quote!( #generated_name ) parse_quote!( #generated_name )
}, },
Pat::Ident(mut pat) => {
pat.mutability = None;
pat.into()
},
_ => pat, _ => pat,
} }
} }
...@@ -138,8 +143,7 @@ pub fn extract_parameter_names_types_and_borrows( ...@@ -138,8 +143,7 @@ pub fn extract_parameter_names_types_and_borrows(
t => (t.clone(), None), t => (t.clone(), None),
}; };
let name = let name = sanitize_pattern((*arg.pat).clone(), &mut generated_pattern_counter);
generate_unique_pattern((*arg.pat).clone(), &mut generated_pattern_counter);
result.push((name, ty, borrow)); result.push((name, ty, borrow));
}, },
FnArg::Receiver(_) if matches!(allow_self, AllowSelfRefInParameters::No) => FnArg::Receiver(_) if matches!(allow_self, AllowSelfRefInParameters::No) =>
......
...@@ -81,7 +81,8 @@ impl_runtime_apis! { ...@@ -81,7 +81,8 @@ impl_runtime_apis! {
unimplemented!() unimplemented!()
} }
fn something_with_block(_: Block) -> Block { // Ensure that we accept `mut`
fn something_with_block(mut _block: Block) -> Block {
unimplemented!() unimplemented!()
} }
......