Skip to content

Commit

Permalink
Refactor farmer piece provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
shamil-gadelshin committed Dec 21, 2023
1 parent 0a17002 commit 015674a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
6 changes: 2 additions & 4 deletions crates/subspace-farmer/src/utils/farmer_piece_getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use subspace_networking::utils::multihash::ToMultihash;
use subspace_networking::utils::piece_provider::{PieceProvider, PieceValidator, RetryPolicy};
use tracing::{debug, error, trace};

const MAX_RANDOM_WALK_ROUNDS: usize = 50;
const MAX_RANDOM_WALK_ROUNDS: usize = 35;

pub struct FarmerPieceGetter<PV, NC> {
piece_provider: PieceProvider<PV>,
Expand Down Expand Up @@ -67,7 +67,7 @@ where
trace!(%piece_index, "Getting piece from DSN L2 cache");
let maybe_piece = self
.piece_provider
.get_piece(piece_index, Self::convert_retry_policy(retry_policy))
.get_piece_from_dsn_cache(piece_index, Self::convert_retry_policy(retry_policy))
.await?;

if maybe_piece.is_some() {
Expand Down Expand Up @@ -120,8 +120,6 @@ where
trace!(%piece_index, "DSN L1 lookup succeeded");

return Ok(archival_storage_search_result);
} else {
debug!(%piece_index, "Cannot acquire piece from DSN L1");
}

debug!(
Expand Down
4 changes: 2 additions & 2 deletions crates/subspace-networking/examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async fn simple_benchmark(node: Node, max_pieces: usize, start_with: usize, retr
let piece_index = PieceIndex::from(i as u64);
let start = Instant::now();
let piece = piece_provider
.get_piece(piece_index, RetryPolicy::Limited(retries))
.get_piece_from_dsn_cache(piece_index, RetryPolicy::Limited(retries))
.await;
let end = Instant::now();
let duration = end.duration_since(start);
Expand Down Expand Up @@ -220,7 +220,7 @@ async fn parallel_benchmark(
.expect("Semaphore cannot be closed.");
let semaphore_acquired = Instant::now();
let maybe_piece = piece_provider
.get_piece(piece_index, RetryPolicy::Limited(retries))
.get_piece_from_dsn_cache(piece_index, RetryPolicy::Limited(retries))
.await;

let end = Instant::now();
Expand Down
5 changes: 3 additions & 2 deletions crates/subspace-networking/src/utils/piece_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ where
None
}

/// Returns piece by its index. Uses retry policy for error handling.
pub async fn get_piece(
/// Returns piece by its index from farmer's piece cache (L2).
/// Uses retry policy for error handling.
pub async fn get_piece_from_dsn_cache(
&self,
piece_index: PieceIndex,
retry_policy: RetryPolicy,
Expand Down
2 changes: 1 addition & 1 deletion crates/subspace-service/src/sync_from_dsn/import_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ where
}
};
let maybe_piece = match piece_provider
.get_piece(
.get_piece_from_dsn_cache(
piece_index,
RetryPolicy::Limited(PIECE_GETTER_RETRY_NUMBER.get()),
)
Expand Down

0 comments on commit 015674a

Please sign in to comment.