Skip to content

Commit

Permalink
make the server handle fields private
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Dec 10, 2024
1 parent d281cb4 commit 45c2f07
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/dojo/test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ anyhow.workspace = true
assert_fs.workspace = true
async-trait.workspace = true
camino.workspace = true
jsonrpsee = { workspace = true, features = [ "server" ] }
katana-core = { workspace = true }
katana-executor = { workspace = true, features = [ "blockifier" ] }
katana-node.workspace = true
katana-primitives = { workspace = true }
katana-rpc.workspace = true
scarb.workspace = true
scarb-ui.workspace = true
serde.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashSet;
use std::sync::Arc;

use jsonrpsee::core::Error;
use katana_core::backend::Backend;
use katana_core::constants::DEFAULT_SEQUENCER_ADDRESS;
use katana_executor::implementation::blockifier::BlockifierFactory;
Expand All @@ -11,6 +10,7 @@ pub use katana_node::config::*;
use katana_node::LaunchedNode;
use katana_primitives::chain::ChainId;
use katana_primitives::chain_spec::ChainSpec;
use katana_rpc::Error;
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::chain_id;
use starknet::core::types::{BlockId, BlockTag, Felt};
Expand Down Expand Up @@ -42,7 +42,8 @@ impl TestSequencer {
.await
.expect("Failed to launch node");

let url = Url::parse(&format!("http://{}", handle.rpc.addr)).expect("Failed to parse URL");
let url =
Url::parse(&format!("http://{}", handle.rpc.addr())).expect("Failed to parse URL");

let account = handle.node.backend.chain_spec.genesis.accounts().next().unwrap();
let account = TestAccount {
Expand Down Expand Up @@ -104,7 +105,7 @@ impl TestSequencer {
}

pub fn stop(self) -> Result<(), Error> {
self.handle.rpc.handle.stop()
self.handle.rpc.stop()
}

pub fn url(&self) -> Url {
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/node/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a> NodeStoppedFuture<'a> {
pub(crate) fn new(handle: &'a LaunchedNode) -> Self {
let fut = Box::pin(async {
handle.node.task_manager.wait_for_shutdown().await;
handle.rpc.handle.clone().stopped().await;
handle.rpc.clone().stopped().await;

Check warning on line 21 in crates/katana/node/src/exit.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/node/src/exit.rs#L21

Added line #L21 was not covered by tests
Ok(())
});
Self { fut }
Expand Down
2 changes: 1 addition & 1 deletion crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl LaunchedNode {
/// This will instruct the node to stop and wait until it has actually stop.
pub async fn stop(&self) -> Result<()> {
// TODO: wait for the rpc server to stop instead of just stopping it.
self.rpc.handle.stop()?;
self.rpc.stop()?;

Check warning on line 67 in crates/katana/node/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/katana/node/src/lib.rs#L67

Added line #L67 was not covered by tests
self.node.task_manager.shutdown().await;
Ok(())
}
Expand Down
15 changes: 12 additions & 3 deletions crates/katana/rpc/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ pub enum Error {
AlreadyStopped,
}

#[derive(Debug)]
/// The RPC server handle.
#[derive(Debug, Clone)]
pub struct RpcServerHandle {
pub addr: SocketAddr,
pub handle: ServerHandle,
/// The actual address that the server is binded to.
addr: SocketAddr,
/// The handle to the spawned [`jsonrpsee::server::Server`].
handle: ServerHandle,
}

impl RpcServerHandle {
/// Tell the server to stop without waiting for the server to stop.
pub fn stop(&self) -> Result<(), Error> {
self.handle.stop().map_err(|_| Error::AlreadyStopped)
}
Expand All @@ -48,6 +52,11 @@ impl RpcServerHandle {
pub async fn stopped(self) {
self.handle.stopped().await
}

/// Returns the socket address the server is listening on.
pub fn addr(&self) -> &SocketAddr {
&self.addr
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 45c2f07

Please sign in to comment.