Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions grey/crates/build-javm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ use std::path::PathBuf;

use build_crate::{BuildKind, GuestBuild};

/// Convert a [`PathBuf`] to a string suitable for use inside `include_bytes!(…)`.
///
/// On Windows, `PathBuf::display()` emits backslash separators which the Rust
/// lexer then interprets as escape sequences inside string literals (e.g. `\b`,
/// `\j`, `\s`). Replacing backslashes with forward slashes produces paths that
/// are valid on every platform — the Rust compiler accepts forward slashes on
/// Windows, and Unix paths never contain backslashes in the first place.
pub fn include_path(path: &std::path::Path) -> String {
path.to_string_lossy().replace('\\', "/")
}

const TARGET_JSON: &str = include_str!("riscv64em-javm.json");
const TARGET_NAME: &str = "riscv64em-javm";

Expand Down
11 changes: 11 additions & 0 deletions grey/crates/build-pvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ use build_crate::{BuildKind, GuestBuild};
const TARGET_JSON: &str = include_str!("riscv64emac-polkavm.json");
const TARGET_NAME: &str = "riscv64emac-polkavm";

/// Convert a [`PathBuf`] to a string suitable for use inside `include_bytes!(…)`.
///
/// On Windows, `PathBuf::display()` emits backslash separators which the Rust
/// lexer then interprets as escape sequences inside string literals (e.g. `\b`,
/// `\j`, `\s`). Replacing backslashes with forward slashes produces paths that
/// are valid on every platform — the Rust compiler accepts forward slashes on
/// Windows, and Unix paths never contain backslashes in the first place.
pub fn include_path(path: &std::path::Path) -> String {
path.to_string_lossy().replace('\\', "/")
}

/// Build a PolkaVM blob from a service crate.
///
/// - `manifest_dir`: path to the service crate, relative to `CARGO_MANIFEST_DIR`
Expand Down
22 changes: 11 additions & 11 deletions grey/crates/grey-bench/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ fn main() {
const GREY_KECCAK_BLOB: &[u8] = include_bytes!(\"{}\");\n\
const POLKAVM_KECCAK_BLOB: &[u8] = include_bytes!(\"{}\");\n\
const SAMPLE_SERVICE_BLOB: &[u8] = include_bytes!(\"{}\");\n",
javm_ecrecover.display(),
pvm_ecrecover.display(),
javm_sieve.display(),
pvm_sieve.display(),
javm_ed25519.display(),
pvm_ed25519.display(),
javm_blake2b.display(),
pvm_blake2b.display(),
javm_keccak.display(),
pvm_keccak.display(),
service_blob.display(),
build_javm::include_path(&javm_ecrecover),
build_pvm::include_path(&pvm_ecrecover),
build_javm::include_path(&javm_sieve),
build_pvm::include_path(&pvm_sieve),
build_javm::include_path(&javm_ed25519),
build_pvm::include_path(&pvm_ed25519),
build_javm::include_path(&javm_blake2b),
build_pvm::include_path(&pvm_blake2b),
build_javm::include_path(&javm_keccak),
build_pvm::include_path(&pvm_keccak),
build_javm::include_path(&service_blob),
),
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions grey/crates/grey/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fn main() {
format!(
"const SAMPLE_SERVICE_BLOB: &[u8] = include_bytes!(\"{}\");\n\
const PIXELS_SERVICE_BLOB: &[u8] = include_bytes!(\"{}\");\n",
sample.display(),
pixels.display(),
build_javm::include_path(&sample),
build_javm::include_path(&pixels),
),
)
.unwrap();
Expand Down
62 changes: 45 additions & 17 deletions grey/crates/grey/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,50 @@ pub async fn run_node(config: NodeConfig) -> Result<(), Box<dyn std::error::Erro
genesis_time
);

// Graceful shutdown on SIGINT (Ctrl+C) or SIGTERM (kill)
let mut sigterm = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("failed to register SIGTERM handler");
let shutdown = async {
// Graceful shutdown on SIGINT (Ctrl+C) or SIGTERM (kill).
// On Unix, also listen for SIGTERM. On Windows, only Ctrl+C is available.
#[cfg(unix)]
let shutdown_signal = async {
let mut sigterm =
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("failed to register SIGTERM handler");
tokio::select! {
_ = tokio::signal::ctrl_c() => "SIGINT",
_ = sigterm.recv() => "SIGTERM",
}
};
tokio::pin!(shutdown);

// SIGUSR1: dump debug state to log
let mut sigusr1 = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::user_defined1())
.expect("failed to register SIGUSR1 handler");

// SIGHUP: reload config file
let mut sighup = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::hangup())
.expect("failed to register SIGHUP handler");
#[cfg(not(unix))]
let shutdown_signal = async {
let _ = tokio::signal::ctrl_c().await;
"SIGINT"
};
tokio::pin!(shutdown_signal);

// SIGUSR1: dump debug state to log (Unix only).
// On non-Unix platforms, the future is pending forever so this arm never fires.
#[cfg(unix)]
let sigusr1_signal = async {
let mut sigusr1 =
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::user_defined1())
.expect("failed to register SIGUSR1 handler");
sigusr1.recv().await
};
#[cfg(not(unix))]
let sigusr1_signal = std::future::pending::<()>();
tokio::pin!(sigusr1_signal);

// SIGHUP: reload config file (Unix only).
// On non-Unix platforms, the future is pending forever so this arm never fires.
#[cfg(unix)]
let sighup_signal = async {
let mut sighup =
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::hangup())
.expect("failed to register SIGHUP handler");
sighup.recv().await
};
#[cfg(not(unix))]
let sighup_signal = std::future::pending::<()>();
tokio::pin!(sighup_signal);
let config_path = config.config_path.clone();

// Main loop: check timeslots every 500ms
Expand All @@ -426,7 +452,7 @@ pub async fn run_node(config: NodeConfig) -> Result<(), Box<dyn std::error::Erro

loop {
tokio::select! {
signal_name = &mut shutdown => {
signal_name = &mut shutdown_signal => {
tracing::info!(
"Validator {} received {}, flushing state...",
config.validator_index,
Expand All @@ -444,8 +470,9 @@ pub async fn run_node(config: NodeConfig) -> Result<(), Box<dyn std::error::Erro
);
break;
}
// SIGUSR1: dump debug state snapshot to log
_ = sigusr1.recv() => {
// SIGUSR1: dump debug state snapshot to log.
// On non-Unix platforms sigusr1_signal is pending forever, so this arm never fires.
_ = sigusr1_signal.as_mut() => {
let head_hash = state
.recent_blocks
.headers
Expand Down Expand Up @@ -477,7 +504,8 @@ pub async fn run_node(config: NodeConfig) -> Result<(), Box<dyn std::error::Erro
blocks_imported,
);
}
_ = sighup.recv() => {
// SIGHUP: reload config. On non-Unix platforms sighup_signal is pending forever.
_ = sighup_signal.as_mut() => {
if let Some(ref path) = config_path {
tracing::info!("SIGHUP received — reloading config from {}", path);
match crate::config::ConfigFile::load(std::path::Path::new(path)) {
Expand Down
2 changes: 1 addition & 1 deletion grey/services/javm-guest-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
format!("{out_dir}/guest_blob.rs"),
format!(
"const GUEST_TESTS_BLOB: &[u8] = include_bytes!(\"{}\");\n",
blob.display(),
build_javm::include_path(&blob),
),
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions grey/services/spec-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fn main() {
format!(
"const MINIMAL_BLOB: &[u8] = include_bytes!(\"{}\");\n\
const BOOTSTRAP_BLOB: &[u8] = include_bytes!(\"{}\");\n",
minimal.display(),
bootstrap.display(),
build_javm::include_path(&minimal),
build_javm::include_path(&bootstrap),
),
)
.unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
Loading