Skip to content

Commit

Permalink
remove rent logic from core-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gshep committed Dec 14, 2023
1 parent bb3b52c commit c3341a4
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 392 deletions.
14 changes: 0 additions & 14 deletions core-processor/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeId, Vec<(MessageId, ProgramId)>>,
/// Map of program ids to paid blocks.
pub program_rents: BTreeMap<ProgramId, u32>,
/// Gas amount after execution.
pub gas_amount: GasAmount,
/// Gas amount programs reserved.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions core-processor/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>, u32),
/// Rent cost per block.
pub rent_cost: u128,
/// Gas multiplier.
pub gas_multiplier: gsys::GasMultiplier,
}
Expand Down Expand Up @@ -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,
}
5 changes: 0 additions & 5 deletions core-processor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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),
};

Expand Down
9 changes: 0 additions & 9 deletions core-processor/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CodeId, Vec<(MessageId, ProgramId)>>,
/// Map of program ids to paid blocks.
pub program_rents: BTreeMap<ProgramId, u32>,
/// Weights of host functions.
pub host_fn_weights: HostFnWeights,
/// Functions forbidden to be called.
Expand All @@ -108,8 +106,6 @@ pub struct ProcessorContext {
pub reservation: u64,
/// Output from Randomness.
pub random_data: (Vec<u8>, u32),
/// Rent cost per block.
pub rent_cost: u128,
/// Gas multiplier.
pub gas_multiplier: gsys::GasMultiplier,
}
Expand Down Expand Up @@ -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,
Expand All @@ -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),
}
}
Expand All @@ -173,7 +167,6 @@ pub struct ExtInfo {
pub awakening: Vec<(MessageId, u32)>,
pub reply_deposits: Vec<(MessageId, u64)>,
pub program_candidates_data: BTreeMap<CodeId, Vec<(MessageId, ProgramId)>>,
pub program_rents: BTreeMap<ProgramId, u32>,
pub context_store: ContextStore,
}

Expand Down Expand Up @@ -382,7 +375,6 @@ impl ProcessorExternalities for Ext {
gas_reserver,
system_reservation,
program_candidates_data,
program_rents,
..
} = self.context;

Expand Down Expand Up @@ -433,7 +425,6 @@ impl ProcessorExternalities for Ext {
reply_deposits,
context_store,
program_candidates_data,
program_rents,
};
Ok(info)
}
Expand Down
5 changes: 0 additions & 5 deletions core-processor/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions core-processor/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ where
reserve_for,
reservation,
write_cost,
rent_cost,
gas_multiplier,
..
} = block_config.clone();
Expand All @@ -89,7 +88,6 @@ where
reserve_for,
reservation,
random_data,
rent_cost,
gas_multiplier,
};

Expand Down Expand Up @@ -287,7 +285,6 @@ pub fn process_success(
generated_dispatches,
awakening,
program_candidates,
program_rents,
gas_amount,
gas_reserver,
system_reservation_context,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions gtest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 1 addition & 5 deletions gtest/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -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),
};

Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions pallets/gear/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fn default_processor_context<T: Config>() -> 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,
Expand All @@ -197,7 +196,6 @@ fn default_processor_context<T: Config>() -> 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),
}
}
Expand Down
34 changes: 2 additions & 32 deletions pallets/gear/src/benchmarking/tests/syscalls_integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
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};
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<T>()
Expand Down Expand Up @@ -192,40 +191,11 @@ where
SyscallName::ReservationReply => check_gr_reservation_reply::<T>(),
SyscallName::ReservationReplyCommit => check_gr_reservation_reply_commit::<T>(),
SyscallName::SystemReserveGas => check_gr_system_reserve_gas::<T>(),
SyscallName::PayProgramRent => check_gr_pay_program_rent::<T>(),
SyscallName::PayProgramRent => { /*no need for tests */ }
}
});
}

fn check_gr_pay_program_rent<T>()
where
T: Config,
T::AccountId: Origin,
{
run_tester::<T, _, _, T::AccountId>(|tester_pid, _| {
let default_account = utils::default_account();
CurrencyOf::<T>::deposit_creating(
&default_account,
100_000_000_000_000_u128.unique_saturated_into(),
);

let block_count = 10;
let unused_rent: BalanceOf<T> = 1u32.into();
let rent = RentCostPerBlockOf::<T>::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::<DefaultPostCheck>)
});
}

fn check_gr_system_reserve_gas<T>()
where
T: Config,
Expand Down
3 changes: 1 addition & 2 deletions pallets/gear/src/benchmarking/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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::<T>::get().unique_saturated_into(),
gas_multiplier: <T as pallet_gear_bank::Config>::GasMultiplier::get().into(),
}
}
Expand Down
Loading

0 comments on commit c3341a4

Please sign in to comment.