-
Notifications
You must be signed in to change notification settings - Fork 704
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
PoV Reclaim Runtime Side #3002
PoV Reclaim Runtime Side #3002
Conversation
previous_proof_weight: u64, | ||
previous_reported_proof_size: Option<u64>, |
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.
Nit: is it on purpose that one of the variables called proof_weight
, and another proof_size
? I can see it as convention that weight
refers to benchmarked "weight" and size
refers to actually consumed proof size, but below in post_dispatch()
there is a variable called consumed_weight
.
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 tried to use proof_size as the absolute number that is reported by the host function. Weight as the amount consumed or reported by the runtime facilities.
But I should double check if that makes sense and usage is consistent.
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 good to me, but it's a good idea for somebody else to have a closer look at validate_block
and that the host function is registered everywhere where needed, as I lack the needed knowledge to check this.
Co-authored-by: Dmitry Markin <dmitry@markin.tech>
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.
Mostly nitpicks
); | ||
|
||
run_with_externalities::<B, _, _>(&backend, || { | ||
run_with_externalities_and_recorder::<B, _, _>(&backend, &mut recorder, || { |
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.
Dumb question: do we need access to the recorder in this closure as well?
Shouldn't we need access to the recorder only in the scope where we call execute_block
only?
(i.e. in the call below)
Or we need it to check_inherents
as well?
Another dumb question: why we need two calls to run_with_externalities_and_recorder
?
Can't we unify the closures in a single one?
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, we should not need 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.
Let me phrase it better, we should NOT use the recorder.
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 mean we need to supply the recorder everywhere where host functions are potentially being called. And since the CheckInherent
type is user supplied, host functions could be called there.
The two closures are separate because we want to start with a fresh overlay and externalities. But this is a good point, I now reset the recorder too between these two code sections.
@@ -40,7 +40,10 @@ use substrate_prometheus_endpoint::Registry; | |||
pub struct ParachainNativeExecutor; | |||
|
|||
impl sc_executor::NativeExecutionDispatch for ParachainNativeExecutor { | |||
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions; | |||
type ExtendHostFunctions = ( | |||
cumulus_client_service::storage_proof_size::HostFunctions, |
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.
If we propose this host function in the template. Maybe we should also need to add the StorageWeigthReclaim
signed extension to the runtime signed extensions tuple? (i.e. here)
Otherwise what is its usage?
IIUC the StorageWeightReclaimer
alone can't work correctly if we don't also return the extra weight to frame_system::BlockWeight
( by means of this signed extension hooks right?
Or I'm missing some other means of doing this? E.g. the user directly altering frame_system::BlockWeight
in some other hook
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.
IIUC the StorageWeightReclaimer alone can't work correctly if we don't also return the extra weight to frame_system::BlockWeight ( by means of this signed extension hooks right?
Or I'm missing some other means of doing this? E.g. the user directly altering frame_system::BlockWeight in some other hook.
The StorageWeightReclaimer
is a separate mechanism from the SignedExtension
. It is designed to be used inside the on_idle
hook, where weight management happens manually via WeightMeter
. Users need to check whether the operation they plan fits into the remaining weight. In the end, on_idle
will return the consumed weight and it will be accounted for after the hook finished here:
polkadot-sdk/substrate/frame/executive/src/lib.rs
Lines 607 to 614 in 150a360
let used_weight = <AllPalletsWithSystem as OnIdle<BlockNumberFor<System>>>::on_idle( | |
block_number, | |
remaining_weight, | |
); | |
<frame_system::Pallet<System>>::register_extra_weight_unchecked( | |
used_weight, | |
DispatchClass::Mandatory, | |
); |
This means that the weightreclaimer should only modify the value in the weightmeter, not the storage value itself.
If we propose this host function in the template. Maybe we should also need to add the StorageWeigthReclaim signed extension to the runtime signed extensions tuple? (i.e. here)
Otherwise what is its usage?
This is a good point, I will add it.
Code/concept looking good to me. Just a random thought: did you consider adding signed extensions to one of test runtimes (e.g. substrate-test-runtime or cumulus-test-runtime) to add some client-level testing involving more components? |
Co-authored-by: Davide Galassi <davxy@datawok.net>
3386377
# Runtime side for PoV Reclaim ## Implementation Overview - Hostfunction to fetch the storage proof size has been added to the PVF. It uses the size tracking recorder that was introduced in my previous PR. - Mechanisms to use the reclaim HostFunction have been introduced. - 1. A SignedExtension that checks the node-reported proof size before and after application of an extrinsic. Then it reclaims the difference. - 2. A manual helper to make reclaiming easier when manual interaction is required, for example in `on_idle` or other hooks. - In order to utilize the manual reclaiming, I modified `WeightMeter` to support the reduction of consumed weight, at least for storage proof size. ## How to use To enable the general functionality for a parachain: 1. Add the SignedExtension to your parachain runtime. 2. Provide the HostFunction to the node 3. Enable proof recording during block import ## TODO - [x] PRDoc --------- Co-authored-by: Dmitry Markin <dmitry@markin.tech> Co-authored-by: Davide Galassi <davxy@datawok.net> Co-authored-by: Bastian Köcher <git@kchr.de>
- Upgrade Polkadot-sdk to v.1.8.0. - Update weights to reflect the new version. Notable Changes: - [System Callabacks](paritytech/polkadot-sdk#1781) - [Remove of pallet pallet::getter](paritytech/polkadot-sdk#3456) - [Add storage_proof_size host function](paritytech/polkadot-sdk#3002) For more details, please refer to: [Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.9.0)
- Upgrade Polkadot-sdk to v.1.8.0. - Update weights to reflect the new version. Notable Changes: - [System Callabacks](paritytech/polkadot-sdk#1781) - [Remove of pallet pallet::getter](paritytech/polkadot-sdk#3456) - [Add storage_proof_size host function](paritytech/polkadot-sdk#3002) For more details, please refer to: [Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.9.0)
- Upgrade Polkadot-sdk to v.1.8.0. - Update weights to reflect the new version. Notable Changes: - [System Callabacks](paritytech/polkadot-sdk#1781) - [Remove of pallet pallet::getter](paritytech/polkadot-sdk#3456) - [Add storage_proof_size host function](paritytech/polkadot-sdk#3002) - [Rename of storage version function](https://github.com/paritytech/polkadot-sdk/pull/1554/files#diff-01dc4f43df9baa537f30c6b369525715d596a3068944f38458e9f160d5412d58R306) For more details, please refer to: [Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.9.0)
- Upgrade Polkadot-sdk to v.1.9.0. - Update weights to reflect the new version. Notable Changes: - [System Callabacks](paritytech/polkadot-sdk#1781) - [Remove of pallet pallet::getter](paritytech/polkadot-sdk#3456) - [Add storage_proof_size host function](paritytech/polkadot-sdk#3002) - [Rename of storage version function](https://github.com/paritytech/polkadot-sdk/pull/1554/files#diff-01dc4f43df9baa537f30c6b369525715d596a3068944f38458e9f160d5412d58R306) For more details, please refer to: [Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.9.0)
- Upgrade Polkadot-sdk to v.1.9.0. - Update weights to reflect the new version. Notable Changes: - [System Callbacks](paritytech/polkadot-sdk#1781) - [Remove of pallet pallet::getter](paritytech/polkadot-sdk#3456) - [Add storage_proof_size host function](paritytech/polkadot-sdk#3002) - [Rename of storage version function](https://github.com/paritytech/polkadot-sdk/pull/1554/files#diff-01dc4f43df9baa537f30c6b369525715d596a3068944f38458e9f160d5412d58R306) For more details, please refer to: [Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.9.0)
- Upgrade Polkadot-sdk to v.1.9.0. - Update weights to reflect the new version. Notable Changes: - [System Callbacks](paritytech/polkadot-sdk#1781) - [Remove of pallet pallet::getter](paritytech/polkadot-sdk#3456) - [Add storage_proof_size host function](paritytech/polkadot-sdk#3002) - [Rename of storage version function](https://github.com/paritytech/polkadot-sdk/pull/1554/files#diff-01dc4f43df9baa537f30c6b369525715d596a3068944f38458e9f160d5412d58R306) For more details, please refer to: [Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.9.0)
Runtime side for PoV Reclaim
Implementation Overview
on_idle
or other hooks.WeightMeter
to support the reduction of consumed weight, at least for storage proof size.How to use
To enable the general functionality for a parachain:
TODO