-
Notifications
You must be signed in to change notification settings - Fork 1.1k
introduce inherent handler in pallet revive #10140
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
Draft
dharjeezy
wants to merge
6
commits into
paritytech:master
Choose a base branch
from
dharjeezy:dami/introduce-inherent-handler-in-pallet-revive
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.
+293
−81
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d20b5cf
introduce inherent handler in pallet revive
dharjeezy ab08eca
Merge remote-tracking branch 'origin/master' into dami/introduce-inhe…
dharjeezy ff5b002
fix up merge conflict issues
dharjeezy 18b175a
Merge remote-tracking branch 'origin/master' into dami/introduce-inhe…
dharjeezy b99d3bc
merge conflict fix
dharjeezy a756c22
dispatch message
dharjeezy 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| use alloc::vec::Vec; | ||
| use impl_trait_for_tuples::impl_for_tuples; | ||
| use sp_runtime::{DispatchError, DispatchResult}; | ||
| use crate::InherentHandlerMessage; | ||
|
|
||
| /// Defines the interface for a pallet capable of handling a specific type of inherent system message. | ||
| /// | ||
| /// Pallets implementing this trait register themselves as potential handlers for messages | ||
| /// identified by a unique `name`. | ||
| pub trait InherentHandler { | ||
| /// A unique identifier for this handler | ||
| fn handler_name() -> &'static [u8]; | ||
|
|
||
| /// The function that processes the raw message byte intended for this handler. | ||
| fn handle_message(message: Vec<u8>) -> DispatchResult; | ||
| } | ||
|
|
||
| /// Defines the interface for a collection(tuple) of `InherentHandler` | ||
| /// | ||
| /// This trait provides functions to validate handler names and dispatch mesaages to the | ||
| /// appropriate handler within the collection. | ||
| pub trait InherentHandlers { | ||
| /// Checks if a handler with the given `name` exists within this collection. | ||
| /// | ||
| /// Used during unsigned transaction validation(`ValidateUnsigned`) to ensure the targe handler is known before accepting the extrinsic. | ||
| fn is_valid_handler(name: &[u8]) -> bool; | ||
|
|
||
| /// Finds the handler matching the `handler_name` within the message and call its `handle_message` | ||
| fn dispatch_message(message: InherentHandlerMessage) -> DispatchResult; | ||
| } | ||
|
|
||
|
|
||
| /// Base case implementation for an empty tuple `()` | ||
| impl InherentHandlers for () { | ||
| fn is_valid_handler(_name: &[u8]) -> bool { | ||
| false | ||
| } | ||
|
|
||
| fn dispatch_message(_message: InherentHandlerMessage) -> DispatchResult { | ||
| Err(DispatchError::Other("No matching inherent handler found")) | ||
| } | ||
| } | ||
|
|
||
| /// Recursive implementation for a non-empty tuple up to 8 elements . | ||
| #[impl_for_tuples(1, 8)] | ||
| #[tuple_types_custom_trait_bound(InherentHandler)] | ||
| impl InherentHandlers for Tuple { | ||
| fn is_valid_handler(name: &[u8]) -> bool { | ||
| for_tuples!( #( if Tuple::handler_name() == name { return true; } )* ); | ||
| false | ||
| } | ||
|
|
||
| fn dispatch_message(message: InherentHandlerMessage) -> DispatchResult { | ||
| let handler_name = message.handler_name.as_slice(); | ||
| for_tuples!( #( if Tuple::handler_name() == handler_name { | ||
| return Tuple::handle_message(message.raw_message); | ||
| } )* ); | ||
| Err(DispatchError::Other("No matching inherent handler found")) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Maybe, could we find a different naming around
InherentHandler?Just to avoid confusion with existing
Inherentconcept - extrinsics that are inherently added to each block. (InherentData, InherentIdentifier, ProvideInherent, ...)