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

Make HoldBound errors reachable #1276

Merged
merged 7 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pallets/gear/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,11 @@ where

// Validating duration.
if hold.expected_duration().is_zero() {
unreachable!("Failed to figure out correct wait hold bound");
// TODO: Replace with unreachable call after:
// - `HoldBound` safety usage stabilized;
// - Issue #1173 solved.
log::error!("Failed to figure out correct wait hold bound");
return;
techraed marked this conversation as resolved.
Show resolved Hide resolved
}

// Querying origin message id. Fails in cases of `GasTree` invalidations.
Expand Down
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
18 changes: 18 additions & 0 deletions pallets/gear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3896,6 +3896,24 @@ fn test_reply_to_terminated_program() {
})
}

#[test]
breathx marked this conversation as resolved.
Show resolved Hide resolved
fn calculate_gas_info_for_wait_dispatch_works() {
init_logger();
new_test_ext().execute_with(|| {
// Test should still be valid once #1173 solved.
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);
});
}

#[test]
fn cascading_messages_with_value_do_not_overcharge() {
init_logger();
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("gear-node"),
apis: RUNTIME_API_VERSIONS,
authoring_version: 1,
spec_version: 1480,
spec_version: 1490,
impl_version: 1,
transaction_version: 1,
state_version: 1,
Expand Down