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: local engine #10803

Merged
merged 18 commits into from
Sep 19, 2024
Merged

feat: local engine #10803

merged 18 commits into from
Sep 19, 2024

Conversation

greged93
Copy link
Contributor

Implements a local engine service with the goal to replace the current MiningTask.

Closes #10714.

Comment on lines 136 to 139
let attr = <N::Engine as PayloadTypes>::PayloadBuilderAttributes::try_new(
head, attributes,
)
.map_err(|_| eyre::eyre!("failed to fetch payload attributes"))?;
Copy link
Contributor Author

@greged93 greged93 Sep 10, 2024

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?

Copy link
Collaborator

@onbjerg onbjerg left a 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

/// A mining mode for the local dev engine.
#[derive(Debug)]
pub enum MiningMode {
/// In this mode a block is build as soon as
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// In this mode a block is build as soon as
/// In this mode a block is built as soon as

/// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// In this mode a block is build at a fixed interval
/// In this mode a block is built at a fixed interval.

}

impl MiningMode {
/// Constructor for an [`MiningMode::Instant`]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Constructor for an [`MiningMode::Instant`]
/// Constructor for a [`MiningMode::Instant`]

Self::Instant(ReceiverStream::new(rx).fuse())
}

/// Constructor for an [`MiningMode::Interval`]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Constructor for an [`MiningMode::Interval`]
/// Constructor for a [`MiningMode::Interval`]

@onbjerg onbjerg added C-enhancement New feature or request A-engine Related to the engine implementation labels Sep 10, 2024
Copy link
Collaborator

@mattsse mattsse left a 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

Comment on lines 112 to 118
impl<N> Future for LocalEngineService<N>
where
N: EngineNodeTypes,
{
type Output = ();

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
Copy link
Collaborator

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

Comment on lines 167 to 158
/// 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;
}
Copy link
Contributor Author

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

Copy link
Collaborator

@mattsse mattsse left a 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

match this {
Self::Instant(rx) => {
// drain all transactions notifications
if let Poll::Ready(Some(_)) = pin!(rx).poll_next(cx) {
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

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)

Comment on lines 105 to 120
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");
}
Copy link
Collaborator

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

@greged93 greged93 force-pushed the feat/local-engine branch 2 times, most recently from 6c144ce to 879f77c Compare September 14, 2024 07:12
@greged93
Copy link
Contributor Author

let me know if there is anything else you think needs changing @mattsse

@mattsse
Copy link
Collaborator

mattsse commented Sep 19, 2024

this is a good first step

@mattsse mattsse added this pull request to the merge queue Sep 19, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Sep 19, 2024
@mattsse mattsse enabled auto-merge September 19, 2024 12:53
@mattsse mattsse added this pull request to the merge queue Sep 19, 2024
Merged via the queue into paradigmxyz:main with commit 6688078 Sep 19, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-engine Related to the engine implementation C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add dev ChainOrchestrator / Service
4 participants