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(payload): abstract payload builder in trait #10965

Merged
merged 6 commits into from
Sep 20, 2024

Conversation

greged93
Copy link
Contributor

Abstracts the current PayloadBuilderHandle behind a PayloadBuilder trait. First step towards being able to have the PayloadBuilder be a GAT on the NodeComponents trait.

Resolves #10956.

Pin<Box<dyn Future<Output = Result<P, PayloadBuilderError>> + Send + Sync>>;

/// A type that can request, subscribe to and resolve payloads.
#[async_trait::async_trait]
Copy link
Contributor Author

@greged93 greged93 Sep 17, 2024

Choose a reason for hiding this comment

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

I'm not too sure about this, are you ok with using the async_trait macro or would you rather explicitly returning a future?

Copy link
Collaborator

Choose a reason for hiding this comment

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

async_trait is fine here, then we could use this as dyn trait as well.

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.

cool, some nits

Pin<Box<dyn Future<Output = Result<P, PayloadBuilderError>> + Send + Sync>>;

/// A type that can request, subscribe to and resolve payloads.
#[async_trait::async_trait]
Copy link
Collaborator

Choose a reason for hiding this comment

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

async_trait is fine here, then we could use this as dyn trait as well.


/// A type that can request, subscribe to and resolve payloads.
#[async_trait::async_trait]
pub trait PayloadBuilder {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we move this to payload-primitives perhaps?


/// A type that can request, subscribe to and resolve payloads.
#[async_trait::async_trait]
pub trait PayloadBuilder {
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 Send + Unpin

let (tx, rx) = oneshot::channel();
let _ = self.to_service.send(PayloadServiceCommand::Subscribe(tx));
Ok(PayloadEvents { receiver: rx.await? })
}
}

impl<T> PayloadBuilderHandle<T>
where
T: PayloadTypes + 'static,
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's also make PayloadTypes 'static

@greged93
Copy link
Contributor Author

I noticed there were 2 PayloadBuilderError, one in reth-payload-builder and one in reth-payload-primitives. They looked very similar barring the MissingPayload variant, so I removed the one from reth-payload-builder, and moved the events to primitives as well. This avoids any circular dep between builder and primitives.

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.

very nice, one pedantic nit about re-exports

@@ -28,7 +28,7 @@
//! use std::pin::Pin;
//! use std::task::{Context, Poll};
//! use reth_payload_builder::{EthBuiltPayload, KeepPayloadJobAlive, EthPayloadBuilderAttributes, PayloadJob, PayloadJobGenerator};
//! use reth_payload_builder::error::PayloadBuilderError;
//! use reth_payload_primitives::PayloadBuilderError;
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should re-export the PayloadBuilderError in L125 then this wouldn't break too much and some crates don't require an additional dep

@mattsse mattsse added this pull request to the merge queue Sep 20, 2024
Merged via the queue into paradigmxyz:main with commit 7cf492d Sep 20, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move PayloadBuilderHandle methods out to new trait
2 participants