Several tweaks needed for Governance 2.0 (#11124)

* Add stepped curve for referenda

* Treasury SpendOrigin

* Add tests

* Better Origin Or-gating

* Reciprocal curve

* Tests for reciprical and rounding in PerThings

* Tweaks and new quad curve

* Const derivation of reciprocal curve parameters

* Remove some unneeded code

* Actually useful linear curve

* Fixes

* Provisional curves

* Rejig 'turnout' as 'support'

* Use TypedGet

* Fixes

* Enable curve's ceil to be configured

* Formatting

* Fixes

* Fixes

* Fixes

* Remove EnsureOneOf

* Fixes

* Fixes

* Fixes

* Formatting

* Fixes

* Update frame/support/src/traits/dispatch.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Grumbles

* Formatting

* Fixes

* APIs of VoteTally should include class

* Fixes

* Fix overlay prefix removal result

* Second part of the overlay prefix removal fix.

* Formatting

* Fixes

* Add some tests and make clear rounding algo

* Fixes

* Formatting

* Revert questionable fix

* Introduce test for kill_prefix

* Fixes

* Formatting

* Fixes

* Fix possible overflow

* Docs

* Add benchmark test

* Formatting

* Update frame/referenda/src/types.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Docs

* Fixes

* Use latest API in tests

* Formatting

* Whitespace

* Use latest API in tests

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Gavin Wood
2022-05-31 11:12:34 +01:00
committed by GitHub
parent c808340d9a
commit 7808b0c349
34 changed files with 2050 additions and 339 deletions
+39 -22
View File
@@ -160,12 +160,14 @@ impl TracksInfo<u64, u64> for TestTracksInfo {
confirm_period: 2,
min_enactment_period: 4,
min_approval: Curve::LinearDecreasing {
begin: Perbill::from_percent(100),
delta: Perbill::from_percent(50),
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_turnout: Curve::LinearDecreasing {
begin: Perbill::from_percent(100),
delta: Perbill::from_percent(100),
min_support: Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
),
@@ -180,12 +182,14 @@ impl TracksInfo<u64, u64> for TestTracksInfo {
confirm_period: 1,
min_enactment_period: 2,
min_approval: Curve::LinearDecreasing {
begin: Perbill::from_percent(55),
delta: Perbill::from_percent(5),
length: Perbill::from_percent(100),
floor: Perbill::from_percent(95),
ceil: Perbill::from_percent(100),
},
min_turnout: Curve::LinearDecreasing {
begin: Perbill::from_percent(10),
delta: Perbill::from_percent(10),
min_support: Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(90),
ceil: Perbill::from_percent(100),
},
},
),
@@ -241,35 +245,48 @@ pub fn new_test_ext_execute_with_cond(execute: impl FnOnce(bool) -> () + Clone)
new_test_ext().execute_with(|| execute(true));
}
#[derive(Encode, Debug, Decode, TypeInfo, Eq, PartialEq, Clone, Default, MaxEncodedLen)]
#[derive(Encode, Debug, Decode, TypeInfo, Eq, PartialEq, Clone, MaxEncodedLen)]
pub struct Tally {
pub ayes: u32,
pub nays: u32,
}
impl VoteTally<u32> for Tally {
fn ayes(&self) -> u32 {
impl<Class> VoteTally<u32, Class> for Tally {
fn new(_: Class) -> Self {
Self { ayes: 0, nays: 0 }
}
fn ayes(&self, _: Class) -> u32 {
self.ayes
}
fn turnout(&self) -> Perbill {
Perbill::from_percent(self.ayes + self.nays)
fn support(&self, _: Class) -> Perbill {
Perbill::from_percent(self.ayes)
}
fn approval(&self) -> Perbill {
Perbill::from_rational(self.ayes, self.ayes + self.nays)
fn approval(&self, _: Class) -> Perbill {
if self.ayes + self.nays > 0 {
Perbill::from_rational(self.ayes, self.ayes + self.nays)
} else {
Perbill::zero()
}
}
#[cfg(feature = "runtime-benchmarks")]
fn unanimity() -> Self {
fn unanimity(_: Class) -> Self {
Self { ayes: 100, nays: 0 }
}
#[cfg(feature = "runtime-benchmarks")]
fn from_requirements(turnout: Perbill, approval: Perbill) -> Self {
let turnout = turnout.mul_ceil(100u32);
let ayes = approval.mul_ceil(turnout);
Self { ayes, nays: turnout - ayes }
fn rejection(_: Class) -> Self {
Self { ayes: 0, nays: 100 }
}
#[cfg(feature = "runtime-benchmarks")]
fn from_requirements(support: Perbill, approval: Perbill, _: Class) -> Self {
let ayes = support.mul_ceil(100u32);
let nays = ((ayes as u64) * 1_000_000_000u64 / approval.deconstruct() as u64) as u32 - ayes;
Self { ayes, nays }
}
}