Skip to content

Commit 82d51b2

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 97f9fc8 + 1e9d379 commit 82d51b2

File tree

2 files changed

+157
-20
lines changed

2 files changed

+157
-20
lines changed

rust/src/client_api/client_events.rs

Lines changed: 146 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,13 @@ pub enum ClientRequest<'a> {
259259
}
260260

261261
#[derive(Serialize, Deserialize, Debug, Clone)]
262-
pub enum NodeQuery {
263-
ConnectedPeers,
264-
SubscriptionInfo,
265-
}
262+
pub struct ConnectedPeers {}
266263

267-
// For backward compatibility
268264
#[derive(Serialize, Deserialize, Debug, Clone)]
269-
pub struct ConnectedPeers {}
265+
pub struct NodeDiagnostics {
266+
/// Optional contract key to filter diagnostics for specific contract
267+
pub contract_key: Option<ContractKey>,
268+
}
270269

271270
impl ClientRequest<'_> {
272271
pub fn into_owned(self) -> ClientRequest<'static> {
@@ -724,22 +723,154 @@ pub enum HostResponse<T = WrappedState> {
724723
type Peer = String;
725724

726725
#[derive(Serialize, Deserialize, Debug)]
726+
pub enum QueryResponse {
727+
ConnectedPeers { peers: Vec<(Peer, SocketAddr)> },
728+
NetworkDebug(NetworkDebugInfo),
729+
NodeDiagnostics(NodeDiagnosticsResponse),
730+
}
731+
732+
#[derive(Serialize, Deserialize, Debug, Clone)]
733+
pub struct NetworkDebugInfo {
734+
pub subscriptions: Vec<SubscriptionInfo>,
735+
pub connected_peers: Vec<(String, SocketAddr)>,
736+
}
737+
738+
#[derive(Serialize, Deserialize, Debug, Clone)]
739+
pub struct NodeDiagnosticsResponse {
740+
/// Node information
741+
pub node_info: Option<NodeInfo>,
742+
743+
/// Network connectivity information
744+
pub network_info: Option<NetworkInfo>,
745+
746+
/// Contract subscription information
747+
pub subscriptions: Vec<SubscriptionInfo>,
748+
749+
/// Contract states for specific contracts
750+
pub contract_states: std::collections::HashMap<ContractKey, ContractState>,
751+
752+
/// System metrics
753+
pub system_metrics: Option<SystemMetrics>,
754+
755+
/// Information about connected peers with detailed data
756+
pub connected_peers_detailed: Vec<ConnectedPeerInfo>,
757+
}
758+
759+
#[derive(Serialize, Deserialize, Debug, Clone)]
760+
pub struct NodeInfo {
761+
pub peer_id: String,
762+
pub is_gateway: bool,
763+
pub location: Option<String>,
764+
pub listening_address: Option<String>,
765+
pub uptime_seconds: u64,
766+
}
767+
768+
#[derive(Serialize, Deserialize, Debug, Clone)]
769+
pub struct NetworkInfo {
770+
pub connected_peers: Vec<(String, String)>, // (peer_id, address)
771+
pub active_connections: usize,
772+
}
773+
774+
#[derive(Serialize, Deserialize, Debug, Clone)]
775+
pub struct ContractState {
776+
/// Number of nodes subscribed to this contract
777+
pub subscribers: u32,
778+
/// Peer IDs of nodes that are subscribed to this contract
779+
pub subscriber_peer_ids: Vec<String>,
780+
}
781+
782+
#[derive(Serialize, Deserialize, Debug, Clone)]
783+
pub struct SystemMetrics {
784+
pub active_connections: u32,
785+
pub seeding_contracts: u32,
786+
}
787+
788+
#[derive(Serialize, Deserialize, Debug, Clone)]
727789
pub struct SubscriptionInfo {
728790
pub contract_key: ContractKey,
729791
pub client_id: usize,
730-
pub last_update: Option<std::time::SystemTime>,
731792
}
732793

733-
#[derive(Serialize, Deserialize, Debug)]
734-
pub struct NetworkDebugInfo {
735-
pub subscriptions: Vec<SubscriptionInfo>,
736-
pub connected_peers: Vec<(Peer, SocketAddr)>,
794+
/// Basic information about a connected peer
795+
#[derive(Serialize, Deserialize, Debug, Clone)]
796+
pub struct ConnectedPeerInfo {
797+
pub peer_id: String,
798+
pub address: String,
737799
}
738800

739-
#[derive(Serialize, Deserialize, Debug)]
740-
pub enum QueryResponse {
741-
ConnectedPeers { peers: Vec<(Peer, SocketAddr)> },
742-
NetworkDebug(NetworkDebugInfo),
801+
#[derive(Serialize, Deserialize, Debug, Clone)]
802+
pub enum NodeQuery {
803+
ConnectedPeers,
804+
SubscriptionInfo,
805+
NodeDiagnostics {
806+
/// Diagnostic configuration specifying what information to collect
807+
config: NodeDiagnosticsConfig,
808+
},
809+
}
810+
811+
#[derive(Serialize, Deserialize, Debug, Clone)]
812+
pub struct NodeDiagnosticsConfig {
813+
/// Include basic node information (ID, location, uptime, etc.)
814+
pub include_node_info: bool,
815+
816+
/// Include network connectivity information
817+
pub include_network_info: bool,
818+
819+
/// Include contract subscription information
820+
pub include_subscriptions: bool,
821+
822+
/// Include contract states for specific contracts (empty = all contracts)
823+
pub contract_keys: Vec<ContractKey>,
824+
825+
/// Include memory and performance metrics
826+
pub include_system_metrics: bool,
827+
828+
/// Include detailed information about connected peers (vs basic peer list)
829+
pub include_detailed_peer_info: bool,
830+
831+
/// Include peer IDs of subscribers in contract state information
832+
pub include_subscriber_peer_ids: bool,
833+
}
834+
835+
impl NodeDiagnosticsConfig {
836+
/// Create a comprehensive diagnostic config for debugging update propagation issues
837+
pub fn for_update_propagation_debugging(contract_key: ContractKey) -> Self {
838+
Self {
839+
include_node_info: true,
840+
include_network_info: true,
841+
include_subscriptions: true,
842+
contract_keys: vec![contract_key],
843+
include_system_metrics: true,
844+
include_detailed_peer_info: true,
845+
include_subscriber_peer_ids: true,
846+
}
847+
}
848+
849+
/// Create a lightweight diagnostic config for basic node status
850+
pub fn basic_status() -> Self {
851+
Self {
852+
include_node_info: true,
853+
include_network_info: true,
854+
include_subscriptions: false,
855+
contract_keys: vec![],
856+
include_system_metrics: false,
857+
include_detailed_peer_info: false,
858+
include_subscriber_peer_ids: false,
859+
}
860+
}
861+
862+
/// Create a full diagnostic config (all information)
863+
pub fn full() -> Self {
864+
Self {
865+
include_node_info: true,
866+
include_network_info: true,
867+
include_subscriptions: true,
868+
contract_keys: vec![], // empty = all contracts
869+
include_system_metrics: true,
870+
include_detailed_peer_info: true,
871+
include_subscriber_peer_ids: true,
872+
}
873+
}
743874
}
744875

745876
impl HostResponse {

rust/src/versioning.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ impl DelegateCode<'static> {
124124
mut contract_data: Cursor<Vec<u8>>,
125125
) -> Result<(Self, APIVersion), std::io::Error> {
126126
// Get contract version
127-
let version = contract_data
128-
.read_u64::<BigEndian>()
129-
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidData, "Failed to read version"))?;
127+
let version = contract_data.read_u64::<BigEndian>().map_err(|_| {
128+
std::io::Error::new(std::io::ErrorKind::InvalidData, "Failed to read version")
129+
})?;
130130
let version = APIVersion::from_u64(version).map_err(|e| {
131-
std::io::Error::new(std::io::ErrorKind::InvalidData, format!("Version error: {}", e))
131+
std::io::Error::new(
132+
std::io::ErrorKind::InvalidData,
133+
format!("Version error: {}", e),
134+
)
132135
})?;
133136

134137
if version == APIVersion::Version0_0_1 {
@@ -307,7 +310,10 @@ impl ContractCode<'static> {
307310
std::io::Error::new(std::io::ErrorKind::InvalidData, "Failed to read version")
308311
})?;
309312
let version = APIVersion::from_u64(version).map_err(|e| {
310-
std::io::Error::new(std::io::ErrorKind::InvalidData, format!("Version error: {}", e))
313+
std::io::Error::new(
314+
std::io::ErrorKind::InvalidData,
315+
format!("Version error: {}", e),
316+
)
311317
})?;
312318

313319
if version == APIVersion::Version0_0_1 {

0 commit comments

Comments
 (0)