Skip to content

Commit

Permalink
Merge branch 'main' into rusty-zcash_script
Browse files Browse the repository at this point in the history
  • Loading branch information
mpguerra authored Sep 19, 2024
2 parents 248634b + c5d8eb5 commit 42b4aa1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Rust files
id: changed-files-rust
uses: tj-actions/changed-files@v45.0.1
uses: tj-actions/changed-files@v45.0.2
with:
files: |
**/*.rs
Expand All @@ -56,7 +56,7 @@ jobs:
- name: Workflow files
id: changed-files-workflows
uses: tj-actions/changed-files@v45.0.1
uses: tj-actions/changed-files@v45.0.2
with:
files: |
.github/workflows/*.yml
Expand Down
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

0 comments on commit 42b4aa1

Please sign in to comment.