Use same fmt and clippy configs as in Substrate (#7611)

* Use same rustfmt.toml as Substrate

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* format format file

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Format with new config

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add Substrate Clippy config

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Print Clippy version in CI

Otherwise its difficult to reproduce locally.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Make fmt happy

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update node/core/pvf/src/error.rs

Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>

* Update node/core/pvf/src/error.rs

Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Tsvetomir Dimitrov <tsvetomir@parity.io>
This commit is contained in:
Oliver Tale-Yazdi
2023-08-14 16:29:29 +02:00
committed by GitHub
parent ac435c96cf
commit 342d720573
203 changed files with 1880 additions and 1504 deletions
@@ -285,8 +285,9 @@ pub mod pallet {
}
impl<T: Config> Pallet<T> {
/// Create the `ParachainsInherentData` that gets passed to [`Self::enter`] in [`Self::create_inherent`].
/// This code is pulled out of [`Self::create_inherent`] so it can be unit tested.
/// Create the `ParachainsInherentData` that gets passed to [`Self::enter`] in
/// [`Self::create_inherent`]. This code is pulled out of [`Self::create_inherent`] so it can be
/// unit tested.
fn create_inherent_inner(data: &InherentData) -> Option<ParachainsInherentData<HeaderFor<T>>> {
let parachains_inherent_data = match data.get_data(&Self::INHERENT_IDENTIFIER) {
Ok(Some(d)) => d,
@@ -313,11 +314,11 @@ impl<T: Config> Pallet<T> {
/// The given inherent data is processed and state is altered accordingly. If any data could
/// not be applied (inconsitencies, weight limit, ...) it is removed.
///
/// When called from `create_inherent` the `context` must be set to `ProcessInherentDataContext::ProvideInherent`
/// so it guarantees the invariant that inherent is not overweight.
///
/// It is **mandatory** that calls from `enter` set `context` to `ProcessInherentDataContext::Enter` to ensure
/// the weight invariant is checked.
/// When called from `create_inherent` the `context` must be set to
/// `ProcessInherentDataContext::ProvideInherent` so it guarantees the invariant that inherent
/// is not overweight.
/// It is **mandatory** that calls from `enter` set `context` to
/// `ProcessInherentDataContext::Enter` to ensure the weight invariant is checked.
///
/// Returns: Result containing processed inherent data and weight, the processed inherent would
/// consume.
@@ -379,8 +380,8 @@ impl<T: Config> Pallet<T> {
let dispatch_class = DispatchClass::Mandatory;
let max_block_weight_full = <T as frame_system::Config>::BlockWeights::get();
log::debug!(target: LOG_TARGET, "Max block weight: {}", max_block_weight_full.max_block);
// Get max block weight for the mandatory class if defined, otherwise total max weight of
// the block.
// Get max block weight for the mandatory class if defined, otherwise total max weight
// of the block.
let max_weight = max_block_weight_full
.per_class
.get(dispatch_class)
@@ -412,7 +413,8 @@ impl<T: Config> Pallet<T> {
T::DisputesHandler::filter_dispute_data(set, post_conclusion_acceptance_period)
};
// Limit the disputes first, since the following statements depend on the votes include here.
// Limit the disputes first, since the following statements depend on the votes include
// here.
let (checked_disputes_sets, checked_disputes_sets_consumed_weight) =
limit_and_sanitize_disputes::<T, _>(
disputes,
@@ -449,8 +451,8 @@ impl<T: Config> Pallet<T> {
}
all_weight_after
} else {
// This check is performed in the context of block execution. Ensures inherent weight invariants guaranteed
// by `create_inherent_data` for block authorship.
// This check is performed in the context of block execution. Ensures inherent weight
// invariants guaranteed by `create_inherent_data` for block authorship.
if all_weight_before.any_gt(max_block_weight) {
log::error!(
"Overweight para inherent data reached the runtime {:?}: {} > {}",
@@ -714,13 +716,14 @@ fn random_sel<X, F: Fn(&X) -> Weight>(
/// If there is sufficient space, all bitfields and all candidates
/// will be included.
///
/// Otherwise tries to include all disputes, and then tries to fill the remaining space with bitfields and then candidates.
/// Otherwise tries to include all disputes, and then tries to fill the remaining space with
/// bitfields and then candidates.
///
/// The selection process is random. For candidates, there is an exception for code upgrades as they are preferred.
/// And for disputes, local and older disputes are preferred (see `limit_and_sanitize_disputes`).
/// for backed candidates, since with a increasing number of parachains their chances of
/// inclusion become slim. All backed candidates are checked beforehands in `fn create_inherent_inner`
/// which guarantees sanity.
/// The selection process is random. For candidates, there is an exception for code upgrades as they
/// are preferred. And for disputes, local and older disputes are preferred (see
/// `limit_and_sanitize_disputes`). for backed candidates, since with a increasing number of
/// parachains their chances of inclusion become slim. All backed candidates are checked
/// beforehands in `fn create_inherent_inner` which guarantees sanity.
///
/// Assumes disputes are already filtered by the time this is called.
///
@@ -977,7 +980,8 @@ fn compute_entropy<T: Config>(parent_hash: T::Hash) -> [u8; 32] {
/// 1. If weight is exceeded by locals, pick the older ones (lower indices)
/// until the weight limit is reached.
///
/// Returns the consumed weight amount, that is guaranteed to be less than the provided `max_consumable_weight`.
/// Returns the consumed weight amount, that is guaranteed to be less than the provided
/// `max_consumable_weight`.
fn limit_and_sanitize_disputes<
T: Config,
CheckValidityFn: FnMut(DisputeStatementSet) -> Option<CheckedDisputeStatementSet>,
@@ -68,9 +68,9 @@ mod enter {
}
#[test]
// Validate that if we create 2 backed candidates which are assigned to 2 cores that will be freed via
// becoming fully available, the backed candidates will not be filtered out in `create_inherent` and
// will not cause `enter` to early.
// Validate that if we create 2 backed candidates which are assigned to 2 cores that will be
// freed via becoming fully available, the backed candidates will not be filtered out in
// `create_inherent` and will not cause `enter` to early.
fn include_backed_candidates() {
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
let dispute_statements = BTreeMap::new();
@@ -252,7 +252,8 @@ mod enter {
let expected_para_inherent_data = scenario.data.clone();
// Check the para inherent data is as expected:
// * 1 bitfield per validator (5 validators per core, 3 disputes => 3 cores, 15 validators)
// * 1 bitfield per validator (5 validators per core, 3 disputes => 3 cores, 15
// validators)
assert_eq!(expected_para_inherent_data.bitfields.len(), 15);
// * 0 backed candidate per core
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 0);
@@ -389,7 +390,8 @@ mod enter {
let expected_para_inherent_data = scenario.data.clone();
// Check the para inherent data is as expected:
// * 1 bitfield per validator (4 validators per core, 2 backed candidates, 3 disputes => 4*5 = 20)
// * 1 bitfield per validator (4 validators per core, 2 backed candidates, 3 disputes =>
// 4*5 = 20)
assert_eq!(expected_para_inherent_data.bitfields.len(), 20);
// * 2 backed candidates
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 2);
@@ -408,7 +410,8 @@ mod enter {
Pallet::<Test>::create_inherent_inner(&inherent_data.clone()).unwrap();
assert!(limit_inherent_data != expected_para_inherent_data);
// Three disputes is over weight (see previous test), so we expect to only see 2 disputes
// Three disputes is over weight (see previous test), so we expect to only see 2
// disputes
assert_eq!(limit_inherent_data.disputes.len(), 2);
// Ensure disputes are filtered as expected
assert_eq!(limit_inherent_data.disputes[0].session, 1);
@@ -418,7 +421,8 @@ mod enter {
limit_inherent_data.bitfields.len(),
expected_para_inherent_data.bitfields.len()
);
// Ensure that all backed candidates are filtered out as either would make the block over weight
// Ensure that all backed candidates are filtered out as either would make the block
// over weight
assert_eq!(limit_inherent_data.backed_candidates.len(), 0);
assert_ok!(Pallet::<Test>::enter(
@@ -470,7 +474,8 @@ mod enter {
let expected_para_inherent_data = scenario.data.clone();
// Check the para inherent data is as expected:
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 3 disputes => 4*5 = 20),
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 3 disputes =>
// 4*5 = 20),
assert_eq!(expected_para_inherent_data.bitfields.len(), 25);
// * 2 backed candidates,
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 2);
@@ -493,14 +498,16 @@ mod enter {
assert!(inherent_data_weight(&limit_inherent_data)
.all_lte(max_block_weight_proof_size_adjusted()));
// Three disputes is over weight (see previous test), so we expect to only see 2 disputes
// Three disputes is over weight (see previous test), so we expect to only see 2
// disputes
assert_eq!(limit_inherent_data.disputes.len(), 2);
// Ensure disputes are filtered as expected
assert_eq!(limit_inherent_data.disputes[0].session, 1);
assert_eq!(limit_inherent_data.disputes[1].session, 2);
// Ensure all bitfields are included as these are still not over weight
assert_eq!(limit_inherent_data.bitfields.len(), 20,);
// Ensure that all backed candidates are filtered out as either would make the block over weight
// Ensure that all backed candidates are filtered out as either would make the block
// over weight
assert_eq!(limit_inherent_data.backed_candidates.len(), 0);
assert_ok!(Pallet::<Test>::enter(
@@ -551,7 +558,8 @@ mod enter {
let expected_para_inherent_data = scenario.data.clone();
// Check the para inherent data is as expected:
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 3 disputes => 5*5 = 25)
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 3 disputes =>
// 5*5 = 25)
assert_eq!(expected_para_inherent_data.bitfields.len(), 25);
// * 2 backed candidates
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 2);
@@ -632,7 +640,8 @@ mod enter {
.any_lt(inherent_data_weight(&expected_para_inherent_data)));
// Check the para inherent data is as expected:
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 3 disputes => 5*5 = 25)
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 3 disputes =>
// 5*5 = 25)
assert_eq!(expected_para_inherent_data.bitfields.len(), 25);
// * 2 backed candidates
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 2);
@@ -645,7 +654,8 @@ mod enter {
let limit_inherent_data =
Pallet::<Test>::create_inherent_inner(&inherent_data.clone()).unwrap();
// Expect that inherent data is filtered to include only 1 backed candidate and 2 disputes
// Expect that inherent data is filtered to include only 1 backed candidate and 2
// disputes
assert!(limit_inherent_data != expected_para_inherent_data);
assert!(
max_block_weight_proof_size_adjusted()
@@ -727,7 +737,8 @@ mod enter {
.unwrap();
let limit_inherent_data =
Pallet::<Test>::create_inherent_inner(&inherent_data.clone()).unwrap();
// Expect that inherent data is filtered to include only 1 backed candidate and 2 disputes
// Expect that inherent data is filtered to include only 1 backed candidate and 2
// disputes
assert!(limit_inherent_data != expected_para_inherent_data);
assert!(
max_block_weight_proof_size_adjusted()
@@ -792,7 +803,8 @@ mod enter {
let limit_inherent_data =
Pallet::<Test>::create_inherent_inner(&inherent_data.clone()).unwrap();
// Expect that inherent data is filtered to include only 1 backed candidate and 2 disputes
// Expect that inherent data is filtered to include only 1 backed candidate and 2
// disputes
assert!(limit_inherent_data != expected_para_inherent_data);
assert!(
max_block_weight_proof_size_adjusted()
@@ -841,7 +853,8 @@ mod enter {
.any_lt(inherent_data_weight(&expected_para_inherent_data)));
// Check the para inherent data is as expected:
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 0 disputes => 2*5 = 10)
// * 1 bitfield per validator (5 validators per core, 2 backed candidates, 0 disputes =>
// 2*5 = 10)
assert_eq!(expected_para_inherent_data.bitfields.len(), 10);
// * 2 backed candidates
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 2);
@@ -854,7 +867,8 @@ mod enter {
let limit_inherent_data =
Pallet::<Test>::create_inherent_inner(&inherent_data.clone()).unwrap();
// Expect that inherent data is filtered to include only 1 backed candidate and 2 disputes
// Expect that inherent data is filtered to include only 1 backed candidate and 2
// disputes
assert!(limit_inherent_data != expected_para_inherent_data);
assert!(
max_block_weight_proof_size_adjusted()
@@ -903,7 +917,8 @@ mod enter {
.any_lt(inherent_data_weight(&expected_para_inherent_data)));
// Check the para inherent data is as expected:
// * 1 bitfield per validator (5 validators per core, 30 backed candidates, 3 disputes => 5*33 = 165)
// * 1 bitfield per validator (5 validators per core, 30 backed candidates, 3 disputes
// => 5*33 = 165)
assert_eq!(expected_para_inherent_data.bitfields.len(), 165);
// * 30 backed candidates
assert_eq!(expected_para_inherent_data.backed_candidates.len(), 30);