2323
2424logger = get_logger (__name__ )
2525
26+ # Threshold above which RPC service may become unstable
27+ RPC_OVERLOAD_THRESHOLD = 1000
28+
2629
2730class TransactionPost (BaseExecute ):
2831 """
@@ -38,6 +41,8 @@ class TransactionPost(BaseExecute):
3841 skip_gas_used_validation : bool = (
3942 False # Skip gas validation even if expected is set
4043 )
44+ # Transaction batching to avoid RPC overload
45+ max_transactions_per_batch : int = 750
4146
4247 format_name : ClassVar [str ] = "transaction_post_test"
4348 description : ClassVar [str ] = (
@@ -80,6 +85,22 @@ def execute(
8085 """Execute the format."""
8186 del fork
8287 del engine_rpc
88+
89+ # Check if CLI override for max_transactions_per_batch is provided
90+ cli_max_tx_per_batch = request .config .getoption (
91+ "max_tx_per_batch" , None
92+ )
93+ if cli_max_tx_per_batch is not None :
94+ self .max_transactions_per_batch = cli_max_tx_per_batch
95+
96+ # Warn if max_transactions_per_batch exceeds safe threshold
97+ if self .max_transactions_per_batch > RPC_OVERLOAD_THRESHOLD :
98+ logger .warning (
99+ f"max_transactions_per_batch ({ self .max_transactions_per_batch } ) exceeds "
100+ f"the safe threshold ({ RPC_OVERLOAD_THRESHOLD } ). "
101+ "This may cause RPC service instability or failures."
102+ )
103+
83104 for block in self .blocks :
84105 for tx in block :
85106 if not isinstance (tx , NetworkWrappedTransaction ):
@@ -131,8 +152,18 @@ def execute(
131152 f"Transaction rejected as expected: { exc_info .value } "
132153 )
133154 else :
134- eth_rpc .send_wait_transactions (signed_txs )
135- all_tx_hashes .extend ([tx .hash for tx in signed_txs ])
155+ # Send transactions in batches to avoid RPC overload
156+ batch_size = self .max_transactions_per_batch
157+ for i in range (0 , len (signed_txs ), batch_size ):
158+ batch = signed_txs [i : i + batch_size ]
159+ logger .info (
160+ f"Sending transaction batch { i // batch_size + 1 } "
161+ f"({ len (batch )} transactions, "
162+ f"{ i + 1 } -{ min (i + batch_size , len (signed_txs ))} "
163+ f"of { len (signed_txs )} )"
164+ )
165+ eth_rpc .send_wait_transactions (batch )
166+ all_tx_hashes .extend ([tx .hash for tx in batch ])
136167
137168 # Perform gas validation if required for benchmarking
138169 # Ensures benchmark tests consume exactly the expected gas
0 commit comments