-
Notifications
You must be signed in to change notification settings - Fork 708
Introduce continuous mode to JIT Validator #4269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f651ac
Introduce continuous mode to Validator
bragaigor 03c0727
unify local_target and launch complete_machine in background
bragaigor 50154a3
Merge branch 'master' into braga/only-validation-cont-mode
bragaigor 73cbf6f
Introduce server.rs to handle server lifecycle
bragaigor 0d24aa8
Merge branch 'master' into braga/only-validation-cont-mode
bragaigor a8adf18
update changelog
bragaigor 51d52c0
make lint happy
bragaigor b5b679d
Merge branch 'master' into braga/only-validation-cont-mode
bragaigor 6ef41c9
Add 2nd server test and make Mutex more granular
bragaigor 6b6dda9
Ignore test_server_lifecycle_continuous_mode for now
bragaigor fda3eb1
Merge branch 'master' into braga/only-validation-cont-mode
bragaigor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ### Internal | ||
| - Add continuous mode to JIT validator | ||
| - Introduce `JitMachine` (equivalent to Go counterpart `JitMachine`) | ||
| - Introduce graceful shutdown through signals |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright 2025-2026, Offchain Labs, Inc. | ||
| // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md | ||
|
|
||
| // The default for JIT binary, no need for LLVM right now | ||
| pub(crate) const DEFAULT_JIT_CRANELIFT: bool = true; | ||
|
|
||
| pub(crate) const TARGET_ARM_64: &str = "arm64"; | ||
| pub(crate) const TARGET_AMD_64: &str = "amd64"; | ||
| pub(crate) const TARGET_HOST: &str = "host"; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| pub struct JitMachineConfig { | ||
| pub prover_bin_path: String, | ||
| pub jit_cranelift: bool, | ||
| pub wasm_memory_usage_limit: u64, | ||
| } | ||
|
|
||
| impl Default for JitMachineConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| prover_bin_path: "replay.wasm".to_owned(), | ||
| jit_cranelift: DEFAULT_JIT_CRANELIFT, | ||
| wasm_memory_usage_limit: 1 << 32, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright 2025-2026, Offchain Labs, Inc. | ||
| // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md | ||
|
|
||
| //! Validation Execution Logic and Request Models. | ||
| //! | ||
| //! This module serves as the central entry point for running validation tasks. | ||
| //! It defines the standard `ValidationRequest` structure used by the API and | ||
| //! implements the two primary validation strategies: | ||
| //! | ||
| //! 1. **Native Mode (`validate_native`):** Runs validation in-process using the | ||
| //! embedded `jit` crate. This utilizes the `jit::InputMode::Native` configuration | ||
| //! and is typically used for direct, low-overhead validation. | ||
| //! | ||
| //! 2. **Continuous Mode (`validate_continuous`):** Orchestrates an external "JIT Machine" | ||
| //! process (via `JitMachine`). This mode spawns a separate binary to handle | ||
| //! validation, isolating the execution environment and allowing for specific | ||
| //! binary version targeting. | ||
|
|
||
| use axum::Json; | ||
| use validation::{BatchInfo, GoGlobalState, ValidationInput}; | ||
|
|
||
| use crate::{ | ||
| config::ServerState, engine::config::DEFAULT_JIT_CRANELIFT, spawner_endpoints::local_target, | ||
| }; | ||
|
|
||
| pub async fn validate_native( | ||
| server_state: &ServerState, | ||
| request: ValidationInput, | ||
| ) -> Result<Json<GoGlobalState>, String> { | ||
| let delayed_inbox = match request.has_delayed_msg { | ||
| true => vec![BatchInfo { | ||
| number: request.delayed_msg_nr, | ||
| data: request.delayed_msg, | ||
| }], | ||
| false => vec![], | ||
| }; | ||
|
|
||
| let opts = jit::Opts { | ||
| validator: jit::ValidatorOpts { | ||
| binary: server_state.binary.clone(), | ||
| cranelift: DEFAULT_JIT_CRANELIFT, | ||
| debug: false, // JIT's debug messages are using printlns, which would clutter the server logs | ||
| require_success: false, // Relevant for JIT binary only. | ||
| }, | ||
| input_mode: jit::InputMode::Native(jit::NativeInput { | ||
| old_state: request.start_state.into(), | ||
| inbox: request.batch_info, | ||
| delayed_inbox, | ||
| preimages: request.preimages, | ||
| programs: request.user_wasms[local_target()].clone(), | ||
| }), | ||
| }; | ||
|
|
||
| let result = jit::run(&opts).map_err(|error| format!("{error}"))?; | ||
| if let Some(err) = result.error { | ||
| Err(format!("{err}")) | ||
| } else { | ||
| Ok(Json(GoGlobalState::from(result.new_state))) | ||
| } | ||
| } | ||
|
|
||
| pub async fn validate_continuous( | ||
| server_state: &ServerState, | ||
| request: ValidationInput, | ||
| ) -> Result<Json<GoGlobalState>, String> { | ||
| if server_state.jit_machine.is_none() { | ||
| return Err(format!( | ||
| "Jit machine is required continuous mode. Requested module root: {}", | ||
| server_state.module_root | ||
| )); | ||
| } | ||
|
|
||
| let jit_machine = server_state.jit_machine.as_ref().unwrap(); | ||
|
|
||
| if !jit_machine.is_active().await { | ||
| return Err(format!( | ||
| "Jit machine is not active. Maybe it received a shutdown signal? Requested module root: {}", | ||
| server_state.module_root | ||
| )); | ||
| } | ||
|
|
||
| let new_state = jit_machine | ||
| .feed_machine(&request) | ||
| .await | ||
| .map_err(|error| format!("{error:?}"))?; | ||
|
|
||
| Ok(Json(new_state)) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.