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: exex manager #7340

Merged
merged 49 commits into from
Apr 11, 2024
Merged

feat: exex manager #7340

merged 49 commits into from
Apr 11, 2024

Conversation

onbjerg
Copy link
Member

@onbjerg onbjerg commented Mar 26, 2024

Adds a manager for ExEx's. The manager is responsible for delivering CanonStateNotifications to ExEx's, keeping track of what notifications they have already been delivered, and managing an internal buffer of these notifications, as well as backpressure from anyone holding the handle.

The manager has a handle, ExExManagerHandle that is going to be used by a few components, e.g. the execution stage, blockchain tree, and pruner, to communicate with the manager by sending notifications, or reading the current state of the manager, e.g. what blocks are safe to prune.

The manager also reads events coming from ExEx's.

Finally, the manager is responsible for ExEx metrics.

This PR also implements actually spawning the ExEx's, the manager, as well as processing notifications from the blockchain tree.

A follow up PR will integrate this with the execution stage.

@onbjerg onbjerg added C-enhancement New feature or request A-exex Execution Extensions labels Mar 26, 2024
crates/node-builder/src/components/exex.rs Outdated Show resolved Hide resolved
crates/node-builder/src/components/exex.rs Outdated Show resolved Hide resolved
crates/node-builder/src/components/exex.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
@onbjerg onbjerg force-pushed the onbjerg/exex-manager branch 2 times, most recently from cdbcb5f to 736762e Compare April 4, 2024 14:17
@onbjerg onbjerg mentioned this pull request Apr 8, 2024
@onbjerg onbjerg force-pushed the onbjerg/exex-manager branch 2 times, most recently from c773bab to 0563fce Compare April 9, 2024 09:33
crates/exex/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +10 to +11
//! ExEx's are initialized using an async closure that resolves to the ExEx; this closure gets
//! passed an [`ExExContext`] where it is possible to spawn additional tasks and modify Reth.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we link node builder here?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think that requires importing the node builder?

crates/exex/src/lib.rs Outdated Show resolved Hide resolved
crates/exex/src/lib.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/node-builder/src/builder.rs Outdated Show resolved Hide resolved
@onbjerg onbjerg changed the title wip: exex manager feat: exex manager Apr 10, 2024
exex_tx: self.exex_tx.clone(),
num_exexs: self.num_exexs,
is_ready_receiver: self.is_ready_receiver.clone(),
is_ready: WatchStream::new(self.is_ready_receiver.clone()),
Copy link
Member Author

Choose a reason for hiding this comment

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

you can't clone a WatchStream so we need to keep the receiver as an additional field and create a new WatchStream on clone

@onbjerg
Copy link
Member Author

onbjerg commented Apr 10, 2024

PR is RFR except I'm adding tests

crates/exex/Cargo.toml Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Show resolved Hide resolved
crates/exex/src/manager.rs Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
impl ExExManagerHandle {
/// Synchronously send a notification over the channel to all execution extensions.
///
/// Senders should call [`Self::has_capacity`] first.
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we call it inside this method instead, so that caller can't go beyond the capacity?

crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Show resolved Hide resolved
crates/exex/src/manager.rs Show resolved Hide resolved
crates/exex/src/manager.rs Outdated Show resolved Hide resolved
crates/exex/src/manager.rs Show resolved Hide resolved
crates/node-builder/src/builder.rs Outdated Show resolved Hide resolved
crates/node-builder/src/builder.rs Show resolved Hide resolved
@onbjerg onbjerg requested a review from shekhirin April 10, 2024 23:04
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.

a few nits

crates/node-builder/src/builder.rs Outdated Show resolved Hide resolved
crates/node-builder/src/builder.rs Outdated Show resolved Hide resolved
crates/node-builder/src/builder.rs Outdated Show resolved Hide resolved
Comment on lines +88 to +92
fn send(
&mut self,
cx: &mut Context<'_>,
(event_id, notification): &(usize, CanonStateNotification),
) -> Poll<Result<(), PollSendError<CanonStateNotification>>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this type is basically a Sink,

we should also replicate the logic here with poll_reserve as a separate function the manager calls

Copy link
Member Author

Choose a reason for hiding this comment

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

you want to implement sink?

Copy link
Collaborator

Choose a reason for hiding this comment

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

no, we should just add the equivalent fo poll_reserve,

but can also do this separately, so no blocker here

Comment on lines +281 to +285
let notification_id = exex
.next_notification_id
.checked_sub(self.min_id)
.expect("exex expected notification ID outside the manager's range");
if let Some(notification) = self.buffer.get(notification_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this lookup is a bit weird because this now looks up by index, I guess this is fine since we're keeping track of all the ids in the exexhandle, but ideally we lookup the buffer by id

Copy link
Member Author

Choose a reason for hiding this comment

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

so you'd want a map instead?

@onbjerg onbjerg marked this pull request as ready for review April 11, 2024 16:13
@onbjerg onbjerg requested a review from gakonst as a code owner April 11, 2024 16:13
@onbjerg onbjerg added this pull request to the merge queue Apr 11, 2024
Merged via the queue into main with commit 007e5c2 Apr 11, 2024
28 checks passed
@onbjerg onbjerg deleted the onbjerg/exex-manager branch April 11, 2024 16:26
@onbjerg onbjerg mentioned this pull request Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exex Execution Extensions C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants