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

chore: Remove the current rent functionality #3590

Merged
merged 18 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
42 changes: 2 additions & 40 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 Expand Up @@ -1002,39 +993,10 @@ impl Externalities for Ext {

fn pay_program_rent(
&mut self,
program_id: ProgramId,
_program_id: ProgramId,
rent: u128,
) -> Result<(u128, u32), Self::FallibleError> {
if self.context.rent_cost == 0 {
return Ok((rent, 0));
}

let block_count = u32::try_from(rent / self.context.rent_cost).unwrap_or(u32::MAX);
let old_paid_blocks = self
.context
.program_rents
.get(&program_id)
.copied()
.unwrap_or(0);

let (paid_blocks, blocks_to_pay) = match old_paid_blocks.overflowing_add(block_count) {
(count, false) => (count, block_count),
(_, true) => return Err(ProgramRentError::MaximumBlockCountPaid.into()),
};

if blocks_to_pay == 0 {
return Ok((rent, 0));
}

let cost = self.context.rent_cost.saturating_mul(blocks_to_pay.into());
match self.context.value_counter.reduce(cost) {
ChargeResult::Enough => {
self.context.program_rents.insert(program_id, paid_blocks);
}
ChargeResult::NotEnough => return Err(FallibleExecutionError::NotEnoughValue.into()),
}

Ok((rent.saturating_sub(cost), blocks_to_pay))
Ok((rent, 0))
}

fn program_id(&self) -> Result<ProgramId, Self::UnrecoverableError> {
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
1 change: 1 addition & 0 deletions examples/syscalls/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn process(syscall_kind: Kind) {
let actual_mid: [u8; 32] = msg::id().into();
assert_eq!(expected_mid, actual_mid, "Kind::MessageId: mid test failed");
}
#[allow(deprecated)]
Kind::PayProgramRent(program_id, rent, expected) => {
let (unused_value, paid_block_count) = exec::pay_program_rent(program_id.into(), rent)
.expect(super::PAY_PROGRAM_RENT_EXPECT);
Expand Down
4 changes: 3 additions & 1 deletion gcore/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pub fn program_id() -> ActorId {
///
/// # Examples
///
/// ```
/// ```ignore
/// use gcore::exec;
///
/// #[no_mangle]
Expand All @@ -419,6 +419,8 @@ pub fn program_id() -> ActorId {
/// exec::pay_program_rent(exec::program_id(), 1_000_000).expect("Unable to pay rent");
/// }
/// ```
#[allow(warnings)]
#[deprecated = "Rent program logic is deprecated. The function is now a no-op and will be removed soon."]
pub fn pay_program_rent(program_id: ActorId, value: u128) -> Result<(u128, u32)> {
let rent_pid = HashWithValue {
hash: program_id.0,
Expand Down
36 changes: 0 additions & 36 deletions gsdk/src/metadata/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,34 +2141,6 @@ pub mod runtime_types {
#[codec(index = 7)]
#[doc = "See [`Pallet::set_execute_inherent`]."]
set_execute_inherent { value: ::core::primitive::bool },
#[codec(index = 8)]
#[doc = "See [`Pallet::pay_program_rent`]."]
pay_program_rent {
program_id: runtime_types::gear_core::ids::ProgramId,
block_count: ::core::primitive::u32,
},
#[codec(index = 9)]
#[doc = "See [`Pallet::resume_session_init`]."]
resume_session_init {
program_id: runtime_types::gear_core::ids::ProgramId,
allocations: ::std::vec::Vec<runtime_types::gear_core::pages::WasmPage>,
code_hash: runtime_types::gear_core::ids::CodeId,
},
#[codec(index = 10)]
#[doc = "See [`Pallet::resume_session_push`]."]
resume_session_push {
session_id: ::core::primitive::u32,
memory_pages: ::std::vec::Vec<(
runtime_types::gear_core::pages::GearPage,
runtime_types::gear_core::memory::PageBuf,
)>,
},
#[codec(index = 11)]
#[doc = "See [`Pallet::resume_session_commit`]."]
resume_session_commit {
session_id: ::core::primitive::u32,
block_count: ::core::primitive::u32,
},
}
#[derive(Debug, crate::gp::Decode, crate::gp::DecodeAsType, crate::gp::Encode)]
#[doc = "The `Error` enum of this pallet."]
Expand Down Expand Up @@ -7804,10 +7776,6 @@ pub mod calls {
ClaimValue,
Run,
SetExecuteInherent,
PayProgramRent,
ResumeSessionInit,
ResumeSessionPush,
ResumeSessionCommit,
}
impl CallInfo for GearCall {
const PALLET: &'static str = "Gear";
Expand All @@ -7821,10 +7789,6 @@ pub mod calls {
Self::ClaimValue => "claim_value",
Self::Run => "run",
Self::SetExecuteInherent => "set_execute_inherent",
Self::PayProgramRent => "pay_program_rent",
Self::ResumeSessionInit => "resume_session_init",
Self::ResumeSessionPush => "resume_session_push",
Self::ResumeSessionCommit => "resume_session_commit",
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion gstd/src/exec/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn wake_delayed(message_id: MessageId, delay: u32) -> Result<()> {
///
/// # Examples
///
/// ```
/// ```ignore
/// use gstd::exec;
///
/// #[no_mangle]
Expand All @@ -123,6 +123,8 @@ pub fn wake_delayed(message_id: MessageId, delay: u32) -> Result<()> {
/// exec::pay_program_rent(exec::program_id(), 1_000_000).expect("Unable to pay rent");
/// }
/// ```
#[allow(warnings)]
#[deprecated = "Rent program logic is deprecated. The function is now a no-op and will be removed soon."]
pub fn pay_program_rent(program_id: ActorId, value: u128) -> Result<(u128, u32)> {
Ok(gcore::exec::pay_program_rent(program_id.into(), value)?)
}
Expand Down
1 change: 1 addition & 0 deletions gsys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ extern "C" {
/// Arguments type:
/// - `rent_pid`: `const ptr` for program id and rent value.
/// - `err_bn_value`: `mut ptr` for concatenated error code, paid block count and unused rent value.
#[deprecated]
pub fn gr_pay_program_rent(
rent_pid: *const HashWithValue,
err_bn_value: *mut ErrorWithBlockNumberAndValue,
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 @@ -873,7 +872,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 @@ -1213,8 +1211,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
Loading