Creating pending block with all transactions from the queue (#6942)
* Allow to include all queue transactions in pending block. * Fix tests.
This commit is contained in:
parent
7eacef99b9
commit
ffee6aacff
@ -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(),
|
||||
|
@ -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<bool>,
|
||||
notify_work: Option<Vec<String>>,
|
||||
refuse_service_transactions: Option<bool>,
|
||||
infinite_pending_block: Option<bool>,
|
||||
}
|
||||
|
||||
#[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()),
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user