Skip to content

Commit 8fb4b27

Browse files
authored
refactor(l1): avoid recovering sender two times when txs are received (#5419)
**Motivation** We were doing sender recovery two times for each transaction received. This is inefficient. **Description** This PR deduplicates the action, by sharing the computed sender with `Mempool::add_transaction`
1 parent 46096d1 commit 8fb4b27

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

crates/blockchain/blockchain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ impl Blockchain {
14001400

14011401
// Add transaction and blobs bundle to storage
14021402
self.mempool
1403-
.add_transaction(hash, MempoolTransaction::new(transaction, sender))?;
1403+
.add_transaction(hash, sender, MempoolTransaction::new(transaction, sender))?;
14041404
self.mempool.add_blobs_bundle(hash, blobs_bundle)?;
14051405
Ok(hash)
14061406
}
@@ -1426,7 +1426,7 @@ impl Blockchain {
14261426

14271427
// Add transaction to storage
14281428
self.mempool
1429-
.add_transaction(hash, MempoolTransaction::new(transaction, sender))?;
1429+
.add_transaction(hash, sender, MempoolTransaction::new(transaction, sender))?;
14301430

14311431
Ok(hash)
14321432
}

crates/blockchain/mempool.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl Mempool {
104104
pub fn add_transaction(
105105
&self,
106106
hash: H256,
107+
sender: Address,
107108
transaction: MempoolTransaction,
108109
) -> Result<(), StoreError> {
109110
let mut inner = self.write()?;
@@ -120,7 +121,7 @@ impl Mempool {
120121
inner.txs_order.push_back(hash);
121122
inner
122123
.txs_by_sender_nonce
123-
.insert((transaction.sender(), transaction.nonce()), hash);
124+
.insert((sender, transaction.nonce()), hash);
124125
inner.transaction_pool.insert(hash, transaction);
125126
inner.broadcast_pool.insert(hash);
126127

@@ -822,9 +823,11 @@ mod tests {
822823
let filter =
823824
|tx: &Transaction| -> bool { matches!(tx, Transaction::EIP4844Transaction(_)) };
824825
mempool
825-
.add_transaction(blob_tx_hash, blob_tx.clone())
826+
.add_transaction(blob_tx_hash, blob_tx_sender, blob_tx.clone())
827+
.unwrap();
828+
mempool
829+
.add_transaction(plain_tx_hash, plain_tx_sender, plain_tx)
826830
.unwrap();
827-
mempool.add_transaction(plain_tx_hash, plain_tx).unwrap();
828831
let txs = mempool.filter_transactions_with_filter_fn(&filter).unwrap();
829832
assert_eq!(txs, HashMap::from([(blob_tx.sender(), vec![blob_tx])]));
830833
}

0 commit comments

Comments
 (0)