Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
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
Jun 19, 2019
d36dc9a
Fix local tests
Jun 19, 2019
a18be8c
Builds.
kianenigma Jun 22, 2019
55d39cf
Fix test build.
kianenigma Jun 22, 2019
a4e2816
Tratify tip.
kianenigma Jun 23, 2019
58ae208
Cleanup of checkedExt.
kianenigma Jun 23, 2019
c7fe8bf
More cleanup.
kianenigma Jun 23, 2019
e47bf96
Master.into()
kianenigma Jun 23, 2019
78dde21
Checked Tip + other fixes.
kianenigma Jun 27, 2019
7326e5a
Line width
kianenigma Jun 27, 2019
a568a9b
Update core/sr-primitives/src/generic/tip.rs
4meta5 Jun 28, 2019
b3f69cb
Fix build.
kianenigma Jun 28, 2019
557f6c5
Merge branch 'master' of github.com:paritytech/substrate into kiz-tx-tip
kianenigma Jun 28, 2019
8e713aa
Bump.
kianenigma Jun 28, 2019
b110af6
Merge branch 'kiz-tx-tip' of github.com:paritytech/substrate into kiz…
kianenigma Jun 28, 2019
23df80d
Some cleanup (+should pass the tests).
kianenigma Jun 30, 2019
83721a4
Fix sync test payload.
kianenigma Jun 30, 2019
bd28f0d
Fix subkey and factory sig
kianenigma Jun 30, 2019
120de20
revert back old unchecked ext type to NOT use tip.
kianenigma Jul 9, 2019
0d1de9d
Make balance associated type of payment.
kianenigma Jul 10, 2019
6836f6b
Optionize tip.
kianenigma Jul 10, 2019
7191a7d
Further cleanup.
kianenigma Jul 10, 2019
0846065
Further cleanup.
kianenigma Jul 10, 2019
12ecfcc
Master.into()
kianenigma Jul 10, 2019
bf99e73
Fix tests.
kianenigma Jul 10, 2019
4824776
remove balance as generic.
kianenigma Jul 10, 2019
fb42e4e
Update doc.
kianenigma Jul 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove balance as generic.
  • Loading branch information
kianenigma committed Jul 10, 2019
commit 4824776778395f3152ca043ee262d64dda28e665
6 changes: 3 additions & 3 deletions core/sr-primitives/src/generic/checked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ where
// Or 2- this is built from all other types of uncheckedextrinsic which do not have tip and
// hence are not tip-aware. These modules will naively place a u32 (can be `()` in practice)
// as the type and it does not matter since `None` is used in this case (first arm).
match self.tip {
match &self.tip {
None => None,
Some(Tip::Sender(v)) => Some(Tip::Sender(NodeBalance::from(v))),
Some(Tip::Sender(v)) => Some(Tip::Sender(NodeBalance::from(*v))),
}
}
}
}
2 changes: 1 addition & 1 deletion core/sr-primitives/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub use self::checked_extrinsic::CheckedExtrinsic;
pub use self::header::Header;
pub use self::block::{Block, SignedBlock, BlockId};
pub use self::digest::{Digest, DigestItem, DigestItemRef, OpaqueDigestItemId};
pub use self::tip::{Tip, Tippable};
pub use self::tip::{Tip, Tippable, NoTipBalance};

use crate::codec::Encode;
use rstd::prelude::*;
Expand Down
6 changes: 6 additions & 0 deletions core/sr-primitives/src/generic/tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
use crate::codec::{Encode, Decode};
use crate::traits::Zero;

/// A placeholder tip type that is used to fulfill the generic requirements of `checked_extrinsic`
/// when the underlying `unchecked_extrinsic` actually does not have a tip.
pub type NoTipBalance = u32;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not ()?

Copy link
Contributor Author

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)


/// Representation of a transaction tip.
///
/// Provided as an enum to support potential future use cases such as:
Expand All @@ -28,6 +32,8 @@ use crate::traits::Zero;
#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)]
pub enum Tip<Balance> {
/// The sender of the transaction has included some tip.
///
/// this must be signed and included in the signature payload.
Sender(Balance),
}

Expand Down
3 changes: 2 additions & 1 deletion core/sr-primitives/src/generic/unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::fmt;
use rstd::prelude::*;
use crate::codec::{Decode, Encode, Codec, Input, HasCompact};
use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, Lookup, Extrinsic};
use crate::generic::tip::NoTipBalance;
use super::CheckedExtrinsic;

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
Expand Down Expand Up @@ -85,7 +86,7 @@ where
AccountId: Member + MaybeDisplay,
Context: Lookup<Source=Address, Target=AccountId>,
{
type Checked = CheckedExtrinsic<AccountId, Index, Call, u32>;
type Checked = CheckedExtrinsic<AccountId, Index, Call, NoTipBalance>;

fn check(self, context: &Context) -> Result<Self::Checked, &'static str> {
Ok(match self.signature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::codec::{Decode, Encode, Input, Compact};
use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash,
Lookup, Checkable, Extrinsic, SaturatedConversion};
use super::{CheckedExtrinsic, Era};
use crate::generic::tip::NoTipBalance;

const TRANSACTION_VERSION: u8 = 1;

Expand Down Expand Up @@ -85,7 +86,7 @@ where
{
/// NOTE: this transaction is not tipped i.e. the tip value will be `None`. It does not really
/// matter what the last generic is since it is always `None`.
type Checked = CheckedExtrinsic<AccountId, Index, Call, u32>;
type Checked = CheckedExtrinsic<AccountId, Index, Call, NoTipBalance>;

fn check(self, context: &Context) -> Result<Self::Checked, &'static str> {
Ok(match self.signature {
Expand Down Expand Up @@ -185,8 +186,7 @@ impl<Address: Encode, Index, Signature: Encode, Call: Encode> serde::Serialize
}

#[cfg(feature = "std")]
impl<Address, Index, Call, Signature> fmt::Debug
for UncheckedMortalCompactExtrinsic<Address, Index, Call, Signature>
impl<Address, Index, Call, Signature> fmt::Debug for UncheckedMortalCompactExtrinsic<Address, Index, Call, Signature>
where
Address: fmt::Debug,
Index: fmt::Debug,
Expand Down Expand Up @@ -237,7 +237,7 @@ mod tests {
const DUMMY_ACCOUNTID: u64 = 0;

type Ex = UncheckedMortalCompactExtrinsic<u64, u64, Vec<u8>, TestSig>;
type CEx = CheckedExtrinsic<u64, u64, Vec<u8>, u32>;
type CEx = CheckedExtrinsic<u64, u64, Vec<u8>, NoTipBalance>;

#[test]
fn unsigned_codec_should_work() {
Expand Down
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
Expand Down Expand Up @@ -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> {
Expand All @@ -43,7 +43,8 @@ pub struct UncheckedMortalCompactTippedExtrinsic<Address, Index, Call, Signature
pub signature: Option<(Address, Signature, Compact<Index>, Era)>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub signature: Option<(Address, Signature, Compact<Index>, Era)>,
pub signature: Option<(Address, Signature, Compact<Index>, Era, Tip<Balance>)>,

/// 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>>,
Copy link
Member

Choose a reason for hiding this comment

The 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.

}

Expand All @@ -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),
}
}

Expand All @@ -71,7 +72,7 @@ impl<Address, Index, Call, Signature, Balance>
UncheckedMortalCompactTippedExtrinsic {
signature: None,
function,
tip: None
tip: None,
}
}
}
Expand Down Expand Up @@ -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>();
Copy link
Contributor

Choose a reason for hiding this comment

The 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 payload.

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)
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 },
})
}
}
Expand Down Expand Up @@ -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);
}
})
}
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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) })
);
}

Expand All @@ -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]
Expand All @@ -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) })
);
}

Expand Down Expand Up @@ -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)
);
}
Expand Down
5 changes: 3 additions & 2 deletions core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::traits::{
self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash,
Lookup, Checkable, Extrinsic, SaturatedConversion
};
use crate::generic::tip::NoTipBalance;
use super::{CheckedExtrinsic, Era};

const TRANSACTION_VERSION: u8 = 1;
Expand Down Expand Up @@ -84,7 +85,7 @@ where
{
/// NOTE: this transaction is not tipped i.e. the tip value will be `None`. It does not really
/// matter what the last generic is since it is always `None`.
type Checked = CheckedExtrinsic<AccountId, Index, Call, u32>;
type Checked = CheckedExtrinsic<AccountId, Index, Call, NoTipBalance>;

fn check(self, context: &Context) -> Result<Self::Checked, &'static str> {
Ok(match self.signature {
Expand Down Expand Up @@ -236,7 +237,7 @@ mod tests {
const DUMMY_ACCOUNTID: u64 = 0;

type Ex = UncheckedMortalExtrinsic<u64, u64, Vec<u8>, TestSig>;
type CEx = CheckedExtrinsic<u64, u64, Vec<u8>, u32>;
type CEx = CheckedExtrinsic<u64, u64, Vec<u8>, NoTipBalance>;

#[test]
fn unsigned_codec_should_work() {
Expand Down
2 changes: 1 addition & 1 deletion node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address,
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call, Balance>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Context, Balances, Balance, Runtime, AllModules>;
pub type Executive = executive::Executive<Runtime, Block, Context, Balances, Runtime, AllModules>;

// Implement our runtime API endpoints. This is just a bunch of proxying.
impl_runtime_apis! {
Expand Down
2 changes: 1 addition & 1 deletion node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests {
};
use node_primitives::{Hash, BlockNumber, AccountId};
use runtime_primitives::traits::{Header as HeaderT, Hash as HashT};
use runtime_primitives::{generic::{Era, Tip}, ApplyOutcome, ApplyError, ApplyResult, Perbill};
use runtime_primitives::{generic::Era, ApplyOutcome, ApplyError, ApplyResult, Perbill};
use {balances, contracts, indices, staking, system, timestamp};
use contracts::ContractAddressFor;
use system::{EventRecord, Phase};
Expand Down
9 changes: 1 addition & 8 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,7 @@ pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address,
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Index, Call, Balance>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<
Runtime, Block,
system::ChainContext<Runtime>,
Balances,
Balance,
Runtime,
AllModules,
>;
pub type Executive = executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Balances, Runtime, AllModules>;

impl_runtime_apis! {
impl client_api::Core<Block> for Runtime {
Expand Down
16 changes: 6 additions & 10 deletions srml/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
//! # }
//! # }
//! /// Executive: handles dispatch to the various modules.
//! pub type Executive = executive::Executive<Runtime, Block, Context, Balances, Balances, Runtime, AllModules>;
//! pub type Executive = executive::Executive<Runtime, Block, Context, Balances, Runtime, AllModules>;
//! ```

#![cfg_attr(not(feature = "std"), no_std)]
Expand All @@ -81,7 +81,6 @@ use primitives::{ApplyOutcome, ApplyError,
transaction_validity::{TransactionValidity, TransactionPriority, TransactionLongevity},
traits::{self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize, OnInitialize,
NumberFor, Block as BlockT, OffchainWorker, ValidateUnsigned,
SimpleArithmetic,
},
};
use srml_support::{Dispatchable, traits::MakePayment};
Expand Down Expand Up @@ -116,19 +115,18 @@ pub type CallOf<E, C> = <CheckedOf<E, C> as Applyable>::Call;
pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
pub type BalanceOf<P, A> = <P as MakePayment<A>>::Balance;

pub struct Executive<System, Block, Context, Payment, Balance, UnsignedValidator, AllModules>(
PhantomData<(System, Block, Context, Payment, Balance, UnsignedValidator, AllModules)>
pub struct Executive<System, Block, Context, Payment, UnsignedValidator, AllModules>(
PhantomData<(System, Block, Context, Payment, UnsignedValidator, AllModules)>
);

impl<
System: system::Trait,
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
Context: Default,
Payment: MakePayment<System::AccountId>,
Balance,
UnsignedValidator,
AllModules: OnInitialize<System::BlockNumber> + OnFinalize<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
> ExecuteBlock<Block> for Executive<System, Block, Context, Payment, Balance, UnsignedValidator, AllModules>
> ExecuteBlock<Block> for Executive<System, Block, Context, Payment, UnsignedValidator, AllModules>
where
Block::Extrinsic: Checkable<Context> + Codec,
CheckedOf<Block::Extrinsic, Context>:
Expand All @@ -140,7 +138,7 @@ where
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
{
fn execute_block(block: Block) {
Executive::<System, Block, Context, Payment, Balance, UnsignedValidator, AllModules>::execute_block(block);
Executive::<System, Block, Context, Payment, UnsignedValidator, AllModules>::execute_block(block);
}
}

Expand All @@ -149,10 +147,9 @@ impl<
Block: traits::Block<Header=System::Header, Hash=System::Hash>,
Context: Default,
Payment: MakePayment<System::AccountId>,
Balance: SimpleArithmetic + Copy,
UnsignedValidator,
AllModules: OnInitialize<System::BlockNumber> + OnFinalize<System::BlockNumber> + OffchainWorker<System::BlockNumber>,
> Executive<System, Block, Context, Payment, Balance, UnsignedValidator, AllModules>
> Executive<System, Block, Context, Payment, UnsignedValidator, AllModules>
where
Block::Extrinsic: Checkable<Context> + Codec,
CheckedOf<Block::Extrinsic, Context>:
Expand Down Expand Up @@ -499,7 +496,6 @@ mod tests {
Block<TestXt>,
system::ChainContext<Runtime>,
balances::Module<Runtime>,
u64,
Runtime,
()
>;
Expand Down