-
Notifications
You must be signed in to change notification settings - Fork 761
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 🤝 |
Should be ready for another review @michalkucharczyk @ggwpez |
substrate/frame/balances/src/lib.rs
Outdated
Self { | ||
balances: Default::default(), | ||
|
||
#[cfg(feature = "runtime-benchmarks")] |
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.
As the benchmarks are a little bit different to the runtime benchmarks, I would just expose dev_accounts
always. If not needed, people don't need to set it.
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.
As the benchmarks are a little bit different to the runtime benchmarks,
Could you explain a bit more @bkchr?
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.
maybe a link in the code differentiating benchmarks from runtime benchmarks? familiar with just the feature flag runtime-benchmarks
.
substrate/frame/balances/src/lib.rs
Outdated
.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())); |
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.
.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())); | |
.unwrap_or_else(|| format!("Failed to parse derivation string: {derivation_string}")); | |
// Convert the public key to AccountId. | |
let who = T::AccountId::decode(&mut &pair.public().encode()[..]) | |
.unwrap_or_else(|| format!("Failed to decode public key from pair: {:?}", pair.public())); |
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 would expect a default value for the respective operations, .expect()
can't be used at genesis?
substrate/frame/balances/src/lib.rs
Outdated
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); |
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.
Why this instead of doing a force_set_balance
or something?
The less cases where we manually modify account references, the better.
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.
Getting familiar with the codebase.
I prefer your suggestion.
Thanks for the review!
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.
You can look at the tests of the balances pallet, it has plenty of examples on how to force-set the balance of an account 😄
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 used mutate_account_handling_dust
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.
Looks broadly good, thanks 😄
// Check if `derivation` is `Some` and generate key pair | ||
if let Some(derivation_string) = derivation { | ||
Pallet::<T, I>::derive_dev_account(num_accounts, balance, derivation_string); | ||
} else { | ||
// Derivation string is missing, using default.. | ||
Pallet::<T, I>::derive_dev_account(num_accounts, balance, "//Sender/{}"); | ||
} |
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.
Could be simplified maybe?
// Check if `derivation` is `Some` and generate key pair | |
if let Some(derivation_string) = derivation { | |
Pallet::<T, I>::derive_dev_account(num_accounts, balance, derivation_string); | |
} else { | |
// Derivation string is missing, using default.. | |
Pallet::<T, I>::derive_dev_account(num_accounts, balance, "//Sender/{}"); | |
} | |
// Use `derivation` (or default) to generate key pair | |
Pallet::<T, I>::derive_dev_account(num_accounts, balance, derivation.as_deref().unwrap_or("//Sender/{}")); |
dev_accounts: ( | ||
One::one(), | ||
<T as Config<I>>::ExistentialDeposit::get(), | ||
Some("//Sender/{}".to_string()), |
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.
"//Sender/{}"
could be defined as const to avoid duplications.
Derived Dev Accounts
Resolves #6040
Description
This update introduces support for creating an arbitrary number of developer accounts at the genesis block based on a specified derivation path. This functionality is gated by the runtime-benchmarks feature, ensuring it is only enabled during benchmarking scenarios.
Key Features
Arbitrary Dev Accounts at Genesis: Developers can now specify any number of accounts to be generated at genesis using a derivation path. This enables more flexibility for benchmarking use cases.
Default Derivation Path: If no derivation path is provided (i.e., when
dev_accounts: (..., None)
is set at genesis), the system will default to the path//Sender/{}
.Default Single Dev Account: A single developer account is created by default using the path
//Sender/{}
.No Impact on Total Token Issuance: Developer accounts are excluded from the total issuance of the token supply at genesis, ensuring they do not affect the overall balance or token distribution.
polkadot address: 14SRqZTC1d8rfxL8W1tBTnfUBPU23ACFVPzp61FyGf4ftUFg