From ffee6aacffad3c7d60d29eec1ab97f429d0835c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 3 Nov 2017 15:20:20 +0100 Subject: [PATCH] Creating pending block with all transactions from the queue (#6942) * Allow to include all queue transactions in pending block. * Fix tests. --- ethcore/src/miner/miner.rs | 16 +++++++++++++--- parity/cli/mod.rs | 9 ++++++++- parity/configuration.rs | 1 + rpc/src/v1/tests/eth.rs | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 324619273..6ef26c48b 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -123,6 +123,10 @@ pub struct MinerOptions { pub tx_queue_banning: Banning, /// Do we refuse to accept service transactions even if sender is certified. pub refuse_service_transactions: bool, + /// Create a pending block with maximal possible gas limit. + /// NOTE: Such block will contain all pending transactions but + /// will be invalid if mined. + pub infinite_pending_block: bool, } impl Default for MinerOptions { @@ -145,6 +149,7 @@ impl Default for MinerOptions { enable_resubmission: true, tx_queue_banning: Banning::Disabled, refuse_service_transactions: false, + infinite_pending_block: false, } } } @@ -374,15 +379,14 @@ impl Miner { let mut sealing_work = self.sealing_work.lock(); let last_work_hash = sealing_work.queue.peek_last_ref().map(|pb| pb.block().fields().header.hash()); let best_hash = chain_info.best_block_hash; -/* + // check to see if last ClosedBlock in would_seals is actually same parent block. // if so // duplicate, re-open and push any new transactions. // if at least one was pushed successfully, close and enqueue new ClosedBlock; // otherwise, leave everything alone. // otherwise, author a fresh block. -*/ - let open_block = match sealing_work.queue.pop_if(|b| b.block().fields().header.parent_hash() == &best_hash) { + let mut open_block = match sealing_work.queue.pop_if(|b| b.block().fields().header.parent_hash() == &best_hash) { Some(old_block) => { trace!(target: "miner", "prepare_block: Already have previous work; updating and returning"); // add transactions to old_block @@ -398,6 +402,11 @@ impl Miner { ) } }; + + if self.options.infinite_pending_block { + open_block.set_gas_limit(!U256::zero()); + } + (transactions, open_block, last_work_hash) }; @@ -1301,6 +1310,7 @@ mod tests { enable_resubmission: true, tx_queue_banning: Banning::Disabled, refuse_service_transactions: false, + infinite_pending_block: false, }, GasPricer::new_fixed(0u64.into()), &Spec::new_test(), diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 942dcae13..cf49c6452 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -610,7 +610,11 @@ usage! { FLAG flag_refuse_service_transactions: (bool) = false, or |c: &Config| otry!(c.mining).refuse_service_transactions.clone(), "--refuse-service-transactions", - "Always refuse service transactions..", + "Always refuse service transactions.", + + FLAG flag_infinite_pending_block: (bool) = false, or |c: &Config| otry!(c.mining).infinite_pending_block.clone(), + "--infinite-pending-block", + "Pending block will be created with maximal possible gas limit and will execute all transactions in the queue. Note that such block is invalid and should never be attempted to be mined.", FLAG flag_no_persistent_txqueue: (bool) = false, or |c: &Config| otry!(c.parity).no_persistent_txqueue, "--no-persistent-txqueue", @@ -1140,6 +1144,7 @@ struct Mining { remove_solved: Option, notify_work: Option>, refuse_service_transactions: Option, + infinite_pending_block: Option, } #[derive(Default, Debug, PartialEq, Deserialize)] @@ -1515,6 +1520,7 @@ mod tests { flag_remove_solved: false, arg_notify_work: Some("http://localhost:3001".into()), flag_refuse_service_transactions: false, + flag_infinite_pending_block: false, flag_stratum: false, arg_stratum_interface: "local".to_owned(), @@ -1755,6 +1761,7 @@ mod tests { remove_solved: None, notify_work: None, refuse_service_transactions: None, + infinite_pending_block: None, }), footprint: Some(Footprint { tracing: Some("on".into()), diff --git a/parity/configuration.rs b/parity/configuration.rs index 6690efd37..31febd375 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -543,6 +543,7 @@ impl Configuration { None => Banning::Disabled, }, refuse_service_transactions: self.args.flag_refuse_service_transactions, + infinite_pending_block: self.args.flag_infinite_pending_block, }; Ok(options) diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index dde8008c0..27b98f7f5 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -77,6 +77,7 @@ fn miner_service(spec: &Spec, accounts: Arc) -> Arc { work_queue_size: 50, enable_resubmission: true, refuse_service_transactions: false, + infinite_pending_block: false, }, GasPricer::new_fixed(20_000_000_000u64.into()), &spec,