Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dmp: Check that the para exist before delivering a message #6604

Merged
merged 34 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7c9cea6
dmp: Check that the para exist before delivering a message
bkchr Nov 21, 2024
0d23781
Update from bkchr running command 'prdoc --audience runtime_dev --bum…
actions-user Nov 29, 2024
70b42e0
Fix compilation + tests
bkchr Nov 29, 2024
6c040a4
Merge remote-tracking branch 'refs/remotes/origin/bkchr-dmp-check-par…
bkchr Nov 29, 2024
575294f
Update pr_6604.prdoc
bkchr Nov 29, 2024
a1c1153
Update prdoc/pr_6604.prdoc
bkchr Nov 29, 2024
3646d0f
Update prdoc/pr_6604.prdoc
bkchr Nov 29, 2024
086192a
Add test that checks it fails
bkchr Nov 29, 2024
a6a0406
Merge remote-tracking branch 'refs/remotes/origin/bkchr-dmp-check-par…
bkchr Nov 29, 2024
1b43681
Remove duplicate code
bkchr Nov 29, 2024
040da5d
Starting to fix some benchmarks
bkchr Nov 30, 2024
080ff18
Fix pallet-xcm
bkchr Nov 30, 2024
ef2a7c0
Small clean-up for `EnsureForParachain` stuff (#6714)
bkontur Nov 30, 2024
7d0f520
More fixes
bkchr Nov 30, 2024
af60dd5
Fix coretime benchmark
bkchr Nov 30, 2024
77f6a1e
Fix identity migration benchmarks
bkchr Dec 2, 2024
3bd4868
Fix the treasury benchmarks
bkchr Dec 2, 2024
7f9791a
Use zepter to correct features
bkchr Dec 2, 2024
de2e5ef
Merge remote-tracking branch 'refs/remotes/origin/master'
bkchr Dec 2, 2024
123a805
Update polkadot/runtime/parachains/src/dmp/tests.rs
bkchr Dec 3, 2024
01dc000
Update polkadot/runtime/common/src/xcm_sender.rs
bkchr Dec 3, 2024
eaaf4cb
Update polkadot/runtime/common/src/xcm_sender.rs
bkchr Dec 3, 2024
38b8775
Update polkadot/xcm/src/v5/traits.rs
bkchr Dec 3, 2024
3348079
".git/.scripts/commands/fmt/fmt.sh"
Dec 9, 2024
411de11
Merge branch 'master' into bkchr-dmp-check-para-exists
bkchr Dec 9, 2024
e759d38
Update polkadot/runtime/parachains/src/dmp/tests.rs
bkchr Dec 10, 2024
bb73ce0
Fix test
bkchr Dec 10, 2024
4efbafa
Fix warning
bkchr Dec 10, 2024
29e87af
Update from bkchr running command 'prdoc --audience runtime_dev --bum…
Dec 10, 2024
d285d85
Update prdoc/pr_6604.prdoc
bkchr Dec 10, 2024
141035a
Fix test
bkchr Dec 11, 2024
60c70af
Merge remote-tracking branch 'refs/remotes/origin/bkchr-dmp-check-par…
bkchr Dec 11, 2024
5fe3379
Fix integration tests
bkchr Dec 12, 2024
d198303
Merge branch 'master' into bkchr-dmp-check-para-exists
bkchr Dec 12, 2024
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
3 changes: 3 additions & 0 deletions polkadot/runtime/common/src/paras_sudo_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub mod pallet {
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a
/// downward message.
ExceedsMaxMessageSize,
/// A DMP message couldn't be sent because the destination is unreachable.
Unroutable,
/// Could not schedule para cleanup.
CouldntCleanup,
/// Not a parathread (on-demand parachain).
Expand Down Expand Up @@ -152,6 +154,7 @@ pub mod pallet {
{
dmp::QueueDownwardMessageError::ExceedsMaxMessageSize =>
Error::<T>::ExceedsMaxMessageSize.into(),
dmp::QueueDownwardMessageError::Unroutable => Error::<T>::Unroutable.into(),
})
}

Expand Down
8 changes: 7 additions & 1 deletion polkadot/runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ mod tests {
use crate::integration_tests::new_test_ext;
use alloc::vec;
use frame_support::{assert_ok, parameter_types};
use polkadot_runtime_parachains::FeeTracker;
use polkadot_primitives::HeadData;
use polkadot_runtime_parachains::{paras, FeeTracker};
bkchr marked this conversation as resolved.
Show resolved Hide resolved
use sp_runtime::FixedU128;
use xcm::MAX_XCM_DECODE_DEPTH;

Expand Down Expand Up @@ -349,6 +350,11 @@ mod tests {
c.max_downward_message_size = u32::MAX;
});

paras::Heads::<crate::integration_tests::Test>::insert(
ParaId::from(5555),
HeadData(vec![]),
);

bkchr marked this conversation as resolved.
Show resolved Hide resolved
// Check that the good message is validated:
assert_ok!(<Router as SendXcm>::validate(
&mut Some(dest.into()),
Expand Down
17 changes: 15 additions & 2 deletions polkadot/runtime/parachains/src/dmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

use crate::{
configuration::{self, HostConfiguration},
initializer, FeeTracker,
initializer, paras, FeeTracker,
};
use alloc::vec::Vec;
use core::fmt;
Expand Down Expand Up @@ -72,12 +72,15 @@ const MESSAGE_SIZE_FEE_BASE: FixedU128 = FixedU128::from_rational(1, 1000); // 0
pub enum QueueDownwardMessageError {
/// The message being sent exceeds the configured max message size.
ExceedsMaxMessageSize,
/// The destination is unknown.
Unroutable,
}

impl From<QueueDownwardMessageError> for SendError {
fn from(err: QueueDownwardMessageError) -> Self {
match err {
QueueDownwardMessageError::ExceedsMaxMessageSize => SendError::ExceedsMaxMessageSize,
QueueDownwardMessageError::Unroutable => SendError::Unroutable,
}
}
}
Expand Down Expand Up @@ -116,7 +119,7 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config + configuration::Config {}
pub trait Config: frame_system::Config + configuration::Config + paras::Config {}

/// The downward messages addressed for a certain para.
#[pallet::storage]
Expand Down Expand Up @@ -200,6 +203,11 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

// If the head exists, we assume the parachain is legit and exists.
if !paras::Heads::<T>::contains_key(para) {
return Err(QueueDownwardMessageError::Unroutable)
}

Ok(())
}

Expand All @@ -226,6 +234,11 @@ impl<T: Config> Pallet<T> {
return Err(QueueDownwardMessageError::ExceedsMaxMessageSize)
}

// If the head exists, we assume the parachain is legit and exists.
if !paras::Heads::<T>::contains_key(para) {
return Err(QueueDownwardMessageError::Unroutable)
}

bkontur marked this conversation as resolved.
Show resolved Hide resolved
let inbound =
InboundDownwardMessage { msg, sent_at: frame_system::Pallet::<T>::block_number() };

Expand Down
29 changes: 28 additions & 1 deletion polkadot/runtime/parachains/src/dmp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
use codec::Encode;
use frame_support::assert_ok;
use hex_literal::hex;
use polkadot_primitives::BlockNumber;
use polkadot_primitives::{BlockNumber, HeadData};
bkchr marked this conversation as resolved.
Show resolved Hide resolved

pub(crate) fn run_to_block(to: BlockNumber, new_session: Option<Vec<BlockNumber>>) {
while System::block_number() < to {
Expand Down Expand Up @@ -61,13 +61,21 @@ fn queue_downward_message(
Dmp::queue_downward_message(&configuration::ActiveConfig::<Test>::get(), para_id, msg)
}

fn register_paras(paras: &[ParaId]) {
paras.iter().for_each(|p| {
paras::Heads::<Test>::insert(p, HeadData(p.encode().into()));
bkchr marked this conversation as resolved.
Show resolved Hide resolved
});
}

#[test]
fn clean_dmp_works() {
let a = ParaId::from(1312);
let b = ParaId::from(228);
let c = ParaId::from(123);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a, b, c]);

// enqueue downward messages to A, B and C.
queue_downward_message(a, vec![1, 2, 3]).unwrap();
queue_downward_message(b, vec![4, 5, 6]).unwrap();
Expand All @@ -89,6 +97,8 @@ fn dmq_length_and_head_updated_properly() {
let b = ParaId::from(228);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a, b]);

assert_eq!(Dmp::dmq_length(a), 0);
assert_eq!(Dmp::dmq_length(b), 0);

Expand All @@ -106,6 +116,8 @@ fn dmp_mqc_head_fixture() {
let a = ParaId::from(2000);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a]);

run_to_block(2, None);
assert!(Dmp::dmq_mqc_head(a).is_zero());
queue_downward_message(a, vec![1, 2, 3]).unwrap();
Expand All @@ -125,6 +137,8 @@ fn check_processed_downward_messages() {
let a = ParaId::from(1312);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a]);

let block_number = System::block_number();

// processed_downward_messages=0 is allowed when the DMQ is empty.
Expand All @@ -150,6 +164,8 @@ fn check_processed_downward_messages_advancement_rule() {
let a = ParaId::from(1312);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a]);

let block_number = System::block_number();

run_to_block(block_number + 1, None);
Expand All @@ -170,6 +186,8 @@ fn dmq_pruning() {
let a = ParaId::from(1312);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a]);
bkchr marked this conversation as resolved.
Show resolved Hide resolved

assert_eq!(Dmp::dmq_length(a), 0);

queue_downward_message(a, vec![1, 2, 3]).unwrap();
Expand All @@ -194,6 +212,8 @@ fn queue_downward_message_critical() {
genesis.configuration.config.max_downward_message_size = 7;

new_test_ext(genesis).execute_with(|| {
register_paras(&[a]);

let smol = [0; 3].to_vec();
let big = [0; 8].to_vec();

Expand All @@ -215,6 +235,8 @@ fn verify_dmq_mqc_head_is_externally_accessible() {
let a = ParaId::from(2020);

new_test_ext(default_genesis_config()).execute_with(|| {
register_paras(&[a]);

let head = sp_io::storage::get(&well_known_keys::dmq_mqc_head(a));
assert_eq!(head, None);

Expand All @@ -235,9 +257,12 @@ fn verify_dmq_mqc_head_is_externally_accessible() {
#[test]
fn verify_fee_increase_and_decrease() {
let a = ParaId::from(123);

let mut genesis = default_genesis_config();
genesis.configuration.config.max_downward_message_size = 16777216;
new_test_ext(genesis).execute_with(|| {
register_paras(&[a]);

let initial = InitialFactor::get();
assert_eq!(DeliveryFeeFactor::<Test>::get(a), initial);

Expand Down Expand Up @@ -287,6 +312,8 @@ fn verify_fee_factor_reaches_high_value() {
let mut genesis = default_genesis_config();
genesis.configuration.config.max_downward_message_size = 51200;
new_test_ext(genesis).execute_with(|| {
register_paras(&[a]);

let max_messages =
Dmp::dmq_max_length(ActiveConfig::<Test>::get().max_downward_message_size);
let mut total_fee_factor = FixedU128::from_float(1.0);
Expand Down
7 changes: 7 additions & 0 deletions prdoc/pr_6604.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: 'dmp: Check that the para exist before delivering a message'
doc:
- audience: Runtime Dev
description: Or otherwise throw an error.
crates:
- name: polkadot-runtime-parachains
bump: major
bkchr marked this conversation as resolved.
Show resolved Hide resolved
Loading