Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: debug assert reservation states in process_success #3966

Merged
merged 11 commits into from
Aug 1, 2024
1 change: 1 addition & 0 deletions core-processor/src/precharge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ pub fn precharge_for_code_length(
return Err(process_success(
SuccessfulDispatchResultKind::Success,
DispatchResult::success(dispatch, destination_id, gas_counter.to_amount()),
None
));
}

Expand Down
17 changes: 14 additions & 3 deletions core-processor/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ where
res.system_reservation_context,
ActorExecutionErrorReplyReason::Trap(reason),
),
DispatchResultKind::Success => process_success(Success, res),
DispatchResultKind::Success => process_success(Success, res, Some(system_reservation_ctx)),
playX18 marked this conversation as resolved.
Show resolved Hide resolved
DispatchResultKind::Wait(duration, ref waited_type) => {
process_success(Wait(duration, waited_type.clone()), res)
process_success(Wait(duration, waited_type.clone()), res, Some(system_reservation_ctx))
}
DispatchResultKind::Exit(value_destination) => {
process_success(Exit(value_destination), res)
process_success(Exit(value_destination), res, Some(system_reservation_ctx))
}
DispatchResultKind::GasAllowanceExceed => {
process_allowance_exceed(dispatch, program_id, res.gas_amount.burned())
Expand Down Expand Up @@ -365,7 +365,18 @@ pub fn process_non_executable(
pub fn process_success(
kind: SuccessfulDispatchResultKind,
dispatch_result: DispatchResult,
system_reservation_ctx: Option<SystemReservationContext>
) -> Vec<JournalNote> {

if let Some(system_reservation_ctx) = system_reservation_ctx {
if let (Some(current_prev), Some(current_res)) = (system_reservation_ctx.current_reservation, dispatch_result.system_reservation_context.current_reservation) {
debug_assert!(current_res <= current_prev);
}
if let (Some(prev_reservation), Some(prev_res)) = (system_reservation_ctx.previous_reservation, dispatch_result.system_reservation_context.previous_reservation) {
debug_assert!(prev_res <= prev_reservation);
}
}

use crate::precharge::SuccessfulDispatchResultKind::*;

let DispatchResult {
Expand Down
2 changes: 1 addition & 1 deletion pallets/gear-builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<T: Config> BuiltinDispatcher for BuiltinRegistry<T> {
};

// Using the core processor logic create necessary `JournalNote`'s for us.
process_success(SuccessfulDispatchResultKind::Success, dispatch_result)
process_success(SuccessfulDispatchResultKind::Success, dispatch_result, None)
}
Err(err) => {
// Builtin actor call failed.
Expand Down
Loading