diff --git a/Cargo.lock b/Cargo.lock index 702f946ec..a06a4ff81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1673,7 +1673,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fdev" -version = "0.3.30" +version = "0.3.31" dependencies = [ "anyhow", "axum", @@ -1803,7 +1803,7 @@ dependencies = [ [[package]] name = "freenet" -version = "0.1.52" +version = "0.1.53" dependencies = [ "aes-gcm", "ahash", diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index bbddf02d6..79953919b 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "freenet" -version = "0.1.52" +version = "0.1.53" edition = "2021" rust-version = "1.80" publish = true diff --git a/crates/core/src/node/network_bridge/p2p_protoc.rs b/crates/core/src/node/network_bridge/p2p_protoc.rs index c5e72b69b..6eb89bcec 100644 --- a/crates/core/src/node/network_bridge/p2p_protoc.rs +++ b/crates/core/src/node/network_bridge/p2p_protoc.rs @@ -1194,8 +1194,11 @@ impl P2pConnManager { // Collect system metrics if config.include_system_metrics { + // Use the actual seeding cache count, not the subscriber count. + // The seeding cache tracks contracts this node is actively caching, + // while subscribers tracks remote peers subscribed to updates. let seeding_contracts = - op_manager.ring.all_network_subscriptions().len() as u32; + op_manager.ring.seeding_contracts_count() as u32; response.system_metrics = Some(SystemMetrics { active_connections: connected_peer_ids.len() as u32, seeding_contracts, diff --git a/crates/core/src/ring/mod.rs b/crates/core/src/ring/mod.rs index bbaf5f953..d0e36d14d 100644 --- a/crates/core/src/ring/mod.rs +++ b/crates/core/src/ring/mod.rs @@ -380,6 +380,12 @@ impl Ring { self.seeding_manager.all_subscriptions() } + /// Get the number of contracts in the seeding cache. + /// This is the actual count of contracts this node is caching/seeding. + pub fn seeding_contracts_count(&self) -> usize { + self.seeding_manager.seeding_contracts_count() + } + pub async fn prune_connection(&self, peer: PeerId) { tracing::debug!(peer = %peer, "Removing connection"); self.live_tx_tracker.prune_transactions_from_peer(peer.addr); diff --git a/crates/core/src/ring/seeding.rs b/crates/core/src/ring/seeding.rs index bf392ec7c..8ed476031 100644 --- a/crates/core/src/ring/seeding.rs +++ b/crates/core/src/ring/seeding.rs @@ -268,6 +268,12 @@ impl SeedingManager { .map(|entry| (*entry.key(), entry.value().clone())) .collect() } + + /// Get the number of contracts in the seeding cache. + /// This is the actual count of contracts this node is caching/seeding. + pub fn seeding_contracts_count(&self) -> usize { + self.seeding_cache.read().len() + } } #[cfg(test)] @@ -768,4 +774,33 @@ mod tests { "sender (peer1) should NOT be in broadcast targets" ); } + + #[test] + fn test_seeding_contracts_count() { + use super::super::seeding_cache::AccessType; + + let seeding_manager = SeedingManager::new(); + + // Initially no contracts are seeded + assert_eq!(seeding_manager.seeding_contracts_count(), 0); + + // Add first contract + let key1 = make_contract_key(1); + seeding_manager.record_contract_access(key1, 1000, AccessType::Put); + assert_eq!(seeding_manager.seeding_contracts_count(), 1); + + // Add second contract + let key2 = make_contract_key(2); + seeding_manager.record_contract_access(key2, 1000, AccessType::Put); + assert_eq!(seeding_manager.seeding_contracts_count(), 2); + + // Add third contract + let key3 = make_contract_key(3); + seeding_manager.record_contract_access(key3, 1000, AccessType::Get); + assert_eq!(seeding_manager.seeding_contracts_count(), 3); + + // Re-accessing a contract doesn't increase count + seeding_manager.record_contract_access(key1, 1000, AccessType::Get); + assert_eq!(seeding_manager.seeding_contracts_count(), 3); + } } diff --git a/crates/core/src/transport/connection_handler.rs b/crates/core/src/transport/connection_handler.rs index 996d69e23..7c7b60fa0 100644 --- a/crates/core/src/transport/connection_handler.rs +++ b/crates/core/src/transport/connection_handler.rs @@ -2372,7 +2372,7 @@ pub mod mock_transport { let peer_a = tokio::spawn(async move { let peer_b_conn = peer_a.connect(peer_b_pub, peer_b_addr).await; let mut conn = tokio::time::timeout(Duration::from_secs(5), peer_b_conn).await??; - let msg = conn.recv().await?; + let msg = tokio::time::timeout(Duration::from_secs(10), conn.recv()).await??; assert!(msg.len() <= MAX_DATA_SIZE); Ok::<_, anyhow::Error>(()) }); diff --git a/crates/fdev/Cargo.toml b/crates/fdev/Cargo.toml index 19537cdca..9a142a079 100644 --- a/crates/fdev/Cargo.toml +++ b/crates/fdev/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fdev" -version = "0.3.30" +version = "0.3.31" edition = "2021" rust-version = "1.80" publish = true @@ -44,7 +44,7 @@ reqwest = { version = "0.12", features = ["json"] } http = "1.4" # internal -freenet = { path = "../core", version = "0.1.52" } +freenet = { path = "../core", version = "0.1.53" } freenet-stdlib = { workspace = true } [features]