Limit transaction pool size (#1676)

* Avoid excessive hashing. Store extrinsic len.

* Implement pool limits.

* Fix issues.

* Make sure we return error in case it doesn't make into the pool.

* Pass parameters from CLI.

* Remove redundant todo.

* Fix tests.
This commit is contained in:
Tomasz Drwięga
2019-02-06 19:03:05 +01:00
committed by Gav Wood
parent 461cd384fc
commit 4e3eace15f
14 changed files with 398 additions and 38 deletions
+7 -7
View File
@@ -452,16 +452,16 @@ impl<C: Components> network::TransactionPool<ComponentExHash<C>, ComponentBlock<
let encoded = transaction.encode();
if let Some(uxt) = Decode::decode(&mut &encoded[..]) {
let best_block_id = self.best_block_id()?;
let hash = self.pool.hash_of(&uxt);
match self.pool.submit_one(&best_block_id, uxt) {
Ok(hash) => Some(hash),
Err(e) => match e.into_pool_error() {
Ok(e) => match e.kind() {
txpool::error::ErrorKind::AlreadyImported => Some(hash),
_ => {
debug!("Error adding transaction to the pool: {:?}", e);
None
},
Ok(txpool::error::Error(txpool::error::ErrorKind::AlreadyImported(hash), _)) => {
hash.downcast::<ComponentExHash<C>>().ok()
.map(|x| x.as_ref().clone())
},
Ok(e) => {
debug!("Error adding transaction to the pool: {:?}", e);
None
},
Err(e) => {
debug!("Error converting pool error: {:?}", e);