Skip to content

Commit 43f7fd1

Browse files
authored
Merge branch 'master' into voting_hook
2 parents a5a91b5 + 762f902 commit 43f7fd1

File tree

12 files changed

+74
-37
lines changed

12 files changed

+74
-37
lines changed

cumulus/bin/pov-validator/src/main.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use clap::Parser;
2020
use codec::{Decode, Encode};
2121
use polkadot_node_primitives::{BlockData, PoV, POV_BOMB_LIMIT};
2222
use polkadot_parachain_primitives::primitives::ValidationParams;
23-
use polkadot_primitives::{BlockNumber as RBlockNumber, Hash as RHash, HeadData};
23+
use polkadot_primitives::PersistedValidationData;
2424
use sc_executor::WasmExecutor;
2525
use sp_core::traits::{CallContext, CodeExecutor, RuntimeCode, WrappedRuntimeCode};
2626
use std::{fs, path::PathBuf, time::Instant};
@@ -104,17 +104,10 @@ fn main() -> anyhow::Result<()> {
104104
tracing::error!(%error, "Failed to decode `PoV`");
105105
anyhow::anyhow!("Failed to decode `PoV`")
106106
})?;
107-
let head_data = HeadData::decode(pov_file_ptr).map_err(|error| {
108-
tracing::error!(%error, "Failed to `HeadData`");
109-
anyhow::anyhow!("Failed to decode `HeadData`")
110-
})?;
111-
let relay_parent_storage_root = RHash::decode(pov_file_ptr).map_err(|error| {
112-
tracing::error!(%error, "Failed to relay storage root");
113-
anyhow::anyhow!("Failed to decode relay storage root")
114-
})?;
115-
let relay_parent_number = RBlockNumber::decode(pov_file_ptr).map_err(|error| {
116-
tracing::error!(%error, "Failed to relay block number");
117-
anyhow::anyhow!("Failed to decode relay block number")
107+
108+
let pvd = PersistedValidationData::decode(pov_file_ptr).map_err(|error| {
109+
tracing::error!(%error, "Failed to `PersistedValidationData`");
110+
anyhow::anyhow!("Failed to decode `PersistedValidationData`")
118111
})?;
119112

120113
let pov = sp_maybe_compressed_blob::decompress(&pov.block_data.0, POV_BOMB_LIMIT).map_err(
@@ -125,9 +118,9 @@ fn main() -> anyhow::Result<()> {
125118
)?;
126119

127120
let validation_params = ValidationParams {
128-
relay_parent_number,
129-
relay_parent_storage_root,
130-
parent_head: head_data,
121+
relay_parent_number: pvd.relay_parent_number,
122+
relay_parent_storage_root: pvd.relay_parent_storage_root,
123+
parent_head: pvd.parent_head,
131124
block_data: BlockData(pov.into()),
132125
};
133126

cumulus/client/consensus/aura/src/collators/lookahead.rs

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ where
409409
parent_header.clone(),
410410
*relay_parent_header.state_root(),
411411
*relay_parent_header.number(),
412+
validation_data.max_pov_size,
412413
);
413414
}
414415

cumulus/client/consensus/aura/src/collators/slot_based/block_builder_task.rs

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ where
375375
parachain_candidate: candidate,
376376
validation_code_hash,
377377
core_index: *core_index,
378+
max_pov_size: validation_data.max_pov_size,
378379
}) {
379380
tracing::error!(target: crate::LOG_TARGET, ?err, "Unable to send block to collation task.");
380381
return

cumulus/client/consensus/aura/src/collators/slot_based/collation_task.rs

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
126126
validation_code_hash,
127127
relay_parent,
128128
core_index,
129+
max_pov_size,
129130
} = message;
130131

131132
let hash = parachain_candidate.block.header().hash();
@@ -160,6 +161,7 @@ async fn handle_collation_message<Block: BlockT, RClient: RelayChainInterface +
160161
parent_header.clone(),
161162
relay_parent_header.state_root,
162163
relay_parent_header.number,
164+
max_pov_size,
163165
);
164166
} else {
165167
tracing::error!(target: LOG_TARGET, "Failed to get relay parent header from hash: {relay_parent:?}");

cumulus/client/consensus/aura/src/collators/slot_based/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ struct CollatorMessage<Block: BlockT> {
255255
pub validation_code_hash: ValidationCodeHash,
256256
/// Core index that this block should be submitted on
257257
pub core_index: CoreIndex,
258+
/// Maximum pov size. Currently needed only for exporting PoV.
259+
pub max_pov_size: u32,
258260
}
259261

260262
/// Fetch the `CoreSelector` and `ClaimQueueOffset` for `parent_hash`.

cumulus/client/consensus/aura/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub(crate) fn export_pov_to_path<Block: BlockT>(
273273
parent_header: Block::Header,
274274
relay_parent_storage_root: RHash,
275275
relay_parent_number: RBlockNumber,
276+
max_pov_size: u32,
276277
) {
277278
if let Err(error) = fs::create_dir_all(&path) {
278279
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>(
288289
};
289290

290291
pov.encode_to(&mut file);
291-
HeadData(parent_header.encode()).encode_to(&mut file);
292-
relay_parent_storage_root.encode_to(&mut file);
293-
relay_parent_number.encode_to(&mut file);
292+
PersistedValidationData {
293+
parent_head: HeadData(parent_header.encode()),
294+
relay_parent_number,
295+
relay_parent_storage_root,
296+
max_pov_size,
297+
}
298+
.encode_to(&mut file);
294299
}

prdoc/pr_7924.prdoc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: 'sp-api: Support `mut` in `impl_runtime_apis!`'
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
This brings support for declaring variables in parameters as `mut` inside of `impl_runtime_apis!`.
6+
crates:
7+
- name: sp-api-proc-macro
8+
bump: patch

prdoc/pr_7928.prdoc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: Fix pallet-revive-fixtures build.rs
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
Fix pallet-revive-uapi resolution when building pallet-revive-fixtures
6+
contracts
7+
crates:
8+
- name: pallet-revive-fixtures
9+
bump: patch

substrate/frame/revive/fixtures/build.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,30 @@ fn create_cargo_toml<'a>(
8585
let mut cargo_toml: toml::Value = toml::from_str(include_str!("./build/_Cargo.toml"))?;
8686
let uapi_dep = cargo_toml["dependencies"]["uapi"].as_table_mut().unwrap();
8787

88-
let metadata = MetadataCommand::new()
89-
.manifest_path(fixtures_dir.join("Cargo.toml"))
90-
.exec()
91-
.expect("Failed to fetch cargo metadata");
88+
let manifest_path = fixtures_dir.join("Cargo.toml");
89+
let metadata = MetadataCommand::new().manifest_path(&manifest_path).exec().unwrap();
90+
let dependency_graph = metadata.resolve.unwrap();
9291

93-
let mut uapi_pkgs: Vec<_> = metadata
92+
// Resolve the pallet-revive-fixtures package id
93+
let fixtures_pkg_id = metadata
9494
.packages
9595
.iter()
96-
.filter(|pkg| pkg.name == "pallet-revive-uapi")
97-
.collect();
96+
.find(|pkg| pkg.manifest_path.as_std_path() == manifest_path)
97+
.map(|pkg| pkg.id.clone())
98+
.unwrap();
99+
let fixtures_pkg_node =
100+
dependency_graph.nodes.iter().find(|node| node.id == fixtures_pkg_id).unwrap();
101+
102+
// Get the pallet-revive-uapi package id
103+
let uapi_pkg_id = fixtures_pkg_node
104+
.deps
105+
.iter()
106+
.find(|dep| dep.name == "pallet_revive_uapi")
107+
.map(|dep| dep.pkg.clone())
108+
.expect("pallet-revive-uapi is a build dependency of pallet-revive-fixtures; qed");
98109

99-
uapi_pkgs.sort_by(|a, b| b.version.cmp(&a.version));
100-
let uapi_pkg = uapi_pkgs.first().unwrap();
110+
// Get pallet-revive-uapi package
111+
let uapi_pkg = metadata.packages.iter().find(|pkg| pkg.id == uapi_pkg_id).unwrap();
101112

102113
if uapi_pkg.source.is_none() {
103114
uapi_dep.insert(

substrate/frame/transaction-payment/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ type BalanceOf<T> = <<T as Config>::OnChargeTransaction as OnChargeTransaction<T
140140
/// Meaning that fees can change by around ~23% per day, given extreme congestion.
141141
///
142142
/// More info can be found at:
143-
/// <https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html>
143+
/// <https://research.web3.foundation/Polkadot/overview/token-economics>
144144
pub struct TargetedFeeAdjustment<T, S, V, M, X>(core::marker::PhantomData<(T, S, V, M, X)>);
145145

146146
/// Something that can convert the current multiplier to the next one.

substrate/primitives/api/proc-macro/src/utils.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ pub fn replace_wild_card_parameter_names(input: &mut Signature) {
7474
let mut generated_pattern_counter = 0;
7575
input.inputs.iter_mut().for_each(|arg| {
7676
if let FnArg::Typed(arg) = arg {
77-
arg.pat = Box::new(generate_unique_pattern(
78-
(*arg.pat).clone(),
79-
&mut generated_pattern_counter,
80-
));
77+
arg.pat =
78+
Box::new(sanitize_pattern((*arg.pat).clone(), &mut generated_pattern_counter));
8179
}
8280
});
8381
}
@@ -101,8 +99,11 @@ pub fn fold_fn_decl_for_client_side(
10199
};
102100
}
103101

104-
/// Generate an unique pattern based on the given counter, if the given pattern is a `_`.
105-
pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat {
102+
/// Sanitize the given pattern.
103+
///
104+
/// - `_` patterns are changed to a variable based on `counter`.
105+
/// - `mut something` removes the `mut`.
106+
pub fn sanitize_pattern(pat: Pat, counter: &mut u32) -> Pat {
106107
match pat {
107108
Pat::Wild(_) => {
108109
let generated_name =
@@ -111,6 +112,10 @@ pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat {
111112

112113
parse_quote!( #generated_name )
113114
},
115+
Pat::Ident(mut pat) => {
116+
pat.mutability = None;
117+
pat.into()
118+
},
114119
_ => pat,
115120
}
116121
}
@@ -138,8 +143,7 @@ pub fn extract_parameter_names_types_and_borrows(
138143
t => (t.clone(), None),
139144
};
140145

141-
let name =
142-
generate_unique_pattern((*arg.pat).clone(), &mut generated_pattern_counter);
146+
let name = sanitize_pattern((*arg.pat).clone(), &mut generated_pattern_counter);
143147
result.push((name, ty, borrow));
144148
},
145149
FnArg::Receiver(_) if matches!(allow_self, AllowSelfRefInParameters::No) =>

substrate/primitives/api/test/tests/decl_and_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl_runtime_apis! {
8181
unimplemented!()
8282
}
8383

84-
fn something_with_block(_: Block) -> Block {
84+
// Ensure that we accept `mut`
85+
fn something_with_block(mut _block: Block) -> Block {
8586
unimplemented!()
8687
}
8788

0 commit comments

Comments
 (0)