-
Notifications
You must be signed in to change notification settings - Fork 740
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
feat: add hooks for utility batch #6517
Open
dmoka
wants to merge
11
commits into
paritytech:master
Choose a base branch
from
galacticcouncil:feat/add-hooks-for-utility-batch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+51
−1
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ce484ba
add utility batch hooks
dmoka 1cfce6c
add doc comments
dmoka e804ec5
adding empty hook configs for all the requires utlity pallet config i…
dmoka 187fb9e
add missing hooks
dmoka 0ad2f2b
add missing hooks
dmoka 7e2c42c
add dispatch result as return value for hooks
dmoka 9b62779
adjust readme with hook info
dmoka 755753e
Merge branch 'master' into feat/add-hooks-for-utility-batch
dmoka 9182ec8
Merge branch 'master' into feat/add-hooks-for-utility-batch
dmoka be3c07f
merge batch hook into one trait
dmoka ec40a07
Merge remote-tracking branch 'origin/feat/add-hooks-for-utility-batch…
dmoka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -68,9 +68,24 @@ use sp_core::TypeId; | |||||
use sp_io::hashing::blake2_256; | ||||||
use sp_runtime::traits::{BadOrigin, Dispatchable, TrailingZeroInput}; | ||||||
pub use weights::WeightInfo; | ||||||
|
||||||
pub use pallet::*; | ||||||
|
||||||
pub trait BatchHook { | ||||||
fn on_batch_start() -> sp_runtime::DispatchResult; | ||||||
fn on_batch_end() -> sp_runtime::DispatchResult; | ||||||
|
||||||
} | ||||||
impl BatchHook for () { | ||||||
fn on_batch_start() -> sp_runtime::DispatchResult { | ||||||
Ok(()) | ||||||
} | ||||||
|
||||||
fn on_batch_end() -> sp_runtime::DispatchResult { | ||||||
Ok(()) | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
#[frame_support::pallet] | ||||||
pub mod pallet { | ||||||
use super::*; | ||||||
|
@@ -100,6 +115,9 @@ pub mod pallet { | |||||
Into<<Self as frame_system::Config>::RuntimeOrigin> + | ||||||
IsType<<<Self as frame_system::Config>::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin>; | ||||||
|
||||||
///Hook to be called before any batch operation | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
type BatchHook: BatchHook; | ||||||
|
||||||
/// Weight information for extrinsics in this pallet. | ||||||
type WeightInfo: WeightInfo; | ||||||
} | ||||||
|
@@ -196,6 +214,8 @@ pub mod pallet { | |||||
return Err(BadOrigin.into()) | ||||||
} | ||||||
|
||||||
T::BatchHook::on_batch_start()?; | ||||||
|
||||||
let is_root = ensure_root(origin.clone()).is_ok(); | ||||||
let calls_len = calls.len(); | ||||||
ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::<T>::TooManyCalls); | ||||||
|
@@ -225,6 +245,9 @@ pub mod pallet { | |||||
Self::deposit_event(Event::ItemCompleted); | ||||||
} | ||||||
Self::deposit_event(Event::BatchCompleted); | ||||||
|
||||||
T::BatchHook::on_batch_end()?; | ||||||
|
||||||
let base_weight = T::WeightInfo::batch(calls_len as u32); | ||||||
Ok(Some(base_weight.saturating_add(weight)).into()) | ||||||
} | ||||||
|
@@ -305,6 +328,8 @@ pub mod pallet { | |||||
return Err(BadOrigin.into()) | ||||||
} | ||||||
|
||||||
T::BatchHook::on_batch_start()?; | ||||||
|
||||||
let is_root = ensure_root(origin.clone()).is_ok(); | ||||||
let calls_len = calls.len(); | ||||||
ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::<T>::TooManyCalls); | ||||||
|
@@ -339,6 +364,9 @@ pub mod pallet { | |||||
Self::deposit_event(Event::ItemCompleted); | ||||||
} | ||||||
Self::deposit_event(Event::BatchCompleted); | ||||||
|
||||||
T::BatchHook::on_batch_end()?; | ||||||
|
||||||
let base_weight = T::WeightInfo::batch_all(calls_len as u32); | ||||||
Ok(Some(base_weight.saturating_add(weight)).into()) | ||||||
} | ||||||
|
@@ -401,6 +429,8 @@ pub mod pallet { | |||||
return Err(BadOrigin.into()) | ||||||
} | ||||||
|
||||||
T::BatchHook::on_batch_start()?; | ||||||
|
||||||
let is_root = ensure_root(origin.clone()).is_ok(); | ||||||
let calls_len = calls.len(); | ||||||
ensure!(calls_len <= Self::batched_calls_limit() as usize, Error::<T>::TooManyCalls); | ||||||
|
@@ -431,6 +461,9 @@ pub mod pallet { | |||||
} else { | ||||||
Self::deposit_event(Event::BatchCompleted); | ||||||
} | ||||||
|
||||||
T::BatchHook::on_batch_end()?; | ||||||
|
||||||
let base_weight = T::WeightInfo::batch(calls_len as u32); | ||||||
Ok(Some(base_weight.saturating_add(weight)).into()) | ||||||
} | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.