-
Notifications
You must be signed in to change notification settings - Fork 710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Balances: Configurable Number of Genesis Accounts with Specified Balances for Benchmarking #6267
base: master
Are you sure you want to change the base?
Conversation
Balances of |
Hello @michalkucharczyk @ggwpez please review 🤝 |
{ | ||
let (num_accounts, balance, ref derivation) = self.dev_accounts; | ||
// Check if `derivation` is `Some` and generate key pair | ||
if let Some(derivation_string) = &derivation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use some default (//Sender/{}
) here, if None
is given in genesis config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be placed in a helper function
/// Generate dev account from derivation string.
#[cfg(feature = "runtime-benchmarks")]
pub fn derive_dev_account(
num_accounts: u32,
balance: T::Balance,
derivation: &String,
) {
// Ensure that the number of accounts is not zero
assert!(num_accounts > 0, "num_accounts must be greater than zero");
assert!(
balance >= <T as Config<I>>::ExistentialDeposit::get(),
"the balance of any account should always be at least the existential deposit.",
);
for index in 0..num_accounts {
// Replace "{}" in the derivation string with the index.
let derivation_string = derivation.replace("{}", &index.to_string());
// Attempt to create the key pair from the derivation string with error handling.
let pair: SrPair = Pair::from_string(&derivation_string, None)
.expect(&format!("Failed to parse derivation string: {}", derivation_string));
// Convert the public key to AccountId.
let who = T::AccountId::decode(&mut &pair.public().encode()[..])
.expect(&format!("Failed to decode public key from pair: {}", pair.public()));
frame_system::Pallet::<T>::inc_providers(&who);
// Insert the account into the store and ensure it succeeds.
assert!(T::AccountStore::insert(
&who,
AccountData { free: balance, ..Default::default() }
)
.is_ok());
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add that there are test environments in other pallets that use .default().build()
using Option<>
route with a default //Sender/{}
would require the defaults to have at least one dev_account
in each occurence.
Should be ready for another review @michalkucharczyk @ggwpez |
Derived Dev Accounts
Resolves #6040
Description
Enables an arbitrary number of dev accounts at genesis from a derivation path, feature gated by
runtime-benchmarks
.Notes
In the absence of a derivation path(i.e.
dev_accounts: (...., None)
at genesis), the system defaults to the path//Sender/{}
.One dev account is created by default with the derivation path
//Sender/{}
.Developer accounts are excluded from the total issuance of the token supply, ensuring they do not impact the overall balance at genesis.