pub(crate) mod actions_state;
use std::collections::HashMap;
use ccp_shared::types::*;
use super::roadmap_builder::RoadmapBuilder;
use crate::cu::status::ToCUStatus;
use crate::status::CCStatus;
use actions_state::*;
#[derive(Debug, Eq)]
pub(crate) struct CCProverAlignmentRoadmap {
pub(crate) pre_action: CUProverPreAction,
pub(crate) actions: Vec<CUProverAction>,
pub(crate) epoch: EpochParameters,
}
impl CCProverAlignmentRoadmap {
pub(crate) fn make<T: ToCUStatus>(
new_allocation: CUAllocation,
new_epoch: EpochParameters,
current_allocation: &HashMap<PhysicalCoreId, T>,
current_status: CCStatus,
) -> CCProverAlignmentRoadmap {
RoadmapBuilder::from(new_epoch, current_status)
.collect_allocation_and_new_job_actions(new_allocation, current_allocation)
.collect_removal_actions(current_allocation)
.substitute_removal_and_allocation_actions()
.prepare_allocation_actions()
.prepare_removal_actions()
.build()
}
}
impl PartialEq for CCProverAlignmentRoadmap {
fn eq(&self, other: &Self) -> bool {
use std::collections::HashSet;
if self.epoch != other.epoch {
return false;
}
let self_actions = self.actions.iter().collect::<HashSet<_>>();
let other_actions = other.actions.iter().collect::<HashSet<_>>();
self_actions == other_actions
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub(crate) enum CUProverPreAction {
NoAction,
CleanupProofCache,
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub(crate) enum CUProverAction {
CreateCUProver(CreateCUProverState),
RemoveCUProver(RemoveCUProverState),
NewCCJob(NewCCJobState),
NewCCJobWithRepining(NewCCJobWithRepiningState),
}
impl CUProverAction {
pub(crate) fn create_cu_prover(new_core_id: PhysicalCoreId, new_cu_id: CUID) -> Self {
Self::CreateCUProver(CreateCUProverState::new(new_core_id, new_cu_id))
}
pub(crate) fn remove_cu_prover(current_core_id: PhysicalCoreId) -> Self {
Self::RemoveCUProver(RemoveCUProverState::new(current_core_id))
}
pub(crate) fn new_cc_job(current_core_id: PhysicalCoreId, new_cu_id: CUID) -> Self {
Self::NewCCJob(NewCCJobState::new(current_core_id, new_cu_id))
}
pub(crate) fn new_cc_job_repin(
current_core_id: PhysicalCoreId,
new_core_id: PhysicalCoreId,
new_cu_id: CUID,
) -> Self {
Self::NewCCJobWithRepining(NewCCJobWithRepiningState::new(
current_core_id,
new_core_id,
new_cu_id,
))
}
}
impl CUProverPreAction {
pub(crate) fn cleanup_proof_cache() -> Self {
Self::CleanupProofCache
}
pub(crate) fn no_action() -> Self {
Self::NoAction
}
}