Skip to content

Commit

Permalink
Merge pull request #2278 from subspace/small-tweaks
Browse files Browse the repository at this point in the history
Various small tweaks and conveniences
  • Loading branch information
nazar-pc authored Nov 30, 2023
2 parents 37c3613 + 2310558 commit 6bda2af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,12 @@ where
.await
.map_err(|error| anyhow::anyhow!(error))?;

let first_farm_directory = disk_farms
let first_farm_directory = &disk_farms
.first()
.expect("Disk farm collection is not be empty as checked above; qed")
.directory
.clone();
.directory;

let identity = Identity::open_or_create(&first_farm_directory)
let identity = Identity::open_or_create(first_farm_directory)
.map_err(|error| anyhow!("Failed to open or create identity: {error}"))?;
let keypair = derive_libp2p_keypair(identity.secret_key());
let peer_id = keypair.public().to_peer_id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::commands::farm::DsnArgs;
use parking_lot::Mutex;
use prometheus_client::registry::Registry;
use std::collections::HashSet;
use std::path::PathBuf;
use std::path::Path;
use std::sync::{Arc, Weak};
use subspace_farmer::piece_cache::PieceCache;
use subspace_farmer::utils::readers_and_pieces::ReadersAndPieces;
Expand Down Expand Up @@ -32,7 +32,7 @@ const TARGET_CONNECTIONS: u32 = 15;
#[allow(clippy::type_complexity, clippy::too_many_arguments)]
pub(super) fn configure_dsn(
protocol_prefix: String,
base_path: PathBuf,
base_path: &Path,
keypair: Keypair,
DsnArgs {
listen_on,
Expand Down
3 changes: 2 additions & 1 deletion crates/subspace-farmer/src/node_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub(crate) mod node_rpc_client;

use async_trait::async_trait;
use futures::Stream;
use std::fmt;
use std::pin::Pin;
use subspace_core_primitives::{Piece, PieceIndex, SegmentHeader, SegmentIndex};
use subspace_rpc_primitives::{
Expand All @@ -14,7 +15,7 @@ pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

/// Abstraction of the Node Client
#[async_trait]
pub trait NodeClient: Clone + Send + Sync + 'static {
pub trait NodeClient: Clone + fmt::Debug + Send + Sync + 'static {
/// Get farmer app info
async fn farmer_app_info(&self) -> Result<FarmerAppInfo, Error>;

Expand Down
8 changes: 6 additions & 2 deletions crates/subspace-farmer/src/piece_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use futures::{select, FutureExt, StreamExt};
use parking_lot::RwLock;
use rayon::prelude::*;
use std::collections::HashMap;
use std::mem;
use std::num::NonZeroU16;
use std::sync::Arc;
use std::{fmt, mem};
use subspace_core_primitives::{Piece, PieceIndex, SegmentIndex};
use subspace_farmer_components::plotting::{PieceGetter, PieceGetterRetryPolicy};
use subspace_networking::libp2p::kad::{ProviderRecord, RecordKey};
Expand Down Expand Up @@ -61,8 +61,12 @@ struct CacheWorkerState {
}

/// Cache worker used to drive the cache
#[derive(Debug)]
#[must_use = "Cache will not work unless its worker is running"]
pub struct CacheWorker<NC> {
pub struct CacheWorker<NC>
where
NC: fmt::Debug,
{
peer_id: PeerId,
node_client: NC,
caches: Arc<RwLock<Vec<DiskPieceCacheState>>>,
Expand Down
10 changes: 10 additions & 0 deletions crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::fmt::Debug;
use std::net::IpAddr;
use std::num::NonZeroUsize;
Expand Down Expand Up @@ -150,6 +151,15 @@ where
disable_bootstrap_on_start: bool,
}

impl<LocalRecordProvider> fmt::Debug for NodeRunner<LocalRecordProvider>
where
LocalRecordProvider: constructor::LocalRecordProvider + Send + Sync + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("NodeRunner").finish_non_exhaustive()
}
}

// Helper struct for NodeRunner configuration (clippy requirement).
pub(crate) struct NodeRunnerConfig<LocalRecordProvider>
where
Expand Down

0 comments on commit 6bda2af

Please sign in to comment.