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

Commit

Permalink
Creating pending block with all transactions from the queue (#6942)
Browse files Browse the repository at this point in the history
* Allow to include all queue transactions in pending block.

* Fix tests.
  • Loading branch information
tomusdrw authored and arkpar committed Nov 3, 2017
1 parent 7eacef9 commit ffee6aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
16 changes: 13 additions & 3 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -145,6 +149,7 @@ impl Default for MinerOptions {
enable_resubmission: true,
tx_queue_banning: Banning::Disabled,
refuse_service_transactions: false,
infinite_pending_block: false,
}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
};

Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 8 additions & 1 deletion parity/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1140,6 +1144,7 @@ struct Mining {
remove_solved: Option<bool>,
notify_work: Option<Vec<String>>,
refuse_service_transactions: Option<bool>,
infinite_pending_block: Option<bool>,
}

#[derive(Default, Debug, PartialEq, Deserialize)]
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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()),
Expand Down
1 change: 1 addition & 0 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions rpc/src/v1/tests/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn miner_service(spec: &Spec, accounts: Arc<AccountProvider>) -> Arc<Miner> {
work_queue_size: 50,
enable_resubmission: true,
refuse_service_transactions: false,
infinite_pending_block: false,
},
GasPricer::new_fixed(20_000_000_000u64.into()),
&spec,
Expand Down

0 comments on commit ffee6aa

Please sign in to comment.