-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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: local engine #10803
feat: local engine #10803
Conversation
crates/engine/local/src/service.rs
Outdated
let attr = <N::Engine as PayloadTypes>::PayloadBuilderAttributes::try_new( | ||
head, attributes, | ||
) | ||
.map_err(|_| eyre::eyre!("failed to fetch payload attributes"))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't figure out how to update the attributes here. My current understanding was:
- Pass an initial
PayloadAttributes
and parent hash to the engine - Use this to create the
PayloadBuilderAttributes
- Update the
PayloadAttributes
and the head once block building is done
However I can't figure out how to update these attributes. Maybe I need to add a setter for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smol doc nits, havent looked over the entire pr yet as i'm not too familiar with this code myself
crates/engine/local/src/miner.rs
Outdated
/// A mining mode for the local dev engine. | ||
#[derive(Debug)] | ||
pub enum MiningMode { | ||
/// In this mode a block is build as soon as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// In this mode a block is build as soon as | |
/// In this mode a block is built as soon as |
crates/engine/local/src/miner.rs
Outdated
/// In this mode a block is build as soon as | ||
/// a valid transaction reaches the pool. | ||
Instant(Fuse<ReceiverStream<TxHash>>), | ||
/// In this mode a block is build at a fixed interval |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// In this mode a block is build at a fixed interval | |
/// In this mode a block is built at a fixed interval. |
crates/engine/local/src/miner.rs
Outdated
} | ||
|
||
impl MiningMode { | ||
/// Constructor for an [`MiningMode::Instant`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Constructor for an [`MiningMode::Instant`] | |
/// Constructor for a [`MiningMode::Instant`] |
crates/engine/local/src/miner.rs
Outdated
Self::Instant(ReceiverStream::new(rx).fuse()) | ||
} | ||
|
||
/// Constructor for an [`MiningMode::Interval`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Constructor for an [`MiningMode::Interval`] | |
/// Constructor for a [`MiningMode::Interval`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a nice first draft,
I think we can solve the attributes issue by requiring a type that can create a PayloadAttributes instance
crates/engine/local/src/service.rs
Outdated
impl<N> Future for LocalEngineService<N> | ||
where | ||
N: EngineNodeTypes, | ||
{ | ||
type Output = (); | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's easier we can also do this as an async fn function over tokio select, which would make sense here because we do a lot of sequential processing
3921928
to
8994e17
Compare
/// A builder that can return the current payload attribute. | ||
pub trait PayloadAttributesBuilder: std::fmt::Debug + Send + Sync + 'static { | ||
/// The payload attributes type returned by the builder. | ||
type PayloadAttributes: PayloadAttributes; | ||
|
||
/// Return a new payload attribute from the builder. | ||
fn build(&self) -> Self::PayloadAttributes; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a payload attributes builder as suggested, for now it doesn't have setters and is sitting in the traits of the payload as I felt this was most appropriate, let me know
86b3bf6
to
3e2aca9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks pretty good already, some nits
need to think about how to impl the payloadattr builder
crates/engine/local/src/miner.rs
Outdated
match this { | ||
Self::Instant(rx) => { | ||
// drain all transactions notifications | ||
if let Poll::Ready(Some(_)) = pin!(rx).poll_next(cx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use poll_next_unpin
type PayloadAttributes: PayloadAttributes; | ||
|
||
/// Return a new payload attribute from the builder. | ||
fn build(&self) -> Self::PayloadAttributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense, we probably want to provide some additional context as arguments eventually, e.g. the most recent block, but we can figure this out later.
type PayloadAttributes: PayloadAttributes; | ||
|
||
/// Return a new payload attribute from the builder. | ||
fn build(&self) -> Self::PayloadAttributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanna make this return a result, in case the impl needs to do some io (e.g. fetch current head, etc)
crates/engine/local/src/service.rs
Outdated
loop { | ||
// Wait for the interval or the pool to receive a transaction | ||
(&mut engine.mode).await; | ||
|
||
// Start a new payload building job | ||
let new_head = engine.build_and_save_payload().await; | ||
|
||
if new_head.is_err() { | ||
debug!(target: "local_engine", err = ?new_head.unwrap_err(), "failed payload | ||
building"); | ||
continue | ||
} | ||
|
||
// Update the head | ||
engine.head = new_head.expect("not error"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a standalone function fn run()
that should be spawned
6c144ce
to
879f77c
Compare
let me know if there is anything else you think needs changing @mattsse |
this is a good first step |
879f77c
to
a3c4497
Compare
Implements a local engine service with the goal to replace the current
MiningTask
.Closes #10714.