Skip to content

Commit b326540

Browse files
inclusion emulator: correctly handle UMP signals (#6178)
Changes inclusion emulator to not count the UMP signals when checking ump message constraints. --------- Signed-off-by: Andrei Sandu <[email protected]> Co-authored-by: GitHub Action <[email protected]>
1 parent 8b6f815 commit b326540

File tree

2 files changed

+52
-7
lines changed
  • polkadot
    • node/subsystem-util/src/inclusion_emulator
    • primitives/test-helpers

2 files changed

+52
-7
lines changed

polkadot/node/subsystem-util/src/inclusion_emulator/mod.rs

+51-6
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ pub struct ConstraintModifications {
431431
pub hrmp_watermark: Option<HrmpWatermarkUpdate>,
432432
/// Outbound HRMP channel modifications.
433433
pub outbound_hrmp: HashMap<ParaId, OutboundHrmpChannelModification>,
434-
/// The amount of UMP messages sent.
434+
/// The amount of UMP XCM messages sent. `UMPSignal` and separator are excluded.
435435
pub ump_messages_sent: usize,
436-
/// The amount of UMP bytes sent.
436+
/// The amount of UMP XCM bytes sent. `UMPSignal` and separator are excluded.
437437
pub ump_bytes_sent: usize,
438438
/// The amount of DMP messages processed.
439439
pub dmp_messages_processed: usize,
@@ -600,6 +600,18 @@ impl Fragment {
600600
validation_code_hash: &ValidationCodeHash,
601601
persisted_validation_data: &PersistedValidationData,
602602
) -> Result<ConstraintModifications, FragmentValidityError> {
603+
// Filter UMP signals and the separator.
604+
let upward_messages = if let Some(separator_index) =
605+
commitments.upward_messages.iter().position(|message| message.is_empty())
606+
{
607+
commitments.upward_messages.split_at(separator_index).0
608+
} else {
609+
&commitments.upward_messages
610+
};
611+
612+
let ump_messages_sent = upward_messages.len();
613+
let ump_bytes_sent = upward_messages.iter().map(|msg| msg.len()).sum();
614+
603615
let modifications = {
604616
ConstraintModifications {
605617
required_parent: Some(commitments.head_data.clone()),
@@ -632,8 +644,8 @@ impl Fragment {
632644

633645
outbound_hrmp
634646
},
635-
ump_messages_sent: commitments.upward_messages.len(),
636-
ump_bytes_sent: commitments.upward_messages.iter().map(|msg| msg.len()).sum(),
647+
ump_messages_sent,
648+
ump_bytes_sent,
637649
dmp_messages_processed: commitments.processed_downward_messages as _,
638650
code_upgrade_applied: operating_constraints
639651
.future_validation_code
@@ -750,7 +762,7 @@ fn validate_against_constraints(
750762
})
751763
}
752764

753-
if commitments.upward_messages.len() > constraints.max_ump_num_per_candidate {
765+
if modifications.ump_messages_sent > constraints.max_ump_num_per_candidate {
754766
return Err(FragmentValidityError::UmpMessagesPerCandidateOverflow {
755767
messages_allowed: constraints.max_ump_num_per_candidate,
756768
messages_submitted: commitments.upward_messages.len(),
@@ -814,7 +826,11 @@ impl HypotheticalOrConcreteCandidate for HypotheticalCandidate {
814826
#[cfg(test)]
815827
mod tests {
816828
use super::*;
817-
use polkadot_primitives::{HorizontalMessages, OutboundHrmpMessage, ValidationCode};
829+
use codec::Encode;
830+
use polkadot_primitives::{
831+
vstaging::{ClaimQueueOffset, CoreSelector, UMPSignal, UMP_SEPARATOR},
832+
HorizontalMessages, OutboundHrmpMessage, ValidationCode,
833+
};
818834

819835
#[test]
820836
fn stack_modifications() {
@@ -1267,6 +1283,35 @@ mod tests {
12671283
);
12681284
}
12691285

1286+
#[test]
1287+
fn ump_signals_ignored() {
1288+
let relay_parent = RelayChainBlockInfo {
1289+
number: 6,
1290+
hash: Hash::repeat_byte(0xbe),
1291+
storage_root: Hash::repeat_byte(0xff),
1292+
};
1293+
1294+
let constraints = make_constraints();
1295+
let mut candidate = make_candidate(&constraints, &relay_parent);
1296+
let max_ump = constraints.max_ump_num_per_candidate;
1297+
1298+
// Fill ump queue to the limit.
1299+
candidate
1300+
.commitments
1301+
.upward_messages
1302+
.try_extend((0..max_ump).map(|i| vec![i as u8]))
1303+
.unwrap();
1304+
1305+
// Add ump signals.
1306+
candidate.commitments.upward_messages.force_push(UMP_SEPARATOR);
1307+
candidate
1308+
.commitments
1309+
.upward_messages
1310+
.force_push(UMPSignal::SelectCore(CoreSelector(0), ClaimQueueOffset(1)).encode());
1311+
1312+
Fragment::new(relay_parent, constraints, Arc::new(candidate)).unwrap();
1313+
}
1314+
12701315
#[test]
12711316
fn fragment_relay_parent_too_old() {
12721317
let relay_parent = RelayChainBlockInfo {

polkadot/primitives/test-helpers/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ sp-keyring = { workspace = true, default-features = true }
1414
sp-application-crypto = { workspace = true }
1515
sp-runtime = { workspace = true, default-features = true }
1616
sp-core = { features = ["std"], workspace = true, default-features = true }
17-
polkadot-primitives = { workspace = true, default-features = true }
17+
polkadot-primitives = { features = ["test"], workspace = true, default-features = true }
1818
rand = { workspace = true, default-features = true }

0 commit comments

Comments
 (0)