Skip to content

Commit

Permalink
Merge branch 'master' into cl/issue-3501
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Jan 10, 2024
2 parents a58644f + fb0ea9a commit 06778a2
Show file tree
Hide file tree
Showing 56 changed files with 167 additions and 2,663 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
tags: ${{ needs.tag-image.outputs.image_tag }}

- name: SSH into VM
uses: appleboy/[email protected].0
uses: appleboy/[email protected].3
env:
NEW_IMAGE: ${{ needs.tag-image.outputs.image_tag }}
with:
Expand Down
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ serde = "^1"
serde_json = "^1"
serde_yaml = "0.8.26"
sha-1 = "0.10.1"
static_assertions = "1"
subxt = "0.32.1"
subxt-metadata = "0.32.1"
subxt-codegen = "0.32.1"
Expand Down
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: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ gear-wasm-instrument.workspace = true
wasmparser.workspace = true
hex = { workspace = true, features = ["alloc"] }
hashbrown.workspace = true
static_assertions.workspace = true
paste.workspace = true
enum-iterator.workspace = true
byteorder.workspace = true
Expand Down
5 changes: 1 addition & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@ pub mod reservation;
pub mod buffer;
pub mod str;

use core::mem::size_of;
use static_assertions::const_assert;

// This allows all casts from u32 into usize be safe.
const_assert!(size_of::<u32>() <= size_of::<usize>());
const _: () = assert!(core::mem::size_of::<u32>() <= core::mem::size_of::<usize>());
4 changes: 1 addition & 3 deletions core/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ impl PageBuf {
/// Host pointer can be 64bit or less, to support both we use u64.
pub type HostPointer = u64;

static_assertions::const_assert!(
core::mem::size_of::<HostPointer>() >= core::mem::size_of::<usize>()
);
const _: () = assert!(core::mem::size_of::<HostPointer>() >= core::mem::size_of::<usize>());

/// Core memory error.
#[derive(Debug, Clone, Eq, PartialEq, derive_more::Display)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub const MAX_PAYLOAD_SIZE: usize = 8 * 1024 * 1024;

// **WARNING**: do not remove this check until be sure that
// all `MAX_PAYLOAD_SIZE` conversions are safe!
static_assertions::const_assert!(MAX_PAYLOAD_SIZE <= u32::MAX as usize);
const _: () = assert!(MAX_PAYLOAD_SIZE <= u32::MAX as usize);

/// Payload size exceed error
#[derive(
Expand Down
Loading

0 comments on commit 06778a2

Please sign in to comment.