Skip to content

Commit

Permalink
Support more than u8::max_value GRANDPA validators (paritytech#896)
Browse files Browse the repository at this point in the history
* Support moar validators.

* Update weights script.

* Use correct type for benchmarking accounts

* Use package name instead of manifest path

Co-authored-by: Hernando Castano <hernando@hcastano.com>
  • Loading branch information
2 people authored and serban300 committed Apr 9, 2024
1 parent b4626be commit 5a5479a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 5 additions & 7 deletions bridges/modules/grandpa/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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::<Vec<_>>();
Expand All @@ -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::<Vec<_>>(),
authorities: accounts(p as u16).iter().map(|k| (*k, 1)).collect::<Vec<_>>(),
votes: v,
forks: 1,
};
Expand Down Expand Up @@ -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::<Vec<_>>();
Expand All @@ -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::<Vec<_>>(),
authorities: accounts(p as u16).iter().map(|k| (*k, 1)).collect::<Vec<_>>(),
votes: p,
forks: p,
};
Expand Down
6 changes: 4 additions & 2 deletions bridges/primitives/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ 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"]
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",
]
10 changes: 7 additions & 3 deletions bridges/primitives/test-utils/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,15 +34,18 @@ 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 {
(&self.secret()).into()
}

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 {
Expand Down Expand Up @@ -87,6 +91,6 @@ pub fn test_keyring() -> Vec<(Account, AuthorityWeight)> {
}

/// Get a list of "unique" accounts.
pub fn accounts(len: u8) -> Vec<Account> {
pub fn accounts(len: u16) -> Vec<Account> {
(0..len).into_iter().map(Account).collect()
}

0 comments on commit 5a5479a

Please sign in to comment.