Skip to content
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

merge queue: embarking main (3f94303) and #8863 together #8873

Closed
wants to merge 5 commits into from
Closed
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
19 changes: 19 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"

[[package]]
name = "chacha20"
version = "0.9.1"
Expand Down Expand Up @@ -2650,6 +2656,18 @@ dependencies = [
"winapi",
]

[[package]]
name = "nix"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
dependencies = [
"bitflags 2.6.0",
"cfg-if 1.0.0",
"cfg_aliases",
"libc",
]

[[package]]
name = "nom"
version = "7.1.3"
Expand Down Expand Up @@ -6154,6 +6172,7 @@ dependencies = [
"jsonrpc-core",
"jsonrpc-derive",
"jsonrpc-http-server",
"nix",
"proptest",
"prost",
"rand 0.8.5",
Expand Down
2 changes: 2 additions & 0 deletions zebra-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ tracing = "0.1.39"
hex = { version = "0.4.3", features = ["serde"] }
serde = { version = "1.0.204", features = ["serde_derive"] }

# For the `stop` RPC method.
nix = { version = "0.29.0", features = ["signal"] }

zcash_primitives = { workspace = true, features = ["transparent-inputs"] }

Expand Down
26 changes: 20 additions & 6 deletions zebra-rpc/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,18 @@ pub trait Rpc {
address_strings: AddressStrings,
) -> BoxFuture<Result<Vec<GetAddressUtxos>>>;

#[rpc(name = "stop")]
/// Stop the running zebrad process.
///
/// # Notes
///
/// Only works if the network of the running zebrad process is `Regtest`.
/// - Works for non windows targets only.
/// - Works only if the network of the running zebrad process is `Regtest`.
///
/// zcashd reference: [`stop`](https://zcash.github.io/rpc/stop.html)
/// method: post
/// tags: control
fn stop(&self) -> Result<()>;
#[rpc(name = "stop")]
fn stop(&self) -> Result<String>;
}

/// RPC method implementations.
Expand Down Expand Up @@ -1357,17 +1358,30 @@ where
.boxed()
}

fn stop(&self) -> Result<()> {
fn stop(&self) -> Result<String> {
#[cfg(not(target_os = "windows"))]
if self.network.is_regtest() {
// TODO: Use graceful termination in `stop` RPC (#8850)
std::process::exit(0);
match nix::sys::signal::raise(nix::sys::signal::SIGINT) {
Ok(_) => Ok("Zebra server stopping".to_string()),
Err(error) => Err(Error {
code: ErrorCode::InternalError,
message: format!("Failed to shut down: {}", error),
data: None,
}),
}
} else {
Err(Error {
code: ErrorCode::MethodNotFound,
message: "stop is only available on regtest networks".to_string(),
data: None,
})
}
#[cfg(target_os = "windows")]
Err(Error {
code: ErrorCode::MethodNotFound,
message: "stop is not available in windows targets".to_string(),
data: None,
})
}
}

Expand Down
Loading