-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
refactor(node-builder): use datadir provided by the config #8592
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d887fe
refactor(node-builder): use datadir provided by the config
shekhirin 087b9d3
semicolon
shekhirin cb10213
Revert "semicolon"
shekhirin 4ad109b
remove data dir in more places
shekhirin 554c024
Merge remote-tracking branch 'origin/main' into alexey/node-config-da…
shekhirin 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 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 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 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 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 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 |
---|---|---|
|
@@ -20,7 +20,7 @@ use reth_network::{NetworkBuilder, NetworkConfig, NetworkHandle}; | |
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes}; | ||
use reth_node_core::{ | ||
cli::config::{PayloadBuilderConfig, RethTransactionPoolConfig}, | ||
dirs::{ChainPath, DataDirPath, MaybePlatformPath}, | ||
dirs::{DataDirPath, MaybePlatformPath}, | ||
node_config::NodeConfig, | ||
primitives::{kzg::KzgSettings, Head}, | ||
utils::write_peers_to_file, | ||
|
@@ -161,26 +161,24 @@ impl<DB> NodeBuilder<DB> { | |
/// Preconfigure the builder with the context to launch the node. | ||
/// | ||
/// This provides the task executor and the data directory for the node. | ||
pub const fn with_launch_context( | ||
self, | ||
task_executor: TaskExecutor, | ||
data_dir: ChainPath<DataDirPath>, | ||
) -> WithLaunchContext<Self> { | ||
WithLaunchContext { builder: self, task_executor, data_dir } | ||
pub const fn with_launch_context(self, task_executor: TaskExecutor) -> WithLaunchContext<Self> { | ||
WithLaunchContext { builder: self, task_executor } | ||
} | ||
|
||
/// Creates an _ephemeral_ preconfigured node for testing purposes. | ||
pub fn testing_node( | ||
self, | ||
mut self, | ||
task_executor: TaskExecutor, | ||
) -> WithLaunchContext<NodeBuilder<Arc<TempDatabase<DatabaseEnv>>>> { | ||
let path = MaybePlatformPath::<DataDirPath>::from(tempdir_path()); | ||
self.config.datadir.datadir = path.clone(); | ||
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. can we add setter for this on NodeConfig @shekhirin |
||
|
||
let data_dir = | ||
path.unwrap_or_chain_default(self.config.chain.chain, self.config.datadir.clone()); | ||
|
||
let db = create_test_rw_db_with_path(data_dir.db()); | ||
|
||
WithLaunchContext { builder: self.with_database(db), task_executor, data_dir } | ||
WithLaunchContext { builder: self.with_database(db), task_executor } | ||
} | ||
} | ||
|
||
|
@@ -217,19 +215,13 @@ where | |
pub struct WithLaunchContext<Builder> { | ||
builder: Builder, | ||
task_executor: TaskExecutor, | ||
data_dir: ChainPath<DataDirPath>, | ||
} | ||
|
||
impl<Builder> WithLaunchContext<Builder> { | ||
/// Returns a reference to the task executor. | ||
pub const fn task_executor(&self) -> &TaskExecutor { | ||
&self.task_executor | ||
} | ||
|
||
/// Returns a reference to the data directory. | ||
pub const fn data_dir(&self) -> &ChainPath<DataDirPath> { | ||
&self.data_dir | ||
} | ||
} | ||
|
||
impl<DB> WithLaunchContext<NodeBuilder<DB>> | ||
|
@@ -246,11 +238,7 @@ where | |
where | ||
T: NodeTypes, | ||
{ | ||
WithLaunchContext { | ||
builder: self.builder.with_types(), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
WithLaunchContext { builder: self.builder.with_types(), task_executor: self.task_executor } | ||
} | ||
|
||
/// Preconfigures the node with a specific node implementation. | ||
|
@@ -305,7 +293,6 @@ where | |
WithLaunchContext { | ||
builder: self.builder.with_components(components_builder), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
} | ||
} | ||
|
@@ -326,7 +313,6 @@ where | |
Self { | ||
builder: self.builder.on_component_initialized(hook), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
} | ||
|
||
|
@@ -339,11 +325,7 @@ where | |
+ Send | ||
+ 'static, | ||
{ | ||
Self { | ||
builder: self.builder.on_node_started(hook), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
Self { builder: self.builder.on_node_started(hook), task_executor: self.task_executor } | ||
} | ||
|
||
/// Sets the hook that is run once the rpc server is started. | ||
|
@@ -356,11 +338,7 @@ where | |
+ Send | ||
+ 'static, | ||
{ | ||
Self { | ||
builder: self.builder.on_rpc_started(hook), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
Self { builder: self.builder.on_rpc_started(hook), task_executor: self.task_executor } | ||
} | ||
|
||
/// Sets the hook that is run to configure the rpc modules. | ||
|
@@ -372,11 +350,7 @@ where | |
+ Send | ||
+ 'static, | ||
{ | ||
Self { | ||
builder: self.builder.extend_rpc_modules(hook), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
Self { builder: self.builder.extend_rpc_modules(hook), task_executor: self.task_executor } | ||
} | ||
|
||
/// Installs an `ExEx` (Execution Extension) in the node. | ||
|
@@ -395,17 +369,16 @@ where | |
Self { | ||
builder: self.builder.install_exex(exex_id, exex), | ||
task_executor: self.task_executor, | ||
data_dir: self.data_dir, | ||
} | ||
} | ||
|
||
/// Launches the node and returns a handle to it. | ||
pub async fn launch( | ||
self, | ||
) -> eyre::Result<NodeHandle<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>> { | ||
let Self { builder, task_executor, data_dir } = self; | ||
let Self { builder, task_executor } = self; | ||
|
||
let launcher = DefaultNodeLauncher::new(task_executor, data_dir); | ||
let launcher = DefaultNodeLauncher::new(task_executor, builder.config.datadir()); | ||
builder.launch_with(launcher).await | ||
} | ||
|
||
|
@@ -425,8 +398,6 @@ pub struct BuilderContext<Node: FullNodeTypes> { | |
pub(crate) provider: Node::Provider, | ||
/// The executor of the node. | ||
pub(crate) executor: TaskExecutor, | ||
/// The data dir of the node. | ||
pub(crate) data_dir: ChainPath<DataDirPath>, | ||
/// The config of the node | ||
pub(crate) config: NodeConfig, | ||
/// loaded config | ||
|
@@ -439,11 +410,10 @@ impl<Node: FullNodeTypes> BuilderContext<Node> { | |
head: Head, | ||
provider: Node::Provider, | ||
executor: TaskExecutor, | ||
data_dir: ChainPath<DataDirPath>, | ||
config: NodeConfig, | ||
reth_config: reth_config::Config, | ||
) -> Self { | ||
Self { head, provider, executor, data_dir, config, reth_config } | ||
Self { head, provider, executor, config, reth_config } | ||
} | ||
|
||
/// Returns the configured provider to interact with the blockchain. | ||
|
@@ -461,13 +431,6 @@ impl<Node: FullNodeTypes> BuilderContext<Node> { | |
&self.config | ||
} | ||
|
||
/// Returns the data dir of the node. | ||
/// | ||
/// This gives access to all relevant files and directories of the node's datadir. | ||
pub const fn data_dir(&self) -> &ChainPath<DataDirPath> { | ||
&self.data_dir | ||
} | ||
|
||
/// Returns the executor of the node. | ||
/// | ||
/// This can be used to execute async tasks or functions during the setup. | ||
|
@@ -502,7 +465,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> { | |
self.provider.clone(), | ||
self.executor.clone(), | ||
self.head, | ||
self.data_dir(), | ||
self.config.datadir(), | ||
) | ||
} | ||
|
||
|
@@ -514,7 +477,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> { | |
self.provider.clone(), | ||
self.executor.clone(), | ||
self.head, | ||
self.data_dir(), | ||
self.config.datadir(), | ||
) | ||
.await | ||
} | ||
|
@@ -539,7 +502,7 @@ impl<Node: FullNodeTypes> BuilderContext<Node> { | |
self.executor.spawn_critical("p2p txpool", txpool); | ||
self.executor.spawn_critical("p2p eth request handler", eth); | ||
|
||
let default_peers_path = self.data_dir().known_peers(); | ||
let default_peers_path = self.config.datadir().known_peers(); | ||
let known_peers_file = self.config.network.persistent_peers_file(default_peers_path); | ||
self.executor.spawn_critical_with_graceful_shutdown_signal( | ||
"p2p network task", | ||
|
@@ -560,7 +523,6 @@ impl<Node: FullNodeTypes> std::fmt::Debug for BuilderContext<Node> { | |
.field("head", &self.head) | ||
.field("provider", &std::any::type_name::<Node::Provider>()) | ||
.field("executor", &self.executor) | ||
.field("data_dir", &self.data_dir) | ||
.field("config", &self.config) | ||
.finish() | ||
} | ||
|
This file contains 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 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 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 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 |
---|---|---|
|
@@ -266,7 +266,7 @@ where | |
Err(EthApiError::InvalidTransaction(RpcInvalidTransactionError::GasTooHigh)) | ||
if tx_request_gas_limit.is_some() || tx_request_gas_price.is_some() => | ||
{ | ||
return Err(self.map_out_of_gas_err(block_env_gas_limit, env, &mut db)); | ||
return Err(self.map_out_of_gas_err(block_env_gas_limit, env, &mut db)) | ||
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. -.- |
||
} | ||
// Propagate other results (successful or other errors). | ||
ethres => ethres?, | ||
|
This file contains 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 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 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 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 |
---|---|---|
|
@@ -66,7 +66,7 @@ impl<'a> StructHandler<'a> { | |
}) | ||
} | ||
|
||
return; | ||
return | ||
} | ||
|
||
let name = format_ident!("{name}"); | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's awesome