Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "freenet"
version = "0.1.52"
version = "0.1.53"
edition = "2021"
rust-version = "1.80"
publish = true
Expand Down
5 changes: 4 additions & 1 deletion crates/core/src/node/network_bridge/p2p_protoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions crates/core/src/ring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions crates/core/src/ring/seeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion crates/core/src/transport/connection_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(())
});
Expand Down
4 changes: 2 additions & 2 deletions crates/fdev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fdev"
version = "0.3.30"
version = "0.3.31"
edition = "2021"
rust-version = "1.80"
publish = true
Expand Down Expand Up @@ -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]
Expand Down