From 45c9aefd2738320bf44523342110abefe32fa75f Mon Sep 17 00:00:00 2001 From: Peter Goodspeed-Niklaus Date: Tue, 3 Nov 2020 11:54:52 +0100 Subject: [PATCH] add native logging to check_upward_messages (#1906) * add native logging to check_upward_messages This doesn't affect the WASM builds, but ensures that native versions (such as are used for testing) emit diagnostics anytime the check_upward_messages function exits, which should reduce the pain of debugging when something goes wrong. * Apply suggestions from code review Co-authored-by: Sergei Shulepov * verb tense Co-authored-by: Sergei Shulepov --- polkadot/runtime/parachains/src/router/ump.rs | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/router/ump.rs b/polkadot/runtime/parachains/src/router/ump.rs index 19a81a59fa..63d0726175 100644 --- a/polkadot/runtime/parachains/src/router/ump.rs +++ b/polkadot/runtime/parachains/src/router/ump.rs @@ -18,7 +18,7 @@ use super::{Trait, Module, Store}; use crate::configuration::{self, HostConfiguration}; use sp_std::prelude::*; use sp_std::collections::{btree_map::BTreeMap, vec_deque::VecDeque}; -use frame_support::{StorageMap, StorageValue, weights::Weight, traits::Get}; +use frame_support::{StorageMap, StorageValue, weights::Weight, traits::Get, debug::native as log}; use primitives::v1::{Id as ParaId, UpwardMessage}; /// All upward messages coming from parachains will be funneled into an implementation of this trait. @@ -50,6 +50,8 @@ impl UmpSink for () { } } +const LOG_TARGET: &str = "runtime-parachains::upward-messages"; + /// Routines related to the upward message passing. impl Module { pub(super) fn clean_ump_after_outgoing(outgoing_para: ParaId) { @@ -79,15 +81,28 @@ impl Module { upward_messages: &[UpwardMessage], ) -> bool { if upward_messages.len() as u32 > config.max_upward_message_num_per_candidate { + log::warn!( + target: LOG_TARGET, + "more upward messages than permitted by config ({} > {})", + upward_messages.len(), + config.max_upward_message_num_per_candidate, + ); return false; } let (mut para_queue_count, mut para_queue_size) = ::RelayDispatchQueueSize::get(¶); - for msg in upward_messages { + for (idx, msg) in upward_messages.into_iter().enumerate() { let msg_size = msg.len() as u32; if msg_size > config.max_upward_message_size { + log::warn!( + target: LOG_TARGET, + "upward message idx {} larger than permitted by config ({} > {})", + idx, + msg_size, + config.max_upward_message_size, + ); return false; } para_queue_count += 1; @@ -96,6 +111,20 @@ impl Module { // make sure that the queue is not overfilled. // we do it here only once since returning false invalidates the whole relay-chain block. + if para_queue_count > config.max_upward_queue_count { + log::warn!( + target: LOG_TARGET, + "the ump queue would have more items than permitted by config ({} > {})", + para_queue_count, config.max_upward_queue_count, + ); + } + if para_queue_size > config.max_upward_queue_size { + log::warn!( + target: LOG_TARGET, + "the ump queue would have grown past the max size permitted by config ({} > {})", + para_queue_size, config.max_upward_queue_size, + ); + } para_queue_count <= config.max_upward_queue_count && para_queue_size <= config.max_upward_queue_size }