Skip to content

Commit a6f827a

Browse files
greged93frisitano
andauthored
feat: disallow l1 messages tx pool (#322)
* feat: limit rollup fee in tx pool Signed-off-by: Gregory Edison <[email protected]> * fix: check rollup fee Signed-off-by: Gregory Edison <[email protected]> * feat: limit pool tx size (#317) * feat: add maxTxPayloadBytesPerBlock to ScrollChainConfig Signed-off-by: Gregory Edison <[email protected]> * feat: limit pool max tx input bytes Signed-off-by: Gregory Edison <[email protected]> * test: set max_tx_payload_bytes_per_block Signed-off-by: Gregory Edison <[email protected]> * feat: make MockEthProvider more generic Signed-off-by: Gregory Edison <[email protected]> * test: add pool limit tests Signed-off-by: Gregory Edison <[email protected]> * fix: lints Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]> * test: update Signed-off-by: Gregory Edison <[email protected]> * feat: disallow L1 messages in tx pool Signed-off-by: Gregory Edison <[email protected]> * test: disallow L1 messages in tx pool Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]> Co-authored-by: frisitano <[email protected]>
1 parent 87d3325 commit a6f827a

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

crates/scroll/node/src/builder/pool.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use reth_transaction_pool::{
1313
blobstore::DiskFileBlobStore, CoinbaseTipOrdering, EthPoolTransaction,
1414
TransactionValidationTaskExecutor,
1515
};
16+
use scroll_alloy_consensus::ScrollTransaction;
1617
use scroll_alloy_hardforks::ScrollHardforks;
1718

1819
/// A basic scroll transaction pool.
@@ -52,7 +53,7 @@ where
5253
ChainSpec: EthChainSpec + ScrollHardforks + ChainConfig<Config = ScrollChainConfig>,
5354
>,
5455
>,
55-
T: EthPoolTransaction<Consensus = TxTy<Node::Types>>,
56+
T: EthPoolTransaction<Consensus = TxTy<Node::Types>> + ScrollTransaction,
5657
{
5758
type Pool = ScrollTransactionPool<Node::Provider, DiskFileBlobStore, T>;
5859

@@ -138,7 +139,7 @@ mod tests {
138139
use crate::ScrollNode;
139140

140141
use alloy_consensus::{transaction::Recovered, Header, Signed, TxLegacy};
141-
use alloy_primitives::{private::rand::random_iter, Bytes, Signature, B256, U256};
142+
use alloy_primitives::{private::rand::random_iter, Bytes, Sealed, Signature, B256, U256};
142143
use reth_chainspec::Head;
143144
use reth_db::mock::DatabaseMock;
144145
use reth_node_api::FullNodeTypesAdapter;
@@ -160,7 +161,7 @@ mod tests {
160161
error::{InvalidPoolTransactionError, PoolErrorKind},
161162
PoolConfig, TransactionOrigin, TransactionPool,
162163
};
163-
use scroll_alloy_consensus::ScrollTxEnvelope;
164+
use scroll_alloy_consensus::{ScrollTxEnvelope, TxL1Message};
164165
use scroll_alloy_evm::curie::L1_GAS_PRICE_ORACLE_ADDRESS;
165166

166167
async fn pool() -> (
@@ -351,4 +352,31 @@ mod tests {
351352
// drop all validation tasks.
352353
drop(manager);
353354
}
355+
356+
#[tokio::test]
357+
async fn test_validate_one_disallow_l1_messages() {
358+
// create the pool.
359+
let (pool, manager) = pool().await;
360+
let tx = ScrollTxEnvelope::L1Message(Sealed::new_unchecked(
361+
TxL1Message::default(),
362+
B256::default(),
363+
));
364+
365+
// Create a pool transaction with the L1 message.
366+
let pool_tx =
367+
ScrollPooledTransaction::new(Recovered::new_unchecked(tx, Default::default()), 0);
368+
369+
// add the transaction to the pool and expect an `OversizedData` error.
370+
let err = pool.add_transaction(TransactionOrigin::Local, pool_tx).await.unwrap_err();
371+
assert!(matches!(
372+
err.kind,
373+
PoolErrorKind::InvalidTransaction(InvalidPoolTransactionError::Consensus(
374+
InvalidTransactionError::TxTypeNotSupported
375+
))
376+
));
377+
378+
// explicitly drop the manager here otherwise the `TransactionValidationTaskExecutor` will
379+
// drop all validation tasks.
380+
drop(manager);
381+
}
354382
}

crates/scroll/txpool/src/transaction.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use reth_scroll_primitives::ScrollTransactionSigned;
1010
use reth_transaction_pool::{
1111
EthBlobTransactionSidecar, EthPoolTransaction, EthPooledTransaction, PoolTransaction,
1212
};
13+
use scroll_alloy_consensus::ScrollTransaction;
1314
use std::sync::{Arc, OnceLock};
1415

1516
/// Pool transaction for Scroll.
@@ -209,6 +210,16 @@ where
209210
}
210211
}
211212

213+
impl<Cons: ScrollTransaction, Pooled> ScrollTransaction for ScrollPooledTransaction<Cons, Pooled> {
214+
fn is_l1_message(&self) -> bool {
215+
self.transaction.is_l1_message()
216+
}
217+
218+
fn queue_index(&self) -> Option<u64> {
219+
self.transaction.queue_index()
220+
}
221+
}
222+
212223
#[cfg(test)]
213224
mod tests {
214225
use crate::{ScrollPooledTransaction, ScrollTransactionValidator};

crates/scroll/txpool/src/validator.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use reth_transaction_pool::{
1717
TransactionValidator,
1818
};
1919
use revm_scroll::l1block::L1BlockInfo;
20+
use scroll_alloy_consensus::ScrollTransaction;
2021
use std::sync::{
2122
atomic::{AtomicU64, Ordering},
2223
Arc,
@@ -85,7 +86,7 @@ impl<Client, Tx> ScrollTransactionValidator<Client, Tx> {
8586
impl<Client, Tx> ScrollTransactionValidator<Client, Tx>
8687
where
8788
Client: ChainSpecProvider<ChainSpec: ScrollHardforks> + StateProviderFactory + BlockReaderIdExt,
88-
Tx: EthPoolTransaction,
89+
Tx: EthPoolTransaction + ScrollTransaction,
8990
{
9091
/// Create a new [`ScrollTransactionValidator`].
9192
pub fn new(inner: EthTransactionValidator<Client, Tx>) -> Self {
@@ -139,6 +140,12 @@ where
139140
transaction: Tx,
140141
) -> TransactionValidationOutcome<Tx> {
141142
if transaction.is_eip4844() {
143+
return TransactionValidationOutcome::Invalid(
144+
transaction,
145+
InvalidTransactionError::Eip4844Disabled.into(),
146+
)
147+
}
148+
if transaction.is_l1_message() {
142149
return TransactionValidationOutcome::Invalid(
143150
transaction,
144151
InvalidTransactionError::TxTypeNotSupported.into(),
@@ -232,7 +239,7 @@ where
232239
impl<Client, Tx> TransactionValidator for ScrollTransactionValidator<Client, Tx>
233240
where
234241
Client: ChainSpecProvider<ChainSpec: ScrollHardforks> + StateProviderFactory + BlockReaderIdExt,
235-
Tx: EthPoolTransaction,
242+
Tx: EthPoolTransaction + ScrollTransaction,
236243
{
237244
type Transaction = Tx;
238245

0 commit comments

Comments
 (0)