Skip to content

Commit

Permalink
fix cyclic reference
Browse files Browse the repository at this point in the history
  • Loading branch information
aspect committed Jul 1, 2023
1 parent 77c9458 commit 8158afc
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 28 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ members = [
"rpc/grpc/client",
"rpc/grpc/server",
"rpc/core",
"rpc/wrpc/core",
"rpc/wrpc/server",
"rpc/wrpc/client",
"rpc/wrpc/proxy",
Expand Down Expand Up @@ -103,6 +104,7 @@ kaspa-wallet-cli = { version = "0.1.6", path = "wallet/cli" }
kaspa-wallet-cli-wasm = { version = "0.1.6", path = "wallet/wasm" }
kaspa-wallet-core = { version = "0.1.6", path = "wallet/core" }
kaspa-wasm = { version = "0.1.6", path = "wasm" }
kaspa-wrpc-core = { version = "0.1.6", path = "rpc/wrpc/core" }
kaspa-wrpc-client = { version = "0.1.6", path = "rpc/wrpc/client" }
kaspa-wrpc-proxy = { version = "0.1.6", path = "rpc/wrpc/proxy" }
kaspa-wrpc-server = { version = "0.1.6", path = "rpc/wrpc/server" }
Expand Down
16 changes: 9 additions & 7 deletions kaspad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ do you confirm? (answer y/n or pass --yes to the Kaspad command line to confirm
let (notification_send, notification_recv) = unbounded();
let notification_root = Arc::new(ConsensusNotificationRoot::new(notification_send));
let processing_counters = Arc::new(ProcessingCounters::default());
let wrpc_server_counters = Arc::new(WrpcServerCounters::default());
let wrpc_borsh_counters = Arc::new(WrpcServerCounters::default());
let wrpc_json_counters = Arc::new(WrpcServerCounters::default());

// Use `num_cpus` background threads for the consensus database as recommended by rocksdb
let consensus_db_parallelism = num_cpus::get();
Expand Down Expand Up @@ -279,7 +280,8 @@ do you confirm? (answer y/n or pass --yes to the Kaspad command line to confirm
config,
core.clone(),
processing_counters,
wrpc_server_counters,
wrpc_borsh_counters.clone(),
wrpc_json_counters.clone(),
));
let grpc_service = Arc::new(GrpcService::new(grpc_server_addr, rpc_core_service.clone(), args.rpc_max_clients));

Expand All @@ -298,15 +300,15 @@ do you confirm? (answer y/n or pass --yes to the Kaspad command line to confirm

let wrpc_service_tasks: usize = 2; // num_cpus::get() / 2;
// Register wRPC servers based on command line arguments
[(args.rpclisten_borsh, WrpcEncoding::Borsh), (args.rpclisten_json, WrpcEncoding::SerdeJson)]
.iter()
.filter_map(|(listen_address, encoding)| {
[(args.rpclisten_borsh, WrpcEncoding::Borsh, wrpc_borsh_counters), (args.rpclisten_json, WrpcEncoding::SerdeJson, wrpc_json_counters)]
.into_iter()
.filter_map(|(listen_address, encoding, wrpc_server_counters)| {
listen_address.as_ref().map(|listen_address| {
Arc::new(WrpcService::new(
wrpc_service_tasks,
Some(rpc_core_service.clone()),
encoding,
wrpc_server_counters.clone(),
&encoding,
wrpc_server_counters,
WrpcServerOptions {
listen_address: listen_address.to_string(), // TODO: use a normalized ContextualNetAddress instead of a String
verbose: args.wrpc_verbose,
Expand Down
18 changes: 13 additions & 5 deletions rpc/core/src/model/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,19 @@ pub struct GetMetricsRequest {
#[derive(Default, Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
#[serde(rename_all = "camelCase")]
pub struct ProcessMetrics {
pub uptime: u64,
pub memory_used: u64,
pub storage_used: u64,
pub grpc_connections: u32,
pub wrpc_connections: u32,
// pub uptime: u64,
// pub memory_used: u64,
// pub storage_used: u64,
// pub grpc_connections: u32,
// pub wrpc_connections: u32,

pub borsh_live_connections : u64,
pub borsh_connection_attempts : u64,
pub borsh_handshake_failures : u64,
pub json_live_connections : u64,
pub json_connection_attempts : u64,
pub json_handshake_failures : u64,

}

#[derive(Default, Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, BorshSchema)]
Expand Down
2 changes: 1 addition & 1 deletion rpc/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kaspa-p2p-lib.workspace = true
kaspa-p2p-flows.workspace = true
kaspa-math.workspace = true
kaspa-utxoindex.workspace = true
kaspa-wrpc-server.workspace = true
kaspa-wrpc-core.workspace = true

log.workspace = true
async-trait.workspace = true
Expand Down
20 changes: 15 additions & 5 deletions rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use kaspa_txscript::{extract_script_pub_key_address, pay_to_address_script};
use kaspa_utils::{channel::Channel, triggers::SingleTrigger};
use kaspa_utxoindex::api::UtxoIndexProxy;
use std::{iter::once, sync::{Arc, atomic::Ordering}, vec};
use kaspa_wrpc_server::service::ServerCounters as WrpcServerCounters;
use kaspa_wrpc_core::ServerCounters as WrpcServerCounters;

/// A service implementing the Rpc API at kaspa_rpc_core level.
///
Expand Down Expand Up @@ -80,7 +80,8 @@ pub struct RpcCoreService {
protocol_converter: Arc<ProtocolConverter>,
core: Arc<Core>,
processing_counters: Arc<ProcessingCounters>,
wrpc_server_counters : Arc<WrpcServerCounters>,
wrpc_borsh_counters : Arc<WrpcServerCounters>,
wrpc_json_counters : Arc<WrpcServerCounters>,
shutdown: SingleTrigger,
}

Expand All @@ -97,7 +98,8 @@ impl RpcCoreService {
config: Arc<Config>,
core: Arc<Core>,
processing_counters : Arc<ProcessingCounters>,
wrpc_server_counters : Arc<WrpcServerCounters>,
wrpc_borsh_counters : Arc<WrpcServerCounters>,
wrpc_json_counters : Arc<WrpcServerCounters>,
) -> Self {
// Prepare consensus-notify objects
let consensus_notify_channel = Channel::<ConsensusNotification>::default();
Expand Down Expand Up @@ -155,7 +157,8 @@ impl RpcCoreService {
protocol_converter,
core,
processing_counters,
wrpc_server_counters,
wrpc_borsh_counters,
wrpc_json_counters,
shutdown: SingleTrigger::default(),
}
}
Expand Down Expand Up @@ -621,7 +624,14 @@ impl RpcApi for RpcCoreService {
async fn get_metrics_call(&self, req: GetMetricsRequest) -> RpcResult<GetMetricsResponse> {

let process_metrics = if req.process_metrics {
Some(ProcessMetrics::default())
Some(ProcessMetrics {
borsh_live_connections: self.wrpc_borsh_counters.live_connections.load(Ordering::Relaxed),
borsh_connection_attempts: self.wrpc_borsh_counters.connection_attempts.load(Ordering::Relaxed),
borsh_handshake_failures: self.wrpc_borsh_counters.handshake_failures.load(Ordering::Relaxed),
json_live_connections: self.wrpc_json_counters.live_connections.load(Ordering::Relaxed),
json_connection_attempts: self.wrpc_json_counters.connection_attempts.load(Ordering::Relaxed),
json_handshake_failures: self.wrpc_json_counters.handshake_failures.load(Ordering::Relaxed),
})
} else { None };

let consensus_metrics = if req.consensus_metrics {
Expand Down
34 changes: 34 additions & 0 deletions rpc/wrpc/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "kaspa-wrpc-core"
description = "Kaspa wRPC core"
version.workspace = true
edition.workspace = true
authors.workspace = true
include.workspace = true
license.workspace = true

[lib]
crate-type = ["cdylib", "lib"]

[dependencies]
# async-std.workspace = true
# async-trait.workspace = true
# borsh.workspace = true
# futures.workspace = true
# js-sys.workspace = true
# kaspa-addresses.workspace = true
# kaspa-notify.workspace = true
# kaspa-rpc-core.workspace = true
# kaspa-rpc-macros.workspace = true
# paste.workspace = true
# regex.workspace = true
# serde_json.workspace = true
# serde-wasm-bindgen.workspace = true
# serde.workspace = true
# thiserror.workspace = true
# wasm-bindgen-futures.workspace = true
# wasm-bindgen.workspace = true
# workflow-core.workspace = true
# workflow-log.workspace = true
# workflow-rpc.workspace = true
# workflow-wasm.workspace = true
8 changes: 8 additions & 0 deletions rpc/wrpc/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::sync::atomic::AtomicU64;

#[derive(Debug, Default)]
pub struct ServerCounters {
pub live_connections : AtomicU64,
pub connection_attempts : AtomicU64,
pub handshake_failures : AtomicU64,
}
2 changes: 1 addition & 1 deletion rpc/wrpc/proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ workflow-log.workspace = true
async-trait.workspace = true
kaspa-rpc-macros.workspace = true
num_cpus.workspace = true

kaspa-wrpc-core.workspace = true

[package.metadata.emanate.build]
folder = "setup"
3 changes: 2 additions & 1 deletion rpc/wrpc/proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use kaspa_wrpc_server::{
connection::Connection,
router::Router,
server::Server,
service::{KaspaRpcHandler, Options, ServerCounters as WrpcServerCounters},
service::{KaspaRpcHandler, Options},
};
use kaspa_wrpc_core::ServerCounters as WrpcServerCounters;
use result::Result;
use std::sync::Arc;
use workflow_log::*;
Expand Down
1 change: 1 addition & 0 deletions rpc/wrpc/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kaspa-rpc-service.workspace = true
kaspa-rpc-macros.workspace = true
kaspa-grpc-client.workspace = true
kaspa-utils.workspace = true
kaspa-wrpc-core.workspace = true

log.workspace = true
paste.workspace = true
Expand Down
10 changes: 2 additions & 8 deletions rpc/wrpc/server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use std::sync::Arc;
use tokio::sync::oneshot::{channel as oneshot_channel, Sender as OneshotSender};
use workflow_rpc::server::prelude::*;
pub use workflow_rpc::server::Encoding as WrpcEncoding;
use std::sync::atomic::{AtomicU64,Ordering};
pub use kaspa_wrpc_core::ServerCounters;
use std::sync::atomic::Ordering;

/// Options for configuring the wRPC server
pub struct Options {
Expand All @@ -27,13 +28,6 @@ impl Default for Options {
}
}

#[derive(Debug, Default)]
pub struct ServerCounters {
pub live_connections : AtomicU64,
pub connection_attempts : AtomicU64,
pub handshake_failures : AtomicU64,
}


/// ### KaspaRpcHandler
///
Expand Down

0 comments on commit 8158afc

Please sign in to comment.