Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce scheduler and use it for the democracy dispatch queue #5412

Merged
merged 34 commits into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a551fdd
Merge remote-tracking branch 'origin/master' into gav-scheduler
gavofyork Mar 23, 2020
0a899fc
Initial draft of the logic
gavofyork Mar 23, 2020
6cd4cca
Build and tests
gavofyork Mar 24, 2020
c8e597c
Merge remote-tracking branch 'origin/master' into gav-scheduler
gavofyork Mar 24, 2020
876e3e5
Make work with new initialize infratructure.
gavofyork Mar 24, 2020
5bed28d
Update frame/scheduler/src/lib.rs
gavofyork Mar 25, 2020
981f27a
Update frame/scheduler/src/lib.rs
gavofyork Mar 25, 2020
6caf97e
Update frame/scheduler/src/lib.rs
gavofyork Mar 25, 2020
ca175a2
Update frame/scheduler/src/lib.rs
gavofyork Mar 25, 2020
eef345d
Fix test
gavofyork Mar 25, 2020
23e0d1d
Merge branch 'gav-scheduler' of github.com:paritytech/substrate into …
gavofyork Mar 25, 2020
fd98570
Update frame/scheduler/src/lib.rs
gavofyork Mar 25, 2020
2985d57
Rejig interface to make it more useful for democracy.
gavofyork Mar 25, 2020
e24b141
Merge branch 'gav-scheduler' of github.com:paritytech/substrate into …
gavofyork Mar 25, 2020
8c119db
Try to get democraxy module to make use of scheduler.
gavofyork Mar 25, 2020
2c783f4
Make democracy use scheduler.
gavofyork Mar 26, 2020
c5de44d
Use actual max weight for enactent
gavofyork Mar 26, 2020
e4f914f
Remove TODO
gavofyork Mar 26, 2020
fb6f5ea
Fix runtime build
gavofyork Mar 26, 2020
4571292
Merge remote-tracking branch 'origin/master' into gav-democracy-uses-…
gavofyork Mar 26, 2020
a4403eb
Minor cleanup
gavofyork Mar 26, 2020
7057704
Fix scheduler.
gavofyork Mar 26, 2020
a467b6c
Fix benchmarks
gavofyork Mar 26, 2020
99644fd
Fix
gavofyork Mar 26, 2020
87f940a
Fix
gavofyork Mar 26, 2020
1190fa5
Fix
gavofyork Mar 26, 2020
0f3b611
More bench fixes
gavofyork Mar 26, 2020
81623ae
Fix
gavofyork Mar 26, 2020
4a563ff
Fix.
gavofyork Mar 26, 2020
6b3ee59
Add more bench constants.
marcio-diaz Mar 27, 2020
1a407a3
Fix cancel_queued bench.
marcio-diaz Mar 27, 2020
5121074
Fix test comment.
marcio-diaz Mar 27, 2020
f1e05f5
Update frame/scheduler/src/lib.rs
gavofyork Mar 31, 2020
e13a337
Merge remote-tracking branch 'origin/master' into gav-democracy-uses-…
gavofyork Apr 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -86,6 +86,7 @@ members = [
"frame/offences",
"frame/randomness-collective-flip",
"frame/recovery",
"frame/scheduler",
"frame/scored-pool",
"frame/session",
"frame/session/benchmarking",
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Expand Up @@ -16,7 +16,7 @@ repository = "https://github.com/paritytech/substrate/"
wasm-opt = false

[badges]
travis-ci = { repository = "paritytech/substrate", branch = "master" }
travis-ci = { repository = "paritytech/substrate" }
maintenance = { status = "actively-developed" }
is-it-maintained-issue-resolution = { repository = "paritytech/substrate" }
is-it-maintained-open-issues = { repository = "paritytech/substrate" }
Expand Down
3 changes: 2 additions & 1 deletion bin/node/runtime/Cargo.toml
Expand Up @@ -61,8 +61,9 @@ pallet-session = { version = "2.0.0-alpha.5", features = ["historical"], path =
pallet-session-benchmarking = { version = "2.0.0-alpha.5", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
pallet-staking = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/staking" }
pallet-staking-reward-curve = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/staking/reward-curve" }
pallet-sudo = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/sudo" }
pallet-scheduler = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/scheduler" }
pallet-society = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/society" }
pallet-sudo = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/sudo" }
pallet-timestamp = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/timestamp" }
pallet-treasury = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/treasury" }
pallet-utility = { version = "2.0.0-alpha.5", default-features = false, path = "../../../frame/utility" }
Expand Down
14 changes: 14 additions & 0 deletions bin/node/runtime/src/lib.rs
Expand Up @@ -207,6 +207,17 @@ impl pallet_utility::Trait for Runtime {
type MaxSignatories = MaxSignatories;
}

parameter_types! {
pub const MaximumWeight: Weight = 2_000_000;
}

impl pallet_scheduler::Trait for Runtime {
type Event = Event;
type Origin = Origin;
type Call = Call;
type MaximumWeight = MaximumWeight;
}

parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS;
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
Expand Down Expand Up @@ -262,6 +273,7 @@ impl pallet_transaction_payment::Trait for Runtime {
parameter_types! {
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
}

impl pallet_timestamp::Trait for Runtime {
type Moment = Moment;
type OnTimestampSet = Babe;
Expand Down Expand Up @@ -392,6 +404,7 @@ impl pallet_democracy::Trait for Runtime {
type CooloffPeriod = CooloffPeriod;
type PreimageByteDeposit = PreimageByteDeposit;
type Slash = Treasury;
type Scheduler = Scheduler;
}

parameter_types! {
Expand Down Expand Up @@ -667,6 +680,7 @@ construct_runtime!(
Society: pallet_society::{Module, Call, Storage, Event<T>, Config<T>},
Recovery: pallet_recovery::{Module, Call, Storage, Event<T>},
Vesting: pallet_vesting::{Module, Call, Storage, Event<T>, Config<T>},
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
}
);

Expand Down
1 change: 1 addition & 0 deletions frame/democracy/Cargo.toml
Expand Up @@ -21,6 +21,7 @@ frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "..
[dev-dependencies]
sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" }
pallet-balances = { version = "2.0.0-alpha.5", path = "../balances" }
pallet-scheduler = { version = "2.0.0-alpha.5", path = "../scheduler" }
sp-storage = { version = "2.0.0-alpha.5", path = "../../primitives/storage" }
hex-literal = "0.2.1"

Expand Down
61 changes: 20 additions & 41 deletions frame/democracy/src/benchmarking.rs
Expand Up @@ -29,6 +29,9 @@ const SEED: u32 = 0;
const MAX_USERS: u32 = 1000;
const MAX_REFERENDUMS: u32 = 100;
const MAX_PROPOSALS: u32 = 100;
const MAX_SECONDERS: u32 = 100;
const MAX_VETOERS: u32 = 100;
const MAX_BYTES: u32 = 16_384;

fn funded_account<T: Trait>(name: &'static str, index: u32) -> T::AccountId {
let caller: T::AccountId = account(name, index, SEED);
Expand Down Expand Up @@ -99,7 +102,7 @@ benchmarks! {
}: _(RawOrigin::Signed(caller), proposal_hash, value.into())

second {
let s in 0 .. 100;
let s in 0 .. MAX_SECONDERS;

// Create s existing "seconds"
for i in 0..s {
Expand Down Expand Up @@ -202,15 +205,15 @@ benchmarks! {

veto_external {
// Existing veto-ers
let v in 0 .. 100;
let v in 0 .. MAX_VETOERS;

let proposal_hash: T::Hash = T::Hashing::hash_of(&v);

let origin_propose = T::ExternalDefaultOrigin::successful_origin();
Democracy::<T>::external_propose_default(origin_propose, proposal_hash.clone())?;

let mut vetoers: Vec<T::AccountId> = Vec::new();
for i in 0..v {
for i in 0 .. v {
vetoers.push(account("vetoer", i, SEED));
}
Blacklist::<T>::insert(proposal_hash, (T::BlockNumber::zero(), vetoers));
Expand All @@ -228,12 +231,7 @@ benchmarks! {
}: _(RawOrigin::Root, referendum_index)

cancel_queued {
let d in 0 .. 100;

let referendum_index = add_referendum::<T>(d)?;
let block_number: T::BlockNumber = 0.into();
let hash: T::Hash = T::Hashing::hash_of(&d);
<DispatchQueue<T>>::put(vec![(block_number, hash, referendum_index.clone()); d as usize]);
let referendum_index = add_referendum::<T>(0)?;
}: _(RawOrigin::Root, referendum_index)

open_proxy {
Expand Down Expand Up @@ -297,67 +295,48 @@ benchmarks! {
}: _(RawOrigin::Signed(delegator))

clear_public_proposals {
let p in 0 .. 100;
let p in 0 .. MAX_PROPOSALS;
for i in 0 .. p {
add_proposal::<T>(i)?;
}
}: _(RawOrigin::Root)

note_preimage {
// Num of bytes in encoded proposal
let b in 0 .. 16_384;
let b in 0 .. MAX_BYTES;

let caller = funded_account::<T>("caller", b);
let encoded_proposal = vec![0; b as usize];
}: _(RawOrigin::Signed(caller), encoded_proposal)

note_imminent_preimage {
// Num of bytes in encoded proposal
let b in 0 .. 16_384;
// Length of dispatch queue
let d in 0 .. 100;
let b in 0 .. MAX_BYTES;

let mut dispatch_queue = Vec::new();
// d + 1 to include the one we are testing
for i in 0 .. d + 1 {
let encoded_proposal = vec![0; i as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
let block_number = T::BlockNumber::zero();
let referendum_index: ReferendumIndex = 0;
dispatch_queue.push((block_number, proposal_hash, referendum_index))
}
<DispatchQueue<T>>::put(dispatch_queue);
let encoded_proposal = vec![0; b as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
let block_number = T::BlockNumber::one();
Preimages::<T>::insert(&proposal_hash, PreimageStatus::Missing(block_number));

let caller = funded_account::<T>("caller", b);
let encoded_proposal = vec![0; d as usize];
let encoded_proposal = vec![0; b as usize];
}: _(RawOrigin::Signed(caller), encoded_proposal)

reap_preimage {
// Num of bytes in encoded proposal
let b in 0 .. 16_384;
// Length of dispatch queue
let d in 0 .. 100;

let mut dispatch_queue = Vec::new();
for i in 0 .. d {
let encoded_proposal = vec![0; i as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
let block_number = T::BlockNumber::zero();
let referendum_index: ReferendumIndex = 0;
dispatch_queue.push((block_number, proposal_hash, referendum_index))
}
<DispatchQueue<T>>::put(dispatch_queue);
let b in 0 .. MAX_BYTES;

let caller = funded_account::<T>("caller", d);
let encoded_proposal = vec![0; d as usize];
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
let encoded_proposal = vec![0; b as usize];
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);

let caller = funded_account::<T>("caller", b);
Democracy::<T>::note_preimage(RawOrigin::Signed(caller.clone()).into(), encoded_proposal.clone())?;

// We need to set this otherwise we get `Early` error.
let block_number = T::VotingPeriod::get() + T::EnactmentPeriod::get() + T::BlockNumber::one();
System::<T>::set_block_number(block_number.into());

let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);

}: _(RawOrigin::Signed(caller), proposal_hash)

unlock {
Expand Down