This repository was archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow configuration of when to reseal blocks. #1460
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6c1802e
Allow configuration of when to reseal blocks.
gavofyork 1667808
More miner options.
gavofyork 2a51a30
Fix up the pending set stuff.
gavofyork a102015
Fix doc test.
gavofyork 10aa32b
Include RPC configurability for max tx gas limit.
gavofyork 5d67a32
Merge remote-tracking branch 'origin/master' into miner-improvements
arkpar 495e560
Merge branch 'master' into miner-improvements
gavofyork 5919c66
Fix typo
gavofyork ff788e4
Fix another typo
gavofyork c221f69
Clean up some of the FP stuff.
gavofyork d0cec24
Merge branch 'miner-improvements' of github.com:ethcore/parity into m…
gavofyork af935df
Merge branch 'master' into miner-improvements
gavofyork 31de739
U256 instead of Option<U256>. Fix up tests.
gavofyork 599a610
Minor renaming.
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,6 +334,8 @@ const GAS_LIMIT_HYSTERESIS: usize = 10; // % | |
pub struct TransactionQueue { | ||
/// Gas Price threshold for transactions that can be imported to this queue (defaults to 0) | ||
minimal_gas_price: U256, | ||
/// The maximum amount of gas any individual transaction may use. | ||
tx_gas_limit: U256, | ||
/// Current gas limit (block gas limit * factor). Transactions above the limit will not be accepted (default to !0) | ||
gas_limit: U256, | ||
/// Priority queue for transactions that can go to block | ||
|
@@ -355,11 +357,11 @@ impl Default for TransactionQueue { | |
impl TransactionQueue { | ||
/// Creates new instance of this Queue | ||
pub fn new() -> Self { | ||
Self::with_limit(1024) | ||
Self::with_limits(1024, !U256::zero()) | ||
} | ||
|
||
/// Create new instance of this Queue with specified limits | ||
pub fn with_limit(limit: usize) -> Self { | ||
pub fn with_limits(limit: usize, tx_gas_limit: U256) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to complain again, but maybe removing it from constructor would be good too? No strong feelings though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's changed by setter anyway, other stuff like |
||
let current = TransactionSet { | ||
by_priority: BTreeSet::new(), | ||
by_address: Table::new(), | ||
|
@@ -374,6 +376,7 @@ impl TransactionQueue { | |
|
||
TransactionQueue { | ||
minimal_gas_price: U256::zero(), | ||
tx_gas_limit: tx_gas_limit, | ||
gas_limit: !U256::zero(), | ||
current: current, | ||
future: future, | ||
|
@@ -418,6 +421,12 @@ impl TransactionQueue { | |
}; | ||
} | ||
|
||
/// Set the new limit for the amount of gas any individual transaction may have. | ||
/// Any transaction already imported to the queue is not affected. | ||
pub fn set_tx_gas_limit(&mut self, limit: U256) { | ||
self.tx_gas_limit = limit; | ||
} | ||
|
||
/// Returns current status for this queue | ||
pub fn status(&self) -> TransactionQueueStatus { | ||
TransactionQueueStatus { | ||
|
@@ -435,7 +444,9 @@ impl TransactionQueue { | |
if tx.gas_price < self.minimal_gas_price { | ||
trace!(target: "miner", | ||
"Dropping transaction below minimal gas price threshold: {:?} (gp: {} < {})", | ||
tx.hash(), tx.gas_price, self.minimal_gas_price | ||
tx.hash(), | ||
tx.gas_price, | ||
self.minimal_gas_price | ||
); | ||
|
||
return Err(Error::Transaction(TransactionError::InsufficientGasPrice { | ||
|
@@ -446,10 +457,13 @@ impl TransactionQueue { | |
|
||
try!(tx.check_low_s()); | ||
|
||
if tx.gas > self.gas_limit { | ||
if tx.gas > self.gas_limit || tx.gas > self.tx_gas_limit { | ||
trace!(target: "miner", | ||
"Dropping transaction above gas limit: {:?} ({} > {})", | ||
tx.hash(), tx.gas, self.gas_limit | ||
"Dropping transaction above gas limit: {:?} ({} > min({}, {}))", | ||
tx.hash(), | ||
tx.gas, | ||
self.gas_limit, | ||
self.tx_gas_limit | ||
); | ||
|
||
return Err(Error::Transaction(TransactionError::GasLimitExceeded { | ||
|
@@ -463,8 +477,13 @@ impl TransactionQueue { | |
|
||
let cost = vtx.transaction.value + vtx.transaction.gas_price * vtx.transaction.gas; | ||
if client_account.balance < cost { | ||
trace!(target: "miner", "Dropping transaction without sufficient balance: {:?} ({} < {})", | ||
vtx.hash(), client_account.balance, cost); | ||
trace!(target: "miner", | ||
"Dropping transaction without sufficient balance: {:?} ({} < {})", | ||
vtx.hash(), | ||
client_account.balance, | ||
cost | ||
); | ||
|
||
return Err(Error::Transaction(TransactionError::InsufficientBalance { | ||
cost: cost, | ||
balance: client_account.balance | ||
|
@@ -1288,7 +1307,7 @@ mod test { | |
#[test] | ||
fn should_drop_old_transactions_when_hitting_the_limit() { | ||
// given | ||
let mut txq = TransactionQueue::with_limit(1); | ||
let mut txq = TransactionQueue::with_limits(1, !U256::zero()); | ||
let (tx, tx2) = new_txs(U256::one()); | ||
let sender = tx.sender().unwrap(); | ||
let nonce = tx.nonce; | ||
|
@@ -1310,7 +1329,7 @@ mod test { | |
#[test] | ||
fn should_return_correct_nonces_when_dropped_because_of_limit() { | ||
// given | ||
let mut txq = TransactionQueue::with_limit(2); | ||
let mut txq = TransactionQueue::with_limits(2, !U256::zero()); | ||
let tx = new_tx(); | ||
let (tx1, tx2) = new_txs(U256::one()); | ||
let sender = tx1.sender().unwrap(); | ||
|
@@ -1331,7 +1350,7 @@ mod test { | |
|
||
#[test] | ||
fn should_limit_future_transactions() { | ||
let mut txq = TransactionQueue::with_limit(1); | ||
let mut txq = TransactionQueue::with_limits(1, !U256::zero()); | ||
txq.current.set_limit(10); | ||
let (tx1, tx2) = new_txs_with_gas_price_diff(U256::from(4), U256::from(1)); | ||
let (tx3, tx4) = new_txs_with_gas_price_diff(U256::from(4), U256::from(2)); | ||
|
@@ -1591,7 +1610,7 @@ mod test { | |
#[test] | ||
fn should_keep_right_order_in_future() { | ||
// given | ||
let mut txq = TransactionQueue::with_limit(1); | ||
let mut txq = TransactionQueue::with_limits(1, !U256::zero()); | ||
let (tx1, tx2) = new_txs(U256::from(1)); | ||
let prev_nonce = |a: &Address| AccountDetails { nonce: default_nonce(a).nonce - U256::one(), balance: | ||
default_nonce(a).balance }; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyone know if this is the correct order for the lock? (it's the same as before, so should be good...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm