Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit c9e7151

Browse files
authored
Merge pull request #60 from PureStake/girazoki-make-mandatory-kick-off
Make kick_off_authorship_validation mandatory again
2 parents 24a19d2 + 8935916 commit c9e7151

5 files changed

Lines changed: 125 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/author-inherent/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch =
2626
[dev-dependencies]
2727
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2828
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
29+
frame-support-test = { version = "3.0.0", git = "https://github.com/paritytech/substrate", branch = "master" }
2930

3031
[features]
3132
default = [ "std" ]
@@ -48,4 +49,4 @@ std = [
4849
runtime-benchmarks = [
4950
"frame-benchmarking",
5051
"nimbus-primitives/runtime-benchmarks",
51-
]
52+
]

pallets/author-inherent/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ mod benchmarks;
3939

4040
pub mod weights;
4141

42+
#[cfg(test)]
43+
mod mock;
44+
#[cfg(test)]
45+
mod tests;
46+
4247
#[frame_support::pallet]
4348
pub mod pallet {
4449
use super::*;
@@ -125,7 +130,7 @@ pub mod pallet {
125130
/// but before transactions are executed.
126131
// This should go into on_post_inherents when it is ready https://github.com/paritytech/substrate/pull/10128
127132
// TODO better weight. For now we just set a somewhat conservative fudge factor
128-
#[pallet::weight(T::WeightInfo::kick_off_authorship_validation())]
133+
#[pallet::weight((T::WeightInfo::kick_off_authorship_validation(), DispatchClass::Mandatory))]
129134
pub fn kick_off_authorship_validation(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
130135
ensure_none(origin)?;
131136

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright 2019-2022 PureStake Inc.
2+
// This file is part of Nimbus.
3+
4+
// Nimbus is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Nimbus is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Nimbus. If not, see <http://www.gnu.org/licenses/>.
16+
17+
use crate as pallet_testing;
18+
use frame_support::parameter_types;
19+
use frame_support::traits::ConstU32;
20+
use frame_support::weights::RuntimeDbWeight;
21+
use frame_system;
22+
use sp_core::H256;
23+
use sp_runtime::{
24+
testing::Header,
25+
traits::{BlakeTwo256, IdentityLookup},
26+
};
27+
28+
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
29+
type Block = frame_system::mocking::MockBlock<Test>;
30+
31+
frame_support::construct_runtime!(
32+
pub enum Test where
33+
Block = Block,
34+
NodeBlock = Block,
35+
UncheckedExtrinsic = UncheckedExtrinsic,
36+
{
37+
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
38+
AuthorInherent: pallet_testing::{Pallet, Call, Storage},
39+
}
40+
);
41+
42+
parameter_types! {
43+
pub const BlockHashCount: u64 = 250;
44+
pub Authors: Vec<u64> = vec![1, 2, 3, 4, 5];
45+
pub const TestDbWeight: RuntimeDbWeight = RuntimeDbWeight {
46+
read: 1,
47+
write: 10,
48+
};
49+
}
50+
51+
impl frame_system::Config for Test {
52+
type BaseCallFilter = frame_support::traits::Everything;
53+
type BlockWeights = ();
54+
type BlockLength = ();
55+
type DbWeight = TestDbWeight;
56+
type Origin = Origin;
57+
type Call = Call;
58+
type Index = u64;
59+
type BlockNumber = u64;
60+
type Hash = H256;
61+
type Hashing = BlakeTwo256;
62+
type AccountId = u64;
63+
type Lookup = IdentityLookup<Self::AccountId>;
64+
type Header = Header;
65+
type Event = Event;
66+
type BlockHashCount = BlockHashCount;
67+
type Version = ();
68+
type PalletInfo = PalletInfo;
69+
type AccountData = ();
70+
type OnNewAccount = ();
71+
type OnKilledAccount = ();
72+
type SystemWeightInfo = ();
73+
type SS58Prefix = ();
74+
type OnSetCode = ();
75+
type MaxConsumers = ConstU32<16>;
76+
}
77+
78+
pub struct DummyBeacon {}
79+
impl nimbus_primitives::SlotBeacon for DummyBeacon {
80+
fn slot() -> u32 {
81+
0
82+
}
83+
}
84+
85+
impl pallet_testing::Config for Test {
86+
type AccountLookup = ();
87+
type EventHandler = ();
88+
type CanAuthor = ();
89+
type SlotBeacon = DummyBeacon;
90+
type WeightInfo = ();
91+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2019-2022 PureStake Inc.
2+
// This file is part of Nimbus.
3+
4+
// Nimbus is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Nimbus is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Nimbus. If not, see <http://www.gnu.org/licenses/>.
16+
17+
use crate::mock::*;
18+
19+
#[test]
20+
fn kick_off_authorship_validation_is_mandatory() {
21+
use frame_support::weights::{DispatchClass, GetDispatchInfo};
22+
23+
let info = crate::Call::<Test>::kick_off_authorship_validation {}.get_dispatch_info();
24+
assert_eq!(info.class, DispatchClass::Mandatory);
25+
}

0 commit comments

Comments
 (0)