ci: add quick-check with rustfmt (#615)

* ci: add quick-check with clippy and rustfmt

* chore: rustfmt round

* chore: set the same rustfmt config than substrate

* chore: fix formatting

* cI: remove clippy

* ci: switch to nightly for the checks

* ci: fix toolchains and naming

* ci: Limit the check to formatting

* chore: fix formatting

* Update .rustfmt.toml

* Update .rustfmt.toml

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Chevdor
2021-09-16 16:57:52 +02:00
committed by GitHub
parent 035a576008
commit 1dd000a011
98 changed files with 1244 additions and 1872 deletions
+54 -84
View File
@@ -34,7 +34,7 @@ mod tests;
use codec::{Decode, Encode};
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError,
ParaId, XcmpMessageHandler, XcmpMessageSource, XcmpMessageFormat,
ParaId, XcmpMessageFormat, XcmpMessageHandler, XcmpMessageSource,
};
use frame_support::weights::Weight;
use rand_chacha::{
@@ -43,8 +43,8 @@ use rand_chacha::{
};
use scale_info::TypeInfo;
use sp_runtime::{traits::Hash, RuntimeDebug};
use sp_std::{prelude::*, convert::TryFrom};
use xcm::{latest::prelude::*, WrapVersion, VersionedXcm};
use sp_std::{convert::TryFrom, prelude::*};
use xcm::{latest::prelude::*, VersionedXcm, WrapVersion};
pub use pallet::*;
@@ -126,11 +126,7 @@ pub mod pallet {
#[pallet::storage]
pub(super) type InboundXcmpStatus<T: Config> = StorageValue<
_,
Vec<(
ParaId,
InboundStatus,
Vec<(RelayBlockNumber, XcmpMessageFormat)>,
)>,
Vec<(ParaId, InboundStatus, Vec<(RelayBlockNumber, XcmpMessageFormat)>)>,
ValueQuery,
>;
@@ -242,28 +238,25 @@ impl<T: Config> Pallet<T> {
let max_message_size =
T::ChannelInfo::get_channel_max(recipient).ok_or(MessageSendError::NoChannel)?;
if data.len() > max_message_size {
return Err(MessageSendError::TooBig);
return Err(MessageSendError::TooBig)
}
let mut s = <OutboundXcmpStatus<T>>::get();
let index = s
.iter()
.position(|item| item.0 == recipient)
.unwrap_or_else(|| {
s.push((recipient, OutboundStatus::Ok, false, 0, 0));
s.len() - 1
});
let index = s.iter().position(|item| item.0 == recipient).unwrap_or_else(|| {
s.push((recipient, OutboundStatus::Ok, false, 0, 0));
s.len() - 1
});
let have_active = s[index].4 > s[index].3;
let appended = have_active
&& <OutboundXcmpMessages<T>>::mutate(recipient, s[index].4 - 1, |s| {
let appended = have_active &&
<OutboundXcmpMessages<T>>::mutate(recipient, s[index].4 - 1, |s| {
if XcmpMessageFormat::decode(&mut &s[..]) != Ok(format) {
return false;
return false
}
if s.len() + data.len() > max_message_size {
return false;
return false
}
s.extend_from_slice(&data[..]);
return true;
return true
});
if appended {
Ok((s[index].4 - s[index].3 - 1) as u32)
@@ -316,10 +309,9 @@ impl<T: Config> Pallet<T> {
// Create a shuffled order for use to iterate through.
// Not a great random seed, but good enough for our purposes.
let seed = frame_system::Pallet::<T>::parent_hash();
let seed = <[u8; 32]>::decode(&mut sp_runtime::traits::TrailingZeroInput::new(
seed.as_ref(),
))
.expect("input is padded with zeroes; qed");
let seed =
<[u8; 32]>::decode(&mut sp_runtime::traits::TrailingZeroInput::new(seed.as_ref()))
.expect("input is padded with zeroes; qed");
let mut rng = ChaChaRng::from_seed(seed);
let mut shuffled = (0..len).collect::<Vec<_>>();
for i in 0..len {
@@ -359,11 +351,8 @@ impl<T: Config> Pallet<T> {
// we just report the weight used.
Outcome::Incomplete(w, e) => (Ok(w), Event::Fail(Some(hash), e)),
}
}
Err(()) => (
Err(XcmError::UnhandledXcmVersion),
Event::BadVersion(Some(hash)),
),
},
Err(()) => (Err(XcmError::UnhandledXcmVersion), Event::BadVersion(Some(hash))),
};
Self::deposit_event(event);
result
@@ -390,18 +379,18 @@ impl<T: Config> Pallet<T> {
// That message didn't get processed this time because of being
// too heavy. We leave it around for next time and bail.
remaining_fragments = last_remaining_fragments;
break;
}
break
},
Err(_) => {
// Message looks invalid; don't attempt to retry
}
},
}
} else {
debug_assert!(false, "Invalid incoming XCMP message data");
remaining_fragments = &b""[..];
}
}
}
},
XcmpMessageFormat::ConcatenatedEncodedBlob => {
while !remaining_fragments.is_empty() {
last_remaining_fragments = remaining_fragments;
@@ -413,22 +402,22 @@ impl<T: Config> Pallet<T> {
// That message didn't get processed this time because of being
// too heavy. We leave it around for next time and bail.
remaining_fragments = last_remaining_fragments;
break;
}
break
},
Err(false) => {
// Message invalid; don't attempt to retry
}
},
}
} else {
debug_assert!(false, "Invalid incoming blob message data");
remaining_fragments = &b""[..];
}
}
}
},
XcmpMessageFormat::Signals => {
debug_assert!(false, "All signals are handled immediately; qed");
remaining_fragments = &b""[..];
}
},
}
let is_empty = remaining_fragments.is_empty();
if is_empty {
@@ -469,15 +458,11 @@ impl<T: Config> Pallet<T> {
fn service_xcmp_queue(max_weight: Weight) -> Weight {
let mut status = <InboundXcmpStatus<T>>::get(); // <- sorted.
if status.len() == 0 {
return 0;
return 0
}
let QueueConfigData {
resume_threshold,
threshold_weight,
weight_restrict_decay,
..
} = <QueueConfig<T>>::get();
let QueueConfigData { resume_threshold, threshold_weight, weight_restrict_decay, .. } =
<QueueConfig<T>>::get();
let mut shuffled = Self::create_shuffle(status.len());
let mut weight_used = 0;
@@ -492,8 +477,8 @@ impl<T: Config> Pallet<T> {
// send more, heavier messages.
let mut shuffle_index = 0;
while shuffle_index < shuffled.len()
&& max_weight.saturating_sub(weight_used) >= threshold_weight
while shuffle_index < shuffled.len() &&
max_weight.saturating_sub(weight_used) >= threshold_weight
{
let index = shuffled[shuffle_index];
let sender = status[index].0;
@@ -514,10 +499,7 @@ impl<T: Config> Pallet<T> {
}
let weight_processed = if status[index].2.is_empty() {
debug_assert!(
false,
"channel exists in status; there must be messages; qed"
);
debug_assert!(false, "channel exists in status; there must be messages; qed");
0
} else {
// Process up to one block's worth for now.
@@ -531,26 +513,24 @@ impl<T: Config> Pallet<T> {
};
weight_used += weight_processed;
if status[index].2.len() as u32 <= resume_threshold
&& status[index].1 == InboundStatus::Suspended
if status[index].2.len() as u32 <= resume_threshold &&
status[index].1 == InboundStatus::Suspended
{
// Resume
let r = Self::send_signal(sender, ChannelSignal::Resume);
debug_assert!(
r.is_ok(),
"WARNING: Failed sending resume into suspended channel"
);
debug_assert!(r.is_ok(), "WARNING: Failed sending resume into suspended channel");
status[index].1 = InboundStatus::Ok;
}
// If there are more and we're making progress, we process them after we've given the
// other channels a look in. If we've still not unlocked all weight, then we set them
// up for processing a second time anyway.
if !status[index].2.is_empty() && (weight_processed > 0 || weight_available != max_weight)
if !status[index].2.is_empty() &&
(weight_processed > 0 || weight_available != max_weight)
{
if shuffle_index + 1 == shuffled.len() {
// Only this queue left. Just run around this loop once more.
continue;
continue
}
shuffled.push(index);
}
@@ -590,10 +570,7 @@ impl<T: Config> Pallet<T> {
s[index].1 = OutboundStatus::Ok;
}
} else {
debug_assert!(
false,
"WARNING: Attempt to resume channel that was not suspended."
);
debug_assert!(false, "WARNING: Attempt to resume channel that was not suspended.");
}
});
}
@@ -606,11 +583,7 @@ impl<T: Config> XcmpMessageHandler for Pallet<T> {
) -> Weight {
let mut status = <InboundXcmpStatus<T>>::get();
let QueueConfigData {
suspend_threshold,
drop_threshold,
..
} = <QueueConfig<T>>::get();
let QueueConfigData { suspend_threshold, drop_threshold, .. } = <QueueConfig<T>>::get();
for (sender, sent_at, data) in iter {
// Figure out the message format.
@@ -618,12 +591,9 @@ impl<T: Config> XcmpMessageHandler for Pallet<T> {
let format = match XcmpMessageFormat::decode(&mut data_ref) {
Ok(f) => f,
Err(_) => {
debug_assert!(
false,
"Unknown XCMP message format. Silently dropping message"
);
continue;
}
debug_assert!(false, "Unknown XCMP message format. Silently dropping message");
continue
},
};
if format == XcmpMessageFormat::Signals {
while !data_ref.is_empty() {
@@ -656,7 +626,7 @@ impl<T: Config> XcmpMessageHandler for Pallet<T> {
"XCMP channel queue full. Silently dropping message"
);
}
}
},
Err(_) => status.push((sender, InboundStatus::Ok, vec![(sent_at, format)])),
}
// Queue the payload for later execution.
@@ -686,10 +656,10 @@ impl<T: Config> XcmpMessageSource for Pallet<T> {
if result.len() == max_message_count {
// We check this condition in the beginning of the loop so that we don't include
// a message where the limit is 0.
break;
break
}
if outbound_status == OutboundStatus::Suspended {
continue;
continue
}
let (max_size_now, max_size_ever) = match T::ChannelInfo::get_channel_status(para_id) {
ChannelStatus::Closed => {
@@ -702,8 +672,8 @@ impl<T: Config> XcmpMessageSource for Pallet<T> {
<SignalMessages<T>>::remove(para_id);
}
*status = (para_id, OutboundStatus::Ok, false, 0, 0);
continue;
}
continue
},
ChannelStatus::Full => continue,
ChannelStatus::Ready(n, e) => (n, e),
};
@@ -715,7 +685,7 @@ impl<T: Config> XcmpMessageSource for Pallet<T> {
signalling = false;
page
} else {
continue;
continue
}
} else if end > begin {
let page = <OutboundXcmpMessages<T>>::get(para_id, begin);
@@ -724,10 +694,10 @@ impl<T: Config> XcmpMessageSource for Pallet<T> {
begin += 1;
page
} else {
continue;
continue
}
} else {
continue;
continue
};
if begin == end {
begin = 0;
@@ -789,7 +759,7 @@ impl<T: Config> SendXcm for Pallet<T> {
.map_err(|e| SendError::Transport(<&'static str>::from(e)))?;
Self::deposit_event(Event::XcmpMessageSent(Some(hash)));
Ok(())
}
},
// Anything else is unhandled. This includes a message this is meant for us.
_ => Err(SendError::CannotReachDestination(dest, msg)),
}
+7 -7
View File
@@ -15,12 +15,14 @@
use super::*;
use crate as xcmp_queue;
use sp_core::H256;
use frame_support::parameter_types;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use xcm_builder::{
FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, CurrencyAdapter,
ParentIsDefault,
CurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsDefault,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
@@ -124,9 +126,7 @@ pub type LocalAssetTransactor = CurrencyAdapter<
(),
>;
pub type LocationToAccountId = (
ParentIsDefault<AccountId>,
);
pub type LocationToAccountId = (ParentIsDefault<AccountId>,);
pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
+3 -12
View File
@@ -14,25 +14,16 @@
// limitations under the License.
use super::*;
use mock::{new_test_ext, XcmpQueue};
use cumulus_primitives_core::XcmpMessageHandler;
use mock::{new_test_ext, XcmpQueue};
#[test]
fn one_message_does_not_panic() {
new_test_ext().execute_with(|| {
let message_format = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
let messages = vec![
(
Default::default(),
1u32.into(),
message_format.as_slice(),
),
];
let messages = vec![(Default::default(), 1u32.into(), message_format.as_slice())];
// This shouldn't cause a panic
XcmpQueue::handle_xcmp_messages(
messages.into_iter(),
Weight::max_value(),
);
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value());
})
}