-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
External operator slashes info pallet (#727)
* Add pallet_external_validators, remove ValidatorManager * Rename extrinsics and add tests * Fix tests * Fix benchmarks * typescript-api * first version stored * Add traits * slowly add stuff * Some PR comments * Change era every n sessions * confirmed and unconfirmed, tests * rename pallet * WIP integration test and hooks * good tests for once * Benchmark new extrinsics * Migrate queued keys instead of current validators * typescript-api * Add era index to hook * impl for tuples * Make tests pass * adapt * continue progress * remove comments * Add integration tests * fixes but pallet incorporated to runtime * added sessionINterface * add offence handler * current era and active era * typescript-api * add invulnerables * Add one typescript test * a few more fixes * more tests * console log * benchmarks * benchmarks generated * a little bit of cleanup * a bit more cleanup * zepter * toml-maid * refactor tests * run_to_block not working * a few fixes2 * Unit tests still not working * Fix unit tests * test babe slashes * slashes tests ts * Start era 0 in session 0 * more slashing tests * one more test * Rewrite pallet logic, copy it from pallet_staking * Test hook calls * testing finished * typescript-api * Add era session start to trait * test cleanup * fmt and typescript api * a few fixes here and there * change a few things * pr comments * wip * typescript-api * typescript-api * new tests * typescript api * try now * Test migration * fix last test * clippy * slashes formatting * ts api * api * fix clippy * typescript api new * wip * fmt * first pr review fixes * more pr feedback * more fmt and pr fixes * remove weight * add doc * add correct typescript api --------- Co-authored-by: Tomasz Polaczyk <[email protected]>
- Loading branch information
1 parent
fafdcc9
commit f8b66f3
Showing
30 changed files
with
3,654 additions
and
846 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
[package] | ||
name = "pallet-external-validator-slashes" | ||
authors = { workspace = true } | ||
description = "External validator info slashes" | ||
edition = "2021" | ||
license = "GPL-3.0-only" | ||
version = "0.1.0" | ||
|
||
[package.metadata.docs.rs] | ||
targets = [ "x86_64-unknown-linux-gnu" ] | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
frame-benchmarking = { workspace = true, optional = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
log = { workspace = true } | ||
pallet-session = { workspace = true } | ||
pallet-staking = { workspace = true } | ||
parity-scale-codec = { workspace = true, features = [ "derive", "max-encoded-len" ] } | ||
scale-info = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-staking = { workspace = true } | ||
sp-std = { workspace = true } | ||
tp-traits = { workspace = true } | ||
|
||
[dev-dependencies] | ||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
|
||
[features] | ||
default = [ "std" ] | ||
std = [ | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"log/std", | ||
"pallet-session/std", | ||
"pallet-staking/std", | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-staking/std", | ||
"sp-std/std", | ||
"tp-traits/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"pallet-staking/runtime-benchmarks", | ||
"scale-info/std", | ||
"sp-runtime/runtime-benchmarks", | ||
"sp-staking/runtime-benchmarks", | ||
"tp-traits/runtime-benchmarks", | ||
] | ||
|
||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"pallet-session/try-runtime", | ||
"pallet-staking/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (C) Moondance Labs Ltd. | ||
// This file is part of Tanssi. | ||
|
||
// Tanssi is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Tanssi is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Tanssi. If not, see <http://www.gnu.org/licenses/> | ||
|
||
//! Benchmarking setup for pallet-external-validator-slashes | ||
|
||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as ExternalValidatorSlashes; | ||
use { | ||
frame_benchmarking::{v2::*, BenchmarkError}, | ||
frame_system::RawOrigin, | ||
pallet_session::{self as session}, | ||
sp_runtime::traits::TrailingZeroInput, | ||
sp_std::prelude::*, | ||
}; | ||
|
||
const MAX_SLASHES: u32 = 1000; | ||
|
||
#[allow(clippy::multiple_bound_locations)] | ||
#[benchmarks(where T: session::Config)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn cancel_deferred_slash(s: Linear<1, MAX_SLASHES>) -> Result<(), BenchmarkError> { | ||
let mut existing_slashes = Vec::new(); | ||
let era = T::EraIndexProvider::active_era().index; | ||
let dummy = || T::AccountId::decode(&mut TrailingZeroInput::zeroes()).unwrap(); | ||
for _ in 0..MAX_SLASHES { | ||
existing_slashes.push(Slash::<T::AccountId, T::SlashId>::default_from(dummy())); | ||
} | ||
Slashes::<T>::insert( | ||
era.saturating_add(T::SlashDeferDuration::get()) | ||
.saturating_add(One::one()), | ||
&existing_slashes, | ||
); | ||
let slash_indices: Vec<u32> = (0..s).collect(); | ||
|
||
#[extrinsic_call] | ||
_( | ||
RawOrigin::Root, | ||
era.saturating_add(T::SlashDeferDuration::get()) | ||
.saturating_add(One::one()), | ||
slash_indices, | ||
); | ||
|
||
assert_eq!( | ||
Slashes::<T>::get( | ||
&era.saturating_add(T::SlashDeferDuration::get()) | ||
.saturating_add(One::one()) | ||
) | ||
.len(), | ||
(MAX_SLASHES - s) as usize | ||
); | ||
Ok(()) | ||
} | ||
|
||
#[benchmark] | ||
fn force_inject_slash() -> Result<(), BenchmarkError> { | ||
let era = T::EraIndexProvider::active_era().index; | ||
let dummy = || T::AccountId::decode(&mut TrailingZeroInput::zeroes()).unwrap(); | ||
#[extrinsic_call] | ||
_(RawOrigin::Root, era, dummy(), Perbill::from_percent(50)); | ||
|
||
assert_eq!( | ||
Slashes::<T>::get( | ||
&era.saturating_add(T::SlashDeferDuration::get()) | ||
.saturating_add(One::one()) | ||
) | ||
.len(), | ||
1_usize | ||
); | ||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
ExternalValidatorSlashes, | ||
crate::mock::new_test_ext(), | ||
crate::mock::Test, | ||
); | ||
} |
Oops, something went wrong.