mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 03:31:05 +00:00
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:
@@ -69,13 +69,13 @@ impl Parse for Input {
|
||||
} else if lookahead.peek(keywords::CheckInherents) {
|
||||
parse_inner::<keywords::CheckInherents>(input, &mut check_inherents)?;
|
||||
} else {
|
||||
return Err(lookahead.error());
|
||||
return Err(lookahead.error())
|
||||
}
|
||||
}
|
||||
|
||||
let rest = input.parse::<TokenStream>()?;
|
||||
if !rest.is_empty() {
|
||||
return Err(Error::new(rest.span(), "Unexpected input data"));
|
||||
return Err(Error::new(rest.span(), "Unexpected input data"))
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
@@ -88,10 +88,8 @@ impl Parse for Input {
|
||||
|
||||
fn crate_() -> Result<Ident, Error> {
|
||||
match crate_name("cumulus-pallet-parachain-system") {
|
||||
Ok(FoundCrate::Itself) => Ok(syn::Ident::new(
|
||||
"cumulus_pallet_parachain_system",
|
||||
Span::call_site(),
|
||||
)),
|
||||
Ok(FoundCrate::Itself) =>
|
||||
Ok(syn::Ident::new("cumulus_pallet_parachain_system", Span::call_site())),
|
||||
Ok(FoundCrate::Name(name)) => Ok(Ident::new(&name, Span::call_site())),
|
||||
Err(e) => Err(Error::new(Span::call_site(), e)),
|
||||
}
|
||||
@@ -99,11 +97,7 @@ fn crate_() -> Result<Ident, Error> {
|
||||
|
||||
#[proc_macro]
|
||||
pub fn register_validate_block(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let Input {
|
||||
runtime,
|
||||
check_inherents,
|
||||
block_executor,
|
||||
} = match syn::parse(input) {
|
||||
let Input { runtime, check_inherents, block_executor } = match syn::parse(input) {
|
||||
Ok(t) => t,
|
||||
Err(e) => return e.into_compile_error().into(),
|
||||
};
|
||||
|
||||
@@ -144,8 +144,8 @@ pub mod pallet {
|
||||
false,
|
||||
"host configuration is promised to set until `on_finalize`; qed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
return
|
||||
},
|
||||
};
|
||||
let relevant_messaging_state = match Self::relevant_messaging_state() {
|
||||
Some(ok) => ok,
|
||||
@@ -155,8 +155,8 @@ pub mod pallet {
|
||||
"relevant messaging state is promised to be set until `on_finalize`; \
|
||||
qed",
|
||||
);
|
||||
return;
|
||||
}
|
||||
return
|
||||
},
|
||||
};
|
||||
|
||||
<PendingUpwardMessages<T>>::mutate(|up| {
|
||||
@@ -172,19 +172,16 @@ pub mod pallet {
|
||||
// available_capacity and available_size.
|
||||
let num = up
|
||||
.iter()
|
||||
.scan(
|
||||
(available_capacity as usize, available_size as usize),
|
||||
|state, msg| {
|
||||
let (cap_left, size_left) = *state;
|
||||
match (cap_left.checked_sub(1), size_left.checked_sub(msg.len())) {
|
||||
(Some(new_cap), Some(new_size)) => {
|
||||
*state = (new_cap, new_size);
|
||||
Some(())
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
)
|
||||
.scan((available_capacity as usize, available_size as usize), |state, msg| {
|
||||
let (cap_left, size_left) = *state;
|
||||
match (cap_left.checked_sub(1), size_left.checked_sub(msg.len())) {
|
||||
(Some(new_cap), Some(new_size)) => {
|
||||
*state = (new_cap, new_size);
|
||||
Some(())
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.count();
|
||||
|
||||
// TODO: #274 Return back messages that do not longer fit into the queue.
|
||||
@@ -366,10 +363,7 @@ pub mod pallet {
|
||||
vfp.relay_parent_number,
|
||||
);
|
||||
|
||||
Ok(PostDispatchInfo {
|
||||
actual_weight: Some(total_weight),
|
||||
pays_fee: Pays::No,
|
||||
})
|
||||
Ok(PostDispatchInfo { actual_weight: Some(total_weight), pays_fee: Pays::No })
|
||||
}
|
||||
|
||||
#[pallet::weight((1_000, DispatchClass::Operational))]
|
||||
@@ -572,11 +566,10 @@ pub mod pallet {
|
||||
cumulus_primitives_parachain_inherent::INHERENT_IDENTIFIER;
|
||||
|
||||
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||
let data: ParachainInherentData = data
|
||||
.get_data(&Self::INHERENT_IDENTIFIER)
|
||||
.ok()
|
||||
.flatten()
|
||||
.expect("validation function params are always injected into inherent data; qed");
|
||||
let data: ParachainInherentData =
|
||||
data.get_data(&Self::INHERENT_IDENTIFIER).ok().flatten().expect(
|
||||
"validation function params are always injected into inherent data; qed",
|
||||
);
|
||||
|
||||
Some(Call::set_validation_data { data })
|
||||
}
|
||||
@@ -611,11 +604,11 @@ pub mod pallet {
|
||||
provides: vec![hash.as_ref().to_vec()],
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
propagate: true,
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
if let Call::set_validation_data { .. } = call {
|
||||
return Ok(Default::default());
|
||||
return Ok(Default::default())
|
||||
}
|
||||
Err(InvalidTransaction::Call.into())
|
||||
}
|
||||
@@ -650,8 +643,8 @@ impl<T: Config> GetChannelInfo for Pallet<T> {
|
||||
let channels = match Self::relevant_messaging_state() {
|
||||
None => {
|
||||
log::warn!("calling `get_channel_status` with no RelevantMessagingState?!");
|
||||
return ChannelStatus::Closed;
|
||||
}
|
||||
return ChannelStatus::Closed
|
||||
},
|
||||
Some(d) => d.egress_channels,
|
||||
};
|
||||
// ^^^ NOTE: This storage field should carry over from the previous block. So if it's
|
||||
@@ -667,7 +660,7 @@ impl<T: Config> GetChannelInfo for Pallet<T> {
|
||||
let meta = &channels[index].1;
|
||||
if meta.msg_count + 1 > meta.max_capacity {
|
||||
// The channel is at its capacity. Skip it for now.
|
||||
return ChannelStatus::Full;
|
||||
return ChannelStatus::Full
|
||||
}
|
||||
let max_size_now = meta.max_total_size - meta.total_size;
|
||||
let max_size_ever = meta.max_message_size;
|
||||
@@ -771,9 +764,7 @@ impl<T: Config> Pallet<T> {
|
||||
// A violation of the assertion below indicates that one of the messages submitted
|
||||
// by the collator was sent from a sender that doesn't have a channel opened to
|
||||
// this parachain, according to the relay-parent state.
|
||||
assert!(ingress_channels
|
||||
.binary_search_by_key(sender, |&(s, _)| s)
|
||||
.is_ok(),);
|
||||
assert!(ingress_channels.binary_search_by_key(sender, |&(s, _)| s).is_ok(),);
|
||||
}
|
||||
|
||||
// Second, prepare horizontal messages for a more convenient processing:
|
||||
@@ -787,9 +778,7 @@ impl<T: Config> Pallet<T> {
|
||||
let mut horizontal_messages = horizontal_messages
|
||||
.into_iter()
|
||||
.flat_map(|(sender, channel_contents)| {
|
||||
channel_contents
|
||||
.into_iter()
|
||||
.map(move |message| (sender, message))
|
||||
channel_contents.into_iter().map(move |message| (sender, message))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
horizontal_messages.sort_by(|a, b| {
|
||||
@@ -806,10 +795,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
{
|
||||
for (sender, ref horizontal_message) in &horizontal_messages {
|
||||
if hrmp_watermark
|
||||
.map(|w| w < horizontal_message.sent_at)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
if hrmp_watermark.map(|w| w < horizontal_message.sent_at).unwrap_or(true) {
|
||||
hrmp_watermark = Some(horizontal_message.sent_at);
|
||||
}
|
||||
|
||||
@@ -882,16 +868,15 @@ impl<T: Config> Pallet<T> {
|
||||
) -> Option<relay_chain::BlockNumber> {
|
||||
if <PendingRelayChainBlockNumber<T>>::get().is_some() {
|
||||
// There is already upgrade scheduled. Upgrade is not allowed.
|
||||
return None;
|
||||
return None
|
||||
}
|
||||
|
||||
let relay_blocks_since_last_upgrade = vfp
|
||||
.relay_parent_number
|
||||
.saturating_sub(<LastUpgrade<T>>::get());
|
||||
let relay_blocks_since_last_upgrade =
|
||||
vfp.relay_parent_number.saturating_sub(<LastUpgrade<T>>::get());
|
||||
|
||||
if relay_blocks_since_last_upgrade <= cfg.validation_upgrade_frequency {
|
||||
// The cooldown after the last upgrade hasn't elapsed yet. Upgrade is not allowed.
|
||||
return None;
|
||||
return None
|
||||
}
|
||||
|
||||
Some(vfp.relay_parent_number + cfg.validation_upgrade_delay)
|
||||
@@ -899,16 +884,10 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// The implementation of the runtime upgrade functionality for parachains.
|
||||
fn set_code_impl(validation_function: Vec<u8>) -> DispatchResult {
|
||||
ensure!(
|
||||
!<PendingValidationCode<T>>::exists(),
|
||||
Error::<T>::OverlappingUpgrades
|
||||
);
|
||||
ensure!(!<PendingValidationCode<T>>::exists(), Error::<T>::OverlappingUpgrades);
|
||||
let vfp = Self::validation_data().ok_or(Error::<T>::ValidationDataNotAvailable)?;
|
||||
let cfg = Self::host_configuration().ok_or(Error::<T>::HostConfigurationNotAvailable)?;
|
||||
ensure!(
|
||||
validation_function.len() <= cfg.max_code_size as usize,
|
||||
Error::<T>::TooBig
|
||||
);
|
||||
ensure!(validation_function.len() <= cfg.max_code_size as usize, Error::<T>::TooBig);
|
||||
let apply_block =
|
||||
Self::code_upgrade_allowed(&vfp, &cfg).ok_or(Error::<T>::ProhibitedByPolkadot)?;
|
||||
|
||||
@@ -1002,11 +981,10 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// However, changing this setting is expected to be rare.
|
||||
match Self::host_configuration() {
|
||||
Some(cfg) => {
|
||||
Some(cfg) =>
|
||||
if message.len() > cfg.max_upward_message_size as usize {
|
||||
return Err(MessageSendError::TooBig);
|
||||
}
|
||||
}
|
||||
return Err(MessageSendError::TooBig)
|
||||
},
|
||||
None => {
|
||||
// This storage field should carry over from the previous block. So if it's None
|
||||
// then it must be that this is an edge-case where a message is attempted to be
|
||||
@@ -1017,7 +995,7 @@ impl<T: Config> Pallet<T> {
|
||||
// returned back to the sender.
|
||||
//
|
||||
// Thus fall through here.
|
||||
}
|
||||
},
|
||||
};
|
||||
<PendingUpwardMessages<T>>::append(message);
|
||||
Ok(0)
|
||||
|
||||
@@ -19,11 +19,10 @@ use cumulus_primitives_core::{
|
||||
relay_chain, AbridgedHostConfiguration, AbridgedHrmpChannel, ParaId,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_trie::{MemoryDB, HashDBT, EMPTY_PREFIX};
|
||||
use sp_runtime::traits::HashFor;
|
||||
use sp_state_machine::{Backend, TrieBackend};
|
||||
use sp_std::vec::Vec;
|
||||
use sp_trie::StorageProof;
|
||||
use sp_trie::{HashDBT, MemoryDB, StorageProof, EMPTY_PREFIX};
|
||||
|
||||
/// A snapshot of some messaging related state of relay chain pertaining to the current parachain.
|
||||
///
|
||||
@@ -130,14 +129,11 @@ impl RelayChainStateProof {
|
||||
) -> Result<Self, Error> {
|
||||
let db = proof.into_memory_db::<HashFor<relay_chain::Block>>();
|
||||
if !db.contains(&relay_parent_storage_root, EMPTY_PREFIX) {
|
||||
return Err(Error::RootMismatch);
|
||||
return Err(Error::RootMismatch)
|
||||
}
|
||||
let trie_backend = TrieBackend::new(db, relay_parent_storage_root);
|
||||
|
||||
Ok(Self {
|
||||
para_id,
|
||||
trie_backend,
|
||||
})
|
||||
Ok(Self { para_id, trie_backend })
|
||||
}
|
||||
|
||||
/// Read the [`MessagingStateSnapshot`] from the relay chain state proof.
|
||||
@@ -174,10 +170,7 @@ impl RelayChainStateProof {
|
||||
|
||||
let mut ingress_channels = Vec::with_capacity(ingress_channel_index.len());
|
||||
for sender in ingress_channel_index {
|
||||
let channel_id = relay_chain::v1::HrmpChannelId {
|
||||
sender,
|
||||
recipient: self.para_id,
|
||||
};
|
||||
let channel_id = relay_chain::v1::HrmpChannelId { sender, recipient: self.para_id };
|
||||
let hrmp_channel: AbridgedHrmpChannel = read_entry(
|
||||
&self.trie_backend,
|
||||
&relay_chain::well_known_keys::hrmp_channels(channel_id),
|
||||
@@ -189,10 +182,7 @@ impl RelayChainStateProof {
|
||||
|
||||
let mut egress_channels = Vec::with_capacity(egress_channel_index.len());
|
||||
for recipient in egress_channel_index {
|
||||
let channel_id = relay_chain::v1::HrmpChannelId {
|
||||
sender: self.para_id,
|
||||
recipient,
|
||||
};
|
||||
let channel_id = relay_chain::v1::HrmpChannelId { sender: self.para_id, recipient };
|
||||
let hrmp_channel: AbridgedHrmpChannel = read_entry(
|
||||
&self.trie_backend,
|
||||
&relay_chain::well_known_keys::hrmp_channels(channel_id),
|
||||
@@ -226,6 +216,7 @@ impl RelayChainStateProof {
|
||||
///
|
||||
/// Returns an error if anything failed at reading or decoding.
|
||||
pub fn read_slot(&self) -> Result<relay_chain::v1::Slot, Error> {
|
||||
read_entry(&self.trie_backend, relay_chain::well_known_keys::CURRENT_SLOT, None).map_err(Error::Slot)
|
||||
read_entry(&self.trie_backend, relay_chain::well_known_keys::CURRENT_SLOT, None)
|
||||
.map_err(Error::Slot)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,17 +17,17 @@ use super::*;
|
||||
|
||||
use codec::Encode;
|
||||
use cumulus_primitives_core::{
|
||||
AbridgedHrmpChannel, InboundDownwardMessage, InboundHrmpMessage, PersistedValidationData,
|
||||
relay_chain::BlockNumber as RelayBlockNumber,
|
||||
relay_chain::BlockNumber as RelayBlockNumber, AbridgedHrmpChannel, InboundDownwardMessage,
|
||||
InboundHrmpMessage, PersistedValidationData,
|
||||
};
|
||||
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
dispatch::UnfilteredDispatchable,
|
||||
inherent::{InherentData, ProvideInherent},
|
||||
parameter_types,
|
||||
traits::{OnFinalize, OnInitialize},
|
||||
weights::Weight,
|
||||
inherent::{InherentData, ProvideInherent},
|
||||
};
|
||||
use frame_system::{InitKind, RawOrigin};
|
||||
use hex_literal::hex;
|
||||
@@ -113,10 +113,7 @@ std::thread_local! {
|
||||
static SENT_MESSAGES: RefCell<Vec<(ParaId, Vec<u8>)>> = RefCell::new(Vec::new());
|
||||
}
|
||||
|
||||
fn send_message(
|
||||
dest: ParaId,
|
||||
message: Vec<u8>,
|
||||
) {
|
||||
fn send_message(dest: ParaId, message: Vec<u8>) {
|
||||
SENT_MESSAGES.with(|m| m.borrow_mut().push((dest, message)));
|
||||
}
|
||||
|
||||
@@ -125,9 +122,9 @@ impl XcmpMessageSource for FromThreadLocal {
|
||||
let mut ids = std::collections::BTreeSet::<ParaId>::new();
|
||||
let mut taken = 0;
|
||||
let mut result = Vec::new();
|
||||
SENT_MESSAGES.with(|ms| ms.borrow_mut()
|
||||
.retain(|m| {
|
||||
let status = <Pallet::<Test> as GetChannelInfo>::get_channel_status(m.0);
|
||||
SENT_MESSAGES.with(|ms| {
|
||||
ms.borrow_mut().retain(|m| {
|
||||
let status = <Pallet<Test> as GetChannelInfo>::get_channel_status(m.0);
|
||||
let ready = matches!(status, ChannelStatus::Ready(..));
|
||||
if ready && !ids.contains(&m.0) && taken < maximum_channels {
|
||||
ids.insert(m.0);
|
||||
@@ -138,14 +135,14 @@ impl XcmpMessageSource for FromThreadLocal {
|
||||
true
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl DmpMessageHandler for SaveIntoThreadLocal {
|
||||
fn handle_dmp_messages(
|
||||
iter: impl Iterator<Item=(RelayBlockNumber, Vec<u8>)>,
|
||||
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
|
||||
_max_weight: Weight,
|
||||
) -> Weight {
|
||||
HANDLED_DMP_MESSAGES.with(|m| {
|
||||
@@ -158,7 +155,7 @@ impl DmpMessageHandler for SaveIntoThreadLocal {
|
||||
}
|
||||
|
||||
impl XcmpMessageHandler for SaveIntoThreadLocal {
|
||||
fn handle_xcmp_messages<'a, I: Iterator<Item=(ParaId, RelayBlockNumber, &'a [u8])>>(
|
||||
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
|
||||
iter: I,
|
||||
_max_weight: Weight,
|
||||
) -> Weight {
|
||||
@@ -177,10 +174,7 @@ fn new_test_ext() -> sp_io::TestExternalities {
|
||||
HANDLED_DMP_MESSAGES.with(|m| m.borrow_mut().clear());
|
||||
HANDLED_XCMP_MESSAGES.with(|m| m.borrow_mut().clear());
|
||||
|
||||
frame_system::GenesisConfig::default()
|
||||
.build_storage::<Test>()
|
||||
.unwrap()
|
||||
.into()
|
||||
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
||||
}
|
||||
|
||||
struct ReadRuntimeVersion(Vec<u8>);
|
||||
@@ -204,9 +198,9 @@ fn wasm_ext() -> sp_io::TestExternalities {
|
||||
};
|
||||
|
||||
let mut ext = new_test_ext();
|
||||
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(
|
||||
ReadRuntimeVersion(version.encode()),
|
||||
));
|
||||
ext.register_extension(sp_core::traits::ReadRuntimeVersionExt::new(ReadRuntimeVersion(
|
||||
version.encode(),
|
||||
)));
|
||||
ext
|
||||
}
|
||||
|
||||
@@ -247,11 +241,7 @@ impl BlockTests {
|
||||
where
|
||||
F: 'static + Fn(),
|
||||
{
|
||||
self.add_raw(BlockTest {
|
||||
n,
|
||||
within_block: Box::new(within_block),
|
||||
after_block: None,
|
||||
})
|
||||
self.add_raw(BlockTest { n, within_block: Box::new(within_block), after_block: None })
|
||||
}
|
||||
|
||||
fn add_with_post_test<F1, F2>(
|
||||
@@ -299,12 +289,7 @@ impl BlockTests {
|
||||
fn run(&mut self) {
|
||||
self.ran = true;
|
||||
wasm_ext().execute_with(|| {
|
||||
for BlockTest {
|
||||
n,
|
||||
within_block,
|
||||
after_block,
|
||||
} in self.tests.iter()
|
||||
{
|
||||
for BlockTest { n, within_block, after_block } in self.tests.iter() {
|
||||
// clear pending updates, as applicable
|
||||
if let Some(upgrade_block) = self.pending_upgrade {
|
||||
if n >= &upgrade_block.into() {
|
||||
@@ -313,12 +298,7 @@ impl BlockTests {
|
||||
}
|
||||
|
||||
// begin initialization
|
||||
System::initialize(
|
||||
&n,
|
||||
&Default::default(),
|
||||
&Default::default(),
|
||||
InitKind::Full,
|
||||
);
|
||||
System::initialize(&n, &Default::default(), &Default::default(), InitKind::Full);
|
||||
|
||||
// now mess with the storage the way validate_block does
|
||||
let mut sproof_builder = RelayStateSproofBuilder::default();
|
||||
@@ -398,9 +378,7 @@ impl Drop for BlockTests {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn block_tests_run_on_drop() {
|
||||
BlockTests::new().add(123, || {
|
||||
panic!("if this test passes, block tests run properly")
|
||||
});
|
||||
BlockTests::new().add(123, || panic!("if this test passes, block tests run properly"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -412,10 +390,7 @@ fn events() {
|
||||
.add_with_post_test(
|
||||
123,
|
||||
|| {
|
||||
assert_ok!(System::set_code(
|
||||
RawOrigin::Root.into(),
|
||||
Default::default()
|
||||
));
|
||||
assert_ok!(System::set_code(RawOrigin::Root.into(), Default::default()));
|
||||
},
|
||||
|| {
|
||||
let events = System::events();
|
||||
@@ -445,10 +420,7 @@ fn non_overlapping() {
|
||||
builder.host_config.validation_upgrade_delay = 1000;
|
||||
})
|
||||
.add(123, || {
|
||||
assert_ok!(System::set_code(
|
||||
RawOrigin::Root.into(),
|
||||
Default::default()
|
||||
));
|
||||
assert_ok!(System::set_code(RawOrigin::Root.into(), Default::default()));
|
||||
})
|
||||
.add(234, || {
|
||||
assert_eq!(
|
||||
@@ -466,14 +438,8 @@ fn manipulates_storage() {
|
||||
!<PendingValidationCode<Test>>::exists(),
|
||||
"validation function must not exist yet"
|
||||
);
|
||||
assert_ok!(System::set_code(
|
||||
RawOrigin::Root.into(),
|
||||
Default::default()
|
||||
));
|
||||
assert!(
|
||||
<PendingValidationCode<Test>>::exists(),
|
||||
"validation function must now exist"
|
||||
);
|
||||
assert_ok!(System::set_code(RawOrigin::Root.into(), Default::default()));
|
||||
assert!(<PendingValidationCode<Test>>::exists(), "validation function must now exist");
|
||||
})
|
||||
.add_with_post_test(
|
||||
1234,
|
||||
@@ -573,10 +539,7 @@ fn send_hrmp_message_buffer_channel_close() {
|
||||
sproof.para_id = ParaId::from(200);
|
||||
sproof.hrmp_egress_channel_index = Some(vec![ParaId::from(300), ParaId::from(400)]);
|
||||
sproof.hrmp_channels.insert(
|
||||
HrmpChannelId {
|
||||
sender: ParaId::from(200),
|
||||
recipient: ParaId::from(300),
|
||||
},
|
||||
HrmpChannelId { sender: ParaId::from(200), recipient: ParaId::from(300) },
|
||||
AbridgedHrmpChannel {
|
||||
max_capacity: 1,
|
||||
msg_count: 1, // <- 1/1 means the channel is full
|
||||
@@ -587,10 +550,7 @@ fn send_hrmp_message_buffer_channel_close() {
|
||||
},
|
||||
);
|
||||
sproof.hrmp_channels.insert(
|
||||
HrmpChannelId {
|
||||
sender: ParaId::from(200),
|
||||
recipient: ParaId::from(400),
|
||||
},
|
||||
HrmpChannelId { sender: ParaId::from(200), recipient: ParaId::from(400) },
|
||||
AbridgedHrmpChannel {
|
||||
max_capacity: 1,
|
||||
msg_count: 1,
|
||||
@@ -605,8 +565,8 @@ fn send_hrmp_message_buffer_channel_close() {
|
||||
// Adjustment according to block
|
||||
//
|
||||
match relay_block_num {
|
||||
1 => {}
|
||||
2 => {}
|
||||
1 => {},
|
||||
2 => {},
|
||||
3 => {
|
||||
// The channel 200->400 ceases to exist at the relay chain block 3
|
||||
sproof
|
||||
@@ -628,21 +588,15 @@ fn send_hrmp_message_buffer_channel_close() {
|
||||
})
|
||||
.unwrap()
|
||||
.msg_count = 0;
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
})
|
||||
.add_with_post_test(
|
||||
1,
|
||||
|| {
|
||||
send_message(
|
||||
ParaId::from(300),
|
||||
b"1".to_vec(),
|
||||
);
|
||||
send_message(
|
||||
ParaId::from(400),
|
||||
b"2".to_vec(),
|
||||
);
|
||||
send_message(ParaId::from(300), b"1".to_vec());
|
||||
send_message(ParaId::from(400), b"2".to_vec());
|
||||
},
|
||||
|| {},
|
||||
)
|
||||
@@ -662,10 +616,7 @@ fn send_hrmp_message_buffer_channel_close() {
|
||||
let v = HrmpOutboundMessages::<Test>::get();
|
||||
assert_eq!(
|
||||
v,
|
||||
vec![OutboundHrmpMessage {
|
||||
recipient: ParaId::from(300),
|
||||
data: b"1".to_vec(),
|
||||
}]
|
||||
vec![OutboundHrmpMessage { recipient: ParaId::from(300), data: b"1".to_vec() }]
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -682,27 +633,15 @@ fn message_queue_chain() {
|
||||
// These cases are taken from https://github.com/paritytech/polkadot/pull/2351
|
||||
assert_eq!(
|
||||
MessageQueueChain::default()
|
||||
.extend_downward(&InboundDownwardMessage {
|
||||
sent_at: 2,
|
||||
msg: vec![1, 2, 3],
|
||||
})
|
||||
.extend_downward(&InboundDownwardMessage {
|
||||
sent_at: 3,
|
||||
msg: vec![4, 5, 6],
|
||||
})
|
||||
.extend_downward(&InboundDownwardMessage { sent_at: 2, msg: vec![1, 2, 3] })
|
||||
.extend_downward(&InboundDownwardMessage { sent_at: 3, msg: vec![4, 5, 6] })
|
||||
.head(),
|
||||
hex!["88dc00db8cc9d22aa62b87807705831f164387dfa49f80a8600ed1cbe1704b6b"].into(),
|
||||
);
|
||||
assert_eq!(
|
||||
MessageQueueChain::default()
|
||||
.extend_hrmp(&InboundHrmpMessage {
|
||||
sent_at: 2,
|
||||
data: vec![1, 2, 3],
|
||||
})
|
||||
.extend_hrmp(&InboundHrmpMessage {
|
||||
sent_at: 3,
|
||||
data: vec![4, 5, 6],
|
||||
})
|
||||
.extend_hrmp(&InboundHrmpMessage { sent_at: 2, data: vec![1, 2, 3] })
|
||||
.extend_hrmp(&InboundHrmpMessage { sent_at: 3, data: vec![4, 5, 6] })
|
||||
.head(),
|
||||
hex!["88dc00db8cc9d22aa62b87807705831f164387dfa49f80a8600ed1cbe1704b6b"].into(),
|
||||
);
|
||||
@@ -722,13 +661,13 @@ fn receive_dmp() {
|
||||
1 => {
|
||||
sproof.dmq_mqc_head =
|
||||
Some(MessageQueueChain::default().extend_downward(&MSG).head());
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.with_inherent_data(|_, relay_block_num, data| match relay_block_num {
|
||||
1 => {
|
||||
data.downward_messages.push(MSG.clone());
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.add(1, || {
|
||||
@@ -771,7 +710,7 @@ fn receive_hrmp() {
|
||||
// 300 - one new message
|
||||
sproof.upsert_inbound_channel(ParaId::from(300)).mqc_head =
|
||||
Some(MessageQueueChain::default().extend_hrmp(&MSG_1).head());
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
// 200 - two new messages
|
||||
// 300 - now present with one message.
|
||||
@@ -784,20 +723,19 @@ fn receive_hrmp() {
|
||||
.extend_hrmp(&MSG_3)
|
||||
.head(),
|
||||
);
|
||||
}
|
||||
},
|
||||
3 => {
|
||||
// 200 - no new messages
|
||||
// 300 - is gone
|
||||
sproof.upsert_inbound_channel(ParaId::from(200)).mqc_head =
|
||||
Some(MessageQueueChain::default().extend_hrmp(&MSG_4).head());
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.with_inherent_data(|_, relay_block_num, data| match relay_block_num {
|
||||
1 => {
|
||||
data.horizontal_messages
|
||||
.insert(ParaId::from(300), vec![MSG_1.clone()]);
|
||||
}
|
||||
data.horizontal_messages.insert(ParaId::from(300), vec![MSG_1.clone()]);
|
||||
},
|
||||
2 => {
|
||||
data.horizontal_messages.insert(
|
||||
ParaId::from(300),
|
||||
@@ -809,10 +747,9 @@ fn receive_hrmp() {
|
||||
MSG_3.clone(),
|
||||
],
|
||||
);
|
||||
data.horizontal_messages
|
||||
.insert(ParaId::from(200), vec![MSG_4.clone()]);
|
||||
}
|
||||
3 => {}
|
||||
data.horizontal_messages.insert(ParaId::from(200), vec![MSG_4.clone()]);
|
||||
},
|
||||
3 => {},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.add(1, || {
|
||||
@@ -845,12 +782,12 @@ fn receive_hrmp_empty_channel() {
|
||||
.with_relay_sproof_builder(|_, relay_block_num, sproof| match relay_block_num {
|
||||
1 => {
|
||||
// no channels
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
// one new channel
|
||||
sproof.upsert_inbound_channel(ParaId::from(300)).mqc_head =
|
||||
Some(MessageQueueChain::default().head());
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.add(1, || {})
|
||||
@@ -878,33 +815,30 @@ fn receive_hrmp_after_pause() {
|
||||
1 => {
|
||||
sproof.upsert_inbound_channel(ALICE).mqc_head =
|
||||
Some(MessageQueueChain::default().extend_hrmp(&MSG_1).head());
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
// 300 - no new messages, mqc stayed the same.
|
||||
sproof.upsert_inbound_channel(ALICE).mqc_head =
|
||||
Some(MessageQueueChain::default().extend_hrmp(&MSG_1).head());
|
||||
}
|
||||
},
|
||||
3 => {
|
||||
// 300 - new message.
|
||||
sproof.upsert_inbound_channel(ALICE).mqc_head = Some(
|
||||
MessageQueueChain::default()
|
||||
.extend_hrmp(&MSG_1)
|
||||
.extend_hrmp(&MSG_2)
|
||||
.head(),
|
||||
MessageQueueChain::default().extend_hrmp(&MSG_1).extend_hrmp(&MSG_2).head(),
|
||||
);
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.with_inherent_data(|_, relay_block_num, data| match relay_block_num {
|
||||
1 => {
|
||||
data.horizontal_messages.insert(ALICE, vec![MSG_1.clone()]);
|
||||
}
|
||||
},
|
||||
2 => {
|
||||
// no new messages
|
||||
}
|
||||
},
|
||||
3 => {
|
||||
data.horizontal_messages.insert(ALICE, vec![MSG_2.clone()]);
|
||||
}
|
||||
},
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.add(1, || {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! The actual implementation of the validate block functionality.
|
||||
|
||||
use frame_support::traits::{ExecuteBlock, ExtrinsicCall, IsSubType, Get};
|
||||
use frame_support::traits::{ExecuteBlock, ExtrinsicCall, Get, IsSubType};
|
||||
use sp_runtime::traits::{Block as BlockT, Extrinsic, HashFor, Header as HeaderT, NumberFor};
|
||||
|
||||
use sp_io::KillStorageResult;
|
||||
@@ -64,10 +64,7 @@ where
|
||||
let head_data = HeadData(header.encode());
|
||||
|
||||
let block = B::new(header, extrinsics);
|
||||
assert!(
|
||||
parent_head.hash() == *block.header().parent_hash(),
|
||||
"Invalid parent hash",
|
||||
);
|
||||
assert!(parent_head.hash() == *block.header().parent_hash(), "Invalid parent hash",);
|
||||
|
||||
// Uncompress
|
||||
let mut db = MemoryDB::default();
|
||||
@@ -128,7 +125,8 @@ where
|
||||
.iter()
|
||||
.filter_map(|e| e.call().is_sub_type())
|
||||
.find_map(|c| match c {
|
||||
crate::Call::set_validation_data { data: validation_data } => Some(validation_data.clone()),
|
||||
crate::Call::set_validation_data { data: validation_data } =>
|
||||
Some(validation_data.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.expect("Could not find `set_validation_data` inherent");
|
||||
@@ -196,7 +194,7 @@ fn host_storage_read(key: &[u8], value_out: &mut [u8], value_offset: u32) -> Opt
|
||||
let written = sp_std::cmp::min(data.len(), value_out.len());
|
||||
value_out[..written].copy_from_slice(&data[..written]);
|
||||
Some(value.len() as u32)
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
@@ -276,7 +274,7 @@ fn host_default_child_storage_read(
|
||||
let written = sp_std::cmp::min(data.len(), value_out.len());
|
||||
value_out[..written].copy_from_slice(&data[..written]);
|
||||
Some(value.len() as u32)
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
@@ -312,7 +310,11 @@ fn host_default_child_storage_exists(storage_key: &[u8], key: &[u8]) -> bool {
|
||||
with_externalities(|ext| ext.exists_child_storage(&child_info, key))
|
||||
}
|
||||
|
||||
fn host_default_child_storage_clear_prefix(storage_key: &[u8], prefix: &[u8], limit: Option<u32>) -> KillStorageResult {
|
||||
fn host_default_child_storage_clear_prefix(
|
||||
storage_key: &[u8],
|
||||
prefix: &[u8],
|
||||
limit: Option<u32>,
|
||||
) -> KillStorageResult {
|
||||
let child_info = ChildInfo::new_default(storage_key);
|
||||
with_externalities(|ext| {
|
||||
let (all_removed, num_removed) = ext.clear_child_prefix(&child_info, prefix, limit);
|
||||
|
||||
@@ -79,16 +79,11 @@ fn build_block_with_witness(
|
||||
|
||||
validation_data.relay_parent_storage_root = relay_parent_storage_root;
|
||||
|
||||
extra_extrinsics
|
||||
.into_iter()
|
||||
.for_each(|e| builder.push(e).unwrap());
|
||||
extra_extrinsics.into_iter().for_each(|e| builder.push(e).unwrap());
|
||||
|
||||
let block = builder.build_parachain_block(*parent_head.state_root());
|
||||
|
||||
TestBlockData {
|
||||
block,
|
||||
validation_data,
|
||||
}
|
||||
TestBlockData { block, validation_data }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -96,18 +91,13 @@ fn validate_block_no_extra_extrinsics() {
|
||||
sp_tracing::try_init_simple();
|
||||
|
||||
let (client, parent_head) = create_test_client();
|
||||
let TestBlockData {
|
||||
block,
|
||||
validation_data,
|
||||
} = build_block_with_witness(&client, vec![], parent_head.clone(), Default::default());
|
||||
let TestBlockData { block, validation_data } =
|
||||
build_block_with_witness(&client, vec![], parent_head.clone(), Default::default());
|
||||
let header = block.header().clone();
|
||||
|
||||
let res_header = call_validate_block(
|
||||
parent_head,
|
||||
block,
|
||||
validation_data.relay_parent_storage_root,
|
||||
)
|
||||
.expect("Calls `validate_block`");
|
||||
let res_header =
|
||||
call_validate_block(parent_head, block, validation_data.relay_parent_storage_root)
|
||||
.expect("Calls `validate_block`");
|
||||
assert_eq!(header, res_header);
|
||||
}
|
||||
|
||||
@@ -122,10 +112,7 @@ fn validate_block_with_extra_extrinsics() {
|
||||
transfer(&client, Charlie, Alice, 500),
|
||||
];
|
||||
|
||||
let TestBlockData {
|
||||
block,
|
||||
validation_data,
|
||||
} = build_block_with_witness(
|
||||
let TestBlockData { block, validation_data } = build_block_with_witness(
|
||||
&client,
|
||||
extra_extrinsics,
|
||||
parent_head.clone(),
|
||||
@@ -133,12 +120,9 @@ fn validate_block_with_extra_extrinsics() {
|
||||
);
|
||||
let header = block.header().clone();
|
||||
|
||||
let res_header = call_validate_block(
|
||||
parent_head,
|
||||
block,
|
||||
validation_data.relay_parent_storage_root,
|
||||
)
|
||||
.expect("Calls `validate_block`");
|
||||
let res_header =
|
||||
call_validate_block(parent_head, block, validation_data.relay_parent_storage_root)
|
||||
.expect("Calls `validate_block`");
|
||||
assert_eq!(header, res_header);
|
||||
}
|
||||
|
||||
@@ -148,20 +132,14 @@ fn validate_block_invalid_parent_hash() {
|
||||
|
||||
if env::var("RUN_TEST").is_ok() {
|
||||
let (client, parent_head) = create_test_client();
|
||||
let TestBlockData {
|
||||
block,
|
||||
validation_data,
|
||||
} = build_block_with_witness(&client, vec![], parent_head.clone(), Default::default());
|
||||
let TestBlockData { block, validation_data } =
|
||||
build_block_with_witness(&client, vec![], parent_head.clone(), Default::default());
|
||||
let (mut header, extrinsics, witness) = block.deconstruct();
|
||||
header.set_parent_hash(Hash::from_low_u64_be(1));
|
||||
|
||||
let block_data = ParachainBlockData::new(header, extrinsics, witness);
|
||||
call_validate_block(
|
||||
parent_head,
|
||||
block_data,
|
||||
validation_data.relay_parent_storage_root,
|
||||
)
|
||||
.unwrap_err();
|
||||
call_validate_block(parent_head, block_data, validation_data.relay_parent_storage_root)
|
||||
.unwrap_err();
|
||||
} else {
|
||||
let output = Command::new(env::current_exe().unwrap())
|
||||
.args(&["validate_block_invalid_parent_hash", "--", "--nocapture"])
|
||||
@@ -186,11 +164,7 @@ fn validate_block_fails_on_invalid_validation_data() {
|
||||
call_validate_block(parent_head, block, Hash::random()).unwrap_err();
|
||||
} else {
|
||||
let output = Command::new(env::current_exe().unwrap())
|
||||
.args(&[
|
||||
"validate_block_fails_on_invalid_validation_data",
|
||||
"--",
|
||||
"--nocapture",
|
||||
])
|
||||
.args(&["validate_block_fails_on_invalid_validation_data", "--", "--nocapture"])
|
||||
.env("RUN_TEST", "1")
|
||||
.output()
|
||||
.expect("Runs the test");
|
||||
@@ -208,32 +182,18 @@ fn check_inherent_fails_on_validate_block_as_expected() {
|
||||
if env::var("RUN_TEST").is_ok() {
|
||||
let (client, parent_head) = create_test_client();
|
||||
|
||||
let TestBlockData {
|
||||
block,
|
||||
validation_data,
|
||||
} = build_block_with_witness(
|
||||
let TestBlockData { block, validation_data } = build_block_with_witness(
|
||||
&client,
|
||||
vec![],
|
||||
parent_head.clone(),
|
||||
RelayStateSproofBuilder {
|
||||
current_slot: 1337.into(),
|
||||
..Default::default()
|
||||
},
|
||||
RelayStateSproofBuilder { current_slot: 1337.into(), ..Default::default() },
|
||||
);
|
||||
|
||||
call_validate_block(
|
||||
parent_head,
|
||||
block,
|
||||
validation_data.relay_parent_storage_root,
|
||||
)
|
||||
.unwrap_err();
|
||||
call_validate_block(parent_head, block, validation_data.relay_parent_storage_root)
|
||||
.unwrap_err();
|
||||
} else {
|
||||
let output = Command::new(env::current_exe().unwrap())
|
||||
.args(&[
|
||||
"check_inherent_fails_on_validate_block_as_expected",
|
||||
"--",
|
||||
"--nocapture",
|
||||
])
|
||||
.args(&["check_inherent_fails_on_validate_block_as_expected", "--", "--nocapture"])
|
||||
.env("RUN_TEST", "1")
|
||||
.output()
|
||||
.expect("Runs the test");
|
||||
|
||||
Reference in New Issue
Block a user