From 4808077674e038a5d3aa654540a47a88bbc48fe7 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sat, 26 May 2018 19:14:47 +0800 Subject: [PATCH] Update transaction-pool dependency and remove ethereum-types (#174) --- substrate/Cargo.lock | 70 ++++--------------- .../polkadot/transaction-pool/Cargo.toml | 3 +- .../polkadot/transaction-pool/src/lib.rs | 51 ++++++-------- 3 files changed, 36 insertions(+), 88 deletions(-) diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 7ae553341d..7b45912e53 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -373,18 +373,6 @@ dependencies = [ "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethbloom" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethbloom" version = "0.5.0" @@ -508,20 +496,6 @@ dependencies = [ "tiny-keccak 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethereum-types" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethbloom 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ethereum-types" version = "0.3.1" @@ -590,17 +564,6 @@ dependencies = [ "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "fixed-hash" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "fixed-hash" version = "0.2.1" @@ -1453,7 +1416,6 @@ version = "0.1.0" dependencies = [ "ed25519 0.1.0", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "polkadot-api 0.1.0", "polkadot-primitives 0.1.0", @@ -1463,7 +1425,7 @@ dependencies = [ "substrate-primitives 0.1.0", "substrate-rpc 0.1.0", "substrate-runtime-primitives 0.1.0", - "transaction-pool 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "transaction-pool 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2472,15 +2434,23 @@ dependencies = [ "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "trace-time" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "transaction-pool" -version = "1.9.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "trace-time 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2522,17 +2492,6 @@ dependencies = [ "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "uint" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "uint" version = "0.2.0" @@ -2765,7 +2724,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" "checksum eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)" = "" -"checksum ethbloom 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f240172b976e2421fa5485e45cd45287bbdb56d742aa3a1d77005c49071a8518" "checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" "checksum ethcore-bigint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcb5af77e74a8f70e9c3337e069c37bc82178ef1b459c02091f73c4ad5281eb5" "checksum ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" @@ -2774,14 +2732,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum ethcore-logger 1.12.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum ethcore-network 1.12.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum ethcore-network-devp2p 1.12.0 (git+https://github.com/paritytech/parity.git)" = "" -"checksum ethereum-types 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5cff74129deda8a155b729cad1a22dc3cdd08115abd1165079c519d0cab6917a" "checksum ethereum-types 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3ae691a36ce5d25b433e63128ce5579f4a18457b6a9c849832b2c9e0fec92a" "checksum ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ac59a21a9ce98e188f3dace9eb67a6c4a3c67ec7fbc7218cb827852679dc002" "checksum ethkey 0.3.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum exit-future 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c30ec160f83d938faf4dd6fdaba4f42316f1bd3df76b902df2d824f47fa9db7" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" "checksum fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" -"checksum fixed-hash 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21c520ebc46522d519aec9cba2b7115d49cea707d771b772c46bec61aa0daeb8" "checksum fixed-hash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18d6fd718fb4396e7a9c93ac59ba7143501467ca7a143c145b5555a571d5576" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" @@ -2921,12 +2877,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tokio-retry 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f05746ae87dca83a2016b4f5dba5b237b897dd12fd324f60afe282112f16969a" "checksum tokio-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24da22d077e0f15f55162bdbdc661228c1581892f52074fb242678d015b45162" "checksum tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6131e780037787ff1b3f8aad9da83bca02438b72277850dd6ad0d455e0e20efc" -"checksum transaction-pool 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "23303835df389f9c34ad45cacf392304193f974faaf48c30a4ece2b03da0ed57" +"checksum trace-time 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5aea07da6582e957c6e737eeb63a5af79e648eeeaaaba8fd9a417f1124bafa41" +"checksum transaction-pool 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd61073aadeb282056e97180e5d0dd9774413f954bd221c07692578dab466b26" "checksum triehash 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum triehash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9291c7f0fae44858b5e087dd462afb382354120003778f1695b44aab98c7abd7" "checksum twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "475352206e7a290c5fccc27624a163e8d0d115f7bb60ca18a64fc9ce056d7435" "checksum uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" -"checksum uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53a4340c35703f926ec365c6797bb4a7a10bb6b9affe29ca385c9d804401f5e3" "checksum uint 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6477b2716357758c176c36719023e1f9726974d762150e4fc0a9c8c75488c343" "checksum unicase 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284b6d3db520d67fbe88fd778c21510d1b0ba4a551e5d0fbb023d33405f6de8a" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" diff --git a/substrate/polkadot/transaction-pool/Cargo.toml b/substrate/polkadot/transaction-pool/Cargo.toml index b8bf7f001c..d8cf5ebd80 100644 --- a/substrate/polkadot/transaction-pool/Cargo.toml +++ b/substrate/polkadot/transaction-pool/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] log = "0.4.0" -transaction-pool = "1.9.0" +transaction-pool = "1.12.0" error-chain = "0.11" polkadot-api = { path = "../api" } polkadot-primitives = { path = "../primitives" } @@ -16,4 +16,3 @@ substrate-primitives = { path = "../../substrate/primitives" } substrate-runtime-primitives = { path = "../../substrate/runtime/primitives" } substrate-codec = { path = "../../substrate/codec" } ed25519 = { path = "../../substrate/ed25519" } -ethereum-types = "0.2" diff --git a/substrate/polkadot/transaction-pool/src/lib.rs b/substrate/polkadot/transaction-pool/src/lib.rs index d375c7c371..faa3d09a0b 100644 --- a/substrate/polkadot/transaction-pool/src/lib.rs +++ b/substrate/polkadot/transaction-pool/src/lib.rs @@ -15,7 +15,6 @@ // along with Polkadot. If not, see . extern crate ed25519; -extern crate ethereum_types; extern crate substrate_codec as codec; extern crate substrate_primitives as substrate_primitives; extern crate substrate_runtime_primitives as substrate_runtime_primitives; @@ -35,22 +34,15 @@ use std::cmp::Ordering; use std::sync::Arc; use polkadot_api::PolkadotApi; -use primitives::{AccountId, Timestamp}; +use primitives::{AccountId, Timestamp, Hash}; use primitives::parachain::CandidateReceipt; use runtime::{Block, UncheckedExtrinsic, TimestampCall, ParachainsCall, Call}; use substrate_runtime_primitives::traits::{Bounded, Checkable}; -use transaction_pool::{Pool, Readiness}; +use transaction_pool::{Transaction, Pool, Readiness}; use transaction_pool::scoring::{Change, Choice}; -// TODO: make queue generic over hash and sender so we don't need ethereum-types -pub use ethereum_types::{Address as TruncatedAccountId, H256 as TransactionHash}; pub use transaction_pool::{Options, Status, LightStatus, NoopListener, VerifiedTransaction as VerifiedTransactionOps}; -/// Truncate an account ID to 160 bits. -pub fn truncate_id(id: &AccountId) -> TruncatedAccountId { - TruncatedAccountId::from_slice(&id[..20]) -} - /// Useful functions for working with Polkadot blocks. pub struct PolkadotBlock { block: Block, @@ -152,7 +144,7 @@ error_chain! { display("Transaction had bad signature."), } /// Attempted to queue a transaction that is already in the pool. - AlreadyImported(hash: TransactionHash) { + AlreadyImported(hash: Hash) { description("Transaction is already in the pool."), display("Transaction {:?} is already in the pool.", hash), } @@ -168,8 +160,8 @@ error_chain! { #[derive(Debug, Clone)] pub struct VerifiedTransaction { inner: ::Checked, - hash: TransactionHash, - address: TruncatedAccountId, + hash: Hash, + address: AccountId, insertion_id: u64, encoded_size: usize, } @@ -186,7 +178,7 @@ impl VerifiedTransaction { Ok(xt) => { // TODO: make transaction-pool use generic types. let hash = substrate_primitives::hashing::blake2_256(&message); - let address = truncate_id(&xt.signed); + let address = xt.signed; Ok(VerifiedTransaction { inner: xt, hash: hash.into(), @@ -210,12 +202,12 @@ impl VerifiedTransaction { } /// Get the 256-bit hash of this transaction. - pub fn hash(&self) -> &TransactionHash { + pub fn hash(&self) -> &Hash { &self.hash } - /// Get the truncated account ID of the sender of this transaction. - pub fn sender(&self) -> &TruncatedAccountId { + /// Get the account ID of the sender of this transaction. + pub fn sender(&self) -> &AccountId { &self.address } @@ -232,28 +224,29 @@ impl AsRef< ::Checked > for VerifiedTransaction } impl transaction_pool::VerifiedTransaction for VerifiedTransaction { - fn hash(&self) -> &TransactionHash { + type Hash = Hash; + type Sender = AccountId; + + fn hash(&self) -> &Hash { &self.hash } - fn sender(&self) -> &TruncatedAccountId { + fn sender(&self) -> &AccountId { &self.address } fn mem_usage(&self) -> usize { 1 // TODO } - - fn insertion_id(&self) -> u64 { - self.insertion_id - } } /// Scoring implementation for polkadot transactions. +#[derive(Debug)] pub struct Scoring; impl transaction_pool::Scoring for Scoring { type Score = u64; + type Event = (); fn compare(&self, old: &VerifiedTransaction, other: &VerifiedTransaction) -> Ordering { old.inner.index.cmp(&other.inner.index) @@ -265,9 +258,9 @@ impl transaction_pool::Scoring for Scoring { fn update_scores( &self, - xts: &[Arc], + xts: &[Transaction], scores: &mut [Self::Score], - _change: Change + _change: Change<()> ) { for i in 0..xts.len() { // all the same score since there are no fees. @@ -312,7 +305,7 @@ impl<'a, T: 'a + PolkadotApi> Ready<'a, T> { impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready for Ready<'a, T> { fn is_ready(&mut self, xt: &VerifiedTransaction) -> Readiness { let sender = xt.inner.signed; - trace!(target: "transaction-pool", "Checking readiness of {} (from {})", xt.hash, TransactionHash::from(sender)); + trace!(target: "transaction-pool", "Checking readiness of {} (from {})", xt.hash, Hash::from(sender)); // TODO: find a way to handle index error properly -- will need changes to // transaction-pool trait. @@ -325,7 +318,7 @@ impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready for R match xt.inner.index.cmp(&next_index) { Ordering::Greater => Readiness::Future, Ordering::Equal => Readiness::Ready, - Ordering::Less => Readiness::Stalled, // TODO: this is not "stalled" but rather stale and can be discarded. + Ordering::Less => Readiness::Stale, // TODO: this is not "stalled" but rather stale and can be discarded. } } } @@ -375,12 +368,12 @@ impl TransactionPool { } /// Remove from the pool. - pub fn remove(&mut self, hash: &TransactionHash, is_valid: bool) -> Option> { + pub fn remove(&mut self, hash: &Hash, is_valid: bool) -> Option> { self.inner.remove(hash, is_valid) } /// Cull transactions from the queue. - pub fn cull(&mut self, senders: Option<&[TruncatedAccountId]>, ready: Ready) -> usize { + pub fn cull(&mut self, senders: Option<&[AccountId]>, ready: Ready) -> usize { self.inner.cull(senders, ready) }