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
try-runtime::fast-forward
#12896
Merged
paritytech-processbot
merged 23 commits into
paritytech:master
from
Cardinal-Cryptography:piomiko/try-runtime/forward
Feb 17, 2023
Merged
try-runtime::fast-forward
#12896
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
63ea95b
try-runtime::fast-forward
pmikolajczyk41 6cdf5e0
Revert un`pub`ing command's fields
pmikolajczyk41 4c56a1c
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 4641e1f
Handle storage change failure
pmikolajczyk41 87804f0
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 f8e4e28
Adjust Substrate node
pmikolajczyk41 576204d
Feature-gated imports
pmikolajczyk41 80e35f9
doc link
pmikolajczyk41 9ba596e
Feature-gated imports in node-template
pmikolajczyk41 8fb7ef3
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 785c608
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 b72c49d
Move trait, blanket implementation and auxiliary functions to a new m…
pmikolajczyk41 3d4a6d2
Distinguish between plain babe+timestamp and substrate enhanced info
pmikolajczyk41 620291c
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 dcdca6b
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 9bd97b9
Remove uncles inherents
pmikolajczyk41 30e3428
Missing argument
pmikolajczyk41 3b04222
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 5bbc309
Add doc comment about `blocktime_millis`
pmikolajczyk41 a3b28f2
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 cc6781c
Add licenses
pmikolajczyk41 4a41c76
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 638f224
Merge remote-tracking branch 'origin/master' into piomiko/try-runtime…
pmikolajczyk41 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| use crate::BlockT; | ||
| use parity_scale_codec::Encode; | ||
| use sc_cli::Result; | ||
| use sp_consensus_aura::{Slot, SlotDuration, AURA_ENGINE_ID}; | ||
| use sp_consensus_babe::{ | ||
| digests::{PreDigest, SecondaryPlainPreDigest}, | ||
| BABE_ENGINE_ID, | ||
| }; | ||
| use sp_inherents::{InherentData, InherentDataProvider}; | ||
| use sp_runtime::{Digest, DigestItem}; | ||
| use sp_timestamp::TimestampInherentData; | ||
|
|
||
| /// Something that can create inherent data providers and pre-runtime digest. | ||
| /// | ||
| /// It is possible for the caller to provide custom arguments to the callee by setting the | ||
| /// `ExtraArgs` generic parameter. | ||
| /// | ||
| /// This module already provides some convenience implementation of this trait for closures. So, it | ||
| /// should not be required to implement it directly. | ||
| #[async_trait::async_trait] | ||
| pub trait BlockBuildingInfoProvider<Block: BlockT, ExtraArgs = ()> { | ||
| type InherentDataProviders: InherentDataProvider; | ||
|
|
||
| async fn get_inherent_providers_and_pre_digest( | ||
| &self, | ||
| parent_hash: Block::Hash, | ||
| extra_args: ExtraArgs, | ||
| ) -> Result<(Self::InherentDataProviders, Vec<DigestItem>)>; | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl<F, Block, IDP, ExtraArgs, Fut> BlockBuildingInfoProvider<Block, ExtraArgs> for F | ||
| where | ||
| Block: BlockT, | ||
| F: Fn(Block::Hash, ExtraArgs) -> Fut + Sync + Send, | ||
| Fut: std::future::Future<Output = Result<(IDP, Vec<DigestItem>)>> + Send + 'static, | ||
| IDP: InherentDataProvider + 'static, | ||
| ExtraArgs: Send + 'static, | ||
| { | ||
| type InherentDataProviders = IDP; | ||
|
|
||
| async fn get_inherent_providers_and_pre_digest( | ||
| &self, | ||
| parent: Block::Hash, | ||
| extra_args: ExtraArgs, | ||
| ) -> Result<(Self::InherentDataProviders, Vec<DigestItem>)> { | ||
| (*self)(parent, extra_args).await | ||
| } | ||
| } | ||
|
|
||
| /// Provides [`BlockBuildingInfoProvider`] implementation for chains that include timestamp inherent | ||
| /// and use Aura for a block production. | ||
| pub fn timestamp_with_aura_info<Block: BlockT>( | ||
| blocktime_millis: u64, | ||
| ) -> impl BlockBuildingInfoProvider<Block, Option<(InherentData, Digest)>> { | ||
| move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { | ||
| let timestamp_idp = match maybe_prev_info { | ||
| Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( | ||
| inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, | ||
| ), | ||
| None => sp_timestamp::InherentDataProvider::from_system_time(), | ||
| }; | ||
|
|
||
| let slot = | ||
| Slot::from_timestamp(*timestamp_idp, SlotDuration::from_millis(blocktime_millis)); | ||
| let digest = vec![DigestItem::PreRuntime(AURA_ENGINE_ID, slot.encode())]; | ||
|
|
||
| Ok((timestamp_idp, digest)) | ||
| } | ||
| } | ||
|
|
||
| /// Provides [`BlockBuildingInfoProvider`] implementation for chains that include timestamp inherent | ||
| /// and use Babe for a block production. | ||
| pub fn timestamp_with_babe_info<Block: BlockT>( | ||
| blocktime_millis: u64, | ||
| ) -> impl BlockBuildingInfoProvider<Block, Option<(InherentData, Digest)>> { | ||
| move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { | ||
| let timestamp_idp = match maybe_prev_info { | ||
| Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( | ||
| inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, | ||
| ), | ||
| None => sp_timestamp::InherentDataProvider::from_system_time(), | ||
| }; | ||
|
|
||
| let slot = | ||
| Slot::from_timestamp(*timestamp_idp, SlotDuration::from_millis(blocktime_millis)); | ||
| let slot_idp = sp_consensus_babe::inherents::InherentDataProvider::new(slot); | ||
|
|
||
| let digest = vec![DigestItem::PreRuntime( | ||
| BABE_ENGINE_ID, | ||
| PreDigest::SecondaryPlain(SecondaryPlainPreDigest { slot, authority_index: 0 }) | ||
| .encode(), | ||
| )]; | ||
|
|
||
| Ok(((slot_idp, timestamp_idp), digest)) | ||
| } | ||
| } | ||
|
|
||
| /// Provides [`BlockBuildingInfoProvider`] implementation for chains that use: | ||
| /// - timestamp inherent, | ||
| /// - Babe for a block production (inherent + digest), | ||
| /// - uncles inherent, | ||
| /// - storage proof inherent | ||
| pub fn substrate_info<Block: BlockT>( | ||
| blocktime_millis: u64, | ||
| ) -> impl BlockBuildingInfoProvider<Block, Option<(InherentData, Digest)>> { | ||
| move |_, maybe_prev_info: Option<(InherentData, Digest)>| async move { | ||
| let timestamp_idp = match maybe_prev_info { | ||
| Some((inherent_data, _)) => sp_timestamp::InherentDataProvider::new( | ||
| inherent_data.timestamp_inherent_data().unwrap().unwrap() + blocktime_millis, | ||
| ), | ||
| None => sp_timestamp::InherentDataProvider::from_system_time(), | ||
| }; | ||
|
|
||
| let slot = | ||
| Slot::from_timestamp(*timestamp_idp, SlotDuration::from_millis(blocktime_millis)); | ||
| let slot_idp = sp_consensus_babe::inherents::InherentDataProvider::new(slot); | ||
|
|
||
| let storage_proof_idp = sp_transaction_storage_proof::InherentDataProvider::new(None); | ||
|
|
||
| let digest = vec![DigestItem::PreRuntime( | ||
| BABE_ENGINE_ID, | ||
| PreDigest::SecondaryPlain(SecondaryPlainPreDigest { slot, authority_index: 0 }) | ||
| .encode(), | ||
| )]; | ||
|
|
||
| Ok(((slot_idp, timestamp_idp, storage_proof_idp), digest)) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.