essential_storage/
failed_solution.rs

1use std::fmt::Display;
2
3use essential_types::solution::Solution;
4use serde::{Deserialize, Serialize};
5
6/// Reasons why a solution failed.
7#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
8pub enum SolutionFailReason {
9    /// Constraint check failed.
10    ConstraintsFailed(String),
11    /// Not composable with other solutions to build a batch.
12    NotComposable,
13}
14
15/// A failed solution.
16#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct FailedSolution {
18    /// The failed solution.
19    pub solution: Solution,
20    /// Reason why the solution failed.
21    pub reason: SolutionFailReason,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
25/// Outcome of a solution check.
26pub enum CheckOutcome {
27    /// The solution was successful in this block.
28    Success(u64),
29    /// The solution failed.
30    Fail(SolutionFailReason),
31}
32/// A solution with its outcome.
33#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
34pub struct SolutionOutcomes {
35    /// The solution.
36    pub solution: Solution,
37    /// The outcomes of the solution.
38    pub outcome: Vec<CheckOutcome>,
39}
40
41impl Display for SolutionFailReason {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        match self {
44            SolutionFailReason::ConstraintsFailed(reason) => {
45                write!(f, "ConstraintsFailed: {}", reason)
46            }
47            SolutionFailReason::NotComposable => write!(f, "NotComposable"),
48        }
49    }
50}