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

Commit

Permalink
Fixing penalization in future
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Drwięga committed Oct 6, 2016
1 parent 50021c7 commit d0fc22a
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion ethcore/src/miner/transaction_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ impl TransactionQueue {
};
for k in nonces_from_sender {
let order = self.future.drop(&sender, &k).unwrap();
self.current.insert(sender, k, order.penalize());
self.future.insert(sender, k, order.penalize());
}
}

Expand Down Expand Up @@ -658,6 +658,15 @@ impl TransactionQueue {
.collect()
}

#[cfg(test)]
fn future_transactions(&self) -> Vec<SignedTransaction> {
self.future.by_priority
.iter()
.map(|t| self.by_hash.get(&t.hash).expect("All transactions in `current` and `future` are always included in `by_hash`"))
.map(|t| t.transaction.clone())
.collect()
}

/// Returns hashes of all transactions from current, ordered by priority.
pub fn pending_hashes(&self) -> Vec<H256> {
self.current.by_priority
Expand Down Expand Up @@ -1357,6 +1366,36 @@ mod test {
assert_eq!(top.len(), 2);
}

#[test]
fn should_penalize_transactions_from_sender_in_future() {
// given
let prev_nonce = |a: &Address| AccountDetails{ nonce: default_nonce(a).nonce - U256::one(), balance: !U256::zero() };
let mut txq = TransactionQueue::new();
// txa, txb - slightly bigger gas price to have consistent ordering
let (txa, txb) = new_txs(U256::from(1));
let (tx1, tx2) = new_txs_with_higher_gas_price(U256::from(3));

// insert everything
txq.add(txa.clone(), &prev_nonce, TransactionOrigin::External).unwrap();
txq.add(txb.clone(), &prev_nonce, TransactionOrigin::External).unwrap();
txq.add(tx1.clone(), &prev_nonce, TransactionOrigin::External).unwrap();
txq.add(tx2.clone(), &prev_nonce, TransactionOrigin::External).unwrap();

assert_eq!(txq.status().future, 4);

// when
txq.penalize(&tx1.hash());

// then
let top = txq.future_transactions();
assert_eq!(top[0], txa);
assert_eq!(top[1], txb);
assert_eq!(top[2], tx1);
assert_eq!(top[3], tx2);
assert_eq!(top.len(), 4);
}


#[test]
fn should_penalize_transactions_from_sender() {
// given
Expand Down

0 comments on commit d0fc22a

Please sign in to comment.