From 177d26a25e389166ea6f67baf0aaa709fb849b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 17 Mar 2016 14:39:24 +0100 Subject: [PATCH] Stop adding transactions right after we know that no other will make it to block. --- ethcore/src/client/client.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 7818fcdc8..2c011047d 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -418,26 +418,33 @@ impl BlockChainClient for Client where V: Verifier { // Add transactions let block_number = b.block().header().number(); + let min_tx_gas = U256::from(self.engine.schedule(&b.env_info()).tx_gas); let gas_limit = *b.block().header().gas_limit(); let mut gas_left = gas_limit; let mut invalid_transactions = HashSet::new(); for tx in transactions { - let hash = tx.hash(); - let gas = tx.gas; - // TODO [todr] It seems that calculating gas_left here doesn't really look nice. After moving this function + // Stop early if we are sure that no other transaction will be included + if gas_left < min_tx_gas { + break; + } + + // TODO [todr] It seems that calculating gas_left here doesn't look nice. After moving this function // to miner crate we should consider rewriting this logic in some better way. - if gas > gas_left { - trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", hash); + if tx.gas > gas_left { + trace!(target: "miner", "Skipping adding transaction to block because of gas limit: {:?}", tx.hash()); continue; } + // Push transaction to block + let hash = tx.hash(); let import = b.push_transaction(tx, None); match import { Err(e) => { - trace!(target: "miner", "Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}", - block_number, hash, e); invalid_transactions.insert(hash); + trace!(target: "miner", + "Error adding transaction to block: number={}. transaction_hash={:?}, Error: {:?}", + block_number, hash, e); }, Ok(receipt) => { gas_left = gas_limit - receipt.gas_used;