Skip to content

Commit

Permalink
Rename transition failure to report error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoyla committed Dec 19, 2024
1 parent 3ea9e91 commit 11c1754
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 135 deletions.
4 changes: 2 additions & 2 deletions crates/daphne-server/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ impl AxumDapResponse {
}

pub fn new_error<E: Into<DapError>>(error: E, metrics: &dyn DaphneServiceMetrics) -> Self {
// trigger abort if transition failures reach this point.
// Trigger abort if report errors reach this point.
let error = match error.into() {
DapError::Transition(failure) => DapAbort::report_rejected(failure),
DapError::ReportError(err) => DapAbort::report_rejected(err),
DapError::Fatal(e) => Err(e),
DapError::Abort(abort) => Ok(abort),
};
Expand Down
14 changes: 6 additions & 8 deletions crates/daphne/src/error/aborts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{
constants::DapMediaType,
fatal_error,
messages::{AggregationJobId, ReportId, TaskId, TransitionFailure},
messages::{AggregationJobId, ReportError, ReportId, TaskId},
DapError, DapRequestMeta, DapVersion,
};
use prio::codec::CodecError;
Expand Down Expand Up @@ -237,18 +237,16 @@ impl DapAbort {
}

#[inline]
pub fn report_rejected(failure_reason: TransitionFailure) -> Result<Self, FatalDapError> {
pub fn report_rejected(failure_reason: ReportError) -> Result<Self, FatalDapError> {
let detail = match failure_reason {
TransitionFailure::BatchCollected => {
ReportError::BatchCollected => {
"The report pertains to a batch that has already been collected."
}
TransitionFailure::ReportReplayed => {
"A report with the same ID was uploaded previously."
}
ReportError::ReportReplayed => "A report with the same ID was uploaded previously.",
_ => {
let DapError::Fatal(fatal) = fatal_error!(
err = "Attempted to construct a \"reportRejected\" abort with unexpected transition failure",
unexpected_transition_failure = ?failure_reason,
err = "Attempted to construct a \"reportRejected\" abort with unexpected report error",
unexpected_report_error = ?failure_reason,
) else {
unreachable!("fatal_error! should always create a DapError::Fatal");
};
Expand Down
12 changes: 6 additions & 6 deletions crates/daphne/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod aborts;

use std::fmt::{Debug, Display};

use crate::{messages::TransitionFailure, vdaf::VdafError};
use crate::{messages::ReportError, vdaf::VdafError};
pub use aborts::DapAbort;
use prio::codec::CodecError;

Expand All @@ -25,10 +25,10 @@ pub enum DapError {
#[error("abort: {0}")]
Abort(#[from] DapAbort),

/// Transition failure. This error blocks processing of a paritcular report and may, under
/// Report Error. This error blocks processing of a paritcular report and may, under
/// certain conditions, trigger an abort.
#[error("transition error: {0}")]
Transition(#[from] TransitionFailure),
#[error("report error: {0}")]
ReportError(#[from] ReportError),
}

impl DapError {
Expand All @@ -43,12 +43,12 @@ impl DapError {
match e {
VdafError::CodecDraft09(..) | VdafError::VdafDraft09(..) => {
tracing::warn!(error = ?e, "rejecting report");
Self::Transition(TransitionFailure::VdafPrepError)
Self::ReportError(ReportError::VdafPrepError)
}
VdafError::Dap(e) => e,
VdafError::Codec(..) | VdafError::Vdaf(..) => {
tracing::warn!(error = ?e, "rejecting report - latest");
Self::Transition(TransitionFailure::VdafPrepError)
Self::ReportError(ReportError::VdafPrepError)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/daphne/src/hpke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use hpke_rs_rust_crypto::HpkeRustCrypto as ImplHpkeCrypto;

use crate::{
fatal_error,
messages::{HpkeCiphertext, TaskId, TransitionFailure},
messages::{HpkeCiphertext, ReportError, TaskId},
DapError, DapVersion,
};
use async_trait::async_trait;
Expand All @@ -29,13 +29,13 @@ const AEAD_ID_AES128GCM: u16 = 0x0001;

impl From<HpkeError> for DapError {
fn from(_e: HpkeError) -> Self {
Self::Transition(TransitionFailure::HpkeDecryptError)
Self::ReportError(ReportError::HpkeDecryptError)
}
}

impl From<Error> for DapError {
fn from(_e: Error) -> Self {
Self::Transition(TransitionFailure::HpkeDecryptError)
Self::ReportError(ReportError::HpkeDecryptError)
}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ impl HpkeConfig {
ciphertext: &HpkeCiphertext,
) -> Result<Vec<u8>, DapError> {
if self.id != ciphertext.config_id {
return Err(DapError::Transition(TransitionFailure::HpkeUnknownConfigId));
return Err(DapError::ReportError(ReportError::HpkeUnknownConfigId));
}
let receiver: Hpke<ImplHpkeCrypto> = check_suite(self.kem_id, self.kdf_id, self.aead_id)?;
let mut ctx = receiver.setup_receiver(
Expand Down Expand Up @@ -303,7 +303,7 @@ where
self.clone()
.map(|c| c.borrow())
.find(|c| c.config.id == ciphertext.config_id)
.ok_or(DapError::Transition(TransitionFailure::HpkeUnknownConfigId))?
.ok_or(DapError::ReportError(ReportError::HpkeUnknownConfigId))?
.decrypt(info, ciphertext)
}
}
Expand Down
Loading

0 comments on commit 11c1754

Please sign in to comment.