Skip to content

Commit

Permalink
feat(ethexe): bump programs memory limit to 2GB (#4354)
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx authored Nov 28, 2024
1 parent bdf6c18 commit 6126cc9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 85 deletions.
47 changes: 20 additions & 27 deletions ethexe/runtime/common/src/journal.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand All @@ -38,7 +28,7 @@ pub struct Handler<'a, S: Storage> {
impl<S: Storage> Handler<'_, S> {
fn send_dispatch_to_program(
&mut self,
message_id: MessageId,
_message_id: MessageId,
destination: ActorId,
dispatch: Dispatch,
delay: u32,
Expand All @@ -63,7 +53,7 @@ impl<S: Storage> Handler<'_, S> {

fn send_dispatch_to_user(
&mut self,
message_id: MessageId,
_message_id: MessageId,
dispatch: StoredDispatch,
delay: u32,
) {
Expand Down Expand Up @@ -122,12 +112,12 @@ impl<S: Storage> 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 } => {
Expand All @@ -146,7 +136,8 @@ impl<S: Storage> JournalHandler for Handler<'_, S> {
};

Ok(())
});
})
.expect("failed to update state");
}

DispatchOutcome::InitFailure {
Expand All @@ -172,7 +163,7 @@ impl<S: Storage> 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")
}
Expand Down Expand Up @@ -240,7 +231,7 @@ impl<S: Storage> JournalHandler for Handler<'_, S> {
&mut self,
dispatch: StoredDispatch,
duration: Option<u32>,
waited_type: MessageWaitedType,
_waited_type: MessageWaitedType,
) {
let Some(duration) = duration else {
todo!("Wait dispatch without specified duration");
Expand Down Expand Up @@ -336,7 +327,8 @@ impl<S: Storage> JournalHandler for Handler<'_, S> {
});

Ok(())
});
})
.expect("failed to update state");
}

fn update_allocations(
Expand Down Expand Up @@ -365,7 +357,8 @@ impl<S: Storage> JournalHandler for Handler<'_, S> {
});

Ok(())
});
})
.expect("failed to update state");
}

fn send_value(&mut self, from: ProgramId, to: Option<ProgramId>, value: u128) {
Expand Down Expand Up @@ -393,7 +386,7 @@ impl<S: Storage> 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!()
}

Expand Down
44 changes: 17 additions & 27 deletions ethexe/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<S: Storage> {
type LazyPages: LazyPagesInterface + 'static;
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
17 changes: 6 additions & 11 deletions ethexe/runtime/common/src/schedule.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand All @@ -27,7 +22,7 @@ impl<'a, S: Storage> TaskHandler<Rfm, Sd, Sum> 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)
Expand Down
25 changes: 7 additions & 18 deletions ethexe/runtime/common/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -592,7 +582,7 @@ impl Dispatch {

pub fn from_stored<S: Storage>(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())
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -857,8 +847,6 @@ impl Allocations {
}

pub fn update(&mut self, allocations: IntervalsTree<WasmPage>) -> Vec<GearPage> {
let len = self.tree_len();

let removed_pages: Vec<_> = self
.inner
.difference(&allocations)
Expand Down Expand Up @@ -916,6 +904,7 @@ pub trait Storage {
/// Writes mailbox and returns its hash.
fn write_mailbox(&self, mailbox: Mailbox) -> HashOf<Mailbox>;

// TODO: #4355.
/// Reads memory pages by pages hash.
fn read_pages(&self, hash: HashOf<MemoryPages>) -> Option<MemoryPages>;

Expand Down
3 changes: 1 addition & 2 deletions ethexe/runtime/common/src/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6126cc9

Please sign in to comment.