made_core/ports/ack_outcome.rs
1use crate::value_objects::{HostDeliveryObservation, HostDeliveryRecord};
2
3/// What the ledger did with a host's report about a delivery.
4///
5/// The four answers are deliberately different things. A repeat of the
6/// same report is the same fact arriving twice and costs nothing; a
7/// different report about a delivery already acknowledged is two hosts
8/// disagreeing and must not be flattened into the later one; and a
9/// lease that is not the current one is a host that was replaced while
10/// it was away, whose answer arrives too late to be worth anything.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum AckOutcome {
13 /// Recorded.
14 Acknowledged(HostDeliveryRecord),
15 /// The same report, already recorded.
16 AlreadyAcknowledged(HostDeliveryRecord),
17 /// A different report about a delivery that is already acknowledged.
18 Conflict {
19 existing: Box<HostDeliveryObservation>,
20 },
21 /// The lease offered is not the one that holds this delivery.
22 LeaseNotOwned,
23}
24
25impl AckOutcome {
26 /// The record, when the call reached one.
27 #[must_use]
28 pub const fn record(&self) -> Option<&HostDeliveryRecord> {
29 match self {
30 Self::Acknowledged(record) | Self::AlreadyAcknowledged(record) => Some(record),
31 Self::Conflict { .. } | Self::LeaseNotOwned => None,
32 }
33 }
34
35 #[must_use]
36 pub const fn is_recorded(&self) -> bool {
37 matches!(self, Self::Acknowledged(_) | Self::AlreadyAcknowledged(_))
38 }
39}