Never drop local transactions from different senders. (#9002)
This commit is contained in:
committed by
Afri Schoedon
parent
f3107214f4
commit
00e61a9100
@@ -41,7 +41,6 @@ fn new_queue() -> TransactionQueue {
|
||||
PrioritizationStrategy::GasPriceOnly,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_return_correct_nonces_when_dropped_because_of_limit() {
|
||||
// given
|
||||
@@ -63,8 +62,8 @@ fn should_return_correct_nonces_when_dropped_because_of_limit() {
|
||||
let nonce = tx1.nonce;
|
||||
|
||||
// when
|
||||
let r1= txq.import(TestClient::new(), vec![tx1].local());
|
||||
let r2= txq.import(TestClient::new(), vec![tx2].local());
|
||||
let r1 = txq.import(TestClient::new(), vec![tx1].retracted());
|
||||
let r2 = txq.import(TestClient::new(), vec![tx2].retracted());
|
||||
assert_eq!(r1, vec![Ok(())]);
|
||||
assert_eq!(r2, vec![Err(transaction::Error::LimitReached)]);
|
||||
assert_eq!(txq.status().status.transaction_count, 1);
|
||||
@@ -72,6 +71,58 @@ fn should_return_correct_nonces_when_dropped_because_of_limit() {
|
||||
// then
|
||||
assert_eq!(txq.next_nonce(TestClient::new(), &sender), Some(nonce + 1.into()));
|
||||
|
||||
// when
|
||||
let tx1 = Tx::gas_price(2).signed();
|
||||
let tx2 = Tx::gas_price(2).signed();
|
||||
let tx3 = Tx::gas_price(1).signed();
|
||||
let tx4 = Tx::gas_price(3).signed();
|
||||
let res = txq.import(TestClient::new(), vec![tx1, tx2].retracted());
|
||||
let res2 = txq.import(TestClient::new(), vec![tx3, tx4].retracted());
|
||||
|
||||
// then
|
||||
assert_eq!(res, vec![Ok(()), Ok(())]);
|
||||
assert_eq!(res2, vec![
|
||||
// The error here indicates reaching the limit
|
||||
// and minimal effective gas price taken into account.
|
||||
Err(transaction::Error::InsufficientGasPrice { minimal: 2.into(), got: 1.into() }),
|
||||
Ok(())
|
||||
]);
|
||||
assert_eq!(txq.status().status.transaction_count, 3);
|
||||
// First inserted transacton got dropped because of limit
|
||||
assert_eq!(txq.next_nonce(TestClient::new(), &sender), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_never_drop_local_transactions_from_different_senders() {
|
||||
// given
|
||||
let txq = TransactionQueue::new(
|
||||
txpool::Options {
|
||||
max_count: 3,
|
||||
max_per_sender: 1,
|
||||
max_mem_usage: 50
|
||||
},
|
||||
verifier::Options {
|
||||
minimal_gas_price: 1.into(),
|
||||
block_gas_limit: 1_000_000.into(),
|
||||
tx_gas_limit: 1_000_000.into(),
|
||||
},
|
||||
PrioritizationStrategy::GasPriceOnly,
|
||||
);
|
||||
let (tx1, tx2) = Tx::gas_price(2).signed_pair();
|
||||
let sender = tx1.sender();
|
||||
let nonce = tx1.nonce;
|
||||
|
||||
// when
|
||||
let r1 = txq.import(TestClient::new(), vec![tx1].local());
|
||||
let r2 = txq.import(TestClient::new(), vec![tx2].local());
|
||||
assert_eq!(r1, vec![Ok(())]);
|
||||
// max-per-sender is reached, that's ok.
|
||||
assert_eq!(r2, vec![Err(transaction::Error::LimitReached)]);
|
||||
assert_eq!(txq.status().status.transaction_count, 1);
|
||||
|
||||
// then
|
||||
assert_eq!(txq.next_nonce(TestClient::new(), &sender), Some(nonce + 1.into()));
|
||||
|
||||
// when
|
||||
let tx1 = Tx::gas_price(2).signed();
|
||||
let tx2 = Tx::gas_price(2).signed();
|
||||
@@ -82,10 +133,9 @@ fn should_return_correct_nonces_when_dropped_because_of_limit() {
|
||||
|
||||
// then
|
||||
assert_eq!(res, vec![Ok(()), Ok(())]);
|
||||
assert_eq!(res2, vec![Err(transaction::Error::LimitReached), Ok(())]);
|
||||
assert_eq!(txq.status().status.transaction_count, 3);
|
||||
// First inserted transacton got dropped because of limit
|
||||
assert_eq!(txq.next_nonce(TestClient::new(), &sender), None);
|
||||
assert_eq!(res2, vec![Ok(()), Ok(())]);
|
||||
assert_eq!(txq.status().status.transaction_count, 5);
|
||||
assert_eq!(txq.next_nonce(TestClient::new(), &sender), Some(nonce + 1.into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user