Skip to content

Commit 951c068

Browse files
authored
Merge pull request #37 from nazar-pc/fix-farm-status
Initialize plotting state correctly if initial plotting is done
2 parents 96bd333 + 4e89d8e commit 951c068

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

src/backend.rs

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub enum BackendNotification {
9999
config: Config,
100100
raw_config: RawConfig,
101101
best_block_number: BlockNumber,
102+
initial_plotting_states: Vec<PlottingState>,
102103
},
103104
Node(NodeNotification),
104105
Farmer(FarmerNotification),
@@ -306,6 +307,7 @@ async fn run(
306307
config,
307308
raw_config,
308309
best_block_number: consensus_node.best_block_number(),
310+
initial_plotting_states: farmer.initial_plotting_states().to_vec(),
309311
})
310312
.await?;
311313

src/backend/farmer.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use atomic::Atomic;
88
use event_listener_primitives::HandlerId;
99
use futures::channel::oneshot;
1010
use futures::future::BoxFuture;
11-
use futures::stream::FuturesUnordered;
11+
use futures::stream::{FuturesOrdered, FuturesUnordered};
1212
use futures::{select, FutureExt, StreamExt};
1313
use lru::LruCache;
1414
use parking_lot::Mutex;
@@ -68,6 +68,7 @@ struct Handlers {
6868
pub(super) struct Farmer {
6969
farm_fut: BoxFuture<'static, anyhow::Result<()>>,
7070
piece_cache_worker_fut: BoxFuture<'static, ()>,
71+
initial_plotting_states: Vec<PlottingState>,
7172
handlers: Arc<Handlers>,
7273
}
7374

@@ -109,6 +110,10 @@ impl Farmer {
109110
Ok(())
110111
}
111112

113+
pub(super) fn initial_plotting_states(&self) -> &[PlottingState] {
114+
&self.initial_plotting_states
115+
}
116+
112117
pub(super) fn on_plotting_state_change(
113118
&self,
114119
callback: Handler2Fn<usize, PlottingState>,
@@ -371,6 +376,21 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
371376
}))
372377
.detach();
373378

379+
let initial_plotting_states = single_disk_farms
380+
.iter()
381+
.map(|single_disk_farm| async {
382+
if usize::from(single_disk_farm.total_sectors_count().await)
383+
== single_disk_farm.plotted_sectors_count().await
384+
{
385+
PlottingState::Idle
386+
} else {
387+
PlottingState::Unknown
388+
}
389+
})
390+
.collect::<FuturesOrdered<_>>()
391+
.collect()
392+
.await;
393+
374394
let mut single_disk_farms_stream = single_disk_farms
375395
.into_iter()
376396
.enumerate()
@@ -478,6 +498,7 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
478498
anyhow::Ok(Farmer {
479499
farm_fut,
480500
piece_cache_worker_fut,
501+
initial_plotting_states,
481502
handlers,
482503
})
483504
}

src/frontend/running.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tracing::warn;
1010
pub enum RunningInput {
1111
Initialize {
1212
best_block_number: BlockNumber,
13-
num_farms: usize,
13+
initial_plotting_states: Vec<PlottingState>,
1414
},
1515
NodeNotification(NodeNotification),
1616
FarmerNotification(FarmerNotification),
@@ -244,14 +244,14 @@ impl RunningView {
244244
match input {
245245
RunningInput::Initialize {
246246
best_block_number,
247-
num_farms,
247+
initial_plotting_states,
248248
} => {
249249
self.node_state = NodeState {
250250
best_block_number,
251251
sync_state: SyncState::default(),
252252
};
253253
self.farmer_state = FarmerState {
254-
plotting_state: vec![PlottingState::default(); num_farms],
254+
plotting_state: initial_plotting_states,
255255
piece_cache_sync_progress: 0.0,
256256
};
257257
}

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,16 @@ impl App {
359359
}
360360
},
361361
BackendNotification::Running {
362-
config,
362+
config: _,
363363
raw_config,
364364
best_block_number,
365+
initial_plotting_states,
365366
} => {
366-
let num_farms = config.farms.len();
367367
self.current_raw_config.replace(raw_config);
368368
self.current_view = View::Running;
369369
self.running_view.emit(RunningInput::Initialize {
370370
best_block_number,
371-
num_farms,
371+
initial_plotting_states,
372372
});
373373
}
374374
BackendNotification::Node(node_notification) => {

0 commit comments

Comments
 (0)