Skip to content

Commit f5aba6d

Browse files
temp
1 parent 956f2a0 commit f5aba6d

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

packages/testing/src/execution_testing/cli/pytest_commands/plugins/execute/execute.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ def pytest_addoption(parser: pytest.Parser) -> None:
138138
default=False,
139139
help="Don't send transactions, just print the minimum balance required per test.",
140140
)
141+
execute_group.addoption(
142+
"--max-tx-per-batch",
143+
action="store",
144+
dest="max_tx_per_batch",
145+
type=int,
146+
default=None,
147+
help=(
148+
"Maximum number of transactions to send in a single batch to the RPC. "
149+
"Default=750. Higher values may cause RPC instability."
150+
),
151+
)
141152

142153
report_group = parser.getgroup(
143154
"tests", "Arguments defining html report behavior"
@@ -311,6 +322,12 @@ def dry_run(request: pytest.FixtureRequest) -> bool:
311322
return request.config.getoption("dry_run")
312323

313324

325+
@pytest.fixture(scope="session")
326+
def max_transactions_per_batch(request: pytest.FixtureRequest) -> int | None:
327+
"""Return the maximum number of transactions per batch, or None for default."""
328+
return request.config.getoption("max_tx_per_batch")
329+
330+
314331
@pytest.fixture(scope="session")
315332
def default_max_fee_per_gas(
316333
request: pytest.FixtureRequest,

packages/testing/src/execution_testing/execution/transaction_post.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
logger = get_logger(__name__)
2525

26+
# Threshold above which RPC service may become unstable
27+
RPC_OVERLOAD_THRESHOLD = 1000
28+
2629

2730
class 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

Comments
 (0)