chore: remove redundant suffix in ChainPath methods (#8025)

This commit is contained in:
DaniPopes
2024-05-01 16:59:42 +02:00
committed by GitHub
parent c1f5b45bbd
commit f157ec83b6
30 changed files with 110 additions and 130 deletions

View File

@ -271,63 +271,65 @@ impl<D> ChainPath<D> {
/// Returns the path to the reth data directory for this chain.
///
/// `<DIR>/<CHAIN_ID>`
pub fn data_dir_path(&self) -> PathBuf {
self.0.as_ref().into()
pub fn data_dir(&self) -> &Path {
self.0.as_ref()
}
/// Returns the path to the db directory for this chain.
///
/// `<DIR>/<CHAIN_ID>/db`
pub fn db_path(&self) -> PathBuf {
self.0.join("db").into()
pub fn db(&self) -> PathBuf {
self.data_dir().join("db")
}
/// Returns the path to the static_files directory for this chain.
pub fn static_files_path(&self) -> PathBuf {
self.0.join("static_files").into()
///
/// `<DIR>/<CHAIN_ID>/static_files`
pub fn static_files(&self) -> PathBuf {
self.data_dir().join("static_files")
}
/// Returns the path to the reth p2p secret key for this chain.
///
/// `<DIR>/<CHAIN_ID>/discovery-secret`
pub fn p2p_secret_path(&self) -> PathBuf {
self.0.join("discovery-secret").into()
pub fn p2p_secret(&self) -> PathBuf {
self.data_dir().join("discovery-secret")
}
/// Returns the path to the known peers file for this chain.
///
/// `<DIR>/<CHAIN_ID>/known-peers.json`
pub fn known_peers_path(&self) -> PathBuf {
self.0.join("known-peers.json").into()
pub fn known_peers(&self) -> PathBuf {
self.data_dir().join("known-peers.json")
}
/// Returns the path to the blobstore directory for this chain where blobs of unfinalized
/// transactions are stored.
///
/// `<DIR>/<CHAIN_ID>/blobstore`
pub fn blobstore_path(&self) -> PathBuf {
self.0.join("blobstore").into()
pub fn blobstore(&self) -> PathBuf {
self.data_dir().join("blobstore")
}
/// Returns the path to the local transactions backup file
///
/// `<DIR>/<CHAIN_ID>/txpool-transactions-backup.rlp`
pub fn txpool_transactions_path(&self) -> PathBuf {
self.0.join("txpool-transactions-backup.rlp").into()
pub fn txpool_transactions(&self) -> PathBuf {
self.data_dir().join("txpool-transactions-backup.rlp")
}
/// Returns the path to the config file for this chain.
///
/// `<DIR>/<CHAIN_ID>/reth.toml`
pub fn config_path(&self) -> PathBuf {
self.0.join("reth.toml").into()
pub fn config(&self) -> PathBuf {
self.data_dir().join("reth.toml")
}
/// Returns the path to the jwtsecret file for this chain.
///
/// `<DIR>/<CHAIN_ID>/jwt.hex`
pub fn jwt_path(&self) -> PathBuf {
self.0.join("jwt.hex").into()
pub fn jwt(&self) -> PathBuf {
self.data_dir().join("jwt.hex")
}
}
@ -359,7 +361,7 @@ mod tests {
let path = path.unwrap_or_chain_default(Chain::mainnet());
assert!(path.as_ref().ends_with("reth/mainnet"), "{path:?}");
let db_path = path.db_path();
let db_path = path.db();
assert!(db_path.ends_with("reth/mainnet/db"), "{db_path:?}");
let path = MaybePlatformPath::<DataDirPath>::from_str("my/path/to/datadir").unwrap();

View File

@ -234,7 +234,7 @@ impl NodeConfig {
/// Get the network secret from the given data dir
pub fn network_secret(&self, data_dir: &ChainPath<DataDirPath>) -> eyre::Result<SecretKey> {
let network_secret_path =
self.network.p2p_secret_key.clone().unwrap_or_else(|| data_dir.p2p_secret_path());
self.network.p2p_secret_key.clone().unwrap_or_else(|| data_dir.p2p_secret());
debug!(target: "reth::cli", ?network_secret_path, "Loading p2p key file");
let secret_key = get_secret_key(&network_secret_path)?;
Ok(secret_key)
@ -299,7 +299,7 @@ impl NodeConfig {
) -> eyre::Result<NetworkConfig<C>> {
info!(target: "reth::cli", "Connecting to P2P network");
let secret_key = self.network_secret(data_dir)?;
let default_peers_path = data_dir.known_peers_path();
let default_peers_path = data_dir.known_peers();
Ok(self.load_network_config(config, client, executor, head, secret_key, default_peers_path))
}

View File

@ -100,7 +100,7 @@ where
async fn build_pool(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Pool> {
let data_dir = ctx.data_dir();
let blob_store = DiskFileBlobStore::open(data_dir.blobstore_path(), Default::default())?;
let blob_store = DiskFileBlobStore::open(data_dir.blobstore(), Default::default())?;
let validator = TransactionValidationTaskExecutor::eth_builder(ctx.chain_spec())
.with_head_timestamp(ctx.head().timestamp)
.kzg_settings(ctx.kzg_settings()?)
@ -114,7 +114,7 @@ where
let transaction_pool =
reth_transaction_pool::Pool::eth_pool(validator, blob_store, ctx.pool_config());
info!(target: "reth::cli", "Transaction pool initialized");
let transactions_path = data_dir.txpool_transactions_path();
let transactions_path = data_dir.txpool_transactions();
// spawn txpool maintenance task
{

View File

@ -533,7 +533,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_path();
let default_peers_path = self.data_dir().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",

View File

@ -61,7 +61,7 @@ impl LaunchContext {
/// Loads the reth config with the configured `data_dir` and overrides settings according to the
/// `config`.
pub fn load_toml_config(&self, config: &NodeConfig) -> eyre::Result<reth_config::Config> {
let config_path = config.config.clone().unwrap_or_else(|| self.data_dir.config_path());
let config_path = config.config.clone().unwrap_or_else(|| self.data_dir.config());
let mut toml_config = confy::load_path::<reth_config::Config>(&config_path)
.wrap_err_with(|| format!("Could not load config file {config_path:?}"))?;
@ -192,7 +192,7 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
pub fn ensure_etl_datadir(mut self) -> Self {
if self.toml_config_mut().stages.etl.dir.is_none() {
self.toml_config_mut().stages.etl.dir =
Some(EtlConfig::from_datadir(&self.data_dir().data_dir_path()))
Some(EtlConfig::from_datadir(self.data_dir().data_dir()))
}
self
@ -273,7 +273,7 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
/// Loads the JWT secret for the engine API
pub fn auth_jwt_secret(&self) -> eyre::Result<JwtSecret> {
let default_jwt_path = self.data_dir().jwt_path();
let default_jwt_path = self.data_dir().jwt();
let secret = self.node_config().rpc.auth_jwt_secret(default_jwt_path)?;
Ok(secret)
}
@ -299,7 +299,7 @@ where
let factory = ProviderFactory::new(
self.right().clone(),
self.chain_spec(),
self.data_dir().static_files_path(),
self.data_dir().static_files(),
)?
.with_static_files_metrics();

View File

@ -119,7 +119,7 @@ where
async fn build_pool(self, ctx: &BuilderContext<Node>) -> eyre::Result<Self::Pool> {
let data_dir = ctx.data_dir();
let blob_store = DiskFileBlobStore::open(data_dir.blobstore_path(), Default::default())?;
let blob_store = DiskFileBlobStore::open(data_dir.blobstore(), Default::default())?;
let validator = TransactionValidationTaskExecutor::eth_builder(ctx.chain_spec())
.with_head_timestamp(ctx.head().timestamp)
@ -139,7 +139,7 @@ where
ctx.pool_config(),
);
info!(target: "reth::cli", "Transaction pool initialized");
let transactions_path = data_dir.txpool_transactions_path();
let transactions_path = data_dir.txpool_transactions();
// spawn txpool maintenance task
{