Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Oct 16, 2024
1 parent f613407 commit 136d010
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
20 changes: 12 additions & 8 deletions core/lib/mempool/src/mempool_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions core/lib/mempool/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!(
Expand Down
21 changes: 9 additions & 12 deletions core/node/state_keeper/src/mempool_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,35 @@ 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
.transactions_dal()
.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
Expand Down

0 comments on commit 136d010

Please sign in to comment.