Fix local transactions policy. (#8691)
This commit is contained in:
parent
7fcb082cad
commit
1620eabd9d
@ -107,6 +107,15 @@ impl txpool::Scoring<VerifiedTransaction> for NonceAndGasPrice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always kick out non-local transactions in favour of local ones.
|
||||||
|
if new.priority().is_local() && !old.priority().is_local() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// And never kick out local transactions in favour of external ones.
|
||||||
|
if !new.priority().is_local() && old.priority.is_local() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
self.choose(old, new) == txpool::scoring::Choice::ReplaceOld
|
self.choose(old, new) == txpool::scoring::Choice::ReplaceOld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,6 +128,30 @@ mod tests {
|
|||||||
use pool::tests::tx::{Tx, TxExt};
|
use pool::tests::tx::{Tx, TxExt};
|
||||||
use txpool::Scoring;
|
use txpool::Scoring;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_replace_non_local_transaction_with_local_one() {
|
||||||
|
// given
|
||||||
|
let scoring = NonceAndGasPrice(PrioritizationStrategy::GasPriceOnly);
|
||||||
|
let tx1 = {
|
||||||
|
let tx = Tx::default().signed().verified();
|
||||||
|
txpool::Transaction {
|
||||||
|
insertion_id: 0,
|
||||||
|
transaction: Arc::new(tx),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let tx2 = {
|
||||||
|
let mut tx = Tx::default().signed().verified();
|
||||||
|
tx.priority = ::pool::Priority::Local;
|
||||||
|
txpool::Transaction {
|
||||||
|
insertion_id: 0,
|
||||||
|
transaction: Arc::new(tx),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(scoring.should_replace(&tx1, &tx2));
|
||||||
|
assert!(!scoring.should_replace(&tx2, &tx1));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_calculate_score_correctly() {
|
fn should_calculate_score_correctly() {
|
||||||
// given
|
// given
|
||||||
|
@ -766,4 +766,35 @@ fn should_reject_big_transaction() {
|
|||||||
verifier::Transaction::Local(PendingTransaction::new(big_tx, transaction::Condition::Timestamp(1000).into()))
|
verifier::Transaction::Local(PendingTransaction::new(big_tx, transaction::Condition::Timestamp(1000).into()))
|
||||||
]);
|
]);
|
||||||
assert_eq!(res, vec![Err(transaction::Error::TooBig)]);
|
assert_eq!(res, vec![Err(transaction::Error::TooBig)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_include_local_transaction_to_a_full_pool() {
|
||||||
|
// given
|
||||||
|
let txq = TransactionQueue::new(
|
||||||
|
txpool::Options {
|
||||||
|
max_count: 1,
|
||||||
|
max_per_sender: 2,
|
||||||
|
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 = Tx::gas_price(10_000).signed().unverified();
|
||||||
|
let tx2 = Tx::gas_price(1).signed().local();
|
||||||
|
|
||||||
|
let res = txq.import(TestClient::new().with_balance(1_000_000_000), vec![tx1]);
|
||||||
|
assert_eq!(res, vec![Ok(())]);
|
||||||
|
assert_eq!(txq.status().status.transaction_count, 1);
|
||||||
|
|
||||||
|
// when
|
||||||
|
let res = txq.import(TestClient::new(), vec![tx2]);
|
||||||
|
assert_eq!(res, vec![Ok(())]);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assert_eq!(txq.status().status.transaction_count, 1);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user