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
Tipped Transaction Type. #2930
Closed
Closed
Tipped Transaction Type. #2930
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ab34400
Initial draft of tip enum
d36dc9a
Fix local tests
a18be8c
Builds.
kianenigma 55d39cf
Fix test build.
kianenigma a4e2816
Tratify tip.
kianenigma 58ae208
Cleanup of checkedExt.
kianenigma c7fe8bf
More cleanup.
kianenigma e47bf96
Master.into()
kianenigma 78dde21
Checked Tip + other fixes.
kianenigma 7326e5a
Line width
kianenigma a568a9b
Update core/sr-primitives/src/generic/tip.rs
4meta5 b3f69cb
Fix build.
kianenigma 557f6c5
Merge branch 'master' of github.com:paritytech/substrate into kiz-tx-tip
kianenigma 8e713aa
Bump.
kianenigma b110af6
Merge branch 'kiz-tx-tip' of github.com:paritytech/substrate into kiz…
kianenigma 23df80d
Some cleanup (+should pass the tests).
kianenigma 83721a4
Fix sync test payload.
kianenigma bd28f0d
Fix subkey and factory sig
kianenigma 120de20
revert back old unchecked ext type to NOT use tip.
kianenigma 0d1de9d
Make balance associated type of payment.
kianenigma 6836f6b
Optionize tip.
kianenigma 7191a7d
Further cleanup.
kianenigma 0846065
Further cleanup.
kianenigma 12ecfcc
Master.into()
kianenigma bf99e73
Fix tests.
kianenigma 4824776
remove balance as generic.
kianenigma fb42e4e
Update doc.
kianenigma 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
remove balance as generic.
- Loading branch information
commit 4824776778395f3152ca043ee262d64dda28e665
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| // Copyright 2017-2019 Parity Technologies (UK) Ltd. | ||||||
| // Copyright 2019 Parity Technologies (UK) Ltd. | ||||||
| // This file is part of Substrate. | ||||||
|
|
||||||
| // Substrate is free software: you can redistribute it and/or modify | ||||||
|
|
@@ -26,14 +26,14 @@ use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, | |||||
| Lookup, Checkable, Extrinsic, SaturatedConversion}; | ||||||
| use super::{CheckedExtrinsic, Era, Tip}; | ||||||
|
|
||||||
| const TRANSACTION_VERSION: u8 = 2; | ||||||
| const TRANSACTION_VERSION: u8 = 64; | ||||||
|
|
||||||
| /// A extrinsic right from the external world. This is unchecked and so | ||||||
| /// can contain a signature. | ||||||
| /// | ||||||
| /// This type transaction: | ||||||
| /// - _Must_ always have a valid `Tip` encoded, and included in the signature payload if it is | ||||||
| /// signed. | ||||||
| /// - _Must_ always have a valid `Tip` (not an option!) encoded, and included in the signature | ||||||
| /// payload if it is signed. | ||||||
| /// - _Must_ not provide any `Tip` if it is unsigned. | ||||||
| #[derive(PartialEq, Eq, Clone)] | ||||||
| pub struct UncheckedMortalCompactTippedExtrinsic<Address, Index, Call, Signature, Balance> { | ||||||
|
|
@@ -43,7 +43,8 @@ pub struct UncheckedMortalCompactTippedExtrinsic<Address, Index, Call, Signature | |||||
| pub signature: Option<(Address, Signature, Compact<Index>, Era)>, | ||||||
|
Member
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.
Suggested change
|
||||||
| /// The function that should be called. | ||||||
| pub function: Call, | ||||||
| /// The tip for this transaction | ||||||
| /// The tip for this transaction. This is always `Some` for a signed transaction and always | ||||||
| /// `None` for unsigned. | ||||||
| pub tip: Option<Tip<Balance>>, | ||||||
|
Member
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. doesn't belong here since it's meaningless unless this is a (signed) transaction. |
||||||
| } | ||||||
|
|
||||||
|
|
@@ -57,12 +58,12 @@ impl<Address, Index, Call, Signature, Balance> | |||||
| signed: Address, | ||||||
| signature: Signature, | ||||||
| era: Era, | ||||||
| tip: Option<Tip<Balance>> | ||||||
| tip: Tip<Balance>, | ||||||
| ) -> Self { | ||||||
| UncheckedMortalCompactTippedExtrinsic { | ||||||
| signature: Some((signed, signature, index.into(), era)), | ||||||
| function, | ||||||
| tip, | ||||||
| tip: Some(tip), | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -71,7 +72,7 @@ impl<Address, Index, Call, Signature, Balance> | |||||
| UncheckedMortalCompactTippedExtrinsic { | ||||||
| signature: None, | ||||||
| function, | ||||||
| tip: None | ||||||
| tip: None, | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -105,11 +106,12 @@ where | |||||
| fn check(self, context: &Context) -> Result<Self::Checked, &'static str> { | ||||||
| Ok(match self.signature { | ||||||
| Some((signed, signature, index, era)) => { | ||||||
| let tip = self.tip.ok_or("signed transaction must always have a tip.")?; | ||||||
| let current_u64 = context.current_height().saturated_into::<u64>(); | ||||||
|
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. Some deduplication of this function should be possible, it basically differs only in |
||||||
| let h = context.block_number_to_hash(era.birth(current_u64).saturated_into()) | ||||||
| .ok_or("transaction birth block ancient")?; | ||||||
| let signed = context.lookup(signed)?; | ||||||
| let raw_payload = (index, self.function, self.tip, era, h); | ||||||
| let raw_payload = (index, self.function, tip, era, h); | ||||||
| if !raw_payload.using_encoded(|payload| { | ||||||
| if payload.len() > 256 { | ||||||
| signature.verify(&blake2_256(payload)[..], &signed) | ||||||
|
|
@@ -122,7 +124,7 @@ where | |||||
| CheckedExtrinsic { | ||||||
| signed: Some((signed, (raw_payload.0).0)), | ||||||
| function: raw_payload.1, | ||||||
| tip: raw_payload.2, | ||||||
| tip: Some(raw_payload.2), | ||||||
| } | ||||||
| } | ||||||
| None => { | ||||||
|
|
@@ -169,7 +171,7 @@ where | |||||
| Some(UncheckedMortalCompactTippedExtrinsic { | ||||||
| signature: if is_signed { Some(Decode::decode(input)?) } else { None }, | ||||||
| function: Decode::decode(input)?, | ||||||
| tip: if is_signed { Decode::decode(input)? } else { None }, | ||||||
| tip: if is_signed { Some(Decode::decode(input)?) } else { None }, | ||||||
| }) | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -197,7 +199,7 @@ where | |||||
| } | ||||||
| self.function.encode_to(v); | ||||||
| if self.signature.is_some() { | ||||||
| self.tip.encode_to(v); | ||||||
| self.tip.as_ref().unwrap().encode_to(v); | ||||||
| } | ||||||
| }) | ||||||
| } | ||||||
|
|
@@ -268,7 +270,7 @@ mod tests { | |||||
| type Balance = u64; | ||||||
| type TipType = Tip<Balance>; | ||||||
| const DUMMY_ACCOUNTID: u64 = 0; | ||||||
| const TIP: Option<TipType> = Some(Tip::Sender(66)); | ||||||
| const TIP: TipType = Tip::Sender(66); | ||||||
|
|
||||||
| type Ex = UncheckedMortalCompactTippedExtrinsic<u64, u64, Vec<u8>, TestSig, Balance>; | ||||||
| type CEx = CheckedExtrinsic<u64, u64, Vec<u8>, Balance>; | ||||||
|
|
@@ -348,7 +350,7 @@ mod tests { | |||||
| assert!(ux.is_signed().unwrap_or(false)); | ||||||
| assert_eq!( | ||||||
| <Ex as Checkable<TestContext>>::check(ux, &TestContext), | ||||||
| Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: vec![0u8;0], tip: TIP }) | ||||||
| Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: vec![0u8;0], tip: Some(TIP) }) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -368,7 +370,7 @@ mod tests { | |||||
| assert!(ux.is_signed().unwrap_or(false)); | ||||||
| assert_eq!( | ||||||
| <Ex as Checkable<TestContext>>::check(ux, &TestContext), | ||||||
| Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: vec![0u8;0], tip: TIP })); | ||||||
| Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: vec![0u8;0], tip: Some(TIP) })); | ||||||
| } | ||||||
|
|
||||||
| #[test] | ||||||
|
|
@@ -387,7 +389,7 @@ mod tests { | |||||
| assert!(ux.is_signed().unwrap_or(false)); | ||||||
| assert_eq!( | ||||||
| <Ex as Checkable<TestContext>>::check(ux, &TestContext), | ||||||
| Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: vec![0u8;0], tip: TIP }) | ||||||
| Ok(CEx { signed: Some((DUMMY_ACCOUNTID, 0)), function: vec![0u8;0], tip: Some(TIP) }) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -460,7 +462,7 @@ mod tests { | |||||
| function: vec![0u8;0] | ||||||
| }; | ||||||
| assert_eq!( | ||||||
| <Ex as Checkable<TestContext>>::check(ux, &TestContext).unwrap(), | ||||||
| <Ex as Checkable<TestContext>>::check(ux, &TestContext), | ||||||
| Err(crate::UNSIGNED_TIP) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
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
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 not
()?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.
Could not have it meet the type requirements of the generic type (has to be
SimpleArithmetic-- probably doable but needs a more handy rust dev with more time -- will try)