Skip to content

Commit

Permalink
Merge pull request #37 from nazar-pc/fix-farm-status
Browse files Browse the repository at this point in the history
Initialize plotting state correctly if initial plotting is done
  • Loading branch information
nazar-pc authored Dec 15, 2023
2 parents 96bd333 + 4e89d8e commit 951c068
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub enum BackendNotification {
config: Config,
raw_config: RawConfig,
best_block_number: BlockNumber,
initial_plotting_states: Vec<PlottingState>,
},
Node(NodeNotification),
Farmer(FarmerNotification),
Expand Down Expand Up @@ -306,6 +307,7 @@ async fn run(
config,
raw_config,
best_block_number: consensus_node.best_block_number(),
initial_plotting_states: farmer.initial_plotting_states().to_vec(),
})
.await?;

Expand Down
23 changes: 22 additions & 1 deletion src/backend/farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use atomic::Atomic;
use event_listener_primitives::HandlerId;
use futures::channel::oneshot;
use futures::future::BoxFuture;
use futures::stream::FuturesUnordered;
use futures::stream::{FuturesOrdered, FuturesUnordered};
use futures::{select, FutureExt, StreamExt};
use lru::LruCache;
use parking_lot::Mutex;
Expand Down Expand Up @@ -68,6 +68,7 @@ struct Handlers {
pub(super) struct Farmer {
farm_fut: BoxFuture<'static, anyhow::Result<()>>,
piece_cache_worker_fut: BoxFuture<'static, ()>,
initial_plotting_states: Vec<PlottingState>,
handlers: Arc<Handlers>,
}

Expand Down Expand Up @@ -109,6 +110,10 @@ impl Farmer {
Ok(())
}

pub(super) fn initial_plotting_states(&self) -> &[PlottingState] {
&self.initial_plotting_states
}

pub(super) fn on_plotting_state_change(
&self,
callback: Handler2Fn<usize, PlottingState>,
Expand Down Expand Up @@ -371,6 +376,21 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
}))
.detach();

let initial_plotting_states = single_disk_farms
.iter()
.map(|single_disk_farm| async {
if usize::from(single_disk_farm.total_sectors_count().await)
== single_disk_farm.plotted_sectors_count().await
{
PlottingState::Idle
} else {
PlottingState::Unknown
}
})
.collect::<FuturesOrdered<_>>()
.collect()
.await;

let mut single_disk_farms_stream = single_disk_farms
.into_iter()
.enumerate()
Expand Down Expand Up @@ -478,6 +498,7 @@ pub(super) async fn create_farmer(farmer_options: FarmerOptions) -> anyhow::Resu
anyhow::Ok(Farmer {
farm_fut,
piece_cache_worker_fut,
initial_plotting_states,
handlers,
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tracing::warn;
pub enum RunningInput {
Initialize {
best_block_number: BlockNumber,
num_farms: usize,
initial_plotting_states: Vec<PlottingState>,
},
NodeNotification(NodeNotification),
FarmerNotification(FarmerNotification),
Expand Down Expand Up @@ -244,14 +244,14 @@ impl RunningView {
match input {
RunningInput::Initialize {
best_block_number,
num_farms,
initial_plotting_states,
} => {
self.node_state = NodeState {
best_block_number,
sync_state: SyncState::default(),
};
self.farmer_state = FarmerState {
plotting_state: vec![PlottingState::default(); num_farms],
plotting_state: initial_plotting_states,
piece_cache_sync_progress: 0.0,
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ impl App {
}
},
BackendNotification::Running {
config,
config: _,
raw_config,
best_block_number,
initial_plotting_states,
} => {
let num_farms = config.farms.len();
self.current_raw_config.replace(raw_config);
self.current_view = View::Running;
self.running_view.emit(RunningInput::Initialize {
best_block_number,
num_farms,
initial_plotting_states,
});
}
BackendNotification::Node(node_notification) => {
Expand Down

0 comments on commit 951c068

Please sign in to comment.