Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into al/no-wasm-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ark0f committed Jan 16, 2024
2 parents 8ccaa6a + 8bf1791 commit 0adc9e4
Show file tree
Hide file tree
Showing 48 changed files with 364 additions and 408 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ jobs:
- name: "Check: Compiling gstd on stable"
run: cargo +stable check -p gstd

- name: "Check: crates-io packages"
run: cargo run --release -p crates-io check

fuzzer:
runs-on: [kuberunner, github-runner-01]
env:
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/crates-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ on:
description: "Workspace version to publish"
required: true
type: string
pull_request:
branches: [master]

env:
CARGO_INCREMENTAL: 0
Expand All @@ -33,8 +31,9 @@ jobs:
uses: dsherret/rust-toolchain-file@v1

- name: "Check packages"
if: ${{ !inputs.publish }}
run: cargo run --release -p crates-io check

- name: "Publish packages"
if: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }}
if: ${{ inputs.publish }}
run: cargo run --release -p crates-io publish -v ${{ inputs.version }}
22 changes: 22 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ gcli = { path = "gcli" }
gclient = { path = "gclient" }
gsdk = { path = "gsdk" }
gsdk-codegen = { path = "gsdk/codegen" }
gstd = { path = "gstd", features = [ "nightly" ] }
gstd = { path = "gstd", features = ["nightly"] }
gstd-codegen = { path = "gstd/codegen" }
gsys = { path = "gsys" }
gtest = { path = "gtest" }
Expand Down
1 change: 0 additions & 1 deletion core-backend/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ where
builder.add_func(GasAvailable, wrap_syscall!(gas_available));
builder.add_func(Leave, wrap_syscall!(leave));
builder.add_func(MessageId, wrap_syscall!(message_id));
builder.add_func(PayProgramRent, wrap_syscall!(pay_program_rent));
builder.add_func(ProgramId, wrap_syscall!(program_id));
builder.add_func(Random, wrap_syscall!(random));
builder.add_func(Read, wrap_syscall!(read));
Expand Down
2 changes: 1 addition & 1 deletion core-backend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub enum TrapExplanation {
ProgramAllocOutOfBounds,
#[display(fmt = "Syscall unrecoverable error: {_0}")]
UnrecoverableExt(UnrecoverableExtError),
#[display(fmt = "{_0}")]
#[display(fmt = "Panic occurred: {_0}")]
Panic(LimitedStr<'static>),
#[display(fmt = "Stack limit exceeded")]
StackLimitExceeded,
Expand Down
24 changes: 3 additions & 21 deletions core-backend/src/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ use gear_sandbox::{default_executor::Caller, ReturnValue, Value};
use gear_sandbox_env::{HostError, WasmReturnValue};
use gear_wasm_instrument::SystemBreakCode;
use gsys::{
BlockNumberWithHash, ErrorBytes, ErrorWithBlockNumberAndValue, ErrorWithGas, ErrorWithHandle,
ErrorWithHash, ErrorWithReplyCode, ErrorWithSignalCode, ErrorWithTwoHashes, Gas, Hash,
HashWithValue, TwoHashesWithValue,
BlockNumberWithHash, ErrorBytes, ErrorWithGas, ErrorWithHandle, ErrorWithHash,
ErrorWithReplyCode, ErrorWithSignalCode, ErrorWithTwoHashes, Gas, Hash, HashWithValue,
TwoHashesWithValue,
};

const PTR_SPECIAL: u32 = u32::MAX;
Expand Down Expand Up @@ -1132,24 +1132,6 @@ where
})
}

pub fn pay_program_rent(rent_pid_ptr: u32) -> impl Syscall<Ext> {
FallibleSyscall::new::<ErrorWithBlockNumberAndValue>(
RuntimeCosts::PayProgramRent,
move |ctx: &mut CallerWrap<Ext>| {
let read_rent_pid = ctx.manager.register_read_as(rent_pid_ptr);

let HashWithValue {
hash: program_id,
value: rent,
} = ctx.read_as(read_rent_pid)?;

ctx.ext_mut()
.pay_program_rent(program_id.into(), rent)
.map_err(Into::into)
},
)
}

pub fn source(source_ptr: u32) -> impl Syscall<Ext> {
InfallibleSyscall::new(RuntimeCosts::Source, move |ctx: &mut CallerWrap<Ext>| {
let source = ctx.ext_mut().source()?;
Expand Down
7 changes: 0 additions & 7 deletions core-backend/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,6 @@ impl Externalities for MockExt {
fn message_id(&self) -> Result<MessageId, Self::UnrecoverableError> {
Ok(0.into())
}
fn pay_program_rent(
&mut self,
_program_id: ProgramId,
_rent: u128,
) -> Result<(u128, u32), Self::UnrecoverableError> {
Ok((0, 0))
}
fn program_id(&self) -> Result<ProgramId, Self::UnrecoverableError> {
Ok(0.into())
}
Expand Down
25 changes: 5 additions & 20 deletions core-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,6 @@ pub enum ReservationError {
ReservationBelowMailboxThreshold = 504,
}

/// Program rent error.
#[derive(
Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, Sequence, derive_more::Display,
)]
#[non_exhaustive]
#[repr(u32)]
pub enum ProgramRentError {
/// The error occurs when program's paid block count is maximum.
#[display(fmt = "Rent block count limit has been reached")]
MaximumBlockCountPaid = 600,
}

/// An error occurred in API.
#[derive(
Debug,
Expand Down Expand Up @@ -232,10 +220,6 @@ pub enum ExtError {
#[display(fmt = "Reservation error: {_0}")]
Reservation(ReservationError),

/// Program rent error.
#[display(fmt = "Program rent error: {_0}")]
ProgramRent(ProgramRentError),

/// There is a new error variant old program don't support.
Unsupported,
}
Expand All @@ -248,7 +232,6 @@ impl ExtError {
ExtError::Memory(err) => err as u32,
ExtError::Message(err) => err as u32,
ExtError::Reservation(err) => err as u32,
ExtError::ProgramRent(err) => err as u32,
ExtError::Unsupported => u32::MAX,
}
}
Expand Down Expand Up @@ -287,9 +270,8 @@ impl ExtError {
503 => Some(ReservationError::ZeroReservationAmount.into()),
504 => Some(ReservationError::ReservationBelowMailboxThreshold.into()),
//
600 => Some(ProgramRentError::MaximumBlockCountPaid.into()),
//
0xffff /* SyscallUsage */ |
600 /* ProgramRent(ProgramRentError::MaximumBlockCountPaid) */ |
u32::MAX => Some(ExtError::Unsupported),
_ => None,
}
Expand Down Expand Up @@ -360,7 +342,10 @@ mod tests {
/// if we accidentally re-use such codes
#[test]
fn error_codes_forbidden() {
let codes = [0xffff /* SyscallUsage */];
let codes = [
0xffff, /* SyscallUsage */
600, /* ProgramRent(ProgramRentError::MaximumBlockCountPaid) */
];

// check forbidden code is `Unsupported` variant now
for code in codes {
Expand Down
16 changes: 1 addition & 15 deletions core-processor/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use gear_core_backend::{
};
use gear_core_errors::{
ExecutionError as FallibleExecutionError, ExtError as FallibleExtErrorCore, MessageError,
ProgramRentError, ReplyCode, ReservationError, SignalCode,
ReplyCode, ReservationError, SignalCode,
};
use gear_lazy_pages_common::{GlobalsAccessConfig, LazyPagesWeights, ProcessAccessError, Status};
use gear_wasm_instrument::syscalls::SyscallName;
Expand Down Expand Up @@ -255,12 +255,6 @@ impl From<FallibleExecutionError> for FallibleExtError {
}
}

impl From<ProgramRentError> for FallibleExtError {
fn from(err: ProgramRentError) -> Self {
Self::Core(FallibleExtErrorCore::ProgramRent(err))
}
}

impl From<ReservationError> for FallibleExtError {
fn from(err: ReservationError) -> Self {
Self::Core(FallibleExtErrorCore::Reservation(err))
Expand Down Expand Up @@ -991,14 +985,6 @@ impl Externalities for Ext {
Ok(self.context.message_context.current().id())
}

fn pay_program_rent(
&mut self,
_program_id: ProgramId,
rent: u128,
) -> Result<(u128, u32), Self::FallibleError> {
Ok((rent, 0))
}

fn program_id(&self) -> Result<ProgramId, Self::UnrecoverableError> {
Ok(self.context.program_id)
}
Expand Down
6 changes: 0 additions & 6 deletions core/src/costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ pub struct HostFnWeights {
/// Weight of calling `gr_message_id`.
pub gr_message_id: u64,

/// Weight of calling `gr_pay_program_rent`.
pub gr_pay_program_rent: u64,

/// Weight of calling `gr_program_id`.
pub gr_program_id: u64,

Expand Down Expand Up @@ -346,8 +343,6 @@ pub enum RuntimeCosts {
GasAvailable,
/// Weight of calling `gr_message_id`.
MsgId,
/// Weight of calling `gr_pay_program_rent`.
PayProgramRent,
/// Weight of calling `gr_program_id`.
ProgramId,
/// Weight of calling `gr_source`.
Expand Down Expand Up @@ -484,7 +479,6 @@ impl RuntimeCosts {
SystemReserveGas => s.gr_system_reserve_gas,
GasAvailable => s.gr_gas_available,
MsgId => s.gr_message_id,
PayProgramRent => s.gr_pay_program_rent,
ProgramId => s.gr_program_id,
Source => s.gr_source,
Value => s.gr_value,
Expand Down
7 changes: 0 additions & 7 deletions core/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,6 @@ pub trait Externalities {
/// Get the id of the message currently being handled.
fn message_id(&self) -> Result<MessageId, Self::UnrecoverableError>;

/// Pay rent for the specified program.
fn pay_program_rent(
&mut self,
program_id: ProgramId,
rent: u128,
) -> Result<(u128, u32), Self::FallibleError>;

/// Get the id of program itself
fn program_id(&self) -> Result<ProgramId, Self::UnrecoverableError>;

Expand Down
4 changes: 0 additions & 4 deletions examples/syscalls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ pub enum Kind {
Size(u32),
// Expected(message id)
MessageId(MessageId),
// Params(program id, rent)
PayProgramRent(ActorId, u128, Option<(u128, u32)>),
// Expected(program id)
ProgramId(ActorId),
// Expected(message sender)
Expand Down Expand Up @@ -103,7 +101,5 @@ pub enum Kind {
ReplyDeposit(u64),
}

pub const PAY_PROGRAM_RENT_EXPECT: &str = "Unable to pay rent";

#[cfg(not(feature = "wasm-wrapper"))]
mod wasm;
9 changes: 0 additions & 9 deletions examples/syscalls/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,6 @@ 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);
if let Some((expected_unused_value, expected_paid_block_count)) = expected {
assert_eq!(unused_value, expected_unused_value);
assert_eq!(paid_block_count, expected_paid_block_count);
}
}
Kind::ProgramId(expected_pid) => {
let actual_pid: [u8; 32] = exec::program_id().into();
assert_eq!(expected_pid, actual_pid, "Kind::ProgramId: pid test failed");
Expand Down
8 changes: 2 additions & 6 deletions examples/waiter/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ pub fn assert_panicked(result: &RunResult, panic_msg: &str) {
)))
));
let payload = String::from_utf8(result.log()[0].payload().into())
.expect("Unable to decode panic message")
.split(',')
.map(String::from)
.next()
.expect("Unable to split panic message");
assert_eq!(payload, format!("'{}'", panic_msg));
.expect("Unable to decode panic message");
assert!(payload.contains(&format!("panicked with '{panic_msg}'")));
}
1 change: 0 additions & 1 deletion gcli/src/meta/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ mod env {
"gr_leave" => func!(store),
"gr_message_id" => func!(store, i32),
"gr_system_break" => func!(store, u32),
"gr_pay_program_rent" => func!(store, i32, i32),
"gr_program_id" => func!(store, i32),
"gr_random" => func!(store, i32, i32),
"gr_reply_code" => func!(store, i32),
Expand Down
35 changes: 1 addition & 34 deletions gcore/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use crate::{
ActorId, MessageId, ReservationId,
};
use core::mem::MaybeUninit;
use gsys::{
BlockNumberWithHash, EnvVars, ErrorWithBlockNumberAndValue, ErrorWithGas, ErrorWithHash,
HashWithValue,
};
use gsys::{BlockNumberWithHash, EnvVars, ErrorWithGas, ErrorWithHash};

/// Get current version of environment variables.
pub fn env_vars() -> EnvVars {
Expand Down Expand Up @@ -405,36 +402,6 @@ pub fn program_id() -> ActorId {
program_id
}

/// Pay specified rent for the program. The result contains the remainder of
/// rent value and the count of paid blocks.
///
/// # Examples
///
/// ```ignore
/// use gcore::exec;
///
/// #[no_mangle]
/// extern "C" fn handle() {
/// let (unused_value, paid_block_count) =
/// 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,
value,
};

let mut res: ErrorWithBlockNumberAndValue = Default::default();

unsafe { gsys::gr_pay_program_rent(&rent_pid, res.as_mut_ptr()) }

SyscallError(res.error_code).into_result()?;
Ok((res.value, res.bn))
}

/// Get the random seed, along with the block number from which it is
/// determinable by chain observers.
///
Expand Down
1 change: 0 additions & 1 deletion gsdk/src/metadata/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,6 @@ pub mod runtime_types {
pub gr_system_reserve_gas: runtime_types::sp_weights::weight_v2::Weight,
pub gr_gas_available: runtime_types::sp_weights::weight_v2::Weight,
pub gr_message_id: runtime_types::sp_weights::weight_v2::Weight,
pub gr_pay_program_rent: runtime_types::sp_weights::weight_v2::Weight,
pub gr_program_id: runtime_types::sp_weights::weight_v2::Weight,
pub gr_source: runtime_types::sp_weights::weight_v2::Weight,
pub gr_value: runtime_types::sp_weights::weight_v2::Weight,
Expand Down
Loading

0 comments on commit 0adc9e4

Please sign in to comment.