mirror of
https://github.com/fluencelabs/aquavm
synced 2025-03-15 20:40:50 +00:00
feat(execution-engine)!: intro farewell_if_error_macro (#719)
intro farewell_if_error_macro
This commit is contained in:
parent
0aa23318d9
commit
cdcb86cb55
@ -26,6 +26,7 @@ use crate::verification_step::verify;
|
|||||||
use air_interpreter_interface::InterpreterOutcome;
|
use air_interpreter_interface::InterpreterOutcome;
|
||||||
use air_interpreter_interface::RunParameters;
|
use air_interpreter_interface::RunParameters;
|
||||||
use air_log_targets::RUN_PARAMS;
|
use air_log_targets::RUN_PARAMS;
|
||||||
|
use air_utils::farewell_if_fail;
|
||||||
use air_utils::measure;
|
use air_utils::measure;
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
@ -62,38 +63,22 @@ fn execute_air_impl(
|
|||||||
let ParsedDataPair {
|
let ParsedDataPair {
|
||||||
prev_data,
|
prev_data,
|
||||||
current_data,
|
current_data,
|
||||||
} = match parse_data(&raw_prev_data, &raw_current_data) {
|
} = farewell_if_fail!(parse_data(&raw_prev_data, &raw_current_data), raw_prev_data);
|
||||||
Ok(parsed_datas) => parsed_datas,
|
|
||||||
// return the prev data in case of errors
|
|
||||||
Err(error) => return Err(farewell::from_uncatchable_error(raw_prev_data, error)),
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO currently we use particle ID, but it should be changed to signature,
|
// TODO currently we use particle ID, but it should be changed to signature,
|
||||||
// as partical ID can be equally replayed
|
// as partical ID can be equally replayed
|
||||||
let salt = params.particle_id.clone();
|
let salt = params.particle_id.clone();
|
||||||
let signature_store = match verify(&prev_data, ¤t_data, &salt) {
|
let signature_store = farewell_if_fail!(verify(&prev_data, ¤t_data, &salt), raw_prev_data);
|
||||||
Ok(signature_store) => signature_store,
|
|
||||||
// return the prev data in case of errors
|
|
||||||
Err(error) => return Err(farewell::from_uncatchable_error(raw_prev_data, error)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let PreparationDescriptor {
|
let PreparationDescriptor {
|
||||||
mut exec_ctx,
|
mut exec_ctx,
|
||||||
mut trace_handler,
|
mut trace_handler,
|
||||||
air,
|
air,
|
||||||
keypair,
|
keypair,
|
||||||
} = match prepare(
|
} = farewell_if_fail!(
|
||||||
prev_data,
|
prepare(prev_data, current_data, &air, &call_results, params, signature_store,),
|
||||||
current_data,
|
raw_prev_data
|
||||||
air.as_str(),
|
);
|
||||||
&call_results,
|
|
||||||
params,
|
|
||||||
signature_store,
|
|
||||||
) {
|
|
||||||
Ok(descriptor) => descriptor,
|
|
||||||
// return the prev data in case of errors
|
|
||||||
Err(error) => return Err(farewell::from_uncatchable_error(raw_prev_data, error)),
|
|
||||||
};
|
|
||||||
|
|
||||||
// match here is used instead of map_err, because the compiler can't determine that
|
// match here is used instead of map_err, because the compiler can't determine that
|
||||||
// they are exclusive and would treat exec_ctx and trace_handler as moved
|
// they are exclusive and would treat exec_ctx and trace_handler as moved
|
||||||
@ -103,15 +88,15 @@ fn execute_air_impl(
|
|||||||
"execute",
|
"execute",
|
||||||
);
|
);
|
||||||
|
|
||||||
match sign_produced_cids(
|
farewell_if_fail!(
|
||||||
&mut exec_ctx.peer_cid_tracker,
|
sign_produced_cids(
|
||||||
&mut exec_ctx.signature_store,
|
&mut exec_ctx.peer_cid_tracker,
|
||||||
&salt,
|
&mut exec_ctx.signature_store,
|
||||||
&keypair,
|
&salt,
|
||||||
) {
|
&keypair,
|
||||||
Ok(()) => {}
|
),
|
||||||
Err(error) => return Err(farewell::from_uncatchable_error(raw_prev_data, error)),
|
raw_prev_data
|
||||||
}
|
);
|
||||||
|
|
||||||
measure!(
|
measure!(
|
||||||
match exec_result {
|
match exec_result {
|
||||||
|
@ -48,3 +48,14 @@ macro_rules! auto_checked_add {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! farewell_if_fail {
|
||||||
|
($cmd:expr, $raw_prev_data:expr) => {
|
||||||
|
match $cmd {
|
||||||
|
Ok(result) => result,
|
||||||
|
// return the prev data in case of errors
|
||||||
|
Err(error) => return Err(farewell::from_uncatchable_error($raw_prev_data, error)),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user