Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisInSky committed Oct 17, 2023
1 parent 3cdd83a commit cddc847
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core-backend/src/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ where
pub fn exec_settings(
ctx: &mut CallerWrap<'_, '_, Ext>,
gas: u64,
settings_ptr: u32,
settings_ver: u32,
settings_ptr: u32,
) -> Result<(u64, ()), HostError> {
let settings = ctx.ext_mut().exec_settings(settings_ver)?;
let settings_bytes = settings.to_bytes();
Expand Down
7 changes: 4 additions & 3 deletions examples/sys-calls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
extern crate alloc;

use alloc::{string::String, vec::Vec};
use gstd::{Gas, Value};
use parity_scale_codec::{Decode, Encode};

#[cfg(feature = "wasm-wrapper")]
Expand Down Expand Up @@ -79,9 +80,9 @@ pub enum Kind {
// Expected values
ExecSettings {
performance_multiplier: u32,
existential_deposit: u128,
mailbox_threshold: u64,
gas_to_value_multiplier: u128,
existential_deposit: Value,
mailbox_threshold: Gas,
gas_to_value_multiplier: Value,
},
// Expected(block height)
BlockHeight(u32),
Expand Down
11 changes: 7 additions & 4 deletions gcore/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
errors::{Result, SyscallError},
ActorId, MessageId, ReservationId,
};
use core::mem::MaybeUninit;
use gsys::{
BlockNumberWithHash, ErrorWithBlockNumberAndValue, ErrorWithGas, ErrorWithHash, Gas,
HashWithValue, Value,
Expand All @@ -36,7 +37,7 @@ use gsys::{
/// settings. This structure matches to the most recent version of execution
/// settings supported by backend.
#[repr(C, packed)]
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Clone, Copy)]
pub struct Settings {
/// Current value of performance multiplier in percents.
pub performance_multiplier_percent: u32,
Expand All @@ -50,9 +51,11 @@ pub struct Settings {

/// Get current version of execution settings.
pub fn settings() -> Settings {
let mut settings = Settings::default();
unsafe { gsys::gr_exec_settings(&mut settings as *mut _ as *mut u8, 1) };
settings
let mut settings = MaybeUninit::<Settings>::uninit();
unsafe {
gsys::gr_exec_settings(1, settings.as_mut_ptr() as *mut u8);
settings.assume_init()
}
}

/// Get the current block height.
Expand Down
2 changes: 1 addition & 1 deletion gcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub use general::*;
mod utils;
pub use utils::ext;

pub use gsys::{BlockCount, BlockNumber};
pub use gsys::{BlockCount, BlockNumber, Gas, Value};

use core::mem::size_of;
use static_assertions::const_assert;
Expand Down
2 changes: 1 addition & 1 deletion gstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub mod util;
pub use async_runtime::{handle_signal, message_loop, record_reply};
pub use common::{errors, primitives::*};
pub use config::Config;
pub use gcore::{ext, BlockCount, BlockNumber};
pub use gcore::{ext, BlockCount, BlockNumber, Gas, Value};
pub use gstd_codegen::{async_init, async_main};
pub use prelude::*;
pub use reservations::*;
Expand Down
4 changes: 2 additions & 2 deletions gsys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ extern "C" {
/// Infallible `gr_exec_settings` get syscall.
///
/// Arguments type:
/// - `settings`: `mut ptr` for buffer to store requested version of settings.
/// - `version`: `u32` defining version of settings to get.
pub fn gr_exec_settings(settings: *mut BufferStart, version: u32);
/// - `settings`: `mut ptr` for buffer to store requested version of settings.
pub fn gr_exec_settings(version: u32, settings: *mut BufferStart);

/// Infallible `gr_block_height` get syscall.
///
Expand Down
4 changes: 2 additions & 2 deletions pallets/gear/src/benchmarking/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,10 @@ where
handle_body: Some(body::syscall(
repetitions,
&[
// offset where to write settings
InstrI32Const(settings_offset),
// version. TODO: Should it be benched based on version?
InstrI32Const(1),
// offset where to write settings
InstrI32Const(settings_offset),
],
)),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion utils/wasm-instrument/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ impl SysCallName {
}
Self::MessageId => SysCallSignature::gr([Ptr(PtrInfo::new_mutable(PtrType::Hash))]),
Self::ExecSettings => SysCallSignature::gr([
Size,
// The PtrType::BufferStart doesn't work here as it requires length_param_idx
// Should we introduce something like PtrType::Buffer
Ptr(PtrInfo::new_mutable(PtrType::BlockNumber)),
Size,
]),
Self::Read => SysCallSignature::gr([
MessagePosition,
Expand Down

0 comments on commit cddc847

Please sign in to comment.