Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #754 from ethcore/tx_queue_all
Browse files Browse the repository at this point in the history
Attempting to add all transactions to mined block
  • Loading branch information
arkpar committed Mar 17, 2016
2 parents 4da8ede + dec6965 commit 0d77937
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
5 changes: 1 addition & 4 deletions miner/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
17 changes: 8 additions & 9 deletions miner/src/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
//! }
//! ```
//!
Expand Down Expand Up @@ -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<SignedTransaction> {
pub fn top_transactions(&self) -> Vec<SignedTransaction> {
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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 0d77937

Please sign in to comment.