Skip to content

Commit

Permalink
Offences report system rework (paritytech#13425)
Browse files Browse the repository at this point in the history
* Experiments with common equivocation trait

* Improved equivocation trait

* Fix grandpa equivocation implementation

* Remove some cruft

* Remove some more cruft

* More generic naming

* Simplification of offences manipilation

* More refactory

* Some prograss with the encapsulation of offence report system

* Finally unit type works as a universal null report system

* Align substrate node code

* Further simplification

* Fix test utils

* Remove not required associated type

* Fix benches

* Rollback to prev field name

* Box big params

* Fix typo

* Remove new tag computation

* Remove default implementations

* Better docs

* Return 'Result' instead of bool

* Change offence report system return types

* Some renaming and documentation

* Improve documentation

* More abstract offence report system

* Rename 'consume_evidence' to 'process_evidence'

* Further docs refinements

* Doc for dummy offence report

* Fix rustdoc

* Fix after master merge

* Apply code review suggestions

* Improve docs
  • Loading branch information
davxy authored and ukint-vs committed Apr 10, 2023
1 parent d6ac358 commit 484ca1b
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 716 deletions.
15 changes: 3 additions & 12 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,12 @@ impl pallet_aura::Config for Runtime {
impl pallet_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;

type KeyOwnerProofSystem = ();

type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;

type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
GrandpaId,
)>>::IdentificationTuple;

type HandleEquivocation = ();

type WeightInfo = ();
type MaxAuthorities = ConstU32<32>;
type MaxSetIdSessionEntries = ConstU64<0>;

type KeyOwnerProof = sp_core::Void;
type EquivocationReportSystem = ();
}

impl pallet_timestamp::Config for Runtime {
Expand Down
53 changes: 16 additions & 37 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ pub mod assets_api;
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

/// Max size for serialized extrinsic params for this testing runtime.
/// This is a quite arbitrary but empirically battle tested value.
#[cfg(test)]
pub const CALL_PARAMS_MAX_SIZE: usize = 208;

/// Wasm binary unwrapped. If built with `SKIP_WASM_BUILD`, the function panics.
#[cfg(feature = "std")]
pub fn wasm_binary_unwrap() -> &'static [u8] {
Expand Down Expand Up @@ -399,24 +404,12 @@ impl pallet_babe::Config for Runtime {
type ExpectedBlockTime = ExpectedBlockTime;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
type DisabledValidators = Session;

type KeyOwnerProofSystem = Historical;

type KeyOwnerProof = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
pallet_babe::AuthorityId,
)>>::Proof;

type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
pallet_babe::AuthorityId,
)>>::IdentificationTuple;

type HandleEquivocation =
pallet_babe::EquivocationHandler<Self::KeyOwnerIdentification, Offences, ReportLongevity>;

type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
type EquivocationReportSystem =
pallet_babe::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}

parameter_types! {
Expand Down Expand Up @@ -1328,26 +1321,12 @@ parameter_types! {

impl pallet_grandpa::Config for Runtime {
type RuntimeEvent = RuntimeEvent;

type KeyOwnerProofSystem = Historical;

type KeyOwnerProof =
<Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;

type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(
KeyTypeId,
GrandpaId,
)>>::IdentificationTuple;

type HandleEquivocation = pallet_grandpa::EquivocationHandler<
Self::KeyOwnerIdentification,
Offences,
ReportLongevity,
>;

type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type EquivocationReportSystem =
pallet_grandpa::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}

parameter_types! {
Expand Down Expand Up @@ -2483,10 +2462,10 @@ mod tests {
fn call_size() {
let size = core::mem::size_of::<RuntimeCall>();
assert!(
size <= 208,
"size of RuntimeCall {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the
size of RuntimeCall.
If the limit is too strong, maybe consider increase the limit to 300.",
size <= CALL_PARAMS_MAX_SIZE,
"size of RuntimeCall {} is more than {CALL_PARAMS_MAX_SIZE} bytes.
Some calls have too big arguments, use Box to reduce the size of RuntimeCall.
If the limit is too strong, maybe consider increase the limit.",
size,
);
}
Expand Down
Loading

0 comments on commit 484ca1b

Please sign in to comment.