-
Notifications
You must be signed in to change notification settings - Fork 37
Remove flashblocks conditional compilation #67
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 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a27446f
Simplify vanilla builder types
karim-agha 353e858
Simplify flashblocks builder types
karim-agha c4bd636
checkpoint
karim-agha b3d13e9
Done
karim-agha 246713a
Updated tests
karim-agha d5f40f8
removed dashmap dependency
karim-agha cd4ce63
code comment
karim-agha 95cdc8c
lint and CI
karim-agha a8805da
Unified context between flashblocks and standard builder
karim-agha e1b0579
SozinM feedback
karim-agha 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
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,5 +1,81 @@ | ||
| use crate::builders::BuilderMode; | ||
| use clap::Parser; | ||
| pub use op::OpRbuilderArgs; | ||
| use playground::PlaygroundOptions; | ||
| use reth_optimism_cli::{chainspec::OpChainSpecParser, commands::Commands}; | ||
|
|
||
| mod op; | ||
| mod playground; | ||
|
|
||
| pub use op::OpRbuilderArgs; | ||
| pub use playground::CliExt; | ||
| /// This trait is used to extend Reth's CLI with additional functionality that | ||
| /// are specific to the OP builder, such as populating default values for CLI arguments | ||
| /// when running in the playground mode or checking the builder mode. | ||
| /// | ||
| pub trait CliExt { | ||
| /// Populates the default values for the CLI arguments when the user specifies | ||
| /// the `--builder.playground` flag. | ||
| fn populate_defaults(self) -> Self; | ||
|
|
||
| /// Returns the builder mode that the node is started with. | ||
| fn builder_mode(&self) -> BuilderMode; | ||
|
|
||
| /// Returns the Cli instance with the parsed command line arguments | ||
| /// and defaults populated if applicable. | ||
| fn parsed() -> Self; | ||
| } | ||
|
|
||
| pub type Cli = reth_optimism_cli::Cli<OpChainSpecParser, OpRbuilderArgs>; | ||
|
|
||
| impl CliExt for Cli { | ||
| /// Checks if the node is started with the `--builder.playground` flag, | ||
| /// and if so, populates the default values for the CLI arguments from the | ||
| /// playground configuration. | ||
| /// | ||
| /// The `--builder.playground` flag is used to populate the CLI arguments with | ||
| /// default values for running the builder against the playground environment. | ||
| /// | ||
| /// The values are populated from the default directory of the playground | ||
| /// configuration, which is `$HOME/.playground/devnet/` by default. | ||
| /// | ||
| /// Any manually specified CLI arguments by the user will override the defaults. | ||
| fn populate_defaults(self) -> Self { | ||
| let Commands::Node(ref node_command) = self.command else { | ||
| // playground defaults are only relevant if running the node commands. | ||
| return self; | ||
| }; | ||
|
|
||
| let Some(ref playground_dir) = node_command.ext.playground else { | ||
| // not running in playground mode. | ||
| return self; | ||
| }; | ||
|
|
||
| let options = match PlaygroundOptions::new(playground_dir) { | ||
| Ok(options) => options, | ||
| Err(e) => exit(e), | ||
| }; | ||
|
|
||
| options.apply(self) | ||
| } | ||
|
|
||
| fn parsed() -> Self { | ||
| Cli::parse().populate_defaults() | ||
| } | ||
|
|
||
| /// Returns the type of builder implementation that the node is started with. | ||
| /// Currently supports `Standard` and `Flashblocks` modes. | ||
| fn builder_mode(&self) -> BuilderMode { | ||
| if let Commands::Node(ref node_command) = self.command { | ||
| if node_command.ext.enable_flashblocks { | ||
| return BuilderMode::Flashblocks; | ||
| } | ||
| } | ||
| BuilderMode::Standard | ||
| } | ||
| } | ||
|
|
||
| /// Following clap's convention, a failure to parse the command line arguments | ||
| /// will result in terminating the program with a non-zero exit code. | ||
| fn exit(error: eyre::Report) -> ! { | ||
| eprintln!("{error}"); | ||
| std::process::exit(-1); | ||
| } |
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,55 @@ | ||
| use crate::{args::OpRbuilderArgs, builders::BuilderConfig}; | ||
| use core::{ | ||
| net::{Ipv4Addr, SocketAddr}, | ||
| time::Duration, | ||
| }; | ||
|
|
||
| /// Configuration values that are specific to the flashblocks builder. | ||
| #[derive(Debug, Clone)] | ||
| pub struct FlashblocksConfig { | ||
| /// The address of the websockets endpoint that listens for subscriptions to | ||
| /// new flashblocks updates. | ||
| pub ws_addr: SocketAddr, | ||
|
|
||
| /// How often a flashblock is produced. This is independent of the block time of the chain. | ||
| /// Each block will contain one or more flashblocks. On average, the number of flashblocks | ||
| /// per block is equal to the block time divided by the flashblock interval. | ||
| pub interval: Duration, | ||
| } | ||
|
|
||
| impl Default for FlashblocksConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| ws_addr: SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 1111), | ||
| interval: Duration::from_millis(250), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<OpRbuilderArgs> for FlashblocksConfig { | ||
| type Error = eyre::Report; | ||
|
|
||
| fn try_from(args: OpRbuilderArgs) -> Result<Self, Self::Error> { | ||
| let ws_addr = args | ||
| .flashblocks_ws_url | ||
| .parse() | ||
| .map_err(|_| eyre::eyre!("Invalid flashblocks websocket address"))?; | ||
|
|
||
| let interval = Duration::from_millis(args.flashblock_block_time); | ||
|
|
||
| Ok(Self { ws_addr, interval }) | ||
| } | ||
| } | ||
|
|
||
| pub trait FlashBlocksConfigExt { | ||
| fn flashblocks_per_block(&self) -> u64; | ||
| } | ||
|
|
||
| impl FlashBlocksConfigExt for BuilderConfig<FlashblocksConfig> { | ||
| fn flashblocks_per_block(&self) -> u64 { | ||
| if self.block_time.as_millis() == 0 { | ||
| return 0; | ||
| } | ||
| (self.block_time.as_millis() / self.specific.interval.as_millis()) as u64 | ||
| } | ||
| } |
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.