Merge pull request #754 from ethcore/tx_queue_all

Attempting to add all transactions to mined block
This commit is contained in:
Arkadiy Paronyan 2016-03-17 20:02:54 +01:00
commit 0d77937caf
2 changed files with 9 additions and 13 deletions

View File

@ -125,10 +125,7 @@ impl MinerService for Miner {
} }
fn prepare_sealing(&self, chain: &BlockChainClient) { fn prepare_sealing(&self, chain: &BlockChainClient) {
let no_of_transactions = 128; let transactions = self.transaction_queue.lock().unwrap().top_transactions();
// 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 b = chain.prepare_sealing( let b = chain.prepare_sealing(
self.author(), self.author(),
self.gas_floor_target(), self.gas_floor_target(),

View File

@ -59,7 +59,7 @@
//! // Check status //! // Check status
//! assert_eq!(txq.status().pending, 2); //! assert_eq!(txq.status().pending, 2);
//! // Check top transactions //! // Check top transactions
//! let top = txq.top_transactions(3); //! let top = txq.top_transactions();
//! assert_eq!(top.len(), 2); //! assert_eq!(top.len(), 2);
//! assert_eq!(top[0], st1); //! assert_eq!(top[0], st1);
//! assert_eq!(top[1], st2); //! assert_eq!(top[1], st2);
@ -69,7 +69,7 @@
//! txq.remove(&st1.hash(), &default_nonce); //! txq.remove(&st1.hash(), &default_nonce);
//! assert_eq!(txq.status().pending, 0); //! assert_eq!(txq.status().pending, 0);
//! assert_eq!(txq.status().future, 1); //! 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 // Will be used when mining merged
#[allow(dead_code)] #[allow(dead_code)]
/// Returns top transactions from the queue ordered by priority. /// Returns top transactions from the queue ordered by priority.
pub fn top_transactions(&self, size: usize) -> Vec<SignedTransaction> { pub fn top_transactions(&self) -> Vec<SignedTransaction> {
self.current.by_priority self.current.by_priority
.iter() .iter()
.take(size)
.map(|t| self.by_hash.get(&t.hash).expect("Transaction Queue Inconsistency")) .map(|t| self.by_hash.get(&t.hash).expect("Transaction Queue Inconsistency"))
.map(|t| t.transaction.clone()) .map(|t| t.transaction.clone())
.collect() .collect()
@ -754,7 +753,7 @@ mod test {
txq.add(tx2.clone(), &default_nonce).unwrap(); txq.add(tx2.clone(), &default_nonce).unwrap();
// then // then
let top = txq.top_transactions(5); let top = txq.top_transactions();
assert_eq!(top[0], tx); assert_eq!(top[0], tx);
assert_eq!(top[1], tx2); assert_eq!(top[1], tx2);
assert_eq!(top.len(), 2); assert_eq!(top.len(), 2);
@ -793,7 +792,7 @@ mod test {
let stats = txq.status(); let stats = txq.status();
assert_eq!(stats.pending, 1); assert_eq!(stats.pending, 1);
assert_eq!(stats.future, 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.len(), 1);
assert_eq!(top[0], tx); assert_eq!(top[0], tx);
} }
@ -920,7 +919,7 @@ mod test {
txq.add(tx2.clone(), &default_nonce).unwrap(); txq.add(tx2.clone(), &default_nonce).unwrap();
// then // then
let t = txq.top_transactions(2); let t = txq.top_transactions();
assert_eq!(txq.status().pending, 1); assert_eq!(txq.status().pending, 1);
assert_eq!(t.len(), 1); assert_eq!(t.len(), 1);
assert_eq!(t[0], tx); assert_eq!(t[0], tx);
@ -1044,7 +1043,7 @@ mod test {
let stats = txq.status(); let stats = txq.status();
assert_eq!(stats.pending, 1); assert_eq!(stats.pending, 1);
assert_eq!(stats.future, 0); 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] #[test]
@ -1074,7 +1073,7 @@ mod test {
let stats = txq.status(); let stats = txq.status();
assert_eq!(stats.future, 0); assert_eq!(stats.future, 0);
assert_eq!(stats.pending, 2); 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] #[test]