mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
cargo +nightly fmt (#3540)
* cargo +nightly fmt * add cargo-fmt check to ci * update ci * fmt * fmt * skip macro * ignore bridges
This commit is contained in:
@@ -21,26 +21,26 @@
|
||||
//! as it has no initialization logic and its finalization logic depends only on the details of
|
||||
//! this module.
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
use primitives::v1::{
|
||||
BackedCandidate, PARACHAINS_INHERENT_IDENTIFIER, InherentData as ParachainsInherentData,
|
||||
};
|
||||
use frame_support::{
|
||||
decl_error, decl_module, decl_storage, ensure,
|
||||
dispatch::DispatchResultWithPostInfo,
|
||||
weights::{DispatchClass, Weight},
|
||||
traits::Get,
|
||||
inherent::{InherentIdentifier, InherentData, MakeFatalError, ProvideInherent},
|
||||
};
|
||||
use frame_system::ensure_none;
|
||||
use crate::{
|
||||
disputes::DisputesHandler,
|
||||
inclusion,
|
||||
scheduler::{self, FreedReason},
|
||||
shared,
|
||||
ump,
|
||||
shared, ump,
|
||||
};
|
||||
use frame_support::{
|
||||
decl_error, decl_module, decl_storage,
|
||||
dispatch::DispatchResultWithPostInfo,
|
||||
ensure,
|
||||
inherent::{InherentData, InherentIdentifier, MakeFatalError, ProvideInherent},
|
||||
traits::Get,
|
||||
weights::{DispatchClass, Weight},
|
||||
};
|
||||
use frame_system::ensure_none;
|
||||
use primitives::v1::{
|
||||
BackedCandidate, InherentData as ParachainsInherentData, PARACHAINS_INHERENT_IDENTIFIER,
|
||||
};
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
const LOG_TARGET: &str = "runtime::inclusion-inherent";
|
||||
// In the future, we should benchmark these consts; these are all untested assumptions for now.
|
||||
@@ -249,7 +249,7 @@ fn limit_backed_candidates<T: Config>(
|
||||
return false
|
||||
}
|
||||
|
||||
code_upgrades +=1;
|
||||
code_upgrades += 1;
|
||||
}
|
||||
|
||||
true
|
||||
@@ -258,7 +258,9 @@ fn limit_backed_candidates<T: Config>(
|
||||
|
||||
// the weight of the paras inherent is already included in the current block weight,
|
||||
// so our operation is simple: if the block is currently overloaded, make this intrinsic smaller
|
||||
if frame_system::Pallet::<T>::block_weight().total() > <T as frame_system::Config>::BlockWeights::get().max_block {
|
||||
if frame_system::Pallet::<T>::block_weight().total() >
|
||||
<T as frame_system::Config>::BlockWeights::get().max_block
|
||||
{
|
||||
Vec::new()
|
||||
} else {
|
||||
backed_candidates
|
||||
@@ -271,47 +273,41 @@ impl<T: Config> ProvideInherent for Module<T> {
|
||||
const INHERENT_IDENTIFIER: InherentIdentifier = PARACHAINS_INHERENT_IDENTIFIER;
|
||||
|
||||
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||
let mut inherent_data: ParachainsInherentData<T::Header>
|
||||
= match data.get_data(&Self::INHERENT_IDENTIFIER)
|
||||
{
|
||||
Ok(Some(d)) => d,
|
||||
Ok(None) => return None,
|
||||
Err(_) => {
|
||||
log::warn!(
|
||||
target: LOG_TARGET,
|
||||
"ParachainsInherentData failed to decode",
|
||||
);
|
||||
let mut inherent_data: ParachainsInherentData<T::Header> =
|
||||
match data.get_data(&Self::INHERENT_IDENTIFIER) {
|
||||
Ok(Some(d)) => d,
|
||||
Ok(None) => return None,
|
||||
Err(_) => {
|
||||
log::warn!(target: LOG_TARGET, "ParachainsInherentData failed to decode",);
|
||||
|
||||
return None;
|
||||
}
|
||||
};
|
||||
return None
|
||||
},
|
||||
};
|
||||
|
||||
// filter out any unneeded dispute statements
|
||||
T::DisputesHandler::filter_multi_dispute_data(&mut inherent_data.disputes);
|
||||
|
||||
// Sanity check: session changes can invalidate an inherent, and we _really_ don't want that to happen.
|
||||
// See github.com/paritytech/polkadot/issues/1327
|
||||
let inherent_data = match Self::enter(
|
||||
frame_system::RawOrigin::None.into(),
|
||||
inherent_data.clone(),
|
||||
) {
|
||||
Ok(_) => inherent_data,
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
target: LOG_TARGET,
|
||||
"dropping signed_bitfields and backed_candidates because they produced \
|
||||
let inherent_data =
|
||||
match Self::enter(frame_system::RawOrigin::None.into(), inherent_data.clone()) {
|
||||
Ok(_) => inherent_data,
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
target: LOG_TARGET,
|
||||
"dropping signed_bitfields and backed_candidates because they produced \
|
||||
an invalid paras inherent: {:?}",
|
||||
err,
|
||||
);
|
||||
err,
|
||||
);
|
||||
|
||||
ParachainsInherentData {
|
||||
bitfields: Vec::new(),
|
||||
backed_candidates: Vec::new(),
|
||||
disputes: Vec::new(),
|
||||
parent_header: inherent_data.parent_header,
|
||||
}
|
||||
}
|
||||
};
|
||||
ParachainsInherentData {
|
||||
bitfields: Vec::new(),
|
||||
backed_candidates: Vec::new(),
|
||||
disputes: Vec::new(),
|
||||
parent_header: inherent_data.parent_header,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Some(Call::enter(inherent_data))
|
||||
}
|
||||
@@ -325,9 +321,7 @@ impl<T: Config> ProvideInherent for Module<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::mock::{
|
||||
new_test_ext, System, MockGenesisConfig, Test
|
||||
};
|
||||
use crate::mock::{new_test_ext, MockGenesisConfig, System, Test};
|
||||
|
||||
mod limit_backed_candidates {
|
||||
use super::*;
|
||||
@@ -345,7 +339,8 @@ mod tests {
|
||||
fn does_not_truncate_on_exactly_full_block() {
|
||||
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
|
||||
let backed_candidates = vec![BackedCandidate::default()];
|
||||
let max_block_weight = <Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let max_block_weight =
|
||||
<Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
// if the consumed resources are precisely equal to the max block weight, we do not truncate.
|
||||
System::set_block_consumed_resources(max_block_weight, 0);
|
||||
assert_eq!(limit_backed_candidates::<Test>(backed_candidates).len(), 1);
|
||||
@@ -356,7 +351,8 @@ mod tests {
|
||||
fn truncates_on_over_full_block() {
|
||||
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
|
||||
let backed_candidates = vec![BackedCandidate::default()];
|
||||
let max_block_weight = <Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let max_block_weight =
|
||||
<Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
// if the consumed resources are precisely equal to the max block weight, we do not truncate.
|
||||
System::set_block_consumed_resources(max_block_weight + 1, 0);
|
||||
assert_eq!(limit_backed_candidates::<Test>(backed_candidates).len(), 0);
|
||||
@@ -367,7 +363,8 @@ mod tests {
|
||||
fn all_backed_candidates_get_truncated() {
|
||||
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
|
||||
let backed_candidates = vec![BackedCandidate::default(); 10];
|
||||
let max_block_weight = <Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let max_block_weight =
|
||||
<Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
// if the consumed resources are precisely equal to the max block weight, we do not truncate.
|
||||
System::set_block_consumed_resources(max_block_weight + 1, 0);
|
||||
assert_eq!(limit_backed_candidates::<Test>(backed_candidates).len(), 0);
|
||||
@@ -388,9 +385,7 @@ mod tests {
|
||||
mod paras_inherent_weight {
|
||||
use super::*;
|
||||
|
||||
use crate::mock::{
|
||||
new_test_ext, System, MockGenesisConfig, Test
|
||||
};
|
||||
use crate::mock::{new_test_ext, MockGenesisConfig, System, Test};
|
||||
use primitives::v1::Header;
|
||||
|
||||
use frame_support::traits::UnfilteredDispatchable;
|
||||
@@ -425,7 +420,8 @@ mod tests {
|
||||
(backed_candidates.len() as Weight * BACKED_CANDIDATE_WEIGHT);
|
||||
|
||||
// we've used half the block weight; there's plenty of margin
|
||||
let max_block_weight = <Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let max_block_weight =
|
||||
<Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let used_block_weight = max_block_weight / 2;
|
||||
System::set_block_consumed_resources(used_block_weight, 0);
|
||||
|
||||
@@ -436,7 +432,9 @@ mod tests {
|
||||
disputes: Vec::new(),
|
||||
parent_header: default_header(),
|
||||
})
|
||||
.dispatch_bypass_filter(None.into()).unwrap_err().post_info;
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.unwrap_err()
|
||||
.post_info;
|
||||
|
||||
// we don't directly check the block's weight post-call. Instead, we check that the
|
||||
// call has returned the appropriate post-dispatch weight for refund, and trust
|
||||
@@ -470,7 +468,8 @@ mod tests {
|
||||
let expected_weight = MINIMAL_INCLUSION_INHERENT_WEIGHT;
|
||||
|
||||
// oops, looks like this mandatory call pushed the block weight over the limit
|
||||
let max_block_weight = <Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let max_block_weight =
|
||||
<Test as frame_system::Config>::BlockWeights::get().max_block;
|
||||
let used_block_weight = max_block_weight + 1;
|
||||
System::set_block_consumed_resources(used_block_weight, 0);
|
||||
|
||||
@@ -481,15 +480,13 @@ mod tests {
|
||||
disputes: Vec::new(),
|
||||
parent_header: header,
|
||||
})
|
||||
.dispatch_bypass_filter(None.into()).unwrap();
|
||||
.dispatch_bypass_filter(None.into())
|
||||
.unwrap();
|
||||
|
||||
// we don't directly check the block's weight post-call. Instead, we check that the
|
||||
// call has returned the appropriate post-dispatch weight for refund, and trust
|
||||
// Substrate to do the right thing with that information.
|
||||
assert_eq!(
|
||||
post_info.actual_weight.unwrap(),
|
||||
expected_weight,
|
||||
);
|
||||
assert_eq!(post_info.actual_weight.unwrap(), expected_weight,);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user