Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ethexe): bucketed parallel executor/runtime runner #4488

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

39 changes: 34 additions & 5 deletions ethexe/common/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ impl BlockHeader {
}
}

#[derive(PartialEq, Eq, Debug, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(serde::Serialize))]
pub struct ProgramStateHashAndSize {
pub hash: H256,
pub cached_queue_size: u64,
}

impl ProgramStateHashAndSize {
pub fn zero() -> Self {
Self {
hash: H256::zero(),
cached_queue_size: 0,
}
}
}
#[derive(Debug, Clone, Default, Encode, Decode)]
pub struct CodeInfo {
pub timestamp: u64,
Expand All @@ -87,11 +102,25 @@ pub trait BlockMetaStorage: Send + Sync {
fn previous_committed_block(&self, block_hash: H256) -> Option<H256>;
fn set_previous_committed_block(&self, block_hash: H256, prev_commitment: H256);

fn block_start_program_states(&self, block_hash: H256) -> Option<BTreeMap<ActorId, H256>>;
fn set_block_start_program_states(&self, block_hash: H256, map: BTreeMap<ActorId, H256>);

fn block_end_program_states(&self, block_hash: H256) -> Option<BTreeMap<ActorId, H256>>;
fn set_block_end_program_states(&self, block_hash: H256, map: BTreeMap<ActorId, H256>);
fn block_start_program_states(
&self,
block_hash: H256,
) -> Option<BTreeMap<ActorId, ProgramStateHashAndSize>>;
fn set_block_start_program_states(
&self,
block_hash: H256,
map: BTreeMap<ActorId, ProgramStateHashAndSize>,
);

fn block_end_program_states(
&self,
block_hash: H256,
) -> Option<BTreeMap<ActorId, ProgramStateHashAndSize>>;
fn set_block_end_program_states(
&self,
block_hash: H256,
map: BTreeMap<ActorId, ProgramStateHashAndSize>,
);

fn block_events(&self, block_hash: H256) -> Option<Vec<BlockRequestEvent>>;
fn set_block_events(&self, block_hash: H256, events: Vec<BlockRequestEvent>);
Expand Down
3 changes: 2 additions & 1 deletion ethexe/compute/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ impl ChainHeadProcessContext {

let block_outcomes = self
.processor
.process_block_events(block_hash, block_request_events)?;
.process_block_events(block_hash, block_request_events)
.await?;

let transition_outcomes: Vec<_> = block_outcomes
.into_iter()
Expand Down
29 changes: 23 additions & 6 deletions ethexe/db/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use crate::{
};
use anyhow::{bail, Result};
use ethexe_common::{
db::{BlockHeader, BlockMetaStorage, CodeInfo, CodesStorage, Schedule},
db::{
BlockHeader, BlockMetaStorage, CodeInfo, CodesStorage, ProgramStateHashAndSize, Schedule,
},
events::BlockRequestEvent,
gear::StateTransition,
tx_pool::{OffchainTransaction, SignedOffchainTransaction},
Expand Down Expand Up @@ -197,7 +199,10 @@ impl BlockMetaStorage for Database {
);
}

fn block_start_program_states(&self, block_hash: H256) -> Option<BTreeMap<ActorId, H256>> {
fn block_start_program_states(
&self,
block_hash: H256,
) -> Option<BTreeMap<ActorId, ProgramStateHashAndSize>> {
self.kv
.get(&KeyPrefix::BlockStartProgramStates.two(self.router_address, block_hash))
.map(|data| {
Expand All @@ -206,15 +211,22 @@ impl BlockMetaStorage for Database {
})
}

fn set_block_start_program_states(&self, block_hash: H256, map: BTreeMap<ActorId, H256>) {
fn set_block_start_program_states(
&self,
block_hash: H256,
map: BTreeMap<ActorId, ProgramStateHashAndSize>,
) {
log::trace!(target: LOG_TARGET, "For block {block_hash} set start program states: {map:?}");
self.kv.put(
&KeyPrefix::BlockStartProgramStates.two(self.router_address, block_hash),
map.encode(),
);
}

fn block_end_program_states(&self, block_hash: H256) -> Option<BTreeMap<ActorId, H256>> {
fn block_end_program_states(
&self,
block_hash: H256,
) -> Option<BTreeMap<ActorId, ProgramStateHashAndSize>> {
self.kv
.get(&KeyPrefix::BlockEndProgramStates.two(self.router_address, block_hash))
.map(|data| {
Expand All @@ -223,7 +235,11 @@ impl BlockMetaStorage for Database {
})
}

fn set_block_end_program_states(&self, block_hash: H256, map: BTreeMap<ActorId, H256>) {
fn set_block_end_program_states(
&self,
block_hash: H256,
map: BTreeMap<ActorId, ProgramStateHashAndSize>,
) {
self.kv.put(
&KeyPrefix::BlockEndProgramStates.two(self.router_address, block_hash),
map.encode(),
Expand Down Expand Up @@ -645,7 +661,8 @@ mod tests {

let block_hash = H256::zero();
// let parent_hash = H256::zero();
let map: BTreeMap<ActorId, H256> = [(ActorId::zero(), H256::zero())].into();
let map: BTreeMap<ActorId, ProgramStateHashAndSize> =
[(ActorId::zero(), ProgramStateHashAndSize::zero())].into();

database.set_block_start_program_states(block_hash, map.clone());
assert_eq!(database.block_start_program_states(block_hash), Some(map));
Expand Down
2 changes: 2 additions & 0 deletions ethexe/processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ parity-scale-codec = { workspace = true, features = ["std", "derive"] }
sp-allocator = { workspace = true, features = ["std"] }
sp-wasm-interface = { workspace = true, features = ["std", "wasmtime"] }
tokio = { workspace = true, features = ["full"] }
itertools.workspace = true

[dev-dependencies]
rand.workspace = true
env_logger.workspace = true
demo-ping = { workspace = true, features = ["debug", "ethexe"] }
demo-async = { workspace = true, features = ["debug", "ethexe"] }
Expand Down
6 changes: 3 additions & 3 deletions ethexe/processor/src/handling/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl ProcessingHandler {
)?;

state
.queue_hash
.queue
.modify_queue(storage, |queue| queue.queue(dispatch));

Ok(())
Expand Down Expand Up @@ -138,7 +138,7 @@ impl ProcessingHandler {
)?;

state
.queue_hash
.queue
.modify_queue(storage, |queue| queue.queue(reply));

Ok(())
Expand Down Expand Up @@ -175,7 +175,7 @@ impl ProcessingHandler {
);

state
.queue_hash
.queue
.modify_queue(storage, |queue| queue.queue(reply));

Ok(())
Expand Down
Loading
Loading