From c3fa7216039875cc928dea800454255e7ebdf181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 13 Apr 2021 22:15:33 +0200 Subject: [PATCH] Support more than `u8::max_value` GRANDPA validators (#896) * Support moar validators. * Update weights script. * Use correct type for benchmarking accounts * Use package name instead of manifest path Co-authored-by: Hernando Castano --- Cargo.lock | 1 + modules/grandpa/src/benchmarking.rs | 12 +++++------- primitives/test-utils/Cargo.toml | 6 ++++-- primitives/test-utils/src/keyring.rs | 10 +++++++--- scripts/update-weights.sh | 22 +++++++++++++++++++--- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef1e8edd7125b..ec7ea8a70ac76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -826,6 +826,7 @@ dependencies = [ "bp-header-chain", "ed25519-dalek", "finality-grandpa 0.14.0", + "parity-scale-codec 2.0.1", "sp-application-crypto", "sp-finality-grandpa", "sp-runtime", diff --git a/modules/grandpa/src/benchmarking.rs b/modules/grandpa/src/benchmarking.rs index a3abe508d8a88..cb170fdc8b193 100644 --- a/modules/grandpa/src/benchmarking.rs +++ b/modules/grandpa/src/benchmarking.rs @@ -64,9 +64,7 @@ const MAX_VOTE_ANCESTRIES: u32 = 1000; // The maximum number of pre-commits to include in a justification. In practice this scales with the // number of validators. -// -// TODO [#846]: Right now this will break benchmarking if it is greater than `u8::MAX` -const MAX_VALIDATOR_SET_SIZE: u32 = 255; +const MAX_VALIDATOR_SET_SIZE: u32 = 1024; benchmarks_instance_pallet! { // This is the "gold standard" benchmark for this extrinsic, and it's what should be used to @@ -80,7 +78,7 @@ benchmarks_instance_pallet! { let caller: T::AccountId = whitelisted_caller(); - let authority_list = accounts(p as u8) + let authority_list = accounts(p as u16) .iter() .map(|id| (AuthorityId::from(*id), 1)) .collect::>(); @@ -99,7 +97,7 @@ benchmarks_instance_pallet! { header: header.clone(), round: TEST_GRANDPA_ROUND, set_id: TEST_GRANDPA_SET_ID, - authorities: accounts(p as u8).iter().map(|k| (*k, 1)).collect::>(), + authorities: accounts(p as u16).iter().map(|k| (*k, 1)).collect::>(), votes: v, forks: 1, }; @@ -160,7 +158,7 @@ benchmarks_instance_pallet! { let caller: T::AccountId = whitelisted_caller(); - let authority_list = accounts(p as u8) + let authority_list = accounts(p as u16) .iter() .map(|id| (AuthorityId::from(*id), 1)) .collect::>(); @@ -179,7 +177,7 @@ benchmarks_instance_pallet! { header: header.clone(), round: TEST_GRANDPA_ROUND, set_id: TEST_GRANDPA_SET_ID, - authorities: accounts(p as u8).iter().map(|k| (*k, 1)).collect::>(), + authorities: accounts(p as u16).iter().map(|k| (*k, 1)).collect::>(), votes: p, forks: p, }; diff --git a/primitives/test-utils/Cargo.toml b/primitives/test-utils/Cargo.toml index 64a85a2c67098..5adb2c2b55f54 100644 --- a/primitives/test-utils/Cargo.toml +++ b/primitives/test-utils/Cargo.toml @@ -9,10 +9,11 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" bp-header-chain = { path = "../header-chain", default-features = false } ed25519-dalek = { version = "1.0", default-features = false, features = ["u64_backend"] } finality-grandpa = { version = "0.14.0", default-features = false } +parity-scale-codec = { version = "2.0.0", default-features = false } +sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } [features] default = ["std"] @@ -20,8 +21,9 @@ std = [ "bp-header-chain/std", "ed25519-dalek/std", "finality-grandpa/std", + "parity-scale-codec/std", + "sp-application-crypto/std", "sp-finality-grandpa/std", "sp-runtime/std", "sp-std/std", - "sp-application-crypto/std", ] diff --git a/primitives/test-utils/src/keyring.rs b/primitives/test-utils/src/keyring.rs index fbc1496e16358..6c5b1cae9114a 100644 --- a/primitives/test-utils/src/keyring.rs +++ b/primitives/test-utils/src/keyring.rs @@ -18,6 +18,7 @@ use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature}; use finality_grandpa::voter_set::VoterSet; +use parity_scale_codec::Encode; use sp_application_crypto::Public; use sp_finality_grandpa::{AuthorityId, AuthorityList, AuthorityWeight}; use sp_runtime::RuntimeDebug; @@ -33,7 +34,7 @@ pub const FERDIE: Account = Account(5); /// A test account which can be used to sign messages. #[derive(RuntimeDebug, Clone, Copy)] -pub struct Account(pub u8); +pub struct Account(pub u16); impl Account { pub fn public(&self) -> PublicKey { @@ -41,7 +42,10 @@ impl Account { } pub fn secret(&self) -> SecretKey { - SecretKey::from_bytes(&[self.0; 32]).expect("A static array of the correct length is a known good.") + let data = self.0.encode(); + let mut bytes = [0_u8; 32]; + bytes[0..data.len()].copy_from_slice(&*data); + SecretKey::from_bytes(&bytes).expect("A static array of the correct length is a known good.") } pub fn pair(&self) -> Keypair { @@ -87,6 +91,6 @@ pub fn test_keyring() -> Vec<(Account, AuthorityWeight)> { } /// Get a list of "unique" accounts. -pub fn accounts(len: u8) -> Vec { +pub fn accounts(len: u16) -> Vec { (0..len).into_iter().map(Account).collect() } diff --git a/scripts/update-weights.sh b/scripts/update-weights.sh index 0fb4d30d2bbee..0ac773e8d7b46 100755 --- a/scripts/update-weights.sh +++ b/scripts/update-weights.sh @@ -1,9 +1,13 @@ #!/bin/sh +# +# Runtime benchmarks for the `pallet-bridge-messages` and `pallet-bridge-grandpa` pallets. +# +# Run this script from root of the repo. -# Run this script from root of the repo +set -eux -cargo run --manifest-path=bin/rialto/node/Cargo.toml --release --features=runtime-benchmarks -- benchmark \ - --chain=local \ +time cargo run --release -p rialto-bridge-node --features=runtime-benchmarks -- benchmark \ + --chain=dev \ --steps=50 \ --repeat=20 \ --pallet=pallet_bridge_messages \ @@ -13,3 +17,15 @@ cargo run --manifest-path=bin/rialto/node/Cargo.toml --release --features=runtim --heap-pages=4096 \ --output=./modules/messages/src/weights.rs \ --template=./.maintain/rialto-weight-template.hbs + +time cargo run --release -p rialto-bridge-node --features=runtime-benchmarks -- benchmark \ + --chain=dev \ + --steps=50 \ + --repeat=20 \ + --pallet=pallet_bridge_grandpa \ + --extrinsic=* \ + --execution=wasm \ + --wasm-execution=Compiled \ + --heap-pages=4096 \ + --output=./modules/grandpa/src/weights.rs \ + --template=./.maintain/rialto-weight-template.hbs