reth::payload

Trait PayloadJob

pub trait PayloadJob:
    Future<Output = Result<(), PayloadBuilderError>>
    + Send
    + Sync {
    type PayloadAttributes: PayloadBuilderAttributes + Debug;
    type ResolvePayloadFuture: Future<Output = Result<Self::BuiltPayload, PayloadBuilderError>> + Send + Sync + 'static;
    type BuiltPayload: BuiltPayload + Clone + Debug;

    // Required methods
    fn best_payload(&self) -> Result<Self::BuiltPayload, PayloadBuilderError>;
    fn payload_attributes(
        &self,
    ) -> Result<Self::PayloadAttributes, PayloadBuilderError>;
    fn resolve_kind(
        &mut self,
        kind: PayloadKind,
    ) -> (Self::ResolvePayloadFuture, KeepPayloadJobAlive);

    // Provided method
    fn resolve(&mut self) -> (Self::ResolvePayloadFuture, KeepPayloadJobAlive) { ... }
}
Expand description

A type that can build a payload.

This type is a Future that resolves when the job is done (e.g. complete, timed out) or it failed. It’s not supposed to return the best payload built when it resolves, instead PayloadJob::best_payload should be used for that.

A PayloadJob must always be prepared to return the best payload built so far to ensure there is a valid payload to deliver to the CL, so it does not miss a slot, even if the payload is empty.

Note: A PayloadJob need to be cancel safe because it might be dropped after the CL has requested the payload via engine_getPayloadV1 (see also engine API docs)

Required Associated Types§

type PayloadAttributes: PayloadBuilderAttributes + Debug

Represents the payload attributes type that is used to spawn this payload job.

type ResolvePayloadFuture: Future<Output = Result<Self::BuiltPayload, PayloadBuilderError>> + Send + Sync + 'static

Represents the future that resolves the block that’s returned to the CL.

type BuiltPayload: BuiltPayload + Clone + Debug

Represents the built payload type that is returned to the CL.

Required Methods§

fn best_payload(&self) -> Result<Self::BuiltPayload, PayloadBuilderError>

Returns the best payload that has been built so far.

Note: This is never called by the CL.

fn payload_attributes( &self, ) -> Result<Self::PayloadAttributes, PayloadBuilderError>

Returns the payload attributes for the payload being built.

fn resolve_kind( &mut self, kind: PayloadKind, ) -> (Self::ResolvePayloadFuture, KeepPayloadJobAlive)

Called when the payload is requested by the CL.

This is invoked on engine_getPayloadV2 and engine_getPayloadV1.

The timeout for returning the payload to the CL is 1s, thus the future returned should resolve in under 1 second.

Ideally this is the best payload built so far, or an empty block without transactions, if nothing has been built yet.

According to the spec:

Client software MAY stop the corresponding build process after serving this call.

It is at the discretion of the implementer whether the build job should be kept alive or terminated.

If this returns KeepPayloadJobAlive::Yes, then the PayloadJob will be polled once more. If this returns KeepPayloadJobAlive::No then the PayloadJob will be dropped after this call.

The PayloadKind determines how the payload should be resolved in the ResolvePayloadFuture. PayloadKind::Earliest should return the earliest available payload (as fast as possible), e.g. racing an empty payload job against a pending job if there’s no payload available yet. PayloadKind::WaitForPending is allowed to wait until a built payload is available.

Provided Methods§

fn resolve(&mut self) -> (Self::ResolvePayloadFuture, KeepPayloadJobAlive)

Resolves the payload as fast as possible.

Implementations on Foreign Types§

§

impl<Client, Pool, Tasks, Builder> PayloadJob for BasicPayloadJob<Client, Pool, Tasks, Builder>
where Client: StateProviderFactory + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, Tasks: TaskSpawner + Clone + 'static, Builder: PayloadBuilder<Pool, Client> + Unpin + 'static, <Builder as PayloadBuilder<Pool, Client>>::Attributes: Unpin + Clone, <Builder as PayloadBuilder<Pool, Client>>::BuiltPayload: Unpin + Clone,

§

type PayloadAttributes = <Builder as PayloadBuilder<Pool, Client>>::Attributes

§

type ResolvePayloadFuture = ResolveBestPayload<<BasicPayloadJob<Client, Pool, Tasks, Builder> as PayloadJob>::BuiltPayload>

§

type BuiltPayload = <Builder as PayloadBuilder<Pool, Client>>::BuiltPayload

§

fn best_payload( &self, ) -> Result<<BasicPayloadJob<Client, Pool, Tasks, Builder> as PayloadJob>::BuiltPayload, PayloadBuilderError>

§

fn payload_attributes( &self, ) -> Result<<BasicPayloadJob<Client, Pool, Tasks, Builder> as PayloadJob>::PayloadAttributes, PayloadBuilderError>

§

fn resolve_kind( &mut self, kind: PayloadKind, ) -> (<BasicPayloadJob<Client, Pool, Tasks, Builder> as PayloadJob>::ResolvePayloadFuture, KeepPayloadJobAlive)

Implementors§