Avoid penalizing legit transactions

This commit is contained in:
Tomasz Drwięga 2016-09-23 17:26:36 +02:00
parent 2874f464aa
commit efaef85565
2 changed files with 11 additions and 3 deletions

View File

@ -292,7 +292,7 @@ impl Miner {
}; };
let mut invalid_transactions = HashSet::new(); let mut invalid_transactions = HashSet::new();
let mut too_big_transactions = HashSet::new(); let mut transactions_to_penalize = HashSet::new();
let block_number = open_block.block().fields().header.number(); let block_number = open_block.block().fields().header.number();
// TODO: push new uncles, too. // TODO: push new uncles, too.
for tx in transactions { for tx in transactions {
@ -300,7 +300,11 @@ impl Miner {
match open_block.push_transaction(tx, None) { match open_block.push_transaction(tx, None) {
Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })) => { Err(Error::Execution(ExecutionError::BlockGasLimitReached { gas_limit, gas_used, gas })) => {
debug!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?} (limit: {:?}, used: {:?}, gas: {:?})", hash, gas_limit, gas_used, gas); debug!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?} (limit: {:?}, used: {:?}, gas: {:?})", hash, gas_limit, gas_used, gas);
too_big_transactions.insert(hash);
// Penalize transaction if it's above current gas limit
if gas > gas_limit {
transactions_to_penalize.insert(hash);
}
// Exit early if gas left is smaller then min_tx_gas // Exit early if gas left is smaller then min_tx_gas
let min_tx_gas: U256 = 21000.into(); // TODO: figure this out properly. let min_tx_gas: U256 = 21000.into(); // TODO: figure this out properly.
@ -337,7 +341,7 @@ impl Miner {
for hash in invalid_transactions.into_iter() { for hash in invalid_transactions.into_iter() {
queue.remove_invalid(&hash, &fetch_account); queue.remove_invalid(&hash, &fetch_account);
} }
for hash in too_big_transactions { for hash in transactions_to_penalize {
queue.penalize(&hash); queue.penalize(&hash);
} }
} }

View File

@ -610,6 +610,10 @@ impl TransactionQueue {
/// Penalize transactions from sender of transaction with given hash. /// Penalize transactions from sender of transaction with given hash.
/// I.e. it should change the priority of the transaction in the queue. /// I.e. it should change the priority of the transaction in the queue.
///
/// NOTE: We need to penalize all transactions from particular sender
/// to avoid breaking invariants in queue (ordered by nonces).
/// Consecutive transactions from this sender would fail otherwise (because of invalid nonce).
pub fn penalize(&mut self, transaction_hash: &H256) { pub fn penalize(&mut self, transaction_hash: &H256) {
let transaction = self.by_hash.get(transaction_hash); let transaction = self.by_hash.get(transaction_hash);
if transaction.is_none() { if transaction.is_none() {