diff --git a/core-processor/src/common.rs b/core-processor/src/common.rs index 26db8af94c5..6ec99100eb6 100644 --- a/core-processor/src/common.rs +++ b/core-processor/src/common.rs @@ -79,8 +79,6 @@ pub struct DispatchResult { pub reply_deposits: Vec<(MessageId, u64)>, /// New programs to be created with additional data (corresponding code hash and init message id). pub program_candidates: BTreeMap>, - /// Map of program ids to paid blocks. - pub program_rents: BTreeMap, /// Gas amount after execution. pub gas_amount: GasAmount, /// Gas amount programs reserved. @@ -132,7 +130,6 @@ impl DispatchResult { awakening: Default::default(), reply_deposits: Default::default(), program_candidates: Default::default(), - program_rents: Default::default(), gas_amount, gas_reserver: None, system_reservation_context, @@ -331,15 +328,6 @@ pub enum JournalNote { /// Simple signal error. code: SignalCode, }, - /// Pay rent for the program. - PayProgramRent { - /// Rent payer. - payer: ProgramId, - /// Program whose rent will be paid. - program_id: ProgramId, - /// Amount of blocks to pay for. - block_count: u32, - }, /// Create deposit for future reply. ReplyDeposit { /// Message id of the message that generated this message. @@ -429,8 +417,6 @@ pub trait JournalHandler { fn system_unreserve_gas(&mut self, message_id: MessageId); /// Send system signal. fn send_signal(&mut self, message_id: MessageId, destination: ProgramId, code: SignalCode); - /// Pay rent for the program. - fn pay_program_rent(&mut self, payer: ProgramId, program_id: ProgramId, block_count: u32); /// Create deposit for future reply. fn reply_deposit(&mut self, message_id: MessageId, future_reply_id: MessageId, amount: u64); } diff --git a/core-processor/src/configs.rs b/core-processor/src/configs.rs index 11c7f9724fc..b1ea8bc62c4 100644 --- a/core-processor/src/configs.rs +++ b/core-processor/src/configs.rs @@ -169,8 +169,6 @@ pub struct ExecutionSettings { /// Most recently determined random seed, along with the time in the past since when it was determinable by chain observers. // TODO: find a way to put a random seed inside block config. pub random_data: (Vec, u32), - /// Rent cost per block. - pub rent_cost: u128, /// Gas multiplier. pub gas_multiplier: gsys::GasMultiplier, } @@ -220,8 +218,6 @@ pub struct BlockConfig { pub code_instrumentation_cost: u64, /// WASM code instrumentation per-byte cost. pub code_instrumentation_byte_cost: u64, - /// Rent cost per block. - pub rent_cost: u128, /// Gas multiplier. pub gas_multiplier: gsys::GasMultiplier, } diff --git a/core-processor/src/executor.rs b/core-processor/src/executor.rs index 35069e56a95..a9811d05781 100644 --- a/core-processor/src/executor.rs +++ b/core-processor/src/executor.rs @@ -214,7 +214,6 @@ where existential_deposit: settings.existential_deposit, program_id, program_candidates_data: Default::default(), - program_rents: Default::default(), host_fn_weights: settings.host_fn_weights, forbidden_funcs: settings.forbidden_funcs, mailbox_threshold: settings.mailbox_threshold, @@ -223,7 +222,6 @@ where reserve_for: settings.reserve_for, reservation: settings.reservation, random_data: settings.random_data, - rent_cost: settings.rent_cost, gas_multiplier: settings.gas_multiplier, }; @@ -338,7 +336,6 @@ where awakening: info.awakening, reply_deposits: info.reply_deposits, program_candidates, - program_rents: info.program_rents, gas_amount: info.gas_amount, gas_reserver: Some(info.gas_reserver), system_reservation_context: info.system_reservation_context, @@ -412,7 +409,6 @@ where existential_deposit: Default::default(), program_id: program.id(), program_candidates_data: Default::default(), - program_rents: Default::default(), host_fn_weights: Default::default(), forbidden_funcs: Default::default(), mailbox_threshold: Default::default(), @@ -422,7 +418,6 @@ where reservation: Default::default(), random_data: Default::default(), system_reservation: Default::default(), - rent_cost: Default::default(), gas_multiplier: gsys::GasMultiplier::from_value_per_gas(1), }; diff --git a/core-processor/src/ext.rs b/core-processor/src/ext.rs index 155e76fa0f8..16801ee4cce 100644 --- a/core-processor/src/ext.rs +++ b/core-processor/src/ext.rs @@ -90,8 +90,6 @@ pub struct ProcessorContext { /// Map of code hashes to program ids of future programs, which are planned to be /// initialized with the corresponding code (with the same code hash). pub program_candidates_data: BTreeMap>, - /// Map of program ids to paid blocks. - pub program_rents: BTreeMap, /// Weights of host functions. pub host_fn_weights: HostFnWeights, /// Functions forbidden to be called. @@ -108,8 +106,6 @@ pub struct ProcessorContext { pub reservation: u64, /// Output from Randomness. pub random_data: (Vec, u32), - /// Rent cost per block. - pub rent_cost: u128, /// Gas multiplier. pub gas_multiplier: gsys::GasMultiplier, } @@ -147,7 +143,6 @@ impl ProcessorContext { existential_deposit: 0, program_id: Default::default(), program_candidates_data: Default::default(), - program_rents: Default::default(), host_fn_weights: Default::default(), forbidden_funcs: Default::default(), mailbox_threshold: 0, @@ -156,7 +151,6 @@ impl ProcessorContext { reserve_for: 0, reservation: 0, random_data: ([0u8; 32].to_vec(), 0), - rent_cost: 0, gas_multiplier: gsys::GasMultiplier::from_value_per_gas(1), } } @@ -173,7 +167,6 @@ pub struct ExtInfo { pub awakening: Vec<(MessageId, u32)>, pub reply_deposits: Vec<(MessageId, u64)>, pub program_candidates_data: BTreeMap>, - pub program_rents: BTreeMap, pub context_store: ContextStore, } @@ -382,7 +375,6 @@ impl ProcessorExternalities for Ext { gas_reserver, system_reservation, program_candidates_data, - program_rents, .. } = self.context; @@ -433,7 +425,6 @@ impl ProcessorExternalities for Ext { reply_deposits, context_store, program_candidates_data, - program_rents, }; Ok(info) } diff --git a/core-processor/src/handler.rs b/core-processor/src/handler.rs index 5a208f21e37..694ed70617a 100644 --- a/core-processor/src/handler.rs +++ b/core-processor/src/handler.rs @@ -108,11 +108,6 @@ pub fn handle_journal( destination, code, } => handler.send_signal(message_id, destination, code), - JournalNote::PayProgramRent { - payer, - program_id, - block_count, - } => handler.pay_program_rent(payer, program_id, block_count), JournalNote::ReplyDeposit { message_id, future_reply_id, diff --git a/core-processor/src/processing.rs b/core-processor/src/processing.rs index 14a8e47c06c..09e67142957 100644 --- a/core-processor/src/processing.rs +++ b/core-processor/src/processing.rs @@ -70,7 +70,6 @@ where reserve_for, reservation, write_cost, - rent_cost, gas_multiplier, .. } = block_config.clone(); @@ -89,7 +88,6 @@ where reserve_for, reservation, random_data, - rent_cost, gas_multiplier, }; @@ -287,7 +285,6 @@ pub fn process_success( generated_dispatches, awakening, program_candidates, - program_rents, gas_amount, gas_reserver, system_reservation_context, @@ -385,16 +382,6 @@ pub fn process_success( }); } - // Must be handled after processing programs creation. - let payer = program_id; - for (program_id, block_count) in program_rents { - journal.push(JournalNote::PayProgramRent { - payer, - program_id, - block_count, - }); - } - for (message_id_sent, amount) in reply_deposits { journal.push(JournalNote::ReplyDeposit { message_id, diff --git a/gtest/src/lib.rs b/gtest/src/lib.rs index 40fab30a57a..40def872acb 100644 --- a/gtest/src/lib.rs +++ b/gtest/src/lib.rs @@ -489,10 +489,6 @@ pub mod constants { pub const RESERVATION_COST: Gas = 100; /// Cost of storing delayed message per block. pub const DISPATCH_HOLD_COST: Gas = 100; - /// Cost of storing program per block. - /// - /// (!) Currently disabled: storing programs are free. - pub const RENT_COST: Value = 330; /* Execution-related constants */ // TODO: use proper weights of instantiation and instrumentation (#3509). diff --git a/gtest/src/manager.rs b/gtest/src/manager.rs index 366d6836464..98c7c680ac4 100644 --- a/gtest/src/manager.rs +++ b/gtest/src/manager.rs @@ -22,8 +22,7 @@ use crate::{ Result, TestError, DISPATCH_HOLD_COST, EPOCH_DURATION_IN_BLOCKS, EXISTENTIAL_DEPOSIT, INITIAL_RANDOM_SEED, MAILBOX_THRESHOLD, MAX_RESERVATIONS, MODULE_INSTANTIATION_BYTE_COST, MODULE_INSTRUMENTATION_BYTE_COST, MODULE_INSTRUMENTATION_COST, READ_COST, READ_PER_BYTE_COST, - RENT_COST, RESERVATION_COST, RESERVE_FOR, VALUE_PER_GAS, WAITLIST_COST, WRITE_COST, - WRITE_PER_BYTE_COST, + RESERVATION_COST, RESERVE_FOR, VALUE_PER_GAS, WAITLIST_COST, WRITE_COST, WRITE_PER_BYTE_COST, }; use core_processor::{ common::*, @@ -847,7 +846,6 @@ impl ExtManager { max_reservations: MAX_RESERVATIONS, code_instrumentation_cost: MODULE_INSTRUMENTATION_COST, code_instrumentation_byte_cost: MODULE_INSTRUMENTATION_BYTE_COST, - rent_cost: RENT_COST, gas_multiplier: gsys::GasMultiplier::from_value_per_gas(VALUE_PER_GAS), }; @@ -1180,8 +1178,6 @@ impl JournalHandler for ExtManager { fn send_signal(&mut self, _message_id: MessageId, _destination: ProgramId, _code: SignalCode) {} - fn pay_program_rent(&mut self, _payer: ProgramId, _program_id: ProgramId, _block_count: u32) {} - fn reply_deposit(&mut self, _message_id: MessageId, future_reply_id: MessageId, amount: u64) { self.gas_limits.insert(future_reply_id, amount); } diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index 3ed70dc675e..d591daa532a 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -188,7 +188,6 @@ fn default_processor_context() -> ProcessorContext { existential_deposit: 42, program_id: Default::default(), program_candidates_data: Default::default(), - program_rents: Default::default(), host_fn_weights: Default::default(), forbidden_funcs: Default::default(), mailbox_threshold: 500, @@ -197,7 +196,6 @@ fn default_processor_context() -> ProcessorContext { reserve_for: 0, reservation: 0, random_data: ([0u8; 32].to_vec(), 0), - rent_cost: 0, gas_multiplier: gsys::GasMultiplier::from_value_per_gas(30), } } diff --git a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs index 379734d72c1..571d26e4534 100644 --- a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs +++ b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs @@ -29,7 +29,7 @@ use super::*; -use crate::{BlockGasLimitOf, CurrencyOf, Event, RentCostPerBlockOf, String, WaitlistOf}; +use crate::{BlockGasLimitOf, CurrencyOf, Event, String, WaitlistOf}; use common::event::DispatchStatus; use frame_support::traits::Randomness; use gear_core::ids::{CodeId, ReservationId}; @@ -37,7 +37,6 @@ use gear_core_errors::{ReplyCode, SuccessReplyReason}; use gear_wasm_instrument::syscalls::SyscallName; use pallet_timestamp::Pallet as TimestampPallet; use parity_scale_codec::Decode; -use sp_runtime::SaturatedConversion; use test_syscalls::{Kind, WASM_BINARY as SYSCALLS_TEST_WASM_BINARY}; pub fn read_big_state() @@ -192,40 +191,11 @@ where SyscallName::ReservationReply => check_gr_reservation_reply::(), SyscallName::ReservationReplyCommit => check_gr_reservation_reply_commit::(), SyscallName::SystemReserveGas => check_gr_system_reserve_gas::(), - SyscallName::PayProgramRent => check_gr_pay_program_rent::(), + SyscallName::PayProgramRent => { /*no need for tests */ } } }); } -fn check_gr_pay_program_rent() -where - T: Config, - T::AccountId: Origin, -{ - run_tester::(|tester_pid, _| { - let default_account = utils::default_account(); - CurrencyOf::::deposit_creating( - &default_account, - 100_000_000_000_000_u128.unique_saturated_into(), - ); - - let block_count = 10; - let unused_rent: BalanceOf = 1u32.into(); - let rent = RentCostPerBlockOf::::get() * block_count.into() + unused_rent; - let mp = MessageParamsBuilder::new( - vec![Kind::PayProgramRent( - tester_pid.into_origin().into(), - rent.saturated_into(), - Some((unused_rent.saturated_into(), block_count)), - )] - .encode(), - ) - .with_value(50_000_000_000_000); - - (TestCall::send_message(mp), None::) - }); -} - fn check_gr_system_reserve_gas() where T: Config, diff --git a/pallets/gear/src/benchmarking/utils.rs b/pallets/gear/src/benchmarking/utils.rs index e17a4e5c9f1..0a569512727 100644 --- a/pallets/gear/src/benchmarking/utils.rs +++ b/pallets/gear/src/benchmarking/utils.rs @@ -22,7 +22,7 @@ use super::Exec; use crate::{ manager::{CodeInfo, ExtManager, HandleKind}, Config, CostsPerBlockOf, CurrencyOf, DbWeightOf, MailboxOf, Pallet as Gear, ProgramStorageOf, - QueueOf, RentCostPerBlockOf, + QueueOf, }; use common::{scheduler::SchedulingCostsPerBlock, storage::*, CodeStorage, Origin, ProgramStorage}; use core_processor::{ @@ -83,7 +83,6 @@ where max_reservations: T::ReservationsLimit::get(), code_instrumentation_cost: schedule.code_instrumentation_cost.ref_time(), code_instrumentation_byte_cost: schedule.code_instrumentation_byte_cost.ref_time(), - rent_cost: RentCostPerBlockOf::::get().unique_saturated_into(), gas_multiplier: ::GasMultiplier::get().into(), } } diff --git a/pallets/gear/src/internal.rs b/pallets/gear/src/internal.rs index af4cc41d665..12edb521b9d 100644 --- a/pallets/gear/src/internal.rs +++ b/pallets/gear/src/internal.rs @@ -19,21 +19,21 @@ //! Internal details of Gear Pallet implementation. use crate::{ - Authorship, Config, CostsPerBlockOf, CurrencyOf, DispatchStashOf, Event, ExtManager, - GasBalanceOf, GasHandlerOf, GasNodeIdOf, GearBank, MailboxOf, Pallet, QueueOf, - SchedulingCostOf, TaskPoolOf, WaitlistOf, + Config, CostsPerBlockOf, CurrencyOf, DispatchStashOf, Event, ExtManager, GasBalanceOf, + GasHandlerOf, GasNodeIdOf, GearBank, MailboxOf, Pallet, QueueOf, SchedulingCostOf, TaskPoolOf, + WaitlistOf, }; use alloc::collections::BTreeSet; use common::{ event::{ MessageWaitedReason, MessageWaitedRuntimeReason::*, - MessageWaitedSystemReason::ProgramIsNotInitialized, MessageWokenReason, ProgramChangeKind, - Reason::*, UserMessageReadReason, + MessageWaitedSystemReason::ProgramIsNotInitialized, MessageWokenReason, Reason::*, + UserMessageReadReason, }, gas_provider::{GasNodeId, Imbalance}, scheduler::*, storage::*, - ActiveProgram, GasTree, LockId, LockableTree, Origin, + GasTree, LockId, LockableTree, Origin, }; use core::cmp::{Ord, Ordering}; use core_processor::common::ActorExecutionErrorReplyReason; @@ -46,12 +46,7 @@ use gear_core::{ UserStoredMessage, }, }; -use sp_runtime::{ - traits::{ - Bounded, CheckedAdd, Get, One, SaturatedConversion, Saturating, UniqueSaturatedInto, Zero, - }, - DispatchError, -}; +use sp_runtime::traits::{Get, One, SaturatedConversion, Saturating, UniqueSaturatedInto, Zero}; /// [`HoldBound`] builder #[derive(Clone, Debug)] @@ -950,58 +945,6 @@ where inheritor } - pub(crate) fn pay_program_rent_impl( - program_id: ProgramId, - program: &mut ActiveProgram>, - from: &T::AccountId, - block_count: BlockNumberFor, - ) -> Result<(), DispatchError> { - if !::ProgramRentEnabled::get() { - return Ok(()); - } - - let old_expiration_block = program.expiration_block; - let (new_expiration_block, blocks_to_pay) = old_expiration_block - .checked_add(&block_count) - .map(|count| (count, block_count)) - .unwrap_or_else(|| { - let max = BlockNumberFor::::max_value(); - - (max, max - old_expiration_block) - }); - - if blocks_to_pay.is_zero() { - return Ok(()); - } - - let block_author = Authorship::::author() - .unwrap_or_else(|| unreachable!("Failed to find block author!")); - CurrencyOf::::transfer( - from, - &block_author, - Self::rent_fee_for(blocks_to_pay), - ExistenceRequirement::AllowDeath, - )?; - - let task = ScheduledTask::PauseProgram(program_id); - TaskPoolOf::::delete(old_expiration_block, task.clone()) - .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); - - program.expiration_block = new_expiration_block; - - TaskPoolOf::::add(new_expiration_block, task) - .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); - - Self::deposit_event(Event::ProgramChanged { - id: program_id, - change: ProgramChangeKind::ExpirationChanged { - expiration: new_expiration_block, - }, - }); - - Ok(()) - } - /// This fn and [`split_with_value`] works the same: they call api of gas /// handler to split (optionally with value) for all cases except reply /// sent and contains deposit in storage. diff --git a/pallets/gear/src/lib.rs b/pallets/gear/src/lib.rs index 311262c084e..a7d84d91191 100644 --- a/pallets/gear/src/lib.rs +++ b/pallets/gear/src/lib.rs @@ -113,10 +113,6 @@ pub type GasNodeIdOf = as GasTree>::NodeId; pub type BlockGasLimitOf = <::BlockLimiter as BlockLimiter>::BlockGasLimit; pub type GasBalanceOf = <::GasProvider as GasProvider>::Balance; pub type ProgramStorageOf = ::ProgramStorage; -pub type RentFreePeriodOf = ::ProgramRentFreePeriod; -pub type RentCostPerBlockOf = ::ProgramRentCostPerBlock; -pub type ResumeMinimalPeriodOf = ::ProgramResumeMinimalRentPeriod; -pub type ResumeSessionDurationOf = ::ProgramResumeSessionDuration; pub(crate) type VoucherOf = ::Voucher; pub(crate) type GearBank = pallet_gear_bank::Pallet; @@ -619,7 +615,7 @@ pub mod pallet { program_id, &code_info, message_id, - block_number.saturating_add(RentFreePeriodOf::::get()), + block_number, ); Self::create( @@ -1047,7 +1043,6 @@ pub mod pallet { max_reservations: T::ReservationsLimit::get(), code_instrumentation_cost: schedule.code_instrumentation_cost.ref_time(), code_instrumentation_byte_cost: schedule.code_instrumentation_byte_cost.ref_time(), - rent_cost: RentCostPerBlockOf::::get().unique_saturated_into(), gas_multiplier: ::GasMultiplier::get().into(), } } @@ -1205,20 +1200,19 @@ pub mod pallet { let message_id = Self::next_message_id(origin); let block_number = Self::block_number(); - let expiration_block = block_number.saturating_add(RentFreePeriodOf::::get()); ExtManager::::default().set_program( packet.destination(), &code_info, message_id, - expiration_block, + block_number, ); let program_id = packet.destination(); let program_event = Event::ProgramChanged { id: program_id, change: ProgramChangeKind::ProgramSet { - expiration: expiration_block, + expiration: block_number, }, }; @@ -1242,10 +1236,6 @@ pub mod pallet { QueueOf::::queue(dispatch) .unwrap_or_else(|e| unreachable!("Messages storage corrupted: {e:?}")); - let task = ScheduledTask::PauseProgram(program_id); - TaskPoolOf::::add(expiration_block, task) - .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); - Self::deposit_event(program_event); Self::deposit_event(event); @@ -1255,12 +1245,6 @@ pub mod pallet { pub fn run_call(max_gas: Option>) -> Call { Call::run { max_gas } } - - pub fn rent_fee_for(block_count: BlockNumberFor) -> BalanceOf { - let block_count: u64 = block_count.unique_saturated_into(); - - RentCostPerBlockOf::::get().saturating_mul(block_count.unique_saturated_into()) - } } #[pallet::call] diff --git a/pallets/gear/src/manager/journal.rs b/pallets/gear/src/manager/journal.rs index 6bbd2c5f566..b257d8237fe 100644 --- a/pallets/gear/src/manager/journal.rs +++ b/pallets/gear/src/manager/journal.rs @@ -20,7 +20,7 @@ use crate::{ internal::HoldBoundBuilder, manager::{CodeInfo, ExtManager}, Config, Event, GasAllowanceOf, GasHandlerOf, GasTree, GearBank, Pallet, ProgramStorageOf, - QueueOf, RentFreePeriodOf, TaskPoolOf, WaitlistOf, + QueueOf, TaskPoolOf, WaitlistOf, }; use common::{ event::*, @@ -39,7 +39,6 @@ use gear_core::{ reservation::GasReserver, }; use gear_core_errors::SignalCode; -use sp_core::Get as _; use sp_runtime::traits::{UniqueSaturatedInto, Zero}; use sp_std::{ collections::{btree_map::BTreeMap, btree_set::BTreeSet}, @@ -389,18 +388,12 @@ where for (init_message, candidate_id) in candidates { if !Pallet::::program_exists(candidate_id) { let block_number = Pallet::::block_number(); - let expiration_block = - block_number.saturating_add(RentFreePeriodOf::::get()); - self.set_program(candidate_id, &code_info, init_message, expiration_block); - - let task = ScheduledTask::PauseProgram(candidate_id); - TaskPoolOf::::add(expiration_block, task) - .unwrap_or_else(|e| unreachable!("Scheduling logic invalidated! {:?}", e)); + self.set_program(candidate_id, &code_info, init_message, block_number); Pallet::::deposit_event(Event::ProgramChanged { id: candidate_id, change: ProgramChangeKind::ProgramSet { - expiration: expiration_block, + expiration: block_number, }, }); } else { @@ -537,21 +530,6 @@ where Self::send_signal(self, message_id, destination, code) } - fn pay_program_rent(&mut self, payer: ProgramId, program_id: ProgramId, block_count: u32) { - let from = payer.cast(); - let block_count = block_count.unique_saturated_into(); - - ProgramStorageOf::::update_active_program(program_id, |program| { - Pallet::::pay_program_rent_impl(program_id, program, &from, block_count) - .unwrap_or_else(|e| unreachable!("Failed to transfer value: {:?}", e)); - }) - .unwrap_or_else(|e| { - log::debug!( - "Could not update active program {program_id}: {e:?}. Program is not active?" - ); - }); - } - fn reply_deposit(&mut self, message_id: MessageId, future_reply_id: MessageId, amount: u64) { log::debug!("Creating reply deposit {amount} gas for message id {future_reply_id}"); diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index 1e957012787..ac04db4d966 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -50,8 +50,8 @@ use crate::{ ProgramStorageOf, QueueOf, Schedule, TaskPoolOf, WaitlistOf, }; use common::{ - event::*, scheduler::*, storage::*, ActiveProgram, CodeStorage, GasTree, LockId, LockableTree, - Origin as _, ProgramStorage, ReservableTree, + event::*, scheduler::*, storage::*, CodeStorage, GasTree, LockId, LockableTree, Origin as _, + ProgramStorage, ReservableTree, }; use core_processor::{common::ActorExecutionErrorReplyReason, ActorPrepareMemoryError}; use frame_support::{ @@ -6193,73 +6193,6 @@ fn terminated_locking_funds() { }); } -#[test] -fn pause_terminated_exited_program() { - use demo_constructor::{demo_exit_init, Calls, Scheme, WASM_BINARY}; - - let test = |program_id| { - let code_id = CodeId::generate(WASM_BINARY); - let program = ProgramStorageOf::::get_program(program_id) - .and_then(|p| ActiveProgram::try_from(p).ok()) - .expect("program should exist"); - let expected_block = program.expiration_block; - assert!(TaskPoolOf::::contains( - &expected_block, - &ScheduledTask::PauseProgram(program_id) - )); - - run_to_block(2, None); - - assert!(!Gear::is_active(program_id)); - assert!(!Gear::is_initialized(program_id)); - assert!(MailboxOf::::is_empty(&USER_1)); - assert!(!TaskPoolOf::::contains( - &expected_block, - &ScheduledTask::PauseProgram(program_id) - )); - - // Program is not removed and can't be submitted again - assert_noop!( - Gear::create_program( - RuntimeOrigin::signed(USER_1), - code_id, - DEFAULT_SALT.to_vec(), - Vec::new(), - 2_000_000_000, - 0u128, - false, - ), - Error::::ProgramAlreadyExists, - ); - }; - - new_test_ext().execute_with(|| { - // exit init - let (_, exited_pid) = - submit_constructor_with_args(USER_1, DEFAULT_SALT, demo_exit_init::scheme(false), 0); - - test(exited_pid); - }); - - new_test_ext().execute_with(|| { - // failed in init - let init = Calls::builder().panic("panicked in init"); - let (_, terminated_pid) = submit_constructor_with_args( - USER_1, - DEFAULT_SALT, - Scheme::predefined( - init, - Default::default(), - Default::default(), - Default::default(), - ), - 0, - ); - - test(terminated_pid); - }); -} - #[test] fn test_create_program_works() { use demo_init_wait::WASM_BINARY; @@ -13791,125 +13724,6 @@ fn test_send_to_terminated_from_program() { }) } -#[test] -fn pause_waited_uninited_program() { - use demo_init_wait::WASM_BINARY; - - init_logger(); - - // closure to get corresponding block numbers - let get_remove_block = |current_gas: u64| { - assert_ok!(Gear::upload_program( - RuntimeOrigin::signed(USER_1), - WASM_BINARY.to_vec(), - current_gas.to_le_bytes().to_vec(), - Vec::new(), - current_gas, - 0u128, - false, - )); - - let program_id = utils::get_last_program_id(); - - assert!(!Gear::is_initialized(program_id)); - assert!(Gear::is_active(program_id)); - - run_to_next_block(None); - - let (_, remove_from_waitlist_block) = get_last_message_waited(); - - let program = ProgramStorageOf::::get_program(program_id) - .and_then(|p| ActiveProgram::try_from(p).ok()) - .expect("program should exist"); - - (remove_from_waitlist_block, program.expiration_block) - }; - - // determine such gas value that init message will be removed - // from the waitlist before an execution of the PauseProgram task - let gas = new_test_ext().execute_with(|| { - let GasInfo { - waited: init_waited, - burned, - .. - } = Gear::calculate_gas_info( - USER_1.into_origin(), - HandleKind::Init(WASM_BINARY.to_vec()), - vec![], - 0, - true, - true, - ) - .expect("calculate_gas_info failed"); - - assert!(init_waited); - - let mut current_gas = 2 * burned; - - let (mut remove_from_waitlist_block, mut expiration_block) = get_remove_block(current_gas); - - while remove_from_waitlist_block >= expiration_block { - current_gas = (current_gas + burned) / 2; - - (remove_from_waitlist_block, expiration_block) = get_remove_block(current_gas); - } - - current_gas - }); - - new_test_ext().execute_with(|| { - assert_ok!(Gear::upload_program( - RuntimeOrigin::signed(USER_1), - WASM_BINARY.to_vec(), - vec![], - Vec::new(), - gas, - 0u128, - false, - )); - - let program_id = utils::get_last_program_id(); - - assert!(!Gear::is_initialized(program_id)); - assert!(Gear::is_active(program_id)); - - run_to_next_block(None); - - let (_, remove_from_waitlist_block) = get_last_message_waited(); - - let program = ProgramStorageOf::::get_program(program_id) - .and_then(|p| ActiveProgram::try_from(p).ok()) - .expect("program should exist"); - let expiration_block = program.expiration_block; - - assert!(TaskPoolOf::::contains( - &expiration_block, - &ScheduledTask::PauseProgram(program_id) - )); - - assert!(!Gear::is_initialized(program_id)); - assert!(Gear::is_active(program_id)); - - run_to_next_block(None); - - System::set_block_number(remove_from_waitlist_block - 1); - Gear::set_block_number(remove_from_waitlist_block - 1); - - run_to_next_block(None); - - assert!(Gear::is_terminated(program_id)); - assert!(!TaskPoolOf::::contains( - &expiration_block, - &ScheduledTask::PauseProgram(program_id) - )); - - System::set_block_number(expiration_block - 1); - Gear::set_block_number(expiration_block - 1); - - run_to_next_block(None); - }) -} - #[test] fn remove_from_waitlist_after_exit_reply() { use demo_constructor::demo_wait_init_exit_reply; diff --git a/utils/wasm-gen/src/tests.rs b/utils/wasm-gen/src/tests.rs index 567133a208a..9b2c96974db 100644 --- a/utils/wasm-gen/src/tests.rs +++ b/utils/wasm-gen/src/tests.rs @@ -406,7 +406,6 @@ fn execute_wasm_with_custom_configs( let processor_context = ProcessorContext { message_context, max_pages: INITIAL_PAGES.into(), - rent_cost: 10, program_id, ..ProcessorContext::new_mock() };