mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 08:21:03 +00:00
aura, babe: don't allow disabled validators to build blocks (#9414)
* frame-support: add trait for checking disabled validators * pallet-session: implement DisabledValidators trait * pallet-babe: check for disabled validators * pallet-babe: add test for disabled validators * pallet-aura: check for disabled validators * pallet-aura: add test for disabled validators * runtime: fix missing DisableValidator * test-runtime: add missing DisabledValidators * frame-support: clean up doc Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -19,7 +19,12 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::mock::{new_test_ext, Aura};
|
||||
use crate::mock::{new_test_ext, Aura, MockDisabledValidators, System};
|
||||
use codec::Encode;
|
||||
use frame_support::traits::OnInitialize;
|
||||
use frame_system::InitKind;
|
||||
use sp_consensus_aura::{Slot, AURA_ENGINE_ID};
|
||||
use sp_runtime::{Digest, DigestItem};
|
||||
|
||||
#[test]
|
||||
fn initial_values() {
|
||||
@@ -28,3 +33,24 @@ fn initial_values() {
|
||||
assert_eq!(Aura::authorities().len(), 4);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "Validator with index 1 is disabled and should not be attempting to author blocks."
|
||||
)]
|
||||
fn disabled_validators_cannot_author_blocks() {
|
||||
new_test_ext(vec![0, 1, 2, 3]).execute_with(|| {
|
||||
// slot 1 should be authored by validator at index 1
|
||||
let slot = Slot::from(1);
|
||||
let pre_digest =
|
||||
Digest { logs: vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())] };
|
||||
|
||||
System::initialize(&42, &System::parent_hash(), &pre_digest, InitKind::Full);
|
||||
|
||||
// let's disable the validator
|
||||
MockDisabledValidators::disable_validator(1);
|
||||
|
||||
// and we should not be able to initialize the block
|
||||
Aura::on_initialize(42);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user