-
Notifications
You must be signed in to change notification settings - Fork 110
chore: migrate txpool/flashblocks from exex to canonical subscription #403
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| //! Contains the [`FlashblocksExtension`] which wires up the flashblocks feature | ||
| //! (both the canon ExEx and RPC surface) on the Base node builder. | ||
| //! (canonical block subscription and RPC surface) on the Base node builder. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use base_client_node::{BaseNodeExtension, FromExtensionConfig, OpBuilder}; | ||
| use futures_util::TryStreamExt; | ||
| use reth_exex::ExExEvent; | ||
| use reth_chain_state::CanonStateSubscriptions; | ||
| use tokio_stream::{StreamExt, wrappers::BroadcastStream}; | ||
| use tracing::info; | ||
| use url::Url; | ||
|
|
||
|
|
@@ -34,7 +34,7 @@ impl FlashblocksConfig { | |
| } | ||
| } | ||
|
|
||
| /// Helper struct that wires the Flashblocks feature (canon ExEx and RPC) into the node builder. | ||
| /// Helper struct that wires the Flashblocks feature (canonical subscription and RPC) into the node builder. | ||
| #[derive(Debug)] | ||
| pub struct FlashblocksExtension { | ||
| /// Optional Flashblocks configuration (includes state). | ||
|
|
@@ -59,55 +59,45 @@ impl BaseNodeExtension for FlashblocksExtension { | |
| let state = cfg.state; | ||
| let mut subscriber = FlashblocksSubscriber::new(state.clone(), cfg.websocket_url); | ||
|
|
||
| let state_for_exex = state.clone(); | ||
| let state_for_canonical = state.clone(); | ||
| let state_for_rpc = state.clone(); | ||
| let state_for_start = state; | ||
|
|
||
| // Install the canon ExEx | ||
| let builder = builder.install_exex("flashblocks-canon", move |mut ctx| { | ||
| let fb = state_for_exex; | ||
| async move { | ||
| Ok(async move { | ||
| while let Some(note) = ctx.notifications.try_next().await? { | ||
| if let Some(committed) = note.committed_chain() { | ||
| let tip = committed.tip().num_hash(); | ||
| let chain = Arc::unwrap_or_clone(committed); | ||
| for (_, block) in chain.into_blocks() { | ||
| fb.on_canonical_block_received(block); | ||
| } | ||
| let _ = ctx.events.send(ExExEvent::FinishedHeight(tip)); | ||
| } | ||
| } | ||
| Ok(()) | ||
| }) | ||
| } | ||
| }); | ||
|
|
||
| // Start state processor and subscriber after node is started | ||
| // Start state processor, subscriber, and canonical subscription after node is started | ||
| let builder = builder.on_node_started(move |ctx| { | ||
| info!(message = "Starting Flashblocks state processor"); | ||
| state_for_start.start(ctx.provider().clone()); | ||
| subscriber.start(); | ||
|
|
||
| let mut canonical_stream = | ||
| BroadcastStream::new(ctx.provider().subscribe_to_canonical_state()); | ||
| tokio::spawn(async move { | ||
| while let Some(Ok(notification)) = canonical_stream.next().await { | ||
| let committed = notification.committed(); | ||
| for block in committed.blocks_iter() { | ||
| state_for_canonical.on_canonical_block_received(block.clone()); | ||
| } | ||
| } | ||
| }); | ||
|
Comment on lines
+72
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow this is nice |
||
|
|
||
| Ok(()) | ||
| }); | ||
|
|
||
| // Extend with RPC modules | ||
| builder.extend_rpc_modules(move |ctx| { | ||
| info!(message = "Starting Flashblocks RPC"); | ||
|
|
||
| let fb = state_for_rpc; | ||
|
|
||
| let api_ext = EthApiExt::new( | ||
| ctx.registry.eth_api().clone(), | ||
| ctx.registry.eth_handlers().filter.clone(), | ||
| fb.clone(), | ||
| state_for_rpc.clone(), | ||
| ); | ||
| ctx.modules.replace_configured(api_ext.into_rpc())?; | ||
|
|
||
| // Register the eth_subscribe subscription endpoint for flashblocks | ||
| // Uses replace_configured since eth_subscribe already exists from reth's standard module | ||
| // Pass eth_api to enable proxying standard subscription types to reth's implementation | ||
| let eth_pubsub = EthPubSub::new(ctx.registry.eth_api().clone(), fb); | ||
| let eth_pubsub = EthPubSub::new(ctx.registry.eth_api().clone(), state_for_rpc); | ||
| ctx.modules.replace_configured(eth_pubsub.into_rpc())?; | ||
|
|
||
| Ok(()) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.