Skip to content

Commit

Permalink
Simplify L1 lookups for DSN farmers. (#1864)
Browse files Browse the repository at this point in the history
Simplify L1 lookups:
- remove cuckoo filter from peer-info protocol.
- remove cuckoo filter form farmer and use connected peers instead
  • Loading branch information
shamil-gadelshin authored Aug 23, 2023
1 parent f782f72 commit 817deb6
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 333 deletions.
24 changes: 0 additions & 24 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion crates/subspace-farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ blake2 = "0.10.6"
blake3 = { version = "1.4.1", default-features = false }
bytesize = "1.2.0"
clap = { version = "4.2.1", features = ["color", "derive"] }
cuckoofilter = { version = "0.5.0", features = ["serde_support"] }
derive_more = "0.99.17"
event-listener-primitives = "2.0.1"
fdlimit = "0.2"
Expand Down
21 changes: 2 additions & 19 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ use std::fs;
use std::num::NonZeroUsize;
use std::sync::Arc;
use subspace_core_primitives::crypto::kzg::{embedded_kzg_settings, Kzg};
use subspace_core_primitives::{Piece, Record, SectorIndex};
use subspace_core_primitives::{Record, SectorIndex};
use subspace_erasure_coding::ErasureCoding;
use subspace_farmer::piece_cache::PieceCache;
use subspace_farmer::single_disk_farm::{
SingleDiskFarm, SingleDiskFarmError, SingleDiskFarmOptions,
};
use subspace_farmer::utils::archival_storage_info::ArchivalStorageInfo;
use subspace_farmer::utils::archival_storage_pieces::ArchivalStoragePieces;
use subspace_farmer::utils::farmer_piece_getter::FarmerPieceGetter;
use subspace_farmer::utils::piece_validator::SegmentCommitmentPieceValidator;
use subspace_farmer::utils::readers_and_pieces::ReadersAndPieces;
Expand Down Expand Up @@ -97,15 +95,6 @@ where
.await
.map_err(|error| anyhow::anyhow!(error))?;

let cuckoo_filter_capacity = disk_farms
.iter()
.map(|df| df.allocated_plotting_space as usize)
.sum::<usize>()
/ Piece::SIZE
+ 1usize;
let archival_storage_pieces = ArchivalStoragePieces::new(cuckoo_filter_capacity);
let archival_storage_info = ArchivalStorageInfo::default();

let first_farm_directory = disk_farms
.first()
.expect("Disk farm collection is not be empty as checked above; qed")
Expand All @@ -130,8 +119,6 @@ where
dsn,
Arc::downgrade(&readers_and_pieces),
node_client.clone(),
archival_storage_pieces.clone(),
archival_storage_info.clone(),
piece_cache.clone(),
)?
};
Expand Down Expand Up @@ -159,7 +146,6 @@ where
piece_provider,
piece_cache.clone(),
node_client.clone(),
archival_storage_info,
Arc::clone(&readers_and_pieces),
));

Expand Down Expand Up @@ -258,10 +244,7 @@ where
// Collect already plotted pieces
{
let mut readers_and_pieces = readers_and_pieces.lock();
let readers_and_pieces = readers_and_pieces.insert(ReadersAndPieces::new(
piece_readers,
archival_storage_pieces,
));
let readers_and_pieces = readers_and_pieces.insert(ReadersAndPieces::new(piece_readers));

single_disk_farms.iter().enumerate().try_for_each(
|(disk_farm_index, single_disk_farm)| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::collections::HashSet;
use std::path::PathBuf;
use std::sync::{Arc, Weak};
use subspace_farmer::piece_cache::PieceCache;
use subspace_farmer::utils::archival_storage_info::ArchivalStorageInfo;
use subspace_farmer::utils::archival_storage_pieces::ArchivalStoragePieces;
use subspace_farmer::utils::readers_and_pieces::ReadersAndPieces;
use subspace_farmer::{NodeClient, NodeRpcClient};
use subspace_networking::libp2p::identity::Keypair;
Expand Down Expand Up @@ -45,8 +43,6 @@ pub(super) fn configure_dsn(
}: DsnArgs,
weak_readers_and_pieces: Weak<Mutex<Option<ReadersAndPieces>>>,
node_client: NodeRpcClient,
archival_storage_pieces: ArchivalStoragePieces,
archival_storage_info: ArchivalStorageInfo,
piece_cache: PieceCache,
) -> Result<(Node, NodeRunner<PieceCache>), anyhow::Error> {
let networking_parameters_registry = NetworkingParametersManager::new(
Expand All @@ -62,9 +58,7 @@ pub(super) fn configure_dsn(
protocol_prefix,
keypair,
piece_cache.clone(),
Some(PeerInfoProvider::new_farmer(Box::new(
archival_storage_pieces,
))),
Some(PeerInfoProvider::new_farmer()),
);
let config = Config {
reserved_peers,
Expand Down Expand Up @@ -206,33 +200,6 @@ pub(super) fn configure_dsn(
}))
.detach();

node.on_peer_info(Arc::new({
let archival_storage_info = archival_storage_info.clone();

move |new_peer_info| {
let peer_id = new_peer_info.peer_id;
let peer_info = &new_peer_info.peer_info;

if let PeerInfo::Farmer { cuckoo_filter } = peer_info {
archival_storage_info.update_cuckoo_filter(peer_id, cuckoo_filter.clone());

debug!(%peer_id, ?peer_info, "Peer info cached",);
}
}
}))
.detach();

node.on_disconnected_peer(Arc::new({
let archival_storage_info = archival_storage_info.clone();

move |peer_id| {
if archival_storage_info.remove_peer_filter(peer_id) {
debug!(%peer_id, "Peer filter removed.",);
}
}
}))
.detach();

// Consider returning HandlerId instead of each `detach()` calls for other usages.
(node, node_runner)
})
Expand Down
2 changes: 0 additions & 2 deletions crates/subspace-farmer/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub mod archival_storage_info;
pub mod archival_storage_pieces;
pub mod farmer_piece_getter;
pub mod piece_validator;
pub mod readers_and_pieces;
Expand Down
51 changes: 0 additions & 51 deletions crates/subspace-farmer/src/utils/archival_storage_info.rs

This file was deleted.

87 changes: 0 additions & 87 deletions crates/subspace-farmer/src/utils/archival_storage_pieces.rs

This file was deleted.

Loading

0 comments on commit 817deb6

Please sign in to comment.