diff --git a/core/lib/mempool/src/mempool_store.rs b/core/lib/mempool/src/mempool_store.rs index 47c6395cd7ab..acaf3f6ee02f 100644 --- a/core/lib/mempool/src/mempool_store.rs +++ b/core/lib/mempool/src/mempool_store.rs @@ -233,14 +233,18 @@ impl MempoolStore { .map(|txs| (pointer.account, txs)) }) .collect(); - let mut number_of_accounts_kept = possibly_kept - .iter() - .scan(0, |sum, (_, txs)| { - *sum += txs.len(); - (*sum <= self.capacity as usize).then_some(()) - }) - .count(); - if number_of_accounts_kept == 0 { + + let mut sum = 0; + let mut number_of_accounts_kept = 0; + for (_, txs) in possibly_kept { + sum += txs.len(); + if sum <= self.capacity as usize { + number_of_accounts_kept += 1; + } else { + break; + } + } + if number_of_accounts_kept == 0 && !possibly_kept.is_empty() { tracing::warn!("mempool capacity is too low to handle txs from single account, consider increasing capacity"); // Keep at least one entry, otherwise mempool won't return any new L2 tx to process. number_of_accounts_kept = 1; diff --git a/core/lib/mempool/src/tests.rs b/core/lib/mempool/src/tests.rs index c5be498a4774..b84ab7d57651 100644 --- a/core/lib/mempool/src/tests.rs +++ b/core/lib/mempool/src/tests.rs @@ -338,7 +338,7 @@ fn mempool_capacity() { // Mempool is full. Accounts with non-sequential nonces and some accounts with lowest score should be purged. assert_eq!( HashSet::<_>::from_iter(mempool.get_mempool_info().purged_accounts), - HashSet::<_>::from_iter(vec![account2, account3]), + HashSet::from([account2, account3]), ); // verify that good-to-go transactions are kept. for _ in 0..3 { @@ -373,10 +373,7 @@ fn mempool_does_not_purge_all_accounts() { mempool.insert(transactions, HashMap::new()); // Mempool is full. Account 1 has tx with non-sequential nonce so it should be purged. // Txs from account 0 have sequential nonces but their number is greater than capacity; they should be kept. - assert_eq!( - HashSet::<_>::from_iter(mempool.get_mempool_info().purged_accounts), - HashSet::<_>::from_iter(vec![account1]), - ); + assert_eq!(mempool.get_mempool_info().purged_accounts, vec![account1]); // verify that good-to-go transactions are kept. for _ in 0..2 { assert_eq!( diff --git a/core/node/state_keeper/src/mempool_actor.rs b/core/node/state_keeper/src/mempool_actor.rs index d19a769e21b8..a17f2670cbb9 100644 --- a/core/node/state_keeper/src/mempool_actor.rs +++ b/core/node/state_keeper/src/mempool_actor.rs @@ -89,29 +89,26 @@ impl MempoolFetcher { .await .context("failed getting pending protocol version")?; - let l2_tx_filter = if let Some(unsealed_batch) = storage + let (fee_per_gas, gas_per_pubdata) = if let Some(unsealed_batch) = storage .blocks_dal() .get_unsealed_l1_batch() .await .context("failed getting unsealed batch")? { - let (base_fee, gas_per_pubdata) = derive_base_fee_and_gas_per_pubdata( + let (fee_per_gas, gas_per_pubdata) = derive_base_fee_and_gas_per_pubdata( unsealed_batch.fee_input, protocol_version.into(), ); - - L2TxFilter { - fee_input: unsealed_batch.fee_input, - fee_per_gas: base_fee, - gas_per_pubdata: gas_per_pubdata as u32, - } + (fee_per_gas, gas_per_pubdata as u32) } else { - l2_tx_filter( + let filter = l2_tx_filter( self.batch_fee_input_provider.as_ref(), protocol_version.into(), ) .await - .context("failed creating L2 transaction filter")? + .context("failed creating L2 transaction filter")?; + + (filter.fee_per_gas, filter.gas_per_pubdata) }; let transactions = storage @@ -119,8 +116,8 @@ impl MempoolFetcher { .sync_mempool( &mempool_info.stashed_accounts, &mempool_info.purged_accounts, - l2_tx_filter.gas_per_pubdata, - l2_tx_filter.fee_per_gas, + gas_per_pubdata, + fee_per_gas, self.sync_batch_size, ) .await