Skip to content

Commit

Permalink
Merge pull request #702 from subspace/fix-dsn-test
Browse files Browse the repository at this point in the history
Fix DSN test
  • Loading branch information
nazar-pc authored Jul 22, 2022
2 parents 1694a6f + a687622 commit 5847b0c
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 166 deletions.
7 changes: 7 additions & 0 deletions crates/subspace-core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,13 @@ impl U256 {
pub const MAX: Self = Self(private_u256::U256::MAX);
}

// Necessary for division derive
impl From<U256> for private_u256::U256 {
fn from(number: U256) -> Self {
number.0
}
}

impl WrappingAdd for U256 {
fn wrapping_add(&self, other: &Self) -> Self {
Self(self.0.overflowing_add(other.0).0)
Expand Down
10 changes: 5 additions & 5 deletions crates/subspace-farmer/src/bench_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct BenchRpcClient {

#[derive(Debug)]
pub struct Inner {
metadata: FarmerProtocolInfo,
farmer_protocol_info: FarmerProtocolInfo,
slot_info_receiver: Arc<Mutex<mpsc::Receiver<SlotInfo>>>,
acknowledge_archived_segment_sender: mpsc::Sender<u64>,
archived_segments_receiver: Arc<Mutex<mpsc::Receiver<ArchivedSegment>>>,
Expand All @@ -39,7 +39,7 @@ pub const BENCH_FARMER_PROTOCOL_INFO: FarmerProtocolInfo = FarmerProtocolInfo {
impl BenchRpcClient {
/// Create a new instance of [`BenchRpcClient`].
pub fn new(
metadata: FarmerProtocolInfo,
farmer_protocol_info: FarmerProtocolInfo,
slot_info_receiver: mpsc::Receiver<SlotInfo>,
mut archived_segments_receiver: mpsc::Receiver<ArchivedSegment>,
acknowledge_archived_segment_sender: mpsc::Sender<u64>,
Expand All @@ -59,7 +59,7 @@ impl BenchRpcClient {

Self {
inner: Arc::new(Inner {
metadata,
farmer_protocol_info,
slot_info_receiver: Arc::new(Mutex::new(slot_info_receiver)),
archived_segments_receiver: Arc::new(Mutex::new(inner_archived_segments_receiver)),
acknowledge_archived_segment_sender,
Expand All @@ -72,7 +72,7 @@ impl BenchRpcClient {
#[async_trait]
impl RpcClient for BenchRpcClient {
async fn farmer_protocol_info(&self) -> Result<FarmerProtocolInfo, Error> {
Ok(self.inner.metadata)
Ok(self.inner.farmer_protocol_info)
}

async fn subscribe_slot_info(
Expand Down Expand Up @@ -115,7 +115,7 @@ impl RpcClient for BenchRpcClient {
async fn subscribe_archived_segments(
&self,
) -> Result<Pin<Box<dyn Stream<Item = ArchivedSegment> + Send + 'static>>, Error> {
let (mut sender, receiver) = mpsc::channel(10);
let (mut sender, receiver) = mpsc::channel(0);
let archived_segments_receiver = self.inner.archived_segments_receiver.clone();
tokio::spawn(async move {
while let Some(archived_segment) = archived_segments_receiver.lock().await.next().await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ pub(crate) async fn bench(
object_mappings: object_mappings.clone(),
reward_address: PublicKey::default(),
bootstrap_nodes: vec![],
listen_on: vec![],
enable_dsn_archiving: false,
enable_dsn_sync: false,
enable_farming: true,
relay_server_node,
relay_server_node: Some(relay_server_node),
},
plot_size,
plot_factory,
Expand Down
10 changes: 7 additions & 3 deletions crates/subspace-farmer/src/bin/subspace-farmer/commands/farm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils::get_usable_plot_space;
use anyhow::{anyhow, Result};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
Expand Down Expand Up @@ -116,6 +117,7 @@ pub(crate) async fn farm_multi_disk(
farming_client,
reward_address,
bootstrap_nodes: bootstrap_nodes.clone(),
listen_on: vec![],
enable_dsn_archiving: matches!(archiving, ArchivingFrom::Dsn),
enable_dsn_sync: dsn_sync,
enable_farming: !disable_farming,
Expand All @@ -128,7 +130,7 @@ pub(crate) async fn farm_multi_disk(
options.max_plot_size,
)
},
relay_server_node: relay_server_node.clone(),
relay_server_node: Some(relay_server_node.clone()),
})
.await?;

Expand Down Expand Up @@ -289,6 +291,7 @@ pub(crate) async fn farm_legacy(

trace!(node_id = %relay_server_node.id(), "Relay Node started");

let usable_space = get_usable_plot_space(plot_size.as_u64());
let multi_plots_farm = LegacyMultiPlotsFarm::new(
MultiFarmingOptions {
base_directory,
Expand All @@ -298,12 +301,13 @@ pub(crate) async fn farm_legacy(
object_mappings: object_mappings.clone(),
reward_address,
bootstrap_nodes,
listen_on: vec![],
enable_dsn_archiving: matches!(archiving, ArchivingFrom::Dsn),
enable_dsn_sync: dsn_sync,
enable_farming: !disable_farming,
relay_server_node,
relay_server_node: Some(relay_server_node.clone()),
},
plot_size.as_u64(),
usable_space,
move |options: PlotFactoryOptions<'_>| {
Plot::open_or_create(
options.single_plot_farm_id,
Expand Down
6 changes: 6 additions & 0 deletions crates/subspace-farmer/src/bin/subspace-farmer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ pub(crate) fn raise_fd_limit() {
}
}
}

pub(crate) fn get_usable_plot_space(allocated_space: u64) -> u64 {
// TODO: Should account for database overhead of various additional databases.
// For now assume 92% will go for plot itself
allocated_space * 92 / 100
}
2 changes: 1 addition & 1 deletion crates/subspace-farmer/src/dsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
let sync_sector_size = if total_pieces < max_plot_size / PIECE_SIZE as u64 {
PieceIndexHashNumber::MAX
} else {
PieceIndexHashNumber::MAX / total_pieces * max_plot_size / PIECE_SIZE as u64
PieceIndexHashNumber::MAX / total_pieces * (max_plot_size / PIECE_SIZE as u64)
};
let from = public_key.wrapping_sub(&(sync_sector_size / 2));

Expand Down
Loading

0 comments on commit 5847b0c

Please sign in to comment.