@@ -6,7 +6,7 @@ use crate::{
66 setup:: { TX_SET_L1_BLOCK , build_payload_attributes} ,
77} ;
88use alloy_network:: { Ethereum , EthereumWallet , TransactionBuilder , eip2718:: Encodable2718 } ;
9- use alloy_primitives:: b64;
9+ use alloy_primitives:: { Bytes , b64} ;
1010use alloy_rpc_types:: TransactionRequest ;
1111use alloy_rpc_types_engine:: PayloadStatusEnum ;
1212use eyre:: eyre:: eyre;
@@ -18,7 +18,7 @@ use reth::{
1818use reth_e2e_test_utils:: testsuite:: actions:: Action ;
1919use reth_optimism_node:: utils:: optimism_payload_attributes;
2020use reth_transaction_pool:: TransactionPool ;
21- use revm_primitives:: { Address , U256 } ;
21+ use revm_primitives:: { Address , B256 , U256 } ;
2222use std:: {
2323 sync:: {
2424 Arc ,
@@ -34,9 +34,35 @@ use world_chain_test::{
3434} ;
3535
3636use crate :: setup:: {
37- CHAIN_SPEC , create_test_transaction, encode_eip1559_params, setup, setup_with_tx_peers,
37+ CHAIN_SPEC , create_test_transaction, encode_eip1559_params, setup,
38+ setup_with_block_uncompressed_size_limit, setup_with_tx_peers,
3839} ;
3940
41+ async fn create_priority_transaction (
42+ signer_index : u32 ,
43+ nonce : u64 ,
44+ calldata_len : usize ,
45+ gas_limit : u64 ,
46+ max_priority_fee_per_gas : u128 ,
47+ ) -> eyre:: Result < ( Bytes , B256 ) > {
48+ let mut tx_request = tx (
49+ CHAIN_SPEC . chain . id ( ) ,
50+ Some ( Bytes :: from ( vec ! [ 0u8 ; calldata_len] ) ) ,
51+ nonce,
52+ Address :: default ( ) ,
53+ gas_limit,
54+ ) ;
55+ tx_request. value = Some ( U256 :: ZERO ) ;
56+ tx_request. max_priority_fee_per_gas = Some ( max_priority_fee_per_gas) ;
57+ tx_request. max_fee_per_gas = Some ( 100_000_000_000u128 + max_priority_fee_per_gas) ;
58+
59+ let wallet = EthereumWallet :: from ( signer ( signer_index) ) ;
60+ let signed =
61+ <TransactionRequest as TransactionBuilder < Ethereum > >:: build ( tx_request, & wallet) . await ?;
62+
63+ Ok ( ( signed. encoded_2718 ( ) . into ( ) , * signed. tx_hash ( ) ) )
64+ }
65+
4066#[ tokio:: test]
4167async fn test_can_build_pbh_payload ( ) -> eyre:: Result < ( ) > {
4268 reth_tracing:: init_test_tracing ( ) ;
@@ -113,6 +139,154 @@ async fn test_transaction_pool_ordering() -> eyre::Result<()> {
113139 Ok ( ( ) )
114140}
115141
142+ #[ tokio:: test]
143+ async fn test_enforces_block_uncompressed_size_limit ( ) -> eyre:: Result < ( ) > {
144+ reth_tracing:: init_test_tracing ( ) ;
145+
146+ let ( tx1, tx1_hash) = create_priority_transaction ( 0 , 0 , 50_000 , 600_000 , 100 ) . await ?;
147+ let ( tx_small, tx_small_hash) = create_priority_transaction ( 1 , 0 , 30_000 , 400_000 , 95 ) . await ?;
148+ let ( tx2, tx2_hash) = create_priority_transaction ( 2 , 0 , 50_000 , 600_000 , 90 ) . await ?;
149+ let ( tx3, tx3_hash) = create_priority_transaction ( 3 , 0 , 50_000 , 600_000 , 80 ) . await ?;
150+
151+ let block_uncompressed_size_limit =
152+ TX_SET_L1_BLOCK . len ( ) as u64 + tx1. len ( ) as u64 + tx_small. len ( ) as u64 ;
153+
154+ let ( _, mut nodes, _tasks, _, _) =
155+ setup_with_block_uncompressed_size_limit :: < FlashblocksContext > (
156+ 1 ,
157+ optimism_payload_attributes,
158+ false ,
159+ Some ( block_uncompressed_size_limit) ,
160+ )
161+ . await ?;
162+ let node = & mut nodes[ 0 ] . node ;
163+
164+ assert_eq ! ( node. rpc. inject_tx( tx1. clone( ) ) . await ?, tx1_hash) ;
165+ assert_eq ! ( node. rpc. inject_tx( tx_small. clone( ) ) . await ?, tx_small_hash) ;
166+ assert_eq ! ( node. rpc. inject_tx( tx2. clone( ) ) . await ?, tx2_hash) ;
167+ assert_eq ! ( node. rpc. inject_tx( tx3. clone( ) ) . await ?, tx3_hash) ;
168+
169+ let block1 = node. advance_block ( ) . await ?;
170+ assert ! (
171+ block1
172+ . block( )
173+ . body( )
174+ . transactions
175+ . iter( )
176+ . any( |tx| * tx. tx_hash( ) == tx1_hash) ,
177+ "tx1 should be included in block 1"
178+ ) ;
179+ assert ! (
180+ block1
181+ . block( )
182+ . body( )
183+ . transactions
184+ . iter( )
185+ . any( |tx| * tx. tx_hash( ) == tx_small_hash) ,
186+ "tx_small should fit in block 1"
187+ ) ;
188+ assert ! (
189+ !block1
190+ . block( )
191+ . body( )
192+ . transactions
193+ . iter( )
194+ . any( |tx| * tx. tx_hash( ) == tx2_hash) ,
195+ "tx2 should go to a later block"
196+ ) ;
197+ assert ! (
198+ !block1
199+ . block( )
200+ . body( )
201+ . transactions
202+ . iter( )
203+ . any( |tx| * tx. tx_hash( ) == tx3_hash) ,
204+ "tx3 should go to a later block"
205+ ) ;
206+
207+ let block2 = node. advance_block ( ) . await ?;
208+ assert ! (
209+ block2
210+ . block( )
211+ . body( )
212+ . transactions
213+ . iter( )
214+ . any( |tx| * tx. tx_hash( ) == tx2_hash) ,
215+ "tx2 should be included in block 2"
216+ ) ;
217+ assert ! (
218+ !block2
219+ . block( )
220+ . body( )
221+ . transactions
222+ . iter( )
223+ . any( |tx| * tx. tx_hash( ) == tx3_hash) ,
224+ "tx3 should still go after block 2"
225+ ) ;
226+
227+ let block3 = node. advance_block ( ) . await ?;
228+ assert ! (
229+ block3
230+ . block( )
231+ . body( )
232+ . transactions
233+ . iter( )
234+ . any( |tx| * tx. tx_hash( ) == tx3_hash) ,
235+ "tx3 should be included in block 3"
236+ ) ;
237+
238+ Ok ( ( ) )
239+ }
240+
241+ #[ tokio:: test]
242+ async fn test_without_block_uncompressed_size_limit_includes_all_transactions ( ) -> eyre:: Result < ( ) >
243+ {
244+ reth_tracing:: init_test_tracing ( ) ;
245+
246+ let ( _, mut nodes, _tasks, _, _) =
247+ setup :: < FlashblocksContext > ( 1 , optimism_payload_attributes, false ) . await ?;
248+ let node = & mut nodes[ 0 ] . node ;
249+
250+ let ( tx1, tx1_hash) = create_priority_transaction ( 0 , 0 , 50_000 , 600_000 , 100 ) . await ?;
251+ let ( tx2, tx2_hash) = create_priority_transaction ( 1 , 0 , 50_000 , 600_000 , 90 ) . await ?;
252+ let ( tx3, tx3_hash) = create_priority_transaction ( 2 , 0 , 50_000 , 600_000 , 80 ) . await ?;
253+
254+ assert_eq ! ( node. rpc. inject_tx( tx1) . await ?, tx1_hash) ;
255+ assert_eq ! ( node. rpc. inject_tx( tx2) . await ?, tx2_hash) ;
256+ assert_eq ! ( node. rpc. inject_tx( tx3) . await ?, tx3_hash) ;
257+
258+ let block = node. advance_block ( ) . await ?;
259+ assert ! (
260+ block
261+ . block( )
262+ . body( )
263+ . transactions
264+ . iter( )
265+ . any( |tx| * tx. tx_hash( ) == tx1_hash) ,
266+ "tx1 should be included"
267+ ) ;
268+ assert ! (
269+ block
270+ . block( )
271+ . body( )
272+ . transactions
273+ . iter( )
274+ . any( |tx| * tx. tx_hash( ) == tx2_hash) ,
275+ "tx2 should be included"
276+ ) ;
277+ assert ! (
278+ block
279+ . block( )
280+ . body( )
281+ . transactions
282+ . iter( )
283+ . any( |tx| * tx. tx_hash( ) == tx3_hash) ,
284+ "tx3 should be included"
285+ ) ;
286+
287+ Ok ( ( ) )
288+ }
289+
116290#[ tokio:: test]
117291async fn test_invalidate_dup_tx_and_nullifier ( ) -> eyre:: Result < ( ) > {
118292 reth_tracing:: init_test_tracing ( ) ;
0 commit comments