Skip to content

Commit

Permalink
Update transaction-pool dependency and remove ethereum-types (parityt…
Browse files Browse the repository at this point in the history
  • Loading branch information
sorpaas authored and gavofyork committed May 26, 2018
1 parent f41a495 commit 15e365f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
3 changes: 1 addition & 2 deletions transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Parity Technologies <[email protected]>"]

[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" }
Expand All @@ -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"
51 changes: 22 additions & 29 deletions transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

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;
Expand All @@ -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,
Expand Down Expand Up @@ -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),
}
Expand All @@ -168,8 +160,8 @@ error_chain! {
#[derive(Debug, Clone)]
pub struct VerifiedTransaction {
inner: <UncheckedExtrinsic as Checkable>::Checked,
hash: TransactionHash,
address: TruncatedAccountId,
hash: Hash,
address: AccountId,
insertion_id: u64,
encoded_size: usize,
}
Expand All @@ -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(),
Expand All @@ -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
}

Expand All @@ -232,28 +224,29 @@ impl AsRef< <UncheckedExtrinsic as Checkable>::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<VerifiedTransaction> for Scoring {
type Score = u64;
type Event = ();

fn compare(&self, old: &VerifiedTransaction, other: &VerifiedTransaction) -> Ordering {
old.inner.index.cmp(&other.inner.index)
Expand All @@ -265,9 +258,9 @@ impl transaction_pool::Scoring<VerifiedTransaction> for Scoring {

fn update_scores(
&self,
xts: &[Arc<VerifiedTransaction>],
xts: &[Transaction<VerifiedTransaction>],
scores: &mut [Self::Score],
_change: Change
_change: Change<()>
) {
for i in 0..xts.len() {
// all the same score since there are no fees.
Expand Down Expand Up @@ -312,7 +305,7 @@ impl<'a, T: 'a + PolkadotApi> Ready<'a, T> {
impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready<VerifiedTransaction> 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.
Expand All @@ -325,7 +318,7 @@ impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready<VerifiedTransaction> 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.
}
}
}
Expand Down Expand Up @@ -375,12 +368,12 @@ impl TransactionPool {
}

/// Remove from the pool.
pub fn remove(&mut self, hash: &TransactionHash, is_valid: bool) -> Option<Arc<VerifiedTransaction>> {
pub fn remove(&mut self, hash: &Hash, is_valid: bool) -> Option<Arc<VerifiedTransaction>> {
self.inner.remove(hash, is_valid)
}

/// Cull transactions from the queue.
pub fn cull<T: PolkadotApi>(&mut self, senders: Option<&[TruncatedAccountId]>, ready: Ready<T>) -> usize {
pub fn cull<T: PolkadotApi>(&mut self, senders: Option<&[AccountId]>, ready: Ready<T>) -> usize {
self.inner.cull(senders, ready)
}

Expand Down

0 comments on commit 15e365f

Please sign in to comment.