This repository was 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.7k
DigestItem trait (v2) #650
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2071ff6
DigestItem trait
svyatonik e9dcb0a
removed autoimpl in impl_outer_log
svyatonik f157c4b
StubDigestItem -> ()
svyatonik 6e185c4
Merge branch 'master' into digest_items
svyatonik b47e65d
Merge branch 'master' into digest_items
svyatonik 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file modified
BIN
+6.9 KB
(100%)
demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.compact.wasm
Binary file not shown.
Binary file modified
BIN
+6.9 KB
(100%)
demo/runtime/wasm/target/wasm32-unknown-unknown/release/demo_runtime.wasm
Binary file not shown.
Binary file modified
BIN
+180 Bytes
(100%)
substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm
Binary file not shown.
Binary file modified
BIN
+180 Bytes
(100%)
substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm
Binary file not shown.
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 |
|---|---|---|
|
|
@@ -112,3 +112,38 @@ macro_rules! impl_outer_event { | |
| )* | ||
| } | ||
| } | ||
|
|
||
| #[macro_export] | ||
| macro_rules! impl_outer_log { | ||
| ($(#[$attr:meta])* pub enum $name:ident for $trait:ident { $( $module:ident($( $log_type_name:ident => $log_type:ty => $as_log:ident ),*) ),* }) => { | ||
|
||
| // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. | ||
| #[derive(Clone, PartialEq, Eq, Encode, Decode)] | ||
| #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] | ||
| $(#[$attr])* | ||
| #[allow(non_camel_case_types)] | ||
| pub enum $name { | ||
| $( | ||
| $module($module::Log<$trait>), | ||
| )* | ||
| } | ||
| $( | ||
| impl From<$module::Log<$trait>> for $name { | ||
| fn from(x: $module::Log<$trait>) -> Self { | ||
| $name::$module(x) | ||
| } | ||
| } | ||
|
|
||
| impl DigestItem for $name { | ||
| $( | ||
| type $log_type_name = $log_type; | ||
|
|
||
| fn $as_log(&self) -> Option<&$log_type> { | ||
| match *self { | ||
| $name::$module(ref item) => item.$as_log(), | ||
| } | ||
| } | ||
| )* | ||
| } | ||
| )* | ||
| } | ||
| } | ||
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
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
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
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.
consider just introducing
trait AsAuthoritiesChange { fn as_authorities_change(self) -> Result<Vec<SessionKey>, Self> }and then manually making animplof it here. might save quite a lot of somewhat opaque syntax.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.
Substrate has an access to digest items only through
DigestItemtrait, which is shared among all possible runtimes (declared in primitives). Extractingas_authorities_change(and other similar conversions later) into separate conversion trait would requireDiggestItemto inherit from all those traits + will make it impossible to use default implementation (which returnsNoneright now) => all runtimes have to explicitly declare support even for those 'system' digest items, which they are not willing to support (by simply usingStubDigestItemand returningNone).I'm not sure it is better - this is an additional overhead for runtimes development. From the other side, it will force runtime developers to explicitly throw away items the do not want to support. Left as is for now, but could extract if you insist.
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.
Probably also could remove
AuthoritiesChangeDigesttrait in favor ofVec<AuthorityId>.