From 6a15b6995fa2b6d457f84fc2ff2e290fe229c454 Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Sat, 10 Apr 2021 06:55:19 +0200 Subject: [PATCH] Cost analysis of a council election full block (#2782) --- polkadot/runtime/polkadot/src/lib.rs | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 6efc15b092..f32fba2a0d 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -1549,6 +1549,39 @@ mod test_fees { test_with_multiplier(Multiplier::saturating_from_rational(1, 1_000_000_000u128)); } + #[test] + fn full_block_council_election_cost() { + // the number of voters needed to consume almost a full block in council election, and how + // much it is going to cost. + use pallet_elections_phragmen::WeightInfo; + + // Loser candidate lose a lot of money; sybil attack by candidates is even more expensive, + // and we don't care about it here. For now, we assume no extra candidates, and only + // superfluous voters. + let candidates = DesiredMembers::get() + DesiredRunnersUp::get(); + let mut voters = 1u32; + let weight_with = |v| { + ::WeightInfo::election_phragmen( + candidates, + v, + v * 16, + ) + }; + + while weight_with(voters) <= BlockWeights::get().max_block { + voters += 1; + } + + let cost = voters as Balance * (VotingBondBase::get() + 16 * VotingBondFactor::get()); + let cost_dollars = cost / DOLLARS; + println!( + "can support {} voters in a single block for council elections; total bond {}", + voters, + cost_dollars, + ); + assert!(cost_dollars > 150_000); // DOLLAR ~ new DOT ~ 10e10 + } + #[test] fn nominator_limit() { use pallet_election_provider_multi_phase::WeightInfo;