Skip to content

Conversation

@akundaz
Copy link
Collaborator

@akundaz akundaz commented Nov 24, 2025

Add an associated type to Platform to hold state that is passed around with checkpoints. This makes it easier to write features like flashblocks, since multiple steps need to access the flashblock number and so we currently define state outside the pipeline and share it with those steps. This PR also makes it possible to access this state during bundle filtering, so we will can filter on flashblock numbers.

Checkpoint metadata can be accessed via checkpoint.metadata() and can be updated like checkpoint.execute(tx).metadata(new_metadata).apply(). If metadata isn't set for the next checkpoint then the current checkpoint's metadata is cloned to the next checkpoint.

I refactored the checkpoint construction api because we want to be able to optionally set tags and/or metadata. Instead of apply(tx) or barrier() returning the next checkpoint, the execute(tx) and barrier() methods now return CheckpointBuilder instances which has an apply() method to create the next checkpoint, along with tag and metadata setter functions. This results in more verbose code but it seems like the clearest way to enable metadata and tags.

@akundaz akundaz self-assigned this Nov 24, 2025
@akundaz akundaz force-pushed the ak-checkpoint-state branch from bf0e1ed to de7f40f Compare November 24, 2025 14:58

impl Platform for Ethereum {
type Bundle = FlashbotsBundle<Self>;
type CheckpointMetadata = EmptyMetadata;
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about we make rust unit type () the empty metadata type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That doesn't impl Display, so I had to make a new type, unless we're fine with using the Debug formatting in the checkpoint display

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's ok to not have Display. Display on the metadata type would actually be too strict of a trait bound for this scenario imo.

Comment on lines +10 to +11
#[derive(Debug, derive_more::Display, Default, Clone)]
pub struct EmptyMetadata;
Copy link
Collaborator

Choose a reason for hiding this comment

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

impl<P: Platform> CheckpointMetadata<P> for () {}

@karim-agha
Copy link
Collaborator

Looks great! Let's just tweak the public API a little bit.

Copy link
Collaborator

@julio4 julio4 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 good!
I generally think that we should be careful about changing API and that moving to a builder pattern should be discussed separately.

Also, we should try to not overload too much method and try to extract metadata from within checkpoint when possible.

And lastly, we attach metadata to checkpoint but this is basically a state that is passed across checkpoint to give more context required by some platform. I think maybe metadata is not exactly the correct name, maybe something like BuildingContext could be more relevant if I understood this correctly.

What do you think?

let metadata = payload.metadata().clone();
let mut orders = self
.order_pool
.best_orders_for_block(ctx.block(), &metadata);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the clone necessary, can't we just take the metadata reference from payload directly?

Comment on lines 75 to +76
db: &DB,
metadata: &P::CheckpointMetadata,
Copy link
Collaborator

Choose a reason for hiding this comment

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

technically we pass checkpoint as db here, so maybe we can slightly change this to extract metadata without having to add metadata arg.

@karim-agha
Copy link
Collaborator

Now that we will have Checkpoint::apply(tx) and Checkpoint::apply_with(tx, metadata) I think it make sense to have BlockContext::start() and BlockContext::start_with(metadata).

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.

3 participants