This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow pallet error enum variants to contain fields #10242
Merged
paritytech-processbot
merged 83 commits into
master
from
kckyeung/nested-pallet-error-enum
Mar 24, 2022
Merged
Changes from 82 commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
e569450
Allow pallet errors to contain at most one field
KiChjang c4f7b51
Update docs on pallet::error
KiChjang 788ea42
Reword documentation
KiChjang 0b70512
cargo fmt
KiChjang d3e5c7c
Introduce CompactPalletError trait and require #[pallet::error] field…
KiChjang e8f6714
cargo fmt
KiChjang 815a616
Do not assume tuple variants
KiChjang 78ff9af
Add CompactPalletError derive macro
KiChjang e86c2d9
Check for error type compactness in construct_runtime
KiChjang 2ba5c5b
cargo fmt
KiChjang 217e1a4
Derive CompactPalletError instead of implementing it directly during …
KiChjang 3a399b6
Implement CompactPalletError on OptionBool instead of Option<bool>
KiChjang a583025
Check for type idents instead of variant ident
KiChjang e68ba71
Add doc comments for ErrorCompactnessTest
KiChjang ed643ff
Add an trait implementation of ErrorCompactnessTest for ()
KiChjang dcddc79
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang 3913e85
Convert the error field of DispatchError to a 4-element byte array
KiChjang 26b0adf
Add static check for pallet error size
KiChjang 82c29a9
Rename to MAX_PALLET_ERROR_ENCODED_SIZE
KiChjang a1a0c32
Remove ErrorCompactnessTest trait
KiChjang 0fb5860
Remove check_compactness
KiChjang 69753e9
Return only the most significant byte when constructing a custom Inva…
KiChjang c57ccb6
Rename CompactPalletError to PalletError
KiChjang f6f8be5
Use counter to generate unique idents for assert macros
KiChjang 9b92379
Make declarative pallet macros compile with pallet error size checks
KiChjang b984433
Remove unused doc comment
KiChjang 2fb09fb
Try and fix build errors
KiChjang adceb34
Fix build errors
KiChjang b018d42
Add macro_use for some test modules
KiChjang 56ff09d
Test fix
KiChjang 29841d9
Fix compilation errors
KiChjang 1ca9680
Remove unneeded #[macro_use]
KiChjang cf1cbd3
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang b7c2b9f
Resolve import ambiguity
KiChjang 8783da5
Make path to pallet Error enum more specific
KiChjang 1f991ff
Fix test expectation
KiChjang d7e3597
Disambiguate imports
KiChjang aea23e0
Fix test expectations
KiChjang 1a4bcdf
Revert appending pallet module name to path
KiChjang d2e42ef
Rename bags_list::list::Error to BagError
KiChjang 9ab1b56
Fixes
KiChjang 1be3227
Fixes
KiChjang 0342859
Fixes
KiChjang 066ec5f
Fix test expectations
KiChjang 1f3ab67
Fix test expectation
KiChjang b45ca96
Add more implementations for PalletError
KiChjang 981a29f
Lift the 1-field requirement for nested pallet errors
KiChjang 0ef2812
Fix UI test expectation
KiChjang fb1b32b
Remove PalletError impl for OptionBool
KiChjang fb73b33
Use saturating operations
KiChjang 8e8a27a
cargo fmt
KiChjang 2a54736
Delete obsolete test
KiChjang a250788
Fix test expectation
KiChjang 7d80dae
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang c44e6e4
Try and use assert macro in const context
KiChjang cc06206
Pull out the pallet error size check macro
KiChjang c037c6d
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang e4c3f47
Fix UI test for const assertion
KiChjang fa0e155
cargo fmt
KiChjang 29e3df1
Apply clippy suggestion
KiChjang a8b6214
Fix doc comment
KiChjang cca5ed6
Docs for create_tt_return_macro
KiChjang 52a0a73
Ensure TryInto is imported in earlier Rust editions
KiChjang ece305e
Apply suggestions from code review
KiChjang 29a131a
Fix up comments and names
KiChjang 9cdf1aa
Implement PalletError for Never
KiChjang 5070335
cargo fmt
KiChjang ac1f198
Don't compile example code
KiChjang 811e2f2
Bump API version for block builder
KiChjang 7595123
Factor in codec attributes while derving PalletError
KiChjang 89abef7
Rename module and fix unit test
KiChjang 161fb88
Add missing attribute
KiChjang babebfc
Check API version and convert ApplyExtrinsicResult accordingly
KiChjang 80ed571
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang 7fed725
Rename BagError to ListError
KiChjang 8d25a2f
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang 9fef2e1
Use codec crate re-exported from frame support
KiChjang ddc2cce
Add links to types mentioned in doc comments
KiChjang 23608e7
cargo fmt
KiChjang 9d0dfa7
cargo fmt
KiChjang 966b177
Merge branch 'master' into kckyeung/nested-pallet-error-enum
KiChjang 2b3b730
Re-add attribute for hidden docs
KiChjang f4157f4
Merge remote-tracking branch 'origin/master' into kckyeung/nested-pal…
KiChjang 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,6 +241,7 @@ fn construct_runtime_final_expansion( | |
expand::expand_outer_inherent(&name, &block, &unchecked_extrinsic, &pallets, &scrate); | ||
let validate_unsigned = expand::expand_outer_validate_unsigned(&name, &pallets, &scrate); | ||
let integrity_test = decl_integrity_test(&scrate); | ||
let static_assertions = decl_static_assertions(&name, &pallets, &scrate); | ||
|
||
let res = quote!( | ||
#scrate_decl | ||
|
@@ -282,6 +283,8 @@ fn construct_runtime_final_expansion( | |
#validate_unsigned | ||
|
||
#integrity_test | ||
|
||
#static_assertions | ||
); | ||
|
||
Ok(res) | ||
|
@@ -471,3 +474,34 @@ fn decl_integrity_test(scrate: &TokenStream2) -> TokenStream2 { | |
} | ||
) | ||
} | ||
|
||
fn decl_static_assertions( | ||
runtime: &Ident, | ||
pallet_decls: &[Pallet], | ||
scrate: &TokenStream2, | ||
) -> TokenStream2 { | ||
let error_encoded_size_check = pallet_decls.iter().map(|decl| { | ||
let path = &decl.path; | ||
let assert_message = format!( | ||
"The maximum encoded size of the error type in the `{}` pallet exceeds \ | ||
`MAX_MODULE_ERROR_ENCODED_SIZE`", | ||
decl.name, | ||
); | ||
|
||
quote! { | ||
#scrate::tt_call! { | ||
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. I have to admit that I'm still confused by this macro :P But yeah, it works ;) |
||
macro = [{ #path::tt_error_token }] | ||
frame_support = [{ #scrate }] | ||
~~> #scrate::assert_error_encoded_size! { | ||
path = [{ #path }] | ||
runtime = [{ #runtime }] | ||
assert_message = [{ #assert_message }] | ||
} | ||
} | ||
} | ||
}); | ||
|
||
quote! { | ||
#(#error_encoded_size_check)* | ||
} | ||
} |
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.
Feels this could be updated to support all the bytes