Skip to content

Commit

Permalink
review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Jan 25, 2025
1 parent 5f84f1e commit f00bdd2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 219 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

7 changes: 0 additions & 7 deletions ethexe/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,3 @@ pub const fn u64_into_uint48_be_bytes_lossy(val: u64) -> [u8; 6] {

[b1, b2, b3, b4, b5, b6]
}

pub fn option_call<S>(
svc: &mut Option<S>,
f: impl FnOnce(&mut S) -> anyhow::Result<()>,
) -> anyhow::Result<()> {
svc.as_mut().map_or(Ok(()), f)
}
2 changes: 0 additions & 2 deletions ethexe/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ repository.workspace = true
[dependencies]
ethexe-common.workspace = true
ethexe-signer.workspace = true
ethexe-validator.workspace = true
ethexe-sequencer.workspace = true
ethexe-db.workspace = true

gprimitives = { workspace = true, features = ["codec"] }
Expand Down
2 changes: 1 addition & 1 deletion ethexe/sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SequencerService {

status: Default::default(),

collection_round: Timer::new("collection", config.block_time / 2),
collection_round: Timer::new("collection", config.block_time / 4),
validation_round: Timer::new("validation", config.block_time / 4),
})
}
Expand Down
17 changes: 13 additions & 4 deletions ethexe/service/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#![allow(async_fn_in_trait)]

use anyhow::Result;
use futures::{future, StreamExt};
use std::future::Future;

Expand All @@ -26,12 +27,10 @@ pub use timer::Timer;
mod timer;

mod private {
use super::*;

pub trait Sealed {}

impl<F: Future> Sealed for Option<F> {}
impl<S: StreamAlike> Sealed for &mut Option<S> {}
impl<T> Sealed for Option<T> {}
impl<T> Sealed for &mut Option<T> {}
}

pub trait OptionFuture<T>: private::Sealed {
Expand Down Expand Up @@ -72,6 +71,16 @@ impl<S: StreamAlike> OptionStreamNext<S::Item> for &mut Option<S> {
}
}

pub trait OptionCall<T>: private::Sealed {
fn maybe_call(self, f: impl FnOnce(&mut T) -> Result<()>) -> Result<()>;
}

impl<T> OptionCall<T> for &mut Option<T> {
fn maybe_call(self, f: impl FnOnce(&mut T) -> Result<()>) -> Result<()> {
self.as_mut().map(f).unwrap_or(Ok(()))
}
}

#[cfg(test)]
mod tests {
use crate::OptionFuture;
Expand Down
Loading

0 comments on commit f00bdd2

Please sign in to comment.