Skip to content

Commit

Permalink
Remove obsolete addresses from subspace-bootstrap-node's DHT routing …
Browse files Browse the repository at this point in the history
…table. (#2256)

* networking: Introduce minor refactoring and exporting types.

* networking: Add networking manager to bootstrap-node.

* networking: Rename NetworkingParametersRegistry to KnownPeersRegistry.

- rename NetworkingParametersManager from subspace-bootstrap-node.

* networking: Make KnownPeersRegistry mandatoryl

* networking: Move KnownPeersRegistry into a separate file.

* Refactor known peers registry.

* networking: Refactor bootstrap-node’s known peers registry.

* networking: Refactor KnownPeersManager.
  • Loading branch information
shamil-gadelshin authored Nov 22, 2023
1 parent 4b595d3 commit b744fba
Show file tree
Hide file tree
Showing 12 changed files with 300 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ use std::path::PathBuf;
use std::sync::{Arc, Weak};
use subspace_farmer::piece_cache::PieceCache;
use subspace_farmer::utils::readers_and_pieces::ReadersAndPieces;
use subspace_farmer::{NodeClient, NodeRpcClient};
use subspace_farmer::{NodeClient, NodeRpcClient, KNOWN_PEERS_CACHE_SIZE};
use subspace_networking::libp2p::identity::Keypair;
use subspace_networking::libp2p::kad::RecordKey;
use subspace_networking::libp2p::metrics::Metrics;
use subspace_networking::libp2p::multiaddr::Protocol;
use subspace_networking::utils::multihash::ToMultihash;
use subspace_networking::utils::strip_peer_id;
use subspace_networking::{
construct, Config, KademliaMode, NetworkingParametersManager, Node, NodeRunner, PeerInfo,
PeerInfoProvider, PieceByIndexRequest, PieceByIndexRequestHandler, PieceByIndexResponse,
SegmentHeaderBySegmentIndexesRequestHandler, SegmentHeaderRequest, SegmentHeaderResponse,
construct, Config, KademliaMode, KnownPeersManager, KnownPeersManagerConfig, Node, NodeRunner,
PeerInfo, PeerInfoProvider, PieceByIndexRequest, PieceByIndexRequestHandler,
PieceByIndexResponse, SegmentHeaderBySegmentIndexesRequestHandler, SegmentHeaderRequest,
SegmentHeaderResponse,
};
use subspace_rpc_primitives::MAX_SEGMENT_HEADERS_PER_REQUEST;
use tracing::{debug, error, info, Instrument};
Expand Down Expand Up @@ -50,13 +51,15 @@ pub(super) fn configure_dsn(
piece_cache: PieceCache,
initialize_metrics: bool,
) -> Result<(Node, NodeRunner<PieceCache>, Registry), anyhow::Error> {
let networking_parameters_registry = NetworkingParametersManager::new(
&base_path.join("known_addresses.bin"),
strip_peer_id(bootstrap_nodes.clone())
let networking_parameters_registry = KnownPeersManager::new(KnownPeersManagerConfig {
path: Some(base_path.join("known_addresses.bin").into_boxed_path()),
ignore_peer_list: strip_peer_id(bootstrap_nodes.clone())
.into_iter()
.map(|(peer_id, _)| peer_id)
.collect::<HashSet<_>>(),
)
cache_size: KNOWN_PEERS_CACHE_SIZE,
..Default::default()
})
.map(Box::new)?;

// Metrics
Expand All @@ -73,7 +76,7 @@ pub(super) fn configure_dsn(
reserved_peers,
listen_on,
allow_non_global_addresses_in_dht: enable_private_ips,
networking_parameters_registry: Some(networking_parameters_registry),
networking_parameters_registry,
request_response_protocols: vec![
PieceByIndexRequestHandler::create(move |_, &PieceByIndexRequest { piece_index }| {
debug!(?piece_index, "Piece request received. Trying cache...");
Expand Down
4 changes: 4 additions & 0 deletions crates/subspace-farmer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub mod reward_signing;
pub mod single_disk_farm;
pub mod utils;

/// Size of the LRU cache for peers.
pub const KNOWN_PEERS_CACHE_SIZE: NonZeroUsize = NonZeroUsize::new(100).expect("Not zero; qed");

pub use identity::Identity;
pub use jsonrpsee;
pub use node_client::node_rpc_client::NodeRpcClient;
pub use node_client::{Error as RpcClientError, NodeClient};
use std::num::NonZeroUsize;
5 changes: 3 additions & 2 deletions crates/subspace-farmer/src/single_disk_farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::single_disk_farm::plotting::{
plotting, plotting_scheduler, PlottingOptions, PlottingSchedulerOptions,
};
use crate::utils::{tokio_rayon_spawn_handler, AsyncJoinOnDrop};
use crate::KNOWN_PEERS_CACHE_SIZE;
use async_lock::RwLock;
use derive_more::{Display, From};
use event_listener_primitives::{Bag, HandlerId};
Expand Down Expand Up @@ -51,7 +52,7 @@ use subspace_farmer_components::file_ext::{FileExt, OpenOptionsExt};
use subspace_farmer_components::plotting::{PieceGetter, PlottedSector};
use subspace_farmer_components::sector::{sector_size, SectorMetadata, SectorMetadataChecksummed};
use subspace_farmer_components::FarmerProtocolInfo;
use subspace_networking::NetworkingParametersManager;
use subspace_networking::KnownPeersManager;
use subspace_proof_of_space::Table;
use subspace_rpc_primitives::{FarmerAppInfo, SolutionResponse};
use thiserror::Error;
Expand Down Expand Up @@ -690,7 +691,7 @@ impl SingleDiskFarm {
let fixed_space_usage = RESERVED_PLOT_METADATA
+ RESERVED_FARM_INFO
+ Identity::file_size() as u64
+ NetworkingParametersManager::file_size() as u64;
+ KnownPeersManager::file_size(KNOWN_PEERS_CACHE_SIZE) as u64;
// Calculate how many sectors can fit
let target_sector_count = {
let potentially_plottable_space = allocated_space.saturating_sub(fixed_space_usage)
Expand Down
Loading

0 comments on commit b744fba

Please sign in to comment.