Skip to main content

ic_backup/policy/ic_snapshot_upload/
mod.rs

1//! Pure current-reservation and passive upload-reply association; no IO or settlement.
2
3#[cfg(test)]
4mod tests;
5
6use super::response_identity::{ResponseIdentity, ResponseIdentityMismatch};
7use crate::model::{
8    attempt_journal::AttemptJournalRecord,
9    ic_mutation::IcMutationAcknowledgement,
10    ic_snapshot_upload::{
11        IcSnapshotUploadAttempt, IcSnapshotUploadAttemptError, IcSnapshotUploadError,
12        IcSnapshotUploadReply,
13    },
14};
15use thiserror::Error;
16
17/// Read-only retained original acknowledgement and bounded source-bound upload reply.
18#[derive(Debug)]
19pub struct IcSnapshotUploadAcknowledgementView<'request, 'source> {
20    acknowledgement: &'request IcMutationAcknowledgement,
21    reply: IcSnapshotUploadReply<'request, 'source>,
22}
23impl<'request, 'source> IcSnapshotUploadAcknowledgementView<'request, 'source> {
24    /// Read exact claimed context/target/authority/attempt/raw bytes/evidence.
25    #[must_use]
26    pub const fn acknowledgement(&self) -> &'request IcMutationAcknowledgement {
27        self.acknowledgement
28    }
29    /// Read passive bounded metadata ID or data acknowledgement; no Applied receipt.
30    #[must_use]
31    pub const fn reply(&self) -> &IcSnapshotUploadReply<'request, 'source> {
32        &self.reply
33    }
34}
35
36/// Recheck exact original pending upload and passive actual association fields.
37///
38/// Reuses the existing bounded acknowledgement owner, with tighter upload decoding.
39/// Actual authentication, exclusive original allocation/write attribution, freshness,
40/// controller/byte custody and independent per-call accounting remain integration-owned.
41/// Lost replies stay pending. Zero/one/multiple inventory entries or absent data never
42/// establish an outcome. Only separately qualified settled observations can reconcile;
43/// no observation, receipt, retry, refund, completion or release is produced here.
44/// # Errors
45/// Rejects original reservation drift, mismatching actual claims and invalid reply shape.
46pub fn validate_acknowledgement<'request, 'source>(
47    request: &IcSnapshotUploadAttempt<'request, 'source>,
48    journal: &AttemptJournalRecord,
49    acknowledgement: &'request IcMutationAcknowledgement,
50) -> Result<IcSnapshotUploadAcknowledgementView<'request, 'source>, IcSnapshotUploadAssociationError>
51{
52    request.validate_journal(journal)?;
53    let input = acknowledgement.input();
54    ResponseIdentity::from(input).compare(&ResponseIdentity {
55        authority: &request.authority().digest(),
56        mutation_attempt: request.mutation_attempt(),
57        context: request.plan().context(),
58        target: request.payload().target(),
59    })?;
60    let reply = IcSnapshotUploadReply::decode(request.payload(), &input.reply)?;
61    Ok(IcSnapshotUploadAcknowledgementView {
62        acknowledgement,
63        reply,
64    })
65}
66
67/// Typed passive association denial; all original obligations and counters remain retained.
68#[derive(Debug, Error)]
69pub enum IcSnapshotUploadAssociationError {
70    /// Exact current original mutation/reservation no longer matches.
71    #[error(transparent)]
72    Reservation(#[from] IcSnapshotUploadAttemptError),
73    /// Passive claims differ from the exact original update identity.
74    #[error(transparent)]
75    Identity(#[from] ResponseIdentityMismatch),
76    /// Canonical bounded upload decoder rejected the raw reply.
77    #[error(transparent)]
78    Reply(#[from] IcSnapshotUploadError),
79}