-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve charge_transaction_payment benchmark ergonomics
#10444
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
base: master
Are you sure you want to change the base?
Improve charge_transaction_payment benchmark ergonomics
#10444
Conversation
|
/cmd label T1-FRAME |
|
/cmd prdoc |
|
Command "label T1-FRAME" has failed ❌! See logs here |
|
Command "prdoc" has failed ❌! See logs here |
3be0033 to
f825eab
Compare
| /// Re-export the pallet for benchmarking with custom Config trait. | ||
| pub struct Pallet<T: Config>(crate::Pallet<T>); |
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 do we need this?
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 see and example use case here: moonbeam-foundation/moonbeam#3558
| /// required state before running benchmarks. For example, runtimes that | ||
| /// distribute fees to block authors may need to set the author before | ||
| /// the benchmark runs. | ||
| pub trait Config: crate::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.
Can we not just name this BenchmarkConfig? and then also put this below into the where_bound?
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.
Follows a similar pattern as https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/pallet-xcm/src/benchmarking.rs#L27
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.
Yeah could you try to just implement the benchmarking trait for the "normal Pallet"? Maybe it doesn't work, but right now I don't see the need for declaring this extra pallet struct.
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.
The downside of this approach is that everyone would need to implement the new Config trait ext even if they do not need any special setup.
For instance we'd need to add the following to /substrate/frame/transaction-payment/src/mock.rs
#[cfg(feature = "runtime-benchmarks")]
impl crate::benchmarking::Config for Runtime {}|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| mod benchmarking; | ||
| pub mod benchmarking; |
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.
Probably enough to just export the config, instead of making the entire module 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.
Similarly to https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/pallet-xcm/src/lib.rs#L22 but I am happy to change it
| let (amount_to_endow, tip) = if existential_deposit.is_zero() { | ||
| let min_tip: <<T as pallet::Config>::OnChargeTransaction as payment::OnChargeTransaction<T>>::Balance = 1_000_000_000u32.into(); | ||
| (min_tip * 1000u32.into(), min_tip) |
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 did you change this?
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.
The amount to endow is computed dynamically later on, while the tip logic stays the same.
| let len: u32 = 10; | ||
| let expected_fee = crate::Pallet::<T>::compute_fee(len, &info, tip); | ||
| let amount_to_endow = expected_fee | ||
| .saturating_mul(10u32.into()) |
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.
We should multiply by ED if not zero.
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 am sorry, I am not sure I understand why we need to do this. Could you please expand on the rationale? Happy to make this change.
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.
Fixed a problem with the computation here: 204b3e0
Description
Runtimes that distribute transaction fees to block authors (like Moonbeam) fail on the
charge_transaction_paymentbenchmark because no author is set when the benchmark runs. The fee distribution logic panics when trying to credit a non-existent author.This PR introduces a
benchmarking::Configtrait with asetup_benchmark_environment()hook that runtimes can implement to set up required state before the benchmark executes.Additionally,
amount_to_endowis now calculated usingcompute_fee()to determine the actual fee (with a 10x buffer), ensuring it is at least the existential deposit.Integration
Runtimes that need to set up state before running the
charge_transaction_paymentbenchmark should implementpallet_transaction_payment::benchmarking::Config:And update the benchmark list to use the wrapper type:
Runtimes that don't need custom setup can use the default implementation (no-op).
Review Notes
benchmarking::Configtrait extendscrate::Configwith asetup_benchmark_environment()method (default no-op)Pallet<T>struct is introduced in the benchmarking module to use this extended traitT::setup_benchmark_environment()at the startamount_to_endowis calculated ascompute_fee(...).saturating_mul(10).max(existential_deposit)to ensure the account can exist and has sufficient fundsChecklist
Trequired)/cmd label <label-name>to add labels