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
Submit (& sign) extrinsics from the runtime. #3514
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
51c3526
Abstract constructing extrinsic and signing.
tomusdrw f4e7284
Initial impl of signer.
tomusdrw 6451ed1
Merge branch 'master' into td-signing
tomusdrw 9a179d9
Implement get payload.
tomusdrw dd6b106
Merge branch 'master' into td-signing
tomusdrw ebe3078
Merge branch 'master' into td-signing
tomusdrw 7222869
Clean up the code.
tomusdrw 6883345
Merge branch 'master' into td-signing
tomusdrw f74cfc4
Improve docs.
tomusdrw 2c23ee0
Bump version.
tomusdrw 1516067
Update core/sr-primitives/src/generic/unchecked_extrinsic.rs
tomusdrw 5ee8936
Fix tests & address grumbles.
tomusdrw 4f13af4
Fix build.
tomusdrw ddf540f
Fix runtime tests.
tomusdrw b14dedb
Fix bound test.
tomusdrw 09611d3
Fix bound test.
tomusdrw 17db4b3
Merge branch 'td-signing' of github.com:paritytech/substrate into td-…
tomusdrw 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 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
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 |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ use sr_primitives::{ApplyResult, impl_opaque_keys, generic, create_runtime_str, | |
| use sr_primitives::transaction_validity::TransactionValidity; | ||
| use sr_primitives::weights::Weight; | ||
| use sr_primitives::traits::{ | ||
| BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, | ||
| self, BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, SaturatedConversion, | ||
| }; | ||
| use version::RuntimeVersion; | ||
| use elections::VoteIndex; | ||
|
|
@@ -48,6 +48,7 @@ use version::NativeVersion; | |
| use primitives::OpaqueMetadata; | ||
| use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight}; | ||
| use im_online::sr25519::{AuthorityId as ImOnlineId}; | ||
| use system::offchain::TransactionSubmitter; | ||
|
|
||
| #[cfg(any(feature = "std", test))] | ||
| pub use sr_primitives::BuildStorage; | ||
|
|
@@ -80,7 +81,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { | |
| // implementation changes and behavior does not, then leave spec_version as | ||
| // is and increment impl_version. | ||
| spec_version: 154, | ||
| impl_version: 157, | ||
| impl_version: 158, | ||
| apis: RUNTIME_API_VERSIONS, | ||
| }; | ||
|
|
||
|
|
@@ -392,11 +393,13 @@ impl sudo::Trait for Runtime { | |
| type Proposal = Call; | ||
| } | ||
|
|
||
| type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>; | ||
|
|
||
| impl im_online::Trait for Runtime { | ||
| type AuthorityId = ImOnlineId; | ||
| type Call = Call; | ||
| type Event = Event; | ||
| type UncheckedExtrinsic = UncheckedExtrinsic; | ||
| type SubmitTransaction = SubmitTransaction; | ||
| type ReportUnresponsiveness = Offences; | ||
| type CurrentElectedSet = staking::CurrentElectedStashAccounts<Runtime>; | ||
| } | ||
|
|
@@ -424,6 +427,33 @@ impl finality_tracker::Trait for Runtime { | |
| type ReportLatency = ReportLatency; | ||
| } | ||
|
|
||
| impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime { | ||
|
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. where is this being used?
Contributor
Author
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. We pass this as (see |
||
| type Signature = Signature; | ||
|
|
||
| fn create_transaction<F: system::offchain::Signer<AccountId, Self::Signature>>( | ||
| call: Call, | ||
| account: AccountId, | ||
| index: Index, | ||
| ) -> Option<(Call, <UncheckedExtrinsic as traits::Extrinsic>::SignaturePayload)> { | ||
| let period = 1 << 8; | ||
| let current_block = System::block_number().saturated_into::<u64>(); | ||
| let tip = 0; | ||
| let extra: SignedExtra = ( | ||
| system::CheckVersion::<Runtime>::new(), | ||
| system::CheckGenesis::<Runtime>::new(), | ||
| system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)), | ||
| system::CheckNonce::<Runtime>::from(index), | ||
| system::CheckWeight::<Runtime>::new(), | ||
| balances::TakeFees::<Runtime>::from(tip), | ||
| ); | ||
| let raw_payload = SignedPayload::new(call, extra).ok()?; | ||
| let signature = F::sign(account.clone(), &raw_payload)?; | ||
| let address = Indices::unlookup(account); | ||
| let (call, extra, _) = raw_payload.deconstruct(); | ||
| Some((call, (address, signature, extra))) | ||
| } | ||
| } | ||
|
|
||
| construct_runtime!( | ||
| pub enum Runtime where | ||
| Block = Block, | ||
|
|
@@ -475,6 +505,8 @@ pub type SignedExtra = ( | |
| ); | ||
| /// Unchecked extrinsic type as expected by this runtime. | ||
| pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>; | ||
| /// The payload being signed in transactions. | ||
| pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>; | ||
| /// Extrinsic type that has already been checked. | ||
| pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>; | ||
| /// Executive: handles dispatch to the various modules. | ||
|
|
@@ -609,3 +641,28 @@ impl_runtime_apis! { | |
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use sr_primitives::app_crypto::RuntimeAppPublic; | ||
| use system::offchain::SubmitSignedTransaction; | ||
|
|
||
| fn is_submit_signed_transaction<T, Signer>(_arg: T) where | ||
| T: SubmitSignedTransaction< | ||
| Runtime, | ||
| Call, | ||
| Extrinsic=UncheckedExtrinsic, | ||
| CreateTransaction=Runtime, | ||
| Signer=Signer, | ||
| >, | ||
| Signer: RuntimeAppPublic + From<AccountId>, | ||
| Signer::Signature: Into<Signature>, | ||
| {} | ||
|
|
||
| #[test] | ||
| fn validate_bounds() { | ||
| let x = SubmitTransaction::default(); | ||
| is_submit_signed_transaction(x); | ||
| } | ||
| } | ||
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.
Why is this implementation required?
Uh oh!
There was an error while loading. Please reload this page.
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.
The generic
Signerworks on anything that isEncode. I'll rather remove theusing_encodedfunction, I've only added it to be able to document the behavior.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.
You can also put documentation on top of a trait implementation. It will be shown in rustdocs as welll.