From b622f09182785137ea35cb53c6fee7f6cdc069d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 13 Aug 2018 11:06:32 +0200 Subject: [PATCH 1/5] Fix is_valid condition when removing transactions from the pool. --- substrate/extrinsic-pool/src/pool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/extrinsic-pool/src/pool.rs b/substrate/extrinsic-pool/src/pool.rs index 488834398e6bb..2fffc1442e428 100644 --- a/substrate/extrinsic-pool/src/pool.rs +++ b/substrate/extrinsic-pool/src/pool.rs @@ -111,7 +111,7 @@ impl Pool where let mut pool = self.pool.write(); let mut results = Vec::with_capacity(hashes.len()); for hash in hashes { - results.push(pool.remove(hash, is_valid)); + results.push(pool.remove(hash, !is_valid)); } results } From 8c34f5aee4378bd5569b399f43f9981710e7575a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 13 Aug 2018 11:08:17 +0200 Subject: [PATCH 2/5] Less verbosity. --- substrate/extrinsic-pool/src/listener.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/extrinsic-pool/src/listener.rs b/substrate/extrinsic-pool/src/listener.rs index 6bf110e55f977..02873f9e04d97 100644 --- a/substrate/extrinsic-pool/src/listener.rs +++ b/substrate/extrinsic-pool/src/listener.rs @@ -80,7 +80,7 @@ impl txpool::Listener for Listener where } fn invalid(&mut self, tx: &Arc) { - warn!("Extrinsic invalid: {:?}", tx); + debug!("Extrinsic invalid: {:?}", tx); } fn canceled(&mut self, tx: &Arc) { From 1e8b0ef15ef7e2ce6083c194f728514c016557c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 13 Aug 2018 11:18:12 +0200 Subject: [PATCH 3/5] Reject too large transctions from the pool. --- polkadot/consensus/src/lib.rs | 6 ------ polkadot/transaction-pool/src/error.rs | 5 +++++ polkadot/transaction-pool/src/lib.rs | 13 +++++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/polkadot/consensus/src/lib.rs b/polkadot/consensus/src/lib.rs index be926d1da1161..244fdeb55df26 100644 --- a/polkadot/consensus/src/lib.rs +++ b/polkadot/consensus/src/lib.rs @@ -770,12 +770,6 @@ impl CreateProposal where C: PolkadotApi { let result = self.transaction_pool.cull_and_get_pending(BlockId::hash(self.parent_hash), |pending_iterator| { let mut pending_size = 0; for pending in pending_iterator { - // skip and cull transactions which are too large. - if pending.encoded_size() > MAX_TRANSACTIONS_SIZE { - unqueue_invalid.push(pending.hash().clone()); - continue - } - if pending_size + pending.encoded_size() >= MAX_TRANSACTIONS_SIZE { break } match block_builder.push_extrinsic(pending.primitive_extrinsic()) { diff --git a/polkadot/transaction-pool/src/error.rs b/polkadot/transaction-pool/src/error.rs index ef6cdf6b4166c..99281e8d78641 100644 --- a/polkadot/transaction-pool/src/error.rs +++ b/polkadot/transaction-pool/src/error.rs @@ -55,6 +55,11 @@ error_chain! { description("Unrecognised address in extrinsic"), display("Unrecognised address in extrinsic: {}", who), } + /// Extrinsic too large + TooLarge(got: usize, max: usize) { + description("Extrinsic too large"), + display("Extrinsic is too large ({} > {})", got, max), + } } } diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index 447d97d004595..ce80abc85ddcf 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -59,6 +59,11 @@ use substrate_runtime_primitives::traits::{Bounded, Checkable, Hash as HashT, Bl pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps}; pub use error::{Error, ErrorKind, Result}; +/// Maximal size of a single encoded extrinsic. +/// +/// See also substrate-consensus::MAX_TRANSACTIONS_SIZE +const MAX_TRANSACTION_SIZE: usize = 4 * 1024 * 1024; + /// Type alias for convenience. pub type CheckedExtrinsic = std::result::Result>>::Checked; @@ -279,14 +284,18 @@ impl<'a, A> txpool::Verifier for Verifier<'a, A> where type Error = Error; fn verify_transaction(&self, uxt: UncheckedExtrinsic) -> Result { - if !uxt.is_signed() { bail!(ErrorKind::IsInherent(uxt)) } let encoded = uxt.encode(); - let (encoded_size, hash) = (encoded.len(), BlakeTwo256::hash(&encoded)); + let encoded_size = encoded.len(); + + if encoded_size > MAX_TRANSACTION_SIZE { + bail!(ErrorKind::TooLarge(encoded_size, MAX_TRANSACTION_SIZE)); + } + let hash = BlakeTwo256::hash(&encoded); debug!(target: "transaction-pool", "Transaction submitted: {}", ::substrate_primitives::hexdisplay::HexDisplay::from(&encoded)); let inner = match uxt.clone().check_with(|a| self.lookup(a)) { From b096c1be6d50a74932f62acf929bb01223cfe41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 13 Aug 2018 11:23:17 +0200 Subject: [PATCH 4/5] Bring back the warning level. --- substrate/extrinsic-pool/src/listener.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/extrinsic-pool/src/listener.rs b/substrate/extrinsic-pool/src/listener.rs index 02873f9e04d97..6bf110e55f977 100644 --- a/substrate/extrinsic-pool/src/listener.rs +++ b/substrate/extrinsic-pool/src/listener.rs @@ -80,7 +80,7 @@ impl txpool::Listener for Listener where } fn invalid(&mut self, tx: &Arc) { - debug!("Extrinsic invalid: {:?}", tx); + warn!("Extrinsic invalid: {:?}", tx); } fn canceled(&mut self, tx: &Arc) { From d48fdbae60609b9bfe4bcd4c8d987e11a31ca783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Mon, 13 Aug 2018 14:10:20 +0200 Subject: [PATCH 5/5] Fix link. --- polkadot/transaction-pool/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/transaction-pool/src/lib.rs b/polkadot/transaction-pool/src/lib.rs index ce80abc85ddcf..4ec5d9dbc2441 100644 --- a/polkadot/transaction-pool/src/lib.rs +++ b/polkadot/transaction-pool/src/lib.rs @@ -61,7 +61,7 @@ pub use error::{Error, ErrorKind, Result}; /// Maximal size of a single encoded extrinsic. /// -/// See also substrate-consensus::MAX_TRANSACTIONS_SIZE +/// See also polkadot-consensus::MAX_TRANSACTIONS_SIZE const MAX_TRANSACTION_SIZE: usize = 4 * 1024 * 1024; /// Type alias for convenience.