mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 07:11:03 +00:00
Dispute spam protection (#4134)
* Mostly notes. * Better error messages. * Introduce Fatal/NonFatal + drop back channel participation - Fatal/NonFatal - in order to make it easier to use utility functions. - We drop the back channel in dispute participation as it won't be needed any more. * Better error messages. * Utility function for receiving `CandidateEvent`s. * Ordering module typechecks. * cargo fmt * Prepare spam slots module. * Implement SpamSlots mechanism. * Implement queues. * cargo fmt * Participation. * Participation taking shape. * Finish participation. * cargo fmt * Cleanup. * WIP: Cleanup + Integration. * Make `RollingSessionWindow` initialized by default. * Make approval voting typecheck. * Get rid of lazy_static & fix approval voting tests * Move `SessionWindowSize` to node primitives. * Implement dispute coordinator initialization. * cargo fmt * Make queues return error instead of boolean. * Initialized: WIP * Introduce chain api for getting finalized block. * Fix ordering to only prune candidates on finalized events. * Pruning of old sessions in spam slots. * New import logic. * Make everything typecheck. * Fix warnings. * Get rid of obsolete dispute-participation. * Fixes. * Add back accidentelly deleted Cargo.lock * Deliver disputes in an ordered fashion. * Add module docs for errors * Use type synonym. * hidden docs. * Fix overseer tests. * Ordering provider taking `CandidateReceipt`. ... To be kicked on one next commit. * Fix ordering to use relay_parent as included block is not unique per candidate. * Add comment in ordering.rs. * Take care of duplicate entries in queues. * Better spam slots. * Review remarks + docs. * Fix db tests. * Participation tests. * Also scrape votes on first leaf for good measure. * Make tests typecheck. * Spelling. * Only participate in actual disputes, not on every import. * Don't account backing votes to spam slots. * Fix more tests. * Don't participate if we don't have keys. * Fix tests, typos and warnings. * Fix merge error. * Spelling fixes. * Add missing docs. * Queue tests. * More tests. * Add metrics + don't short circuit import. * Basic test for ordering provider. * Import fix. * Remove dead link. * One more dead link. Co-authored-by: Lldenaurois <Ljdenaurois@gmail.com>
This commit is contained in:
@@ -65,12 +65,6 @@ pub const VALIDATION_CODE_BOMB_LIMIT: usize = (MAX_CODE_SIZE * 4u32) as usize;
|
||||
/// The bomb limit for decompressing PoV blobs.
|
||||
pub const POV_BOMB_LIMIT: usize = (MAX_POV_SIZE * 4u32) as usize;
|
||||
|
||||
/// It would be nice to draw this from the chain state, but we have no tools for it right now.
|
||||
/// On Polkadot this is 1 day, and on Kusama it's 6 hours.
|
||||
///
|
||||
/// Number of sessions we want to consider in disputes.
|
||||
pub const DISPUTE_WINDOW: SessionIndex = 6;
|
||||
|
||||
/// The amount of time to spend on execution during backing.
|
||||
pub const BACKING_EXECUTION_TIMEOUT: Duration = Duration::from_secs(2);
|
||||
|
||||
@@ -82,6 +76,59 @@ pub const BACKING_EXECUTION_TIMEOUT: Duration = Duration::from_secs(2);
|
||||
/// dispute participants.
|
||||
pub const APPROVAL_EXECUTION_TIMEOUT: Duration = Duration::from_secs(6);
|
||||
|
||||
/// Type of a session window size.
|
||||
///
|
||||
/// We are not using `NonZeroU32` here because `expect` and `unwrap` are not yet const, so global
|
||||
/// constants of `SessionWindowSize` would require `lazy_static` in that case.
|
||||
///
|
||||
/// See: https://github.com/rust-lang/rust/issues/67441
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct SessionWindowSize(SessionIndex);
|
||||
|
||||
#[macro_export]
|
||||
/// Create a new checked `SessionWindowSize`
|
||||
///
|
||||
/// which cannot be 0.
|
||||
macro_rules! new_session_window_size {
|
||||
(0) => {
|
||||
compile_error!("Must be non zero");
|
||||
};
|
||||
(0_u32) => {
|
||||
compile_error!("Must be non zero");
|
||||
};
|
||||
(0 as u32) => {
|
||||
compile_error!("Must be non zero");
|
||||
};
|
||||
(0 as _) => {
|
||||
compile_error!("Must be non zero");
|
||||
};
|
||||
($l:literal) => {
|
||||
SessionWindowSize::unchecked_new($l as _)
|
||||
};
|
||||
}
|
||||
|
||||
/// It would be nice to draw this from the chain state, but we have no tools for it right now.
|
||||
/// On Polkadot this is 1 day, and on Kusama it's 6 hours.
|
||||
///
|
||||
/// Number of sessions we want to consider in disputes.
|
||||
pub const DISPUTE_WINDOW: SessionWindowSize = new_session_window_size!(6);
|
||||
|
||||
impl SessionWindowSize {
|
||||
/// Get the value as `SessionIndex` for doing comparisons with those.
|
||||
pub fn get(self) -> SessionIndex {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Helper function for `new_session_window_size`.
|
||||
///
|
||||
/// Don't use it. The only reason it is public, is because otherwise the
|
||||
/// `new_session_window_size` macro would not work outside of this module.
|
||||
#[doc(hidden)]
|
||||
pub const fn unchecked_new(size: SessionIndex) -> Self {
|
||||
Self(size)
|
||||
}
|
||||
}
|
||||
|
||||
/// The cumulative weight of a block in a fork-choice rule.
|
||||
pub type BlockWeight = u32;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user