From 9b6abb5861386c3e393d7decdd7416cf2d22d44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 17 Mar 2016 13:41:08 +0100 Subject: [PATCH] Attempting to add all transactions to mined block --- miner/src/miner.rs | 5 +---- miner/src/transaction_queue.rs | 17 ++++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 832dc5d02..7bbde6294 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -125,10 +125,7 @@ impl MinerService for Miner { } fn prepare_sealing(&self, chain: &BlockChainClient) { - let no_of_transactions = 128; - // TODO: should select transactions orm queue according to gas limit of block. - let transactions = self.transaction_queue.lock().unwrap().top_transactions(no_of_transactions); - + let transactions = self.transaction_queue.lock().unwrap().top_transactions(); let b = chain.prepare_sealing( self.author(), self.gas_floor_target(), diff --git a/miner/src/transaction_queue.rs b/miner/src/transaction_queue.rs index a1fc20b0f..71d845e38 100644 --- a/miner/src/transaction_queue.rs +++ b/miner/src/transaction_queue.rs @@ -59,7 +59,7 @@ //! // Check status //! assert_eq!(txq.status().pending, 2); //! // Check top transactions -//! let top = txq.top_transactions(3); +//! let top = txq.top_transactions(); //! assert_eq!(top.len(), 2); //! assert_eq!(top[0], st1); //! assert_eq!(top[1], st2); @@ -69,7 +69,7 @@ //! txq.remove(&st1.hash(), &default_nonce); //! assert_eq!(txq.status().pending, 0); //! assert_eq!(txq.status().future, 1); -//! assert_eq!(txq.top_transactions(3).len(), 0); +//! assert_eq!(txq.top_transactions().len(), 0); //! } //! ``` //! @@ -459,10 +459,9 @@ impl TransactionQueue { // Will be used when mining merged #[allow(dead_code)] /// Returns top transactions from the queue ordered by priority. - pub fn top_transactions(&self, size: usize) -> Vec { + pub fn top_transactions(&self) -> Vec { self.current.by_priority .iter() - .take(size) .map(|t| self.by_hash.get(&t.hash).expect("Transaction Queue Inconsistency")) .map(|t| t.transaction.clone()) .collect() @@ -754,7 +753,7 @@ mod test { txq.add(tx2.clone(), &default_nonce).unwrap(); // then - let top = txq.top_transactions(5); + let top = txq.top_transactions(); assert_eq!(top[0], tx); assert_eq!(top[1], tx2); assert_eq!(top.len(), 2); @@ -793,7 +792,7 @@ mod test { let stats = txq.status(); assert_eq!(stats.pending, 1); assert_eq!(stats.future, 1); - let top = txq.top_transactions(5); + let top = txq.top_transactions(); assert_eq!(top.len(), 1); assert_eq!(top[0], tx); } @@ -920,7 +919,7 @@ mod test { txq.add(tx2.clone(), &default_nonce).unwrap(); // then - let t = txq.top_transactions(2); + let t = txq.top_transactions(); assert_eq!(txq.status().pending, 1); assert_eq!(t.len(), 1); assert_eq!(t[0], tx); @@ -1044,7 +1043,7 @@ mod test { let stats = txq.status(); assert_eq!(stats.pending, 1); assert_eq!(stats.future, 0); - assert_eq!(txq.top_transactions(1)[0].gas_price, U256::from(200)); + assert_eq!(txq.top_transactions()[0].gas_price, U256::from(200)); } #[test] @@ -1074,7 +1073,7 @@ mod test { let stats = txq.status(); assert_eq!(stats.future, 0); assert_eq!(stats.pending, 2); - assert_eq!(txq.top_transactions(2)[1].gas_price, U256::from(200)); + assert_eq!(txq.top_transactions()[1].gas_price, U256::from(200)); } #[test]