Skip to content

Commit

Permalink
Merge pull request #181 from subspace/fix-farm-locking-on-windows
Browse files Browse the repository at this point in the history
Fix farm locking on Windows that leads to farm info file corruption by switching to upcoming Subspace release
  • Loading branch information
nazar-pc authored Apr 26, 2024
2 parents dd8ee0b + d3fe902 commit 1f0f0d6
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 92 deletions.
88 changes: 44 additions & 44 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ sc-informant = { git = "https://github.com/subspace/polkadot-sdk", rev = "44d742
sc-network = { git = "https://github.com/subspace/polkadot-sdk", rev = "44d742b90e7852aed1f08ab5299d5d88cfa1c6ed", default-features = false }
sc-service = { git = "https://github.com/subspace/polkadot-sdk", rev = "44d742b90e7852aed1f08ab5299d5d88cfa1c6ed", default-features = false }
sc-storage-monitor = { git = "https://github.com/subspace/polkadot-sdk", rev = "44d742b90e7852aed1f08ab5299d5d88cfa1c6ed", default-features = false }
sc-subspace-chain-specs = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
sc-subspace-chain-specs = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
semver = "1.0.22"
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
simple_moving_average = "1.0.2"
sp-core = { git = "https://github.com/subspace/polkadot-sdk", rev = "44d742b90e7852aed1f08ab5299d5d88cfa1c6ed", default-features = false }
sp-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
sp-domains-fraud-proof = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
sp-consensus-subspace = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
sp-domains-fraud-proof = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
sp-runtime = { git = "https://github.com/subspace/polkadot-sdk", rev = "44d742b90e7852aed1f08ab5299d5d88cfa1c6ed", default-features = false }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-erasure-coding = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a", default-features = false }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-rpc-primitives = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-runtime = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-runtime-primitives = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "17273eeefd6781f4fa570e42cac722e580f9476a" }
subspace-core-primitives = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-erasure-coding = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-farmer = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520", default-features = false }
subspace-farmer-components = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-networking = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-proof-of-space = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-rpc-primitives = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-runtime = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-runtime-primitives = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
subspace-service = { git = "https://github.com/subspace/subspace", rev = "a4180f9e99a848dae87c77a402d2a414558b1520" }
supports-color = "3.0.0"
thiserror = "1.0.59"
thread-priority = "0.16.0"
Expand Down
2 changes: 0 additions & 2 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ pub enum BackendNotification {
best_block_number: BlockNumber,
reward_address_balance: Balance,
initial_farm_states: Vec<InitialFarmState>,
farm_during_initial_plotting: bool,
chain_info: ChainInfo,
},
Node(NodeNotification),
Expand Down Expand Up @@ -494,7 +493,6 @@ async fn run(
best_block_number: consensus_node.best_block_number(),
reward_address_balance: consensus_node.account_balance(&config.reward_address),
initial_farm_states: farmer.initial_farm_states().to_vec(),
farm_during_initial_plotting: farmer.farm_during_initial_plotting(),
chain_info: consensus_node.chain_info().clone(),
})
.await?;
Expand Down
21 changes: 2 additions & 19 deletions src/backend/farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use subspace_farmer::single_disk_farm::{
};
use subspace_farmer::utils::plotted_pieces::PlottedPieces;
use subspace_farmer::utils::{
all_cpu_cores, create_plotting_thread_pool_manager, recommended_number_of_farming_threads,
create_plotting_thread_pool_manager, recommended_number_of_farming_threads,
run_future_in_dedicated_thread, thread_pool_core_indices, AsyncJoinOnDrop,
};
use subspace_farmer::NodeClient;
Expand Down Expand Up @@ -84,7 +84,6 @@ pub(super) struct Farmer {
farmer_fut: BoxFuture<'static, anyhow::Result<()>>,
farmer_cache_worker_fut: BoxFuture<'static, ()>,
initial_farm_states: Vec<InitialFarmState>,
farm_during_initial_plotting: bool,
notifications: Arc<Notifications>,
action_sender: mpsc::Sender<FarmerAction>,
}
Expand All @@ -95,7 +94,6 @@ impl Farmer {
farmer_fut,
farmer_cache_worker_fut,
initial_farm_states,
farm_during_initial_plotting: _,
notifications,
action_sender,
} = self;
Expand Down Expand Up @@ -144,10 +142,6 @@ impl Farmer {
&self.initial_farm_states
}

pub(super) fn farm_during_initial_plotting(&self) -> bool {
self.farm_during_initial_plotting
}

pub(super) fn action_sender(&self) -> mpsc::Sender<FarmerAction> {
self.action_sender.clone()
}
Expand All @@ -163,14 +157,6 @@ impl fmt::Debug for Farmer {
}
}

fn should_farm_during_initial_plotting() -> bool {
let total_cpu_cores = all_cpu_cores()
.iter()
.flat_map(|set| set.cpu_cores())
.count();
total_cpu_cores > 8
}

#[derive(Debug, Clone)]
pub struct DiskFarm {
pub directory: PathBuf,
Expand Down Expand Up @@ -245,7 +231,6 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
.in_current_span(),
);

let farm_during_initial_plotting = should_farm_during_initial_plotting();
let plotting_thread_pool_core_indices = thread_pool_core_indices(None, None);
let replotting_thread_pool_core_indices = {
let mut replotting_thread_pool_core_indices = thread_pool_core_indices(None, None);
Expand Down Expand Up @@ -338,8 +323,7 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
reward_address,
kzg,
erasure_coding,
cache_percentage: CACHE_PERCENTAGE,
farm_during_initial_plotting,
cache_percentage: CACHE_PERCENTAGE.get(),
farming_thread_pool_size: recommended_number_of_farming_threads(),
plotting_delay: Some(plotting_delay_receiver),
global_mutex,
Expand Down Expand Up @@ -702,7 +686,6 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
farmer_fut,
farmer_cache_worker_fut,
initial_farm_states,
farm_during_initial_plotting,
notifications,
action_sender,
})
Expand Down
3 changes: 0 additions & 3 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub enum RunningInput {
best_block_number: BlockNumber,
reward_address_balance: Balance,
initial_farm_states: Vec<InitialFarmState>,
farm_during_initial_plotting: bool,
raw_config: RawConfig,
chain_info: ChainInfo,
},
Expand Down Expand Up @@ -220,7 +219,6 @@ impl RunningView {
best_block_number,
reward_address_balance,
initial_farm_states,
farm_during_initial_plotting,
raw_config,
chain_info,
} => {
Expand All @@ -239,7 +237,6 @@ impl RunningView {
farm,
total_sectors: initial_farm_state.total_sectors_count,
plotted_total_sectors: initial_farm_state.plotted_sectors_count,
farm_during_initial_plotting,
plotting_paused: self.plotting_paused,
},
);
Expand Down
10 changes: 1 addition & 9 deletions src/frontend/running/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub(super) struct FarmWidgetInit {
pub(super) farm: Farm,
pub(super) total_sectors: SectorIndex,
pub(super) plotted_total_sectors: SectorIndex,
pub(super) farm_during_initial_plotting: bool,
pub(super) plotting_paused: bool,
}

Expand Down Expand Up @@ -105,7 +104,6 @@ pub(super) struct FarmWidget {
last_sector_plotted: Option<SectorIndex>,
plotting_state: PlottingState,
is_node_synced: bool,
farm_during_initial_plotting: bool,
sector_rows: gtk::Box,
sectors: HashMap<SectorIndex, gtk::Box>,
non_fatal_farming_error: Option<Arc<FarmingError>>,
Expand Down Expand Up @@ -254,11 +252,6 @@ impl FactoryComponent for FarmWidget {

gtk::Box {
set_spacing: 5,
set_tooltip: if self.farm_during_initial_plotting {
"Farming runs in parallel to plotting on CPUs with more than 8 logical cores"
} else {
"Farming starts after initial plotting is complete on CPUs with 8 or less logical cores"
},

gtk::Label {
set_halign: gtk::Align::Start,
Expand Down Expand Up @@ -286,7 +279,7 @@ impl FactoryComponent for FarmWidget {
} else {
"Initial plotting"
};
let farming = if self.is_node_synced && self.farm_during_initial_plotting {
let farming = if self.is_node_synced {
"farming"
} else {
"not farming"
Expand Down Expand Up @@ -389,7 +382,6 @@ impl FactoryComponent for FarmWidget {
last_sector_plotted: None,
plotting_state: PlottingState::Idle,
is_node_synced: false,
farm_during_initial_plotting: init.farm_during_initial_plotting,
sector_rows,
sectors: HashMap::from_iter((SectorIndex::MIN..).zip(sectors)),
non_fatal_farming_error: None,
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@ impl App {
best_block_number,
reward_address_balance,
initial_farm_states,
farm_during_initial_plotting,
chain_info,
} => {
self.current_raw_config.replace(raw_config.clone());
Expand All @@ -708,7 +707,6 @@ impl App {
best_block_number,
reward_address_balance,
initial_farm_states,
farm_during_initial_plotting,
raw_config,
chain_info,
});
Expand Down

0 comments on commit 1f0f0d6

Please sign in to comment.