Skip to content

Commit

Permalink
Add waited flag to GasInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Aug 2, 2022
1 parent b65cd12 commit da09d8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions pallets/gear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ pub struct GasInfo {
pub reserved: u64,
/// Contains number of gas burned during message processing.
pub burned: u64,
/// The value may be returned if a program happens to be executed the second or next time in a block.
/// The value may be returned if a program happens to be executed
/// the second or next time in a block.
pub may_be_returned: u64,
/// Was the message placed into waitlist at the end of calculating.
///
/// This flag shows, that `min_limit` makes sense and have some guarantees
/// only before insertion into waitlist.
pub waited: bool,
}

#[frame_support::pallet]
Expand Down Expand Up @@ -618,7 +624,9 @@ pub mod pallet {
value: u128,
allow_other_panics: bool,
) -> Result<GasInfo, String> {
let GasInfo { min_limit, .. } = Self::run_with_ext_copy(|| {
let GasInfo {
min_limit, waited, ..
} = Self::run_with_ext_copy(|| {
let initial_gas = BlockGasLimitOf::<T>::get();
Self::calculate_gas_info_impl(
source,
Expand Down Expand Up @@ -654,6 +662,7 @@ pub mod pallet {
reserved,
burned,
may_be_returned,
waited,
},
)
.map_err(|e| {
Expand Down Expand Up @@ -914,11 +923,14 @@ pub mod pallet {
}
}

let waited = WaitlistOf::<T>::contains(&main_program_id, &main_message_id);

Ok(GasInfo {
min_limit,
reserved,
burned,
may_be_returned,
waited,
})
}

Expand Down
4 changes: 3 additions & 1 deletion pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3901,14 +3901,16 @@ fn calculate_gas_info_for_wait_dispatch_works() {
init_logger();
new_test_ext().execute_with(|| {
// Test should still be valid once #1173 solved.
let _ = Gear::calculate_gas_info(
let GasInfo { waited, .. } = Gear::calculate_gas_info(
USER_1.into_origin(),
HandleKind::Init(demo_init_wait::WASM_BINARY.to_vec()),
EMPTY_PAYLOAD.to_vec(),
0,
true,
)
.unwrap();

assert!(waited);
});
}

Expand Down

0 comments on commit da09d8c

Please sign in to comment.