From 6126cc901916c7a013d0d83495f7d4ebe43d20e0 Mon Sep 17 00:00:00 2001 From: Dmitrii Novikov Date: Thu, 28 Nov 2024 17:50:02 +0400 Subject: [PATCH] feat(ethexe): bump programs memory limit to 2GB (#4354) --- ethexe/runtime/common/src/journal.rs | 47 ++++++++++-------------- ethexe/runtime/common/src/lib.rs | 44 +++++++++------------- ethexe/runtime/common/src/schedule.rs | 17 +++------ ethexe/runtime/common/src/state.rs | 25 ++++--------- ethexe/runtime/common/src/transitions.rs | 3 +- 5 files changed, 51 insertions(+), 85 deletions(-) diff --git a/ethexe/runtime/common/src/journal.rs b/ethexe/runtime/common/src/journal.rs index 99bbf56f7a6..af4b6e73729 100644 --- a/ethexe/runtime/common/src/journal.rs +++ b/ethexe/runtime/common/src/journal.rs @@ -1,31 +1,21 @@ use crate::{ - state::{ - self, ActiveProgram, Dispatch, MaybeHashOf, Program, ProgramState, Storage, - ValueWithExpiry, MAILBOX_VALIDITY, - }, - InBlockTransitions, TransitionController, + state::{ActiveProgram, Dispatch, Program, Storage, ValueWithExpiry, MAILBOX_VALIDITY}, + TransitionController, }; -use alloc::{collections::BTreeMap, vec, vec::Vec}; -use anyhow::{bail, Result}; +use alloc::{collections::BTreeMap, vec::Vec}; +use anyhow::bail; use core::{mem, num::NonZero}; -use core_processor::{ - common::{DispatchOutcome, JournalHandler}, - configs::BlockInfo, -}; +use core_processor::common::{DispatchOutcome, JournalHandler}; use ethexe_common::db::ScheduledTask; use gear_core::{ ids::ProgramId, memory::PageBuf, - message::{ - Dispatch as CoreDispatch, Message, MessageWaitedType, Payload, StoredDispatch, - StoredMessage, - }, + message::{Dispatch as CoreDispatch, MessageWaitedType, StoredDispatch}, pages::{numerated::tree::IntervalsTree, GearPage, WasmPage}, - program::ProgramState as InitStatus, reservation::GasReserver, }; use gear_core_errors::SignalCode; -use gprimitives::{ActorId, CodeId, MessageId, ReservationId, H256}; +use gprimitives::{ActorId, CodeId, MessageId, ReservationId}; #[derive(derive_more::Deref, derive_more::DerefMut)] pub struct Handler<'a, S: Storage> { @@ -38,7 +28,7 @@ pub struct Handler<'a, S: Storage> { impl Handler<'_, S> { fn send_dispatch_to_program( &mut self, - message_id: MessageId, + _message_id: MessageId, destination: ActorId, dispatch: Dispatch, delay: u32, @@ -63,7 +53,7 @@ impl Handler<'_, S> { fn send_dispatch_to_user( &mut self, - message_id: MessageId, + _message_id: MessageId, dispatch: StoredDispatch, delay: u32, ) { @@ -122,12 +112,12 @@ impl JournalHandler for Handler<'_, S> { fn message_dispatched( &mut self, message_id: MessageId, - source: ProgramId, + _source: ProgramId, outcome: DispatchOutcome, ) { match outcome { DispatchOutcome::Exit { program_id } => { - log::trace!("Dispatch outcome exit: {message_id}") + log::trace!("Dispatch outcome exit: {message_id} for program {program_id}") } DispatchOutcome::InitSuccess { program_id } => { @@ -146,7 +136,8 @@ impl JournalHandler for Handler<'_, S> { }; Ok(()) - }); + }) + .expect("failed to update state"); } DispatchOutcome::InitFailure { @@ -172,7 +163,7 @@ impl JournalHandler for Handler<'_, S> { } } - fn gas_burned(&mut self, message_id: MessageId, amount: u64) { + fn gas_burned(&mut self, _message_id: MessageId, _amount: u64) { // TODO // unreachable!("Must not be called here") } @@ -240,7 +231,7 @@ impl JournalHandler for Handler<'_, S> { &mut self, dispatch: StoredDispatch, duration: Option, - waited_type: MessageWaitedType, + _waited_type: MessageWaitedType, ) { let Some(duration) = duration else { todo!("Wait dispatch without specified duration"); @@ -336,7 +327,8 @@ impl JournalHandler for Handler<'_, S> { }); Ok(()) - }); + }) + .expect("failed to update state"); } fn update_allocations( @@ -365,7 +357,8 @@ impl JournalHandler for Handler<'_, S> { }); Ok(()) - }); + }) + .expect("failed to update state"); } fn send_value(&mut self, from: ProgramId, to: Option, value: u128) { @@ -393,7 +386,7 @@ impl JournalHandler for Handler<'_, S> { todo!() } - fn stop_processing(&mut self, dispatch: StoredDispatch, gas_burned: u64) { + fn stop_processing(&mut self, _dispatch: StoredDispatch, _gas_burned: u64) { todo!() } diff --git a/ethexe/runtime/common/src/lib.rs b/ethexe/runtime/common/src/lib.rs index cafbb52a661..612adacd046 100644 --- a/ethexe/runtime/common/src/lib.rs +++ b/ethexe/runtime/common/src/lib.rs @@ -19,38 +19,26 @@ //! Runtime common implementation. #![cfg_attr(not(feature = "std"), no_std)] -#![allow(unused)] extern crate alloc; -use alloc::{ - collections::{BTreeMap, VecDeque}, - vec::Vec, -}; -use anyhow::Result; -use core::{marker::PhantomData, mem::swap}; +use alloc::{collections::BTreeMap, vec::Vec}; use core_processor::{ common::{ExecutableActorData, JournalNote}, configs::{BlockConfig, SyscallName}, ContextChargedForCode, ContextChargedForInstrumentation, Ext, ProcessExecutionContext, }; use gear_core::{ - code::InstrumentedCode, + code::{InstrumentedCode, MAX_WASM_PAGES_AMOUNT}, ids::ProgramId, memory::PageBuf, - message::{DispatchKind, IncomingDispatch, IncomingMessage, Value}, - pages::{numerated::tree::IntervalsTree, GearPage, WasmPage}, - program::MemoryInfix, - reservation::GasReservationMap, + message::{DispatchKind, IncomingDispatch, IncomingMessage}, + pages::GearPage, }; use gear_lazy_pages_common::LazyPagesInterface; -use gprimitives::{CodeId, H256}; +use gprimitives::CodeId; use gsys::{GasMultiplier, Percent}; -use parity_scale_codec::{Decode, Encode}; -use state::{ - ActiveProgram, Dispatch, HashOf, InitStatus, MaybeHashOf, MessageQueue, ProgramState, Storage, - Waitlist, -}; +use state::{Dispatch, HashOf, ProgramState, Storage}; pub use core_processor::configs::BlockInfo; pub use journal::Handler as JournalHandler; @@ -65,7 +53,7 @@ mod transitions; pub const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; -const RUNTIME_ID: u32 = 0; +pub const RUNTIME_ID: u32 = 0; pub trait RuntimeInterface { type LazyPages: LazyPagesInterface + 'static; @@ -136,7 +124,6 @@ where // TODO: must be set by some runtime configuration let block_config = BlockConfig { block_info, - performance_multiplier: Percent::new(100), forbidden_funcs: [ // Deprecated SyscallName::CreateProgramWGas, @@ -162,15 +149,18 @@ where SyscallName::Random, ] .into(), - reserve_for: 125_000_000, - gas_multiplier: GasMultiplier::one(), // TODO - costs: Default::default(), // TODO - existential_deposit: 0, // TODO - mailbox_threshold: 3000, - max_reservations: 50, - max_pages: 512.into(), + gas_multiplier: GasMultiplier::one(), + costs: Default::default(), + max_pages: MAX_WASM_PAGES_AMOUNT.into(), outgoing_limit: 1024, outgoing_bytes_limit: 64 * 1024 * 1024, + // TBD about deprecation + performance_multiplier: Percent::new(100), + // Deprecated + existential_deposit: 0, + mailbox_threshold: 0, + max_reservations: 0, + reserve_for: 0, }; let active_state = match program_state.program { diff --git a/ethexe/runtime/common/src/schedule.rs b/ethexe/runtime/common/src/schedule.rs index e8e4d854900..e996aed82ec 100644 --- a/ethexe/runtime/common/src/schedule.rs +++ b/ethexe/runtime/common/src/schedule.rs @@ -1,19 +1,14 @@ use crate::{ - state::{ - Dispatch, MaybeHashOf, PayloadLookup, ProgramState, Storage, ValueWithExpiry, - MAILBOX_VALIDITY, - }, - InBlockTransitions, TransitionController, + state::{Dispatch, PayloadLookup, Storage, ValueWithExpiry, MAILBOX_VALIDITY}, + TransitionController, }; -use alloc::vec; -use anyhow::{anyhow, Result}; use ethexe_common::{ db::{Rfm, ScheduledTask, Sd, Sum}, - gear::{Message, ValueClaim}, + gear::ValueClaim, }; -use gear_core::{ids::ProgramId, message::ReplyMessage, tasks::TaskHandler}; +use gear_core::{ids::ProgramId, tasks::TaskHandler}; use gear_core_errors::SuccessReplyReason; -use gprimitives::{ActorId, CodeId, MessageId, ReservationId, H256}; +use gprimitives::{ActorId, CodeId, MessageId, ReservationId}; #[derive(derive_more::Deref, derive_more::DerefMut)] pub struct Handler<'a, S: Storage> { @@ -27,7 +22,7 @@ impl<'a, S: Storage> TaskHandler for Handler<'a, S> { message_id: MessageId, ) -> u64 { self.update_state(program_id, |state, storage, transitions| { - let ValueWithExpiry { value, expiry } = + let ValueWithExpiry { value, .. } = state.mailbox_hash.modify_mailbox(storage, |mailbox| { mailbox .remove(user_id, message_id) diff --git a/ethexe/runtime/common/src/state.rs b/ethexe/runtime/common/src/state.rs index 7faea2b6172..553e23b4d66 100644 --- a/ethexe/runtime/common/src/state.rs +++ b/ethexe/runtime/common/src/state.rs @@ -25,29 +25,19 @@ use alloc::{ vec::Vec, }; use anyhow::{anyhow, Result}; -use core::{ - any::Any, - marker::PhantomData, - mem, - num::NonZero, - ops::{Deref, DerefMut}, -}; +use core::{any::Any, marker::PhantomData, mem}; use ethexe_common::gear::Message; use gear_core::{ - code::InstrumentedCode, ids::{prelude::MessageIdExt as _, ProgramId}, memory::PageBuf, message::{ - ContextStore, DispatchKind, GasLimit, MessageDetails, Payload, ReplyDetails, - StoredDispatch, Value, MAX_PAYLOAD_SIZE, + ContextStore, DispatchKind, MessageDetails, Payload, ReplyDetails, StoredDispatch, Value, }, pages::{numerated::tree::IntervalsTree, GearPage, WasmPage}, program::MemoryInfix, - reservation::GasReservationMap, }; use gear_core_errors::{ReplyCode, SuccessReplyReason}; -use gprimitives::{ActorId, CodeId, MessageId, H256}; -use gsys::BlockNumber; +use gprimitives::{ActorId, MessageId, H256}; use parity_scale_codec::{Decode, Encode}; use private::Sealed; @@ -592,7 +582,7 @@ impl Dispatch { pub fn from_stored(storage: &S, value: StoredDispatch) -> Self { let (kind, message, context) = value.into_parts(); - let (id, source, destination, payload, value, details) = message.into_parts(); + let (id, source, _destination, payload, value, details) = message.into_parts(); let payload = storage .write_payload_raw(payload.into_vec()) @@ -739,7 +729,7 @@ impl DispatchStash { pub fn remove_to_program(&mut self, message_id: &MessageId) -> Dispatch { let ValueWithExpiry { value: (dispatch, user_id), - expiry, + .. } = self .0 .remove(message_id) @@ -755,7 +745,7 @@ impl DispatchStash { pub fn remove_to_user(&mut self, message_id: &MessageId) -> (Dispatch, ActorId) { let ValueWithExpiry { value: (dispatch, user_id), - expiry, + .. } = self .0 .remove(message_id) @@ -857,8 +847,6 @@ impl Allocations { } pub fn update(&mut self, allocations: IntervalsTree) -> Vec { - let len = self.tree_len(); - let removed_pages: Vec<_> = self .inner .difference(&allocations) @@ -916,6 +904,7 @@ pub trait Storage { /// Writes mailbox and returns its hash. fn write_mailbox(&self, mailbox: Mailbox) -> HashOf; + // TODO: #4355. /// Reads memory pages by pages hash. fn read_pages(&self, hash: HashOf) -> Option; diff --git a/ethexe/runtime/common/src/transitions.rs b/ethexe/runtime/common/src/transitions.rs index 36589164fde..b7b77789f6f 100644 --- a/ethexe/runtime/common/src/transitions.rs +++ b/ethexe/runtime/common/src/transitions.rs @@ -26,8 +26,7 @@ use ethexe_common::{ db::{BlockHeader, Schedule, ScheduledTask}, gear::{Message, StateTransition, ValueClaim}, }; -use gprimitives::{ActorId, CodeId, H256}; -use parity_scale_codec::{Decode, Encode}; +use gprimitives::{ActorId, H256}; #[derive(Debug, Default)] pub struct InBlockTransitions {