diff --git a/examples/binaries/gasless-wasting/build.rs b/examples/binaries/gasless-wasting/build.rs index 199b5faeeff..46e4671d74e 100644 --- a/examples/binaries/gasless-wasting/build.rs +++ b/examples/binaries/gasless-wasting/build.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/gasless-wasting/src/lib.rs b/examples/binaries/gasless-wasting/src/lib.rs index 48c991a9979..3189a782fcc 100644 --- a/examples/binaries/gasless-wasting/src/lib.rs +++ b/examples/binaries/gasless-wasting/src/lib.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/proxy-with-gas/build.rs b/examples/binaries/proxy-with-gas/build.rs index 199b5faeeff..46e4671d74e 100644 --- a/examples/binaries/proxy-with-gas/build.rs +++ b/examples/binaries/proxy-with-gas/build.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/proxy-with-gas/src/lib.rs b/examples/binaries/proxy-with-gas/src/lib.rs index 4e0142227d0..7acbd676bea 100644 --- a/examples/binaries/proxy-with-gas/src/lib.rs +++ b/examples/binaries/proxy-with-gas/src/lib.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/proxy/build.rs b/examples/binaries/proxy/build.rs index 199b5faeeff..46e4671d74e 100644 --- a/examples/binaries/proxy/build.rs +++ b/examples/binaries/proxy/build.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/proxy/src/lib.rs b/examples/binaries/proxy/src/lib.rs index f14cf230c0b..b855084dcc4 100644 --- a/examples/binaries/proxy/src/lib.rs +++ b/examples/binaries/proxy/src/lib.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/waiting-proxy/build.rs b/examples/binaries/waiting-proxy/build.rs index 199b5faeeff..46e4671d74e 100644 --- a/examples/binaries/waiting-proxy/build.rs +++ b/examples/binaries/waiting-proxy/build.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/examples/binaries/waiting-proxy/src/lib.rs b/examples/binaries/waiting-proxy/src/lib.rs index 121a6cfe108..5371be999bd 100644 --- a/examples/binaries/waiting-proxy/src/lib.rs +++ b/examples/binaries/waiting-proxy/src/lib.rs @@ -1,6 +1,6 @@ // This file is part of Gear. -// Copyright (C) 2021 Gear Technologies Inc. +// Copyright (C) 2022 Gear Technologies Inc. // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 // This program is free software: you can redistribute it and/or modify diff --git a/pallets/gear/src/internal.rs b/pallets/gear/src/internal.rs index 5a589029e0d..dee1fe4203a 100644 --- a/pallets/gear/src/internal.rs +++ b/pallets/gear/src/internal.rs @@ -323,7 +323,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; } // TODO: remove, once duration-control added inside programs (#1173). diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index 5008b503c4c..8ecf36fbbeb 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -124,8 +124,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] @@ -632,7 +638,10 @@ pub mod pallet { ) -> Result { log::debug!("\n===== CALCULATE GAS INFO =====\n"); log::debug!("\n--- FIRST TRY ---\n"); - let GasInfo { min_limit, .. } = Self::run_with_ext_copy(|| { + + let GasInfo { + min_limit, waited, .. + } = Self::run_with_ext_copy(|| { let initial_gas = BlockGasLimitOf::::get(); Self::calculate_gas_info_impl( source, @@ -670,6 +679,7 @@ pub mod pallet { reserved, burned, may_be_returned, + waited, }, ) .map_err(|e| { @@ -926,11 +936,14 @@ pub mod pallet { } } + let waited = WaitlistOf::::contains(&main_program_id, &main_message_id); + Ok(GasInfo { min_limit, reserved, burned, may_be_returned, + waited, }) } diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index d37d8ca1052..77c9c2b1dc0 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -1962,6 +1962,47 @@ fn claim_value_works() { }) } +#[test] +fn uninitialized_program_zero_gas() { + use demo_init_wait::WASM_BINARY; + + init_logger(); + new_test_ext().execute_with(|| { + System::reset_events(); + + assert_ok!(GearPallet::::upload_program( + Origin::signed(USER_1), + WASM_BINARY.to_vec(), + vec![], + Vec::new(), + 50_000_000_000u64, + 0u128 + )); + + let init_message_id = utils::get_last_message_id(); + let program_id = utils::get_last_program_id(); + + assert!(!Gear::is_initialized(program_id)); + assert!(!Gear::is_terminated(program_id)); + + run_to_block(2, None); + + assert!(!Gear::is_initialized(program_id)); + assert!(!Gear::is_terminated(program_id)); + assert!(WaitlistOf::::contains(&program_id, &init_message_id)); + + assert_ok!(GearPallet::::send_message( + Origin::signed(1), + program_id, + vec![], + 0, // that may trigger unreachable code + 0, + )); + + run_to_block(3, None); + }) +} + #[test] fn distributor_initialize() { init_logger(); @@ -4099,6 +4140,24 @@ fn test_reply_to_terminated_program() { }) } +#[test] +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(); diff --git a/runtime/gear/src/lib.rs b/runtime/gear/src/lib.rs index 54002770e6a..5ad3ecc512e 100644 --- a/runtime/gear/src/lib.rs +++ b/runtime/gear/src/lib.rs @@ -89,7 +89,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("gear-node"), apis: RUNTIME_API_VERSIONS, authoring_version: 1, - spec_version: 1580, + spec_version: 1590, impl_version: 1, transaction_version: 1, state_version: 1, diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index fcdc84bf3a0..e5639b46aa9 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -86,7 +86,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // The version of the runtime specification. A full node will not attempt to use its native // runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`, // `spec_version`, and `authoring_version` are the same between Wasm and native. - spec_version: 1580, + spec_version: 1590, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,