-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MOON-2519] Use moonbeam generated conviction voting weights (#2417)
* enable benchmarks for conviction voting * use moonbeam runtime weights for pallet-conviction-voting * add tests
- Loading branch information
Showing
8 changed files
with
324 additions
and
2 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
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,19 @@ | ||
// Copyright 2019-2022 PureStake Inc. | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam 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. | ||
|
||
// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Moonbeam common weights. | ||
|
||
pub mod pallet_conviction_voting; |
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,183 @@ | ||
// Copyright 2019-2022 PureStake Inc. | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam 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. | ||
|
||
// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
//! Autogenerated weights for pallet_conviction_voting | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2023-08-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! WORST CASE MAP SIZE: `1000000` | ||
//! HOSTNAME: `nish-pc`, CPU: `AMD Ryzen 9 5900X 12-Core Processor` | ||
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 | ||
|
||
// Executed Command: | ||
// ./target/release/moonbeam | ||
// benchmark | ||
// pallet | ||
// --execution=wasm | ||
// --wasm-execution=compiled | ||
// --pallet | ||
// pallet_conviction_voting | ||
// --extrinsic | ||
// * | ||
// --steps | ||
// 50 | ||
// --repeat | ||
// 20 | ||
// --template=./benchmarking/frame-weight-template.hbs | ||
// --json-file | ||
// raw.json | ||
// --output | ||
// weights.rs | ||
|
||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
use sp_std::marker::PhantomData; | ||
|
||
/// Weights for pallet_conviction_voting using the Substrate node and recommended hardware. | ||
pub struct SubstrateWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> pallet_conviction_voting::weights::WeightInfo for SubstrateWeight<T> { | ||
/// Storage: Referenda ReferendumInfoFor (r:1 w:1) | ||
/// Proof: Referenda ReferendumInfoFor (max_values: None, max_size: Some(912), added: 3387, mode: MaxEncodedLen) | ||
/// Storage: ConvictionVoting VotingFor (r:1 w:1) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: ConvictionVoting ClassLocksFor (r:1 w:1) | ||
/// Proof: ConvictionVoting ClassLocksFor (max_values: None, max_size: Some(119), added: 2594, mode: MaxEncodedLen) | ||
/// Storage: Balances Locks (r:1 w:1) | ||
/// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) | ||
/// Storage: Scheduler Agenda (r:1 w:1) | ||
/// Proof: Scheduler Agenda (max_values: None, max_size: Some(38963), added: 41438, mode: MaxEncodedLen) | ||
fn vote_new() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `13155` | ||
// Estimated: `85835` | ||
// Minimum execution time: 101_782_000 picoseconds. | ||
Weight::from_parts(105_579_000, 85835) | ||
.saturating_add(T::DbWeight::get().reads(5_u64)) | ||
.saturating_add(T::DbWeight::get().writes(5_u64)) | ||
} | ||
/// Storage: Referenda ReferendumInfoFor (r:1 w:1) | ||
/// Proof: Referenda ReferendumInfoFor (max_values: None, max_size: Some(912), added: 3387, mode: MaxEncodedLen) | ||
/// Storage: ConvictionVoting VotingFor (r:1 w:1) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: ConvictionVoting ClassLocksFor (r:1 w:1) | ||
/// Proof: ConvictionVoting ClassLocksFor (max_values: None, max_size: Some(119), added: 2594, mode: MaxEncodedLen) | ||
/// Storage: Balances Locks (r:1 w:1) | ||
/// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) | ||
/// Storage: Scheduler Agenda (r:2 w:2) | ||
/// Proof: Scheduler Agenda (max_values: None, max_size: Some(38963), added: 41438, mode: MaxEncodedLen) | ||
fn vote_existing() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `13876` | ||
// Estimated: `127273` | ||
// Minimum execution time: 176_472_000 picoseconds. | ||
Weight::from_parts(179_026_000, 127273) | ||
.saturating_add(T::DbWeight::get().reads(6_u64)) | ||
.saturating_add(T::DbWeight::get().writes(6_u64)) | ||
} | ||
/// Storage: ConvictionVoting VotingFor (r:1 w:1) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: Referenda ReferendumInfoFor (r:1 w:1) | ||
/// Proof: Referenda ReferendumInfoFor (max_values: None, max_size: Some(912), added: 3387, mode: MaxEncodedLen) | ||
/// Storage: Scheduler Agenda (r:2 w:2) | ||
/// Proof: Scheduler Agenda (max_values: None, max_size: Some(38963), added: 41438, mode: MaxEncodedLen) | ||
fn remove_vote() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `13520` | ||
// Estimated: `118937` | ||
// Minimum execution time: 157_035_000 picoseconds. | ||
Weight::from_parts(161_313_000, 118937) | ||
.saturating_add(T::DbWeight::get().reads(4_u64)) | ||
.saturating_add(T::DbWeight::get().writes(4_u64)) | ||
} | ||
/// Storage: ConvictionVoting VotingFor (r:1 w:1) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: Referenda ReferendumInfoFor (r:1 w:0) | ||
/// Proof: Referenda ReferendumInfoFor (max_values: None, max_size: Some(912), added: 3387, mode: MaxEncodedLen) | ||
fn remove_other_vote() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `12644` | ||
// Estimated: `35071` | ||
// Minimum execution time: 50_755_000 picoseconds. | ||
Weight::from_parts(53_090_000, 35071) | ||
.saturating_add(T::DbWeight::get().reads(2_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
/// Storage: ConvictionVoting VotingFor (r:2 w:2) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: Referenda ReferendumInfoFor (r:100 w:100) | ||
/// Proof: Referenda ReferendumInfoFor (max_values: None, max_size: Some(912), added: 3387, mode: MaxEncodedLen) | ||
/// Storage: Scheduler Agenda (r:2 w:2) | ||
/// Proof: Scheduler Agenda (max_values: None, max_size: Some(38963), added: 41438, mode: MaxEncodedLen) | ||
/// Storage: ConvictionVoting ClassLocksFor (r:1 w:1) | ||
/// Proof: ConvictionVoting ClassLocksFor (max_values: None, max_size: Some(119), added: 2594, mode: MaxEncodedLen) | ||
/// Storage: Balances Locks (r:1 w:1) | ||
/// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) | ||
/// The range of component `r` is `[0, 100]`. | ||
fn delegate(r: u32, ) -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `7235 + r * (386 ±0)` | ||
// Estimated: `153590 + r * (3387 ±0)` | ||
// Minimum execution time: 48_602_000 picoseconds. | ||
Weight::from_parts(34_823_147, 153590) | ||
// Standard Error: 732_665 | ||
.saturating_add(Weight::from_parts(82_938_442, 0).saturating_mul(r.into())) | ||
.saturating_add(T::DbWeight::get().reads(6_u64)) | ||
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) | ||
.saturating_add(T::DbWeight::get().writes(6_u64)) | ||
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(r.into()))) | ||
.saturating_add(Weight::from_parts(0, 3387).saturating_mul(r.into())) | ||
} | ||
/// Storage: ConvictionVoting VotingFor (r:2 w:2) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: Referenda ReferendumInfoFor (r:100 w:100) | ||
/// Proof: Referenda ReferendumInfoFor (max_values: None, max_size: Some(912), added: 3387, mode: MaxEncodedLen) | ||
/// Storage: Scheduler Agenda (r:2 w:2) | ||
/// Proof: Scheduler Agenda (max_values: None, max_size: Some(38963), added: 41438, mode: MaxEncodedLen) | ||
/// The range of component `r` is `[0, 100]`. | ||
fn undelegate(r: u32, ) -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `7020 + r * (386 ±0)` | ||
// Estimated: `145254 + r * (3387 ±0)` | ||
// Minimum execution time: 40_486_000 picoseconds. | ||
Weight::from_parts(43_021_000, 145254) | ||
// Standard Error: 378_061 | ||
.saturating_add(Weight::from_parts(89_418_651, 0).saturating_mul(r.into())) | ||
.saturating_add(T::DbWeight::get().reads(4_u64)) | ||
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) | ||
.saturating_add(T::DbWeight::get().writes(4_u64)) | ||
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(r.into()))) | ||
.saturating_add(Weight::from_parts(0, 3387).saturating_mul(r.into())) | ||
} | ||
/// Storage: ConvictionVoting VotingFor (r:1 w:1) | ||
/// Proof: ConvictionVoting VotingFor (max_values: None, max_size: Some(27229), added: 29704, mode: MaxEncodedLen) | ||
/// Storage: ConvictionVoting ClassLocksFor (r:1 w:1) | ||
/// Proof: ConvictionVoting ClassLocksFor (max_values: None, max_size: Some(119), added: 2594, mode: MaxEncodedLen) | ||
/// Storage: Balances Locks (r:1 w:1) | ||
/// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) | ||
fn unlock() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `11936` | ||
// Estimated: `39030` | ||
// Minimum execution time: 85_281_000 picoseconds. | ||
Weight::from_parts(94_197_000, 39030) | ||
.saturating_add(T::DbWeight::get().reads(3_u64)) | ||
.saturating_add(T::DbWeight::get().writes(3_u64)) | ||
} | ||
} |
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,102 @@ | ||
import "@moonbeam-network/api-augment"; | ||
|
||
import { expect } from "chai"; | ||
|
||
import { alith, generateKeyringPair } from "../../util/accounts"; | ||
import { expectOk } from "../../util/expect"; | ||
import { describeDevMoonbeam, DevTestContext } from "../../util/setup-dev-tests"; | ||
import { MIN_GLMR_STAKING, GLMR } from "../../util/constants"; | ||
import { KeyringPair } from "@substrate/txwrapper-core"; | ||
import { chunk } from "../../util/common"; | ||
|
||
const debug = require("debug")("test:convictionVoting"); | ||
|
||
describeDevMoonbeam("Conviction Voting - delegate", (context) => { | ||
it("should delegate at least 10 txs in a block", async () => { | ||
const randomAccounts = await createAccounts(context, 100); | ||
|
||
await context.createBlock( | ||
randomAccounts.map((account) => | ||
context.polkadotApi.tx.convictionVoting | ||
.delegate(1, alith.address, 1, 1000000000000000000n) | ||
.signAsync(account) | ||
) | ||
); | ||
|
||
const events = await context.polkadotApi.query.system.events(); | ||
const delegatedEvents = events.reduce((acc, event) => { | ||
if (context.polkadotApi.events.convictionVoting.Delegated.is(event.event)) { | ||
acc.push({ | ||
from: event.event.data[0].toString(), | ||
to: event.event.data[1].toString(), | ||
}); | ||
} | ||
|
||
return acc; | ||
}, []); | ||
|
||
expect(delegatedEvents.length).to.be.greaterThanOrEqual(10); | ||
}); | ||
}); | ||
|
||
describeDevMoonbeam("Conviction Voting - undelegate", (context) => { | ||
let randomAccounts = []; | ||
|
||
before("should delegate 50 accounts", async () => { | ||
randomAccounts = await createAccounts(context, 50); | ||
|
||
for (const randomChunk of chunk(randomAccounts, 10)) { | ||
await expectOk( | ||
context.createBlock( | ||
randomChunk.map((account) => | ||
context.polkadotApi.tx.convictionVoting | ||
.delegate(1, alith.address, 1, 1000000000000000000n) | ||
.signAsync(account) | ||
) | ||
) | ||
); | ||
} | ||
}); | ||
|
||
it("should undelegate at least 10 txs in a block", async () => { | ||
await context.createBlock( | ||
randomAccounts.map((account) => | ||
context.polkadotApi.tx.convictionVoting.undelegate(1).signAsync(account) | ||
) | ||
); | ||
|
||
const events = await context.polkadotApi.query.system.events(); | ||
const undelegatedEvents = events.reduce((acc, event) => { | ||
if (context.polkadotApi.events.convictionVoting.Undelegated.is(event.event)) { | ||
acc.push({ | ||
who: event.event.data[0].toString(), | ||
}); | ||
} | ||
|
||
return acc; | ||
}, []); | ||
|
||
console.log(undelegatedEvents.length); | ||
expect(undelegatedEvents.length).to.be.greaterThanOrEqual(10); | ||
}); | ||
}); | ||
|
||
async function createAccounts( | ||
context: DevTestContext, | ||
maxAccounts: number | ||
): Promise<KeyringPair[]> { | ||
const randomAccounts = new Array(Number(maxAccounts)).fill(0).map(() => generateKeyringPair()); | ||
|
||
let alithNonce = await context.web3.eth.getTransactionCount(alith.address); | ||
await expectOk( | ||
context.createBlock( | ||
randomAccounts.map((randomCandidate) => | ||
context.polkadotApi.tx.balances | ||
.transfer(randomCandidate.address, MIN_GLMR_STAKING + 1n * GLMR) | ||
.signAsync(alith, { nonce: alithNonce++ }) | ||
) | ||
) | ||
); | ||
|
||
return randomAccounts; | ||
} |