Unify code paths of create_inherent and enter (#7137)

* Remove redundant enter call.

* Remove optionality in dispute signature checking

* Make enter_inner and create_inherent the same.

* Remove redundant metric.

* Unification: enter and create_inherent.

* Remove `enter_inner` function.

* Remove dead code.

* Remove redundant import.

* Remove dead code in disputes.

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot runtime_parachains::paras_inherent

* ".git/.scripts/commands/bench/bench.sh" runtime kusama runtime_parachains::paras_inherent

* ".git/.scripts/commands/bench/bench.sh" runtime westend runtime_parachains::paras_inherent

* Merge fix.

* Fix tests.

* Remove obsolete comment.

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot runtime_parachains::paras_inherent

* ".git/.scripts/commands/bench/bench.sh" runtime westend runtime_parachains::paras_inherent

* ".git/.scripts/commands/bench/bench.sh" runtime kusama runtime_parachains::paras_inherent

* Review remarks, fixes.

* Guide updates.

* Fmt.

* ".git/.scripts/commands/bench/bench.sh" runtime polkadot runtime_parachains::paras_inherent

---------

Co-authored-by: eskimor <eskimor@no-such-url.com>
Co-authored-by: command-bot <>
This commit is contained in:
eskimor
2023-06-14 10:57:06 +02:00
committed by GitHub
parent e71c541ede
commit 596a9ccd02
13 changed files with 676 additions and 1550 deletions
+22 -93
View File
@@ -136,19 +136,6 @@ impl<BlockNumber> SlashingHandler<BlockNumber> for () {
fn initializer_on_new_session(_: SessionIndex) {}
}
/// Binary discriminator to determine if the expensive signature
/// checks are necessary.
#[derive(Clone, Copy)]
pub enum VerifyDisputeSignatures {
/// Yes, verify the signatures.
Yes,
/// No, skip the signature verification.
///
/// Only done if there exists an invariant that
/// can guaranteed the signature was checked before.
Skip,
}
/// Provide a `Ordering` for the two provided dispute statement sets according to the
/// following prioritization:
/// 1. Prioritize local disputes over remote disputes
@@ -184,36 +171,6 @@ where
}
}
use super::paras_inherent::IsSortedBy;
/// Returns `true` if duplicate items were found, otherwise `false`.
///
/// `check_equal(a: &T, b: &T)` _must_ return `true`, iff `a` and `b` are equal, otherwise `false.
/// The definition of _equal_ is to be defined by the user.
///
/// Attention: Requires the input `iter` to be sorted, such that _equals_
/// would be adjacent in respect whatever `check_equal` defines as equality!
fn contains_duplicates_in_sorted_iter<
'a,
T: 'a,
I: 'a + IntoIterator<Item = &'a T>,
C: 'static + FnMut(&T, &T) -> bool,
>(
iter: I,
mut check_equal: C,
) -> bool {
let mut iter = iter.into_iter();
if let Some(mut previous) = iter.next() {
while let Some(current) = iter.next() {
if check_equal(previous, current) {
return true
}
previous = current;
}
}
return false
}
/// Hook into disputes handling.
///
/// Allows decoupling parachains handling from disputes so that it can
@@ -223,23 +180,6 @@ pub trait DisputesHandler<BlockNumber: Ord> {
/// any new parachain blocks for backing or inclusion.
fn is_frozen() -> bool;
/// Assure sanity
fn assure_deduplicated_and_sorted(statement_sets: &MultiDisputeStatementSet) -> Result<(), ()> {
if !IsSortedBy::is_sorted_by(
statement_sets.as_slice(),
dispute_ordering_compare::<Self, BlockNumber>,
) {
return Err(())
}
// Sorted, so according to session and candidate hash, this will detect duplicates.
if contains_duplicates_in_sorted_iter(statement_sets, |previous, current| {
current.session == previous.session && current.candidate_hash == previous.candidate_hash
}) {
return Err(())
}
Ok(())
}
/// Remove dispute statement duplicates and sort the non-duplicates based on
/// local (lower indicies) vs remotes (higher indices) and age (older with lower indices).
///
@@ -274,7 +214,6 @@ pub trait DisputesHandler<BlockNumber: Ord> {
fn filter_dispute_data(
statement_set: DisputeStatementSet,
post_conclusion_acceptance_period: BlockNumber,
verify_sigs: VerifyDisputeSignatures,
) -> Option<CheckedDisputeStatementSet>;
/// Handle sets of dispute statements corresponding to 0 or more candidates.
@@ -322,7 +261,6 @@ impl<BlockNumber: Ord> DisputesHandler<BlockNumber> for () {
fn filter_dispute_data(
_set: DisputeStatementSet,
_post_conclusion_acceptance_period: BlockNumber,
_verify_sigs: VerifyDisputeSignatures,
) -> Option<CheckedDisputeStatementSet> {
None
}
@@ -371,14 +309,9 @@ where
fn filter_dispute_data(
set: DisputeStatementSet,
post_conclusion_acceptance_period: T::BlockNumber,
verify_sigs: VerifyDisputeSignatures,
) -> Option<CheckedDisputeStatementSet> {
pallet::Pallet::<T>::filter_dispute_data(
&set,
post_conclusion_acceptance_period,
verify_sigs,
)
.filter_statement_set(set)
pallet::Pallet::<T>::filter_dispute_data(&set, post_conclusion_acceptance_period)
.filter_statement_set(set)
}
fn process_checked_multi_dispute_data(
@@ -1005,7 +938,6 @@ impl<T: Config> Pallet<T> {
fn filter_dispute_data(
set: &DisputeStatementSet,
post_conclusion_acceptance_period: <T as frame_system::Config>::BlockNumber,
verify_sigs: VerifyDisputeSignatures,
) -> StatementSetFilter {
let mut filter = StatementSetFilter::RemoveIndices(Vec::new());
@@ -1068,29 +1000,26 @@ impl<T: Config> Pallet<T> {
},
};
// Avoid checking signatures repeatedly.
if let VerifyDisputeSignatures::Yes = verify_sigs {
// Check signature after attempting import.
//
// Since we expect that this filter will be applied to
// disputes long after they're concluded, 99% of the time,
// the duplicate filter above will catch them before needing
// to do a heavy signature check.
//
// This is only really important until the post-conclusion acceptance threshold
// is reached, and then no part of this loop will be hit.
if let Err(()) = check_signature(
&validator_public,
set.candidate_hash,
set.session,
statement,
signature,
) {
importer.undo(undo);
filter.remove_index(i);
continue
}
}
// Check signature after attempting import.
//
// Since we expect that this filter will be applied to
// disputes long after they're concluded, 99% of the time,
// the duplicate filter above will catch them before needing
// to do a heavy signature check.
//
// This is only really important until the post-conclusion acceptance threshold
// is reached, and then no part of this loop will be hit.
if let Err(()) = check_signature(
&validator_public,
set.candidate_hash,
set.session,
statement,
signature,
) {
importer.undo(undo);
filter.remove_index(i);
continue
};
}
importer.finish()