-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Kanas/module invalidity #11724
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?
Kanas/module invalidity #11724
Changes from 4 commits
5e968cb
eb7d2f3
f8e8d5b
64e4811
e7286c3
77b84e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| title: Kanas/module invalidity | ||
| doc: | ||
| - audience: | ||
| - Node Dev | ||
| - Runtime Dev | ||
| description: |- | ||
| # Description | ||
|
|
||
| This PR implements descriptive module invalidity support for transactions as proposed in #11337. It extends the `InvalidTransaction` enum with a new `Module(ModuleError)` variant, allowing pallets to return pallet-specific, descriptive error data during the transaction validation phase (e.g., in `TransactionExtension`). | ||
|
|
||
| crates: | ||
| - name: sc-rpc-api | ||
| bump: minor | ||
| - name: sc-rpc-spec-v2 | ||
| bump: minor | ||
| - name: sp-runtime | ||
| bump: minor | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
|
|
||
| use crate::{ | ||
| codec::{Decode, Encode}, | ||
| Debug, | ||
| Debug, ModuleError, | ||
| }; | ||
| use alloc::{vec, vec::Vec}; | ||
| use scale_info::TypeInfo; | ||
|
|
@@ -89,6 +89,8 @@ pub enum InvalidTransaction { | |
| IndeterminateImplicit, | ||
| /// The transaction extension did not authorize any origin. | ||
| UnknownOrigin, | ||
| /// An error in a module. | ||
| Module(ModuleError), | ||
|
Contributor
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. Reusing the same kind of type as ModuleError is good. We want a small embedabble information. But maybe the name Error make it confusing with dispatch error. And reusing the same error type for module dispatch error and invalidity can be confusing in the future. Like using 'into' will no longer mean anything, it could convert to an invalidity or a dispatch error which has a very different consequence. So maybe we want a new metadata information for module invalidities, etc... It would be cleaner but it is also more work. In the current shape it feels like pallet errors are now just a type for succint information. |
||
| } | ||
|
|
||
| impl InvalidTransaction { | ||
|
|
@@ -129,6 +131,9 @@ impl From<InvalidTransaction> for &'static str { | |
| InvalidTransaction::UnknownOrigin => { | ||
| "The transaction extension did not authorize any origin" | ||
| }, | ||
| InvalidTransaction::Module(ModuleError { message, .. }) => { | ||
| message.unwrap_or("Unknown module error") | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -480,7 +485,7 @@ mod tests { | |
| ); | ||
|
|
||
| // decode back | ||
| assert_eq!(TransactionValidity::decode(&mut &*encoded), Ok(v)); | ||
| assert_eq!(TransactionValidity::decode(&mut &*encoded), Ok(v.clone())); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
@@ -507,4 +512,23 @@ mod tests { | |
| } | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn module_invalidity_should_encode_and_decode() { | ||
| let v: TransactionValidity = Err(InvalidTransaction::Module(ModuleError { | ||
| index: 1, | ||
| error: [2, 0, 0, 0], | ||
| message: Some("Test error"), | ||
| }) | ||
| .into()); | ||
|
|
||
| let encoded = v.encode(); | ||
| assert_eq!(TransactionValidity::decode(&mut &*encoded), Ok(v.clone())); | ||
|
|
||
| let error_str: &'static str = match v { | ||
| Err(TransactionValidityError::Invalid(e)) => e.into(), | ||
| _ => panic!("Expected invalid error"), | ||
| }; | ||
| assert_eq!(error_str, "Test error"); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.