- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.1k
          feat: enable external EngineApi access
          #16248
        
          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 31 commits
      Commits
    
    
            Show all changes
          
          
            32 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      ab05449
              
                refactor: first relax iter
              
              
                lean-apple 97da9ed
              
                refactor: add default type for OppAddons
              
              
                lean-apple b13dd5a
              
                Merge branch 'paradigmxyz:main' into main
              
              
                lean-apple e6277c5
              
                Merge branch 'paradigmxyz:main' into main
              
              
                lean-apple f021412
              
                feat: init EngineApiSender
              
              
                lean-apple 9bf1107
              
                Merge branch 'paradigmxyz:main' into main
              
              
                lean-apple 8d13e14
              
                refactor: change from engine api sender to engine api fn
              
              
                lean-apple a75eb9e
              
                docs: update doc
              
              
                lean-apple 011099c
              
                Merge branch 'paradigmxyz:main' into main
              
              
                lean-apple 1721560
              
                Merge branch 'paradigmxyz:main' into main
              
              
                lean-apple 0517a8c
              
                docs: init example
              
              
                lean-apple 52b1447
              
                docs: remove useless comment
              
              
                lean-apple 7ca23ce
              
                Merge branch 'main' into custome-api-builder
              
              
                lean-apple 40033c3
              
                fix: fix taplo
              
              
                lean-apple 2576918
              
                Merge branch 'main' of github.com:lean-apple/reth
              
              
                lean-apple 3f8f2c3
              
                Merge branch 'main' into custome-api-builder
              
              
                lean-apple 9898c10
              
                Merge branch 'main' of github.com:lean-apple/reth
              
              
                lean-apple bf4b4e7
              
                Merge branch 'main' into custome-api-builder
              
              
                lean-apple 319bbc8
              
                feat: complete engine api ext example
              
              
                lean-apple 1bca3eb
              
                Merge branch 'main' of github.com:lean-apple/reth
              
              
                lean-apple cd8bf69
              
                Merge branch 'main' into custome-api-builder
              
              
                lean-apple 25ecb7f
              
                refactor: simplify and use directly EngineApiFn instead of EngineApiB…
              
              
                lean-apple 0401f27
              
                fix: remove unused deps
              
              
                lean-apple 0b299ca
              
                feat: draft to add NodeAddons impl for AddOns with EngineApiFn
              
              
                lean-apple dd23df3
              
                refactor: rempve duplicate traits by relaxing defaults on OpAddons
              
              
                lean-apple 47ac69e
              
                fix: use checklaunch
              
              
                lean-apple 7b113b9
              
                chore: fmt with updated nightly
              
              
                lean-apple 8c4fea6
              
                style: renaming to explicit example name
              
              
                lean-apple 563a737
              
                style: rename to EngineApiExt
              
              
                lean-apple 977a657
              
                docs: wording
              
              
                lean-apple 9c65f3c
              
                Merge branch 'main' into custome-api-builder
              
              
                lean-apple 412936f
              
                Update examples/engine-api-access/src/main.rs
              
              
                lean-apple 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //! `EngineApiBuilder` callback wrapper | ||
| //! | ||
| //! Wraps an `EngineApiBuilder` to provide access to the built Engine API instance. | ||
|  | ||
| use crate::rpc::EngineApiBuilder; | ||
| use eyre::Result; | ||
| use reth_node_api::{AddOnsContext, FullNodeComponents}; | ||
| use reth_rpc_api::IntoEngineApiRpcModule; | ||
|  | ||
| /// Provides access to an `EngineApi` instance with a callback | ||
| #[derive(Debug)] | ||
| pub struct EngineApiExt<B, F> { | ||
| /// The inner builder that constructs the actual `EngineApi` | ||
| inner: B, | ||
| /// Optional callback function to execute with the built API | ||
| callback: Option<F>, | ||
| } | ||
|  | ||
| impl<B, F> EngineApiExt<B, F> { | ||
| /// Creates a new wrapper that calls `callback` when the API is built. | ||
| pub const fn new(inner: B, callback: F) -> Self { | ||
| Self { inner, callback: Some(callback) } | ||
| } | ||
| } | ||
|  | ||
| impl<N, B, F> EngineApiBuilder<N> for EngineApiExt<B, F> | ||
| where | ||
| B: EngineApiBuilder<N>, | ||
| N: FullNodeComponents, | ||
| B::EngineApi: IntoEngineApiRpcModule + Send + Sync + Clone + 'static, | ||
| F: FnOnce(B::EngineApi) + Send + Sync + 'static, | ||
| { | ||
| type EngineApi = B::EngineApi; | ||
|  | ||
| /// Builds the `EngineApi` and executes the callback if present. | ||
| async fn build_engine_api(mut self, ctx: &AddOnsContext<'_, N>) -> Result<Self::EngineApi> { | ||
| let api = self.inner.build_engine_api(ctx).await?; | ||
|  | ||
| if let Some(callback) = self.callback.take() { | ||
| callback(api.clone()); | ||
| } | ||
|  | ||
| Ok(api) | ||
| } | ||
| } | 
  
    
      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 | 
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [package] | ||
| name = "example-engine-api-access" | ||
| version = "0.0.0" | ||
| publish = false | ||
| edition.workspace = true | ||
| license.workspace = true | ||
|  | ||
| [dependencies] | ||
| # reth | ||
| reth-db = { workspace = true, features = ["op", "test-utils"] } | ||
| reth-node-builder.workspace = true | ||
| reth-optimism-consensus.workspace = true | ||
| reth-tasks.workspace = true | ||
| reth-node-api.workspace = true | ||
| reth-rpc-api.workspace = true | ||
| reth-tracing.workspace = true | ||
| reth-provider.workspace = true | ||
| reth-optimism-node.workspace = true | ||
| reth-optimism-chainspec.workspace = true | ||
|  | ||
| # alloy | ||
| alloy-rpc-types-engine.workspace = true | ||
|  | ||
| async-trait.workspace = true | ||
| clap = { workspace = true, features = ["derive"] } | ||
| eyre.workspace = true | ||
| jsonrpsee.workspace = true | ||
| futures.workspace = true | ||
| serde_json.workspace = true | ||
| tokio = { workspace = true, features = ["sync"] } | 
  
    
      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 | 
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //! Example demonstrating how to access the Engine API instance during construction. | ||
| //! | ||
| //! Run with | ||
| //! | ||
| //! ```sh | ||
| //! cargo run -p engine-api-access | ||
| //! ``` | ||
|  | ||
| use reth_db::test_utils::create_test_rw_db; | ||
| use reth_node_builder::{EngineApiExt, FullNodeComponents, NodeBuilder, NodeConfig}; | ||
| use reth_optimism_chainspec::BASE_MAINNET; | ||
| use reth_optimism_node::{ | ||
| args::RollupArgs, | ||
| node::{OpAddOns, OpEngineValidatorBuilder}, | ||
| OpEngineApiBuilder, OpNode, | ||
| }; | ||
| use tokio::sync::oneshot; | ||
|  | ||
| #[tokio::main] | ||
| async fn main() { | ||
| // Op node configuration and setup | ||
| let config = NodeConfig::new(BASE_MAINNET.clone()); | ||
| let db = create_test_rw_db(); | ||
| let args = RollupArgs::default(); | ||
| let op_node = OpNode::new(args); | ||
|  | ||
| let (engine_api_tx, _engine_api_rx) = oneshot::channel(); | ||
|  | ||
| let engine_api = | ||
| EngineApiExt::new(OpEngineApiBuilder::<OpEngineValidatorBuilder>::default(), move |api| { | ||
| let _ = engine_api_tx.send(api); | ||
| }); | ||
|         
                  lean-apple marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| let _builder = NodeBuilder::new(config) | ||
| .with_database(db) | ||
| .with_types::<OpNode>() | ||
| .with_components(op_node.components()) | ||
| .with_add_ons(OpAddOns::default().with_engine_api(engine_api)) | ||
| .on_component_initialized(move |ctx| { | ||
| let _provider = ctx.provider(); | ||
| Ok(()) | ||
| }) | ||
| .on_node_started(|_full_node| Ok(())) | ||
| .on_rpc_started(|_ctx, handles| { | ||
| let _client = handles.rpc.http_client(); | ||
| Ok(()) | ||
| }) | ||
| .check_launch(); | ||
| } | ||
      
      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.