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
Add after_inherents
#14414
Draft
ggwpez
wants to merge
47
commits into
master
Choose a base branch
from
oty-after-inherents
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.
Draft
Add after_inherents
#14414
Changes from 34 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7f6a396
Add after_inherents
ggwpez 03f6b4e
Fix template runtime
ggwpez 6d04b2a
Fix test
ggwpez 76fb1bc
Fix test
ggwpez 2f62b6a
Move executive tests to own file
ggwpez 5740d37
fmt
ggwpez 911111d
Add test
ggwpez 93d2171
Fix try-runtime
ggwpez b1b4b43
Merge branch 'master' into oty-after-inherents
ggwpez b12af3a
Fix test?
ggwpez cead998
Cleanup
ggwpez 94e4658
Cleanup
ggwpez 4ac155d
Consume weight instead of return
ggwpez 627b57a
Review
ggwpez 99d37ee
Check runtime API version
ggwpez 3aca2c3
Cleanup
ggwpez 85d6eb2
Merge remote-tracking branch 'origin/master' into oty-after-inherents
ggwpez 0aa9112
Revert "Consume weight instead of return"
ggwpez f29b46f
Return ExecutiveMode from initialize_block
ggwpez e9b15c7
Fix tests
ggwpez 975b8c1
Merge remote-tracking branch 'origin/master' into oty-after-inherents
ggwpez b9bfdd7
Cleanup
ggwpez ce2b00c
Fixup
ggwpez a54f5fd
Move initialize_block to the block builder
ggwpez a01f247
Fix test
ggwpez b50a78b
Fix test
ggwpez 8f7751c
Fix imports
ggwpez baa9a39
Update UI tests
ggwpez 2c6f764
Check runtime API
ggwpez 706bcd9
Revert "Update UI tests"
ggwpez 835941c
Fix doc tests
ggwpez 708ede6
Fix UI tests
ggwpez b7869da
Also version initialize_block
ggwpez 2ce81eb
Cleanup
ggwpez 83bbe6f
Update client/block-builder/src/lib.rs
ggwpez 66b1091
Review fixes
ggwpez 1c1f71c
Remove unused dep
ggwpez 0e589e0
Merge remote-tracking branch 'origin/master' into oty-after-inherents
ggwpez e9e60ef
Adapt to set_call_context
ggwpez a36bcc6
Review fixes and renames
ggwpez 469a103
Merge remote-tracking branch 'origin/master' into oty-after-inherents
ggwpez da4c138
Review
ggwpez d04928c
Comment
ggwpez 7369e42
Fix docs
ggwpez 585373a
Remove after_inherents
ggwpez cb59e4f
Merge remote-tracking branch 'origin/master' into oty-after-inherents
ggwpez 0929252
Fixup
ggwpez 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 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 | ||
---|---|---|---|---|
|
@@ -36,7 +36,7 @@ use sp_core::ExecutionContext; | |||
use sp_runtime::{ | ||||
legacy, | ||||
traits::{Block as BlockT, Hash, HashFor, Header as HeaderT, NumberFor, One}, | ||||
Digest, | ||||
Digest, RuntimeExecutiveMode, | ||||
}; | ||||
|
||||
use sc_client_api::backend; | ||||
|
@@ -139,6 +139,8 @@ pub struct BlockBuilder<'a, Block: BlockT, A: ProvideRuntimeApi<Block>, B> { | |||
backend: &'a B, | ||||
/// The estimated size of the block header. | ||||
estimated_header_size: usize, | ||||
/// The executive mode of the block that is currently being built. | ||||
pub executive_mode: RuntimeExecutiveMode, | ||||
} | ||||
|
||||
impl<'a, Block, A, B> BlockBuilder<'a, Block, A, B> | ||||
|
@@ -173,20 +175,29 @@ where | |||
let estimated_header_size = header.encoded_size(); | ||||
|
||||
let mut api = api.runtime_api(); | ||||
let version = api | ||||
.api_version::<dyn BlockBuilderApi<Block>>(parent_hash)? | ||||
.ok_or_else(|| Error::VersionInvalid("BlockBuilderApi".to_string()))?; | ||||
|
||||
if record_proof.yes() { | ||||
api.record_proof(); | ||||
} | ||||
|
||||
api.initialize_block_with_context( | ||||
parent_hash, | ||||
ExecutionContext::BlockConstruction, | ||||
&header, | ||||
)?; | ||||
|
||||
let version = api | ||||
.api_version::<dyn BlockBuilderApi<Block>>(parent_hash)? | ||||
.ok_or_else(|| Error::VersionInvalid("BlockBuilderApi".to_string()))?; | ||||
let executive_mode = if version >= 5 { | ||||
api.initialize_block_with_context( | ||||
parent_hash, | ||||
ExecutionContext::BlockConstruction, | ||||
&header, | ||||
)? | ||||
} else { | ||||
#[allow(deprecated)] | ||||
api.initialize_block_before_version_5_with_context( | ||||
parent_hash, | ||||
ExecutionContext::BlockConstruction, | ||||
&header, | ||||
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. substrate/client/transaction-pool/src/api.rs Line 258 in 63246b6
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. Okay calling |
||||
)?; | ||||
RuntimeExecutiveMode::Normal | ||||
}; | ||||
|
||||
Ok(Self { | ||||
parent_hash, | ||||
|
@@ -195,9 +206,25 @@ where | |||
version, | ||||
backend, | ||||
estimated_header_size, | ||||
executive_mode, | ||||
}) | ||||
} | ||||
|
||||
/// Called after inherents but before extrinsics have been applied. | ||||
pub fn after_inherents(&self, mode: RuntimeExecutiveMode) -> Result<(), Error> { | ||||
if self.version >= 7 { | ||||
self.api | ||||
.after_inherents_with_context( | ||||
self.parent_hash, | ||||
ExecutionContext::BlockConstruction, | ||||
mode, | ||||
) | ||||
.map_err(Into::into) | ||||
} else { | ||||
Ok(()) | ||||
} | ||||
} | ||||
|
||||
/// Push onto the block's list of extrinsics. | ||||
/// | ||||
/// This will ensure the extrinsic can be validly executed (by executing it). | ||||
|
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
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.
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.
I am actually using this in the authorship here
substrate/client/basic-authorship/src/basic_authorship.rs
Line 352 in 2ce81eb
Do you think it should rather be returned by the
new
function?