Skip to content

Commit

Permalink
fix(performance): avoiding particle data printout in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raftedproc authored Jan 23, 2024
1 parent 7554568 commit 6c1cb28
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 51 deletions.
57 changes: 15 additions & 42 deletions air/src/preparation_step/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use air_interpreter_data::CidStoreVerificationError;
use air_interpreter_data::DataDeserializationError;
use air_interpreter_data::Versions;
use air_interpreter_interface::CallResultsDeserializeError;
use air_interpreter_interface::SerializedCallResults;
use strum::IntoEnumIterator;
use strum_macros::EnumDiscriminants;
use strum_macros::EnumIter;
Expand All @@ -38,58 +37,40 @@ pub enum PreparationError {
/// Errors occurred on executed trace deserialization.
#[error(
"an error occurred while data deserialization: {error:?}.\n\
AquaVM version is {} and it expect data of {} version,\
it's failed to get version of AquaVM produced this data.\n\
Data: {raw_data:?}",
AquaVM version is {} and it expects {} version.",
super::interpreter_version(),
data_version()
)]
DataDeFailed {
raw_data: Vec<u8>,
error: DataDeserializationError,
},
DataDeFailed { error: DataDeserializationError },

/// Errors occurred on executed trace deserialization.
#[error(
"an error occurred while envelope deserialization: {error:?}.\n\
AquaVM version is {} and it expect data of {} version,\
it's failed to get version of AquaVM produced this data.\n\
Envelope data: {env_raw_data:?}",
AquaVM version is {} and it expects {} version.",
super::interpreter_version(),
data_version()
)]
EnvelopeDeFailed {
env_raw_data: Vec<u8>,
error: DataDeserializationError,
},
EnvelopeDeFailed { error: DataDeserializationError },

/// Errors occurred on executed trace deserialization
/// when it was possible to recover versions.
#[error(
"an error occurred while data deserialization: {error:?}.\n\
AquaVM's version is {} and it expects data of {} version.\n\
Supplied data version is {}, it's produced by AquaVM of {} version.\n\
Envelope data: {env_raw_data:?}",
Supplied data version is {}, it's produced by AquaVM of {} version.",
super::interpreter_version(),
data_version(),
versions.data_version,
versions.interpreter_version,
)]
EnvelopeDeFailedWithVersions {
env_raw_data: Vec<u8>,
error: DataDeserializationError,
versions: Versions,
},

/// Error occurred on call results deserialization.
#[error(
"error occurred while deserialize call results: {error:?}.\n\
Call results: {call_results:?}"
)]
CallResultsDeFailed {
call_results: SerializedCallResults,
error: CallResultsDeserializeError,
},
#[error("error occurred while deserialize call results: {error:?}.")]
CallResultsDeFailed { error: CallResultsDeserializeError },

/// Error occurred when a version of interpreter produced supplied data is less then minimal.
#[error("supplied data was produced by `{actual_version}` version of interpreter, but minimum `{required_version}` version is required")]
Expand Down Expand Up @@ -119,28 +100,20 @@ impl ToErrorCode for PreparationError {
}

impl PreparationError {
pub fn data_de_failed(raw_data: Vec<u8>, error: DataDeserializationError) -> Self {
Self::DataDeFailed { raw_data, error }
pub fn data_de_failed(error: DataDeserializationError) -> Self {
Self::DataDeFailed { error }
}

pub fn envelope_de_failed(env_raw_data: Vec<u8>, error: DataDeserializationError) -> Self {
Self::EnvelopeDeFailed { env_raw_data, error }
pub fn envelope_de_failed(error: DataDeserializationError) -> Self {
Self::EnvelopeDeFailed { error }
}

pub fn env_de_failed_with_versions(
env_raw_data: Vec<u8>,
error: DataDeserializationError,
versions: Versions,
) -> Self {
Self::EnvelopeDeFailedWithVersions {
env_raw_data,
error,
versions,
}
pub fn env_de_failed_with_versions(error: DataDeserializationError, versions: Versions) -> Self {
Self::EnvelopeDeFailedWithVersions { error, versions }
}

pub fn call_results_de_failed(call_results: SerializedCallResults, error: CallResultsDeserializeError) -> Self {
Self::CallResultsDeFailed { call_results, error }
pub fn call_results_de_failed(error: CallResultsDeserializeError) -> Self {
Self::CallResultsDeFailed { error }
}

pub fn unsupported_interpreter_version(actual_version: semver::Version, required_version: semver::Version) -> Self {
Expand Down
12 changes: 6 additions & 6 deletions air/src/preparation_step/preparation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ pub(crate) fn try_to_envelope(raw_env_data: &[u8]) -> PreparationResult<Interpre
}

pub(crate) fn try_to_data(raw_data: &[u8]) -> PreparationResult<InterpreterData> {
InterpreterData::try_from_slice(raw_data).map_err(|de_error| to_data_de_error(raw_data.to_vec(), de_error))
InterpreterData::try_from_slice(raw_data).map_err(to_data_de_error)
}

fn to_envelope_de_error(env_raw_data: Vec<u8>, de_error: DataDeserializationError) -> PreparationError {
match InterpreterDataEnvelope::try_get_versions(&env_raw_data) {
Ok(versions) => PreparationError::env_de_failed_with_versions(env_raw_data, de_error, versions),
Err(_) => PreparationError::envelope_de_failed(env_raw_data, de_error),
Ok(versions) => PreparationError::env_de_failed_with_versions(de_error, versions),
Err(_) => PreparationError::envelope_de_failed(de_error),
}
}

fn to_data_de_error(env_raw_data: Vec<u8>, de_error: DataDeserializationError) -> PreparationError {
PreparationError::data_de_failed(env_raw_data, de_error)
fn to_data_de_error(de_error: DataDeserializationError) -> PreparationError {
PreparationError::data_de_failed(de_error)
}

#[tracing::instrument(skip_all)]
Expand All @@ -147,7 +147,7 @@ fn make_exec_ctx(
let call_results = measure!(
CallResultsRepr
.deserialize(call_results)
.map_err(|e| PreparationError::call_results_de_failed(call_results.clone(), e))?,
.map_err(PreparationError::call_results_de_failed)?,
tracing::Level::INFO,
"CallResultsRepr.deserialize",
);
Expand Down
3 changes: 0 additions & 3 deletions air/tests/test_module/negative_tests/preparation_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ fn invalid_data_without_versions() {

let expected_serde_error = InterpreterDataEnvelope::try_from_slice(&invalid_data).unwrap_err();
let expected_error = PreparationError::EnvelopeDeFailed {
env_raw_data: invalid_data,
error: expected_serde_error,
};
assert!(check_error(&result, expected_error));
Expand Down Expand Up @@ -79,7 +78,6 @@ fn invalid_data_with_versions() {

let expected_serde_error = InterpreterDataEnvelope::try_from_slice(&invalid_data).unwrap_err();
let expected_error = PreparationError::EnvelopeDeFailedWithVersions {
env_raw_data: invalid_data,
error: expected_serde_error,
versions,
};
Expand Down Expand Up @@ -114,7 +112,6 @@ fn invalid_callresults() {
let expected_serde_error = CallResultsRepr.deserialize(&wrong_call_results).unwrap_err();
let expected_error = PreparationError::CallResultsDeFailed {
error: expected_serde_error,
call_results: wrong_call_results.into(),
};

assert!(check_error(&result, expected_error));
Expand Down

0 comments on commit 6c1cb28

Please sign in to comment.