Disable parallel verification and skip verifiying already imported txs. (#8834)

* Reject transactions that are already in pool without verifying them.

* Avoid verifying already imported transactions.
This commit is contained in:
Tomasz Drwięga
2018-06-08 17:05:46 +02:00
committed by Afri Schoedon
parent 13bc922e54
commit af1088ef61
7 changed files with 54 additions and 7 deletions

View File

@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::{atomic, Arc};
use ethereum_types::{U256, H256, Address};
use rlp::Rlp;
use transaction::{self, Transaction, SignedTransaction, UnverifiedTransaction};
@@ -25,6 +27,7 @@ const MAX_TRANSACTION_SIZE: usize = 15 * 1024;
#[derive(Debug, Clone)]
pub struct TestClient {
verification_invoked: Arc<atomic::AtomicBool>,
account_details: AccountDetails,
gas_required: U256,
is_service_transaction: bool,
@@ -35,6 +38,7 @@ pub struct TestClient {
impl Default for TestClient {
fn default() -> Self {
TestClient {
verification_invoked: Default::default(),
account_details: AccountDetails {
nonce: 123.into(),
balance: 63_100.into(),
@@ -88,6 +92,10 @@ impl TestClient {
insertion_id: 1,
}
}
pub fn was_verification_triggered(&self) -> bool {
self.verification_invoked.load(atomic::Ordering::SeqCst)
}
}
impl pool::client::Client for TestClient {
@@ -98,6 +106,7 @@ impl pool::client::Client for TestClient {
fn verify_transaction(&self, tx: UnverifiedTransaction)
-> Result<SignedTransaction, transaction::Error>
{
self.verification_invoked.store(true, atomic::Ordering::SeqCst);
Ok(SignedTransaction::new(tx)?)
}

View File

@@ -796,3 +796,37 @@ fn should_include_local_transaction_to_a_full_pool() {
// then
assert_eq!(txq.status().status.transaction_count, 1);
}
#[test]
fn should_avoid_verifying_transaction_already_in_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 client = TestClient::new();
let tx1 = Tx::default().signed().unverified();
let res = txq.import(client.clone(), vec![tx1.clone()]);
assert_eq!(res, vec![Ok(())]);
assert_eq!(txq.status().status.transaction_count, 1);
assert!(client.was_verification_triggered());
// when
let client = TestClient::new();
let res = txq.import(client.clone(), vec![tx1]);
assert_eq!(res, vec![Err(transaction::Error::AlreadyImported)]);
assert!(!client.was_verification_triggered());
// then
assert_eq!(txq.status().status.transaction_count, 1);
}