Conversation
Walkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
21bfcdf to
04dd205
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (8)
crates/starknet-devnet/src/main.rs (2)
300-303: Small readability tweak for timestamp shift.Pre-compute the shift for clarity; current logic is fine.
- starknet.set_block_timestamp_shift( - start_time as i64 - Starknet::get_unix_timestamp_as_seconds() as i64, - ); + let shift = start_time as i64 - Starknet::get_unix_timestamp_as_seconds() as i64; + starknet.set_block_timestamp_shift(shift);
309-312: Avoid taking an extra reference.If
get_predeployed_accounts()returns&Vec<Account>, passing&...makes it&&Vec<_>. Let deref-coercion work by dropping the&.- log_predeployed_accounts( - &starknet.get_predeployed_accounts(), - starknet_config.seed, - starknet_config.predeployed_accounts_initial_balance.clone(), - ); + log_predeployed_accounts( + starknet.get_predeployed_accounts(), + starknet_config.seed, + starknet_config.predeployed_accounts_initial_balance.clone(), + );scripts/benchmark/startup_test.py (6)
13-15: Make Devnet URL configurable.Hardcoding the URL/port limits usefulness. Add a CLI flag (with sane default).
-DEVNET_URL = "http://127.0.0.1:5050" -REQUEST_TIMEOUT = 2 +DEVNET_URL_DEFAULT = "http://127.0.0.1:5050" +REQUEST_TIMEOUT = 2And see arg parsing change below.
17-35: Polling: reduce request timeout and handle readiness quietly.Current 2s per attempt × 50 can stall >100s. Use short connect/read timeouts; drop the debug print or gate it.
def ensure_process_started(proc: subprocess.Popen): """Ensure the process under test is started""" max_retries = 50 for i in range(max_retries): if proc.returncode is not None: raise RuntimeError(f"Process exited with returncode {proc.returncode}") try: - resp = requests.get(f"{DEVNET_URL}/is_alive", timeout=REQUEST_TIMEOUT) + # Use short connect/read timeouts for snappy polling + resp = requests.get(f"{DEVNET_URL}/is_alive", timeout=(0.2, 0.5)) if resp.status_code == 200: - print(f"DEBUG returning on i={i}") return except requests.exceptions.ConnectionError: pass time.sleep(0.1) raise RuntimeError("Could not start process")
37-41: Terminate robustly (fallback to kill on timeout).Prevents lingering child processes if terminate doesn’t exit promptly.
def terminate_and_wait(proc: subprocess.Popen): """Terminates the process and waits.""" - proc.terminate() - proc.wait() + proc.terminate() + try: + proc.wait(timeout=5) + except subprocess.TimeoutExpired: + proc.kill() + proc.wait()
43-47: Use argparse; validate inputs; allow overriding URL.Improves UX and safety; integrates URL parameterization from above.
-def main(): - """Spawn Devnet""" - command = sys.argv[1] - iterations = int(sys.argv[2]) +def main(): + """Spawn Devnet""" + import argparse + parser = argparse.ArgumentParser(description="Measure Devnet startup time.") + parser.add_argument("command", help="Path to Devnet executable with args") + parser.add_argument("iterations", type=int, help="Number of runs") + parser.add_argument("--devnet-url", default=DEVNET_URL_DEFAULT, help="Health-check base URL") + args = parser.parse_args() + global DEVNET_URL + DEVNET_URL = args.devnet_url + command = args.command + iterations = args.iterations
50-52: Split command safely.
command.split()breaks on quoted args and spaces; useshlex.split.- with subprocess.Popen( - command.split(), stdout=subprocess.DEVNULL - ) as command_proc: + import shlex + with subprocess.Popen( + shlex.split(command), stdout=subprocess.DEVNULL + ) as command_proc:
56-56: Friendlier output formatting.Round to milliseconds for readability.
- print("Time passed:", time.time() - start_time) + elapsed = time.time() - start_time + print(f"Time passed: {elapsed:.3f}s")
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
crates/starknet-devnet/src/main.rs(2 hunks)scripts/benchmark/startup_test.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
scripts/benchmark/startup_test.py
22-22: Avoid specifying long messages outside the exception class
(TRY003)
34-34: Avoid specifying long messages outside the exception class
(TRY003)
50-50: subprocess call: check for execution of untrusted input
(S603)
🔇 Additional comments (3)
crates/starknet-devnet/src/main.rs (2)
294-294: Starknet-first initialization LGTM.Creating Starknet before Api simplifies ownership and reduces locking later.
314-316: Api move + handler wiring LGTM.Passing
Apiby value here aligns with the consumingshutdown_signal(api)later, while the handler keeps a clone.scripts/benchmark/startup_test.py (1)
50-50: Note on subprocess safety.Ensure
commandoriginates from trusted input; otherwise restrict or validate it (matches Ruff S603).
Usage related changes
None
Development related changes
shutdown_signal.Checklist:
./scripts/format.sh./scripts/clippy_check.sh./scripts/check_unused_deps.sh./scripts/check_spelling.sh./website/README.mdSummary by CodeRabbit
Refactor
Tests