Merge branch 'tx_queue_integration' into tx_queue_rpc

This commit is contained in:
Tomasz Drwięga 2016-03-05 17:46:45 +01:00
commit 3f493ab118

View File

@ -247,10 +247,10 @@ impl TransactionQueue {
// Remove from future
let order = self.future.drop(&sender, &nonce);
if order.is_some() {
self.recalculate_future_for_sender(&sender, current_nonce);
self.update_future(&sender, current_nonce);
// And now lets check if there is some chain of transactions in future
// that should be placed in current
self.move_future_txs(sender.clone(), current_nonce, current_nonce);
self.move_matching_future_to_current(sender.clone(), current_nonce, current_nonce);
return;
}
@ -264,12 +264,12 @@ impl TransactionQueue {
self.move_all_to_future(&sender, current_nonce);
// And now lets check if there is some chain of transactions in future
// that should be placed in current. It should also update last_nonces.
self.move_future_txs(sender.clone(), current_nonce, current_nonce);
self.move_matching_future_to_current(sender.clone(), current_nonce, current_nonce);
return;
}
}
fn recalculate_future_for_sender(&mut self, sender: &Address, current_nonce: U256) {
fn update_future(&mut self, sender: &Address, current_nonce: U256) {
// We need to drain all transactions for current sender from future and reinsert them with updated height
let all_nonces_from_sender = match self.future.by_address.row(&sender) {
Some(row_map) => row_map.keys().cloned().collect::<Vec<U256>>(),
@ -318,7 +318,7 @@ impl TransactionQueue {
self.last_nonces.clear();
}
fn move_future_txs(&mut self, address: Address, mut current_nonce: U256, first_nonce: U256) {
fn move_matching_future_to_current(&mut self, address: Address, mut current_nonce: U256, first_nonce: U256) {
{
let by_nonce = self.future.by_address.row_mut(&address);
if let None = by_nonce {
@ -348,8 +348,8 @@ impl TransactionQueue {
return;
}
let nonce = tx.nonce();
let address = tx.sender();
let nonce = tx.nonce();
let state_nonce = fetch_nonce(&address);
let next_nonce = self.last_nonces
@ -370,11 +370,10 @@ impl TransactionQueue {
}
let base_nonce = fetch_nonce(&address);
Self::replace_transaction(tx, base_nonce.clone(), &mut self.current, &mut self.by_hash);
self.last_nonces.insert(address.clone(), nonce);
// But maybe there are some more items waiting in future?
self.move_future_txs(address.clone(), nonce + U256::one(), base_nonce);
self.move_matching_future_to_current(address.clone(), nonce + U256::one(), base_nonce);
self.current.enforce_limit(&mut self.by_hash);
}
@ -387,10 +386,13 @@ impl TransactionQueue {
by_hash.insert(hash.clone(), tx);
if let Some(old) = set.insert(address, nonce, order.clone()) {
// There was already transaction in queue. Let's check which one should stay
if old.cmp(&order) == Ordering::Greater {
assert!(old.nonce_height == order.nonce_height, "Both transactions should have the same height.");
let old_fee = old.gas_price;
let new_fee = order.gas_price;
if old_fee.cmp(&new_fee) == Ordering::Greater {
// Put back old transaction since it has greater priority (higher gas_price)
set.insert(address, nonce, old);
set.by_address.insert(address, nonce, old);
// and remove new one
set.by_priority.remove(&order);
by_hash.remove(&hash);
} else {
// Make sure we remove old transaction entirely