Skip to content

Commit

Permalink
move schedule handler to runtime common and abstract it
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Oct 1, 2024
1 parent f9e4372 commit 75db713
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 86 deletions.
19 changes: 17 additions & 2 deletions ethexe/processor/src/handling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@
use crate::Processor;
use anyhow::Result;
use ethexe_db::CodesStorage;
use ethexe_runtime_common::state::{ComplexStorage as _, Dispatch};
use ethexe_runtime_common::{
state::{ComplexStorage as _, Dispatch},
InBlockTransitions, ScheduleHandler,
};
use gprimitives::{CodeId, H256};

pub(crate) mod events;
pub(crate) mod run;
pub(crate) mod tasks;

impl Processor {
pub fn run_schedule(&mut self, in_block_transitions: &mut InBlockTransitions) {
let tasks = in_block_transitions.take_actual_tasks();

let mut handler = ScheduleHandler {
in_block_transitions,
storage: &self.db,
};

for task in tasks {
let _gas = task.process_with(&mut handler);
}
}

pub(crate) fn handle_message_queueing(
&mut self,
state_hash: H256,
Expand Down
4 changes: 2 additions & 2 deletions ethexe/processor/src/handling/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::host::{InstanceCreator, InstanceWrapper};
use core_processor::common::JournalNote;
use ethexe_db::{CodesStorage, Database};
use ethexe_runtime_common::{Handler, InBlockTransitions};
use ethexe_runtime_common::{InBlockTransitions, JournalHandler};
use gear_core::ids::ProgramId;
use gprimitives::H256;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn run_in_async(
}

for (program_id, journal) in super_journal {
let mut handler = Handler {
let mut handler = JournalHandler {
program_id,
in_block_transitions,
storage: &db,
Expand Down
80 changes: 0 additions & 80 deletions ethexe/processor/src/handling/tasks.rs

This file was deleted.

2 changes: 1 addition & 1 deletion ethexe/processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Processor {
}
}

self.run_tasks(&mut in_block_transitions);
self.run_schedule(&mut in_block_transitions);
self.run(block_hash, &mut in_block_transitions);

let (transitions, states, schedule) = in_block_transitions.finalize();
Expand Down
4 changes: 3 additions & 1 deletion ethexe/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ use state::{
};

pub use core_processor::configs::BlockInfo;
pub use journal::Handler;
pub use journal::Handler as JournalHandler;
pub use schedule::Handler as ScheduleHandler;
pub use transitions::{InBlockTransitions, NonFinalTransition};

pub mod state;

mod journal;
mod schedule;
mod transitions;

pub const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000;
Expand Down
45 changes: 45 additions & 0 deletions ethexe/runtime/common/src/schedule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use gear_core::{ids::ProgramId, tasks::TaskHandler};
use gprimitives::{ActorId, CodeId, MessageId, ReservationId};

use crate::{state::Storage, InBlockTransitions};

pub struct Handler<'a, S: Storage> {
pub in_block_transitions: &'a mut InBlockTransitions,
pub storage: &'a S,
}

impl<'a, S: Storage> TaskHandler<ActorId> for Handler<'a, S> {
fn remove_from_mailbox(&mut self, _user_id: ActorId, _message_id: MessageId) -> u64 {
unimplemented!("TODO (breathx)")
}
fn remove_from_waitlist(&mut self, _program_id: ProgramId, _message_id: MessageId) -> u64 {
unimplemented!("TODO (breathx)")
}
fn send_dispatch(&mut self, _stashed_message_id: MessageId) -> u64 {
unimplemented!("TODO (breathx)")
}
fn send_user_message(&mut self, _stashed_message_id: MessageId, _to_mailbox: bool) -> u64 {
unimplemented!("TODO (breathx)")
}
fn wake_message(&mut self, _program_id: ProgramId, _message_id: MessageId) -> u64 {
// TODO (breathx): consider deprecation of delayed wakes + non-concrete waits.
unimplemented!("TODO (breathx)")
}

/* Deprecated APIs */
fn pause_program(&mut self, _: ProgramId) -> u64 {
unreachable!("deprecated")
}
fn remove_code(&mut self, _: CodeId) -> u64 {
unreachable!("deprecated")
}
fn remove_gas_reservation(&mut self, _: ProgramId, _: ReservationId) -> u64 {
unreachable!("deprecated")
}
fn remove_paused_program(&mut self, _: ProgramId) -> u64 {
unreachable!("deprecated")
}
fn remove_resume_session(&mut self, _: u32) -> u64 {
unreachable!("deprecated")
}
}

0 comments on commit 75db713

Please sign in to comment.