mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: replace std::fs usages with reth-primitives (#5813)
This commit is contained in:
@ -179,7 +179,7 @@ impl Command {
|
|||||||
let mut blobs_bundle = self
|
let mut blobs_bundle = self
|
||||||
.blobs_bundle_path
|
.blobs_bundle_path
|
||||||
.map(|path| -> eyre::Result<BlobsBundleV1> {
|
.map(|path| -> eyre::Result<BlobsBundleV1> {
|
||||||
let contents = std::fs::read_to_string(&path)
|
let contents = fs::read_to_string(&path)
|
||||||
.wrap_err(format!("could not read {}", path.display()))?;
|
.wrap_err(format!("could not read {}", path.display()))?;
|
||||||
serde_json::from_str(&contents).wrap_err("failed to deserialize blobs bundle")
|
serde_json::from_str(&contents).wrap_err("failed to deserialize blobs bundle")
|
||||||
})
|
})
|
||||||
|
|||||||
@ -56,6 +56,7 @@ use reth_network::{NetworkBuilder, NetworkConfig, NetworkEvents, NetworkHandle,
|
|||||||
use reth_network_api::{NetworkInfo, PeersInfo};
|
use reth_network_api::{NetworkInfo, PeersInfo};
|
||||||
use reth_primitives::{
|
use reth_primitives::{
|
||||||
constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP},
|
constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP},
|
||||||
|
fs,
|
||||||
kzg::KzgSettings,
|
kzg::KzgSettings,
|
||||||
stage::StageId,
|
stage::StageId,
|
||||||
BlockHashOrNumber, BlockNumber, ChainSpec, DisplayHardforks, Head, SealedHeader, B256,
|
BlockHashOrNumber, BlockNumber, ChainSpec, DisplayHardforks, Head, SealedHeader, B256,
|
||||||
@ -1056,8 +1057,8 @@ async fn run_network_until_shutdown<C>(
|
|||||||
let known_peers = network.all_peers().collect::<Vec<_>>();
|
let known_peers = network.all_peers().collect::<Vec<_>>();
|
||||||
if let Ok(known_peers) = serde_json::to_string_pretty(&known_peers) {
|
if let Ok(known_peers) = serde_json::to_string_pretty(&known_peers) {
|
||||||
trace!(target: "reth::cli", peers_file =?file_path, num_peers=%known_peers.len(), "Saving current peers");
|
trace!(target: "reth::cli", peers_file =?file_path, num_peers=%known_peers.len(), "Saving current peers");
|
||||||
let parent_dir = file_path.parent().map(std::fs::create_dir_all).transpose();
|
let parent_dir = file_path.parent().map(fs::create_dir_all).transpose();
|
||||||
match parent_dir.and_then(|_| std::fs::write(&file_path, known_peers)) {
|
match parent_dir.and_then(|_| fs::write(&file_path, known_peers)) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!(target: "reth::cli", peers_file=?file_path, "Wrote network peers to file");
|
info!(target: "reth::cli", peers_file=?file_path, "Wrote network peers to file");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use super::{constants, StageRange};
|
|||||||
use reth_db::{
|
use reth_db::{
|
||||||
cursor::DbCursorRO, database::Database, tables, transaction::DbTx, DatabaseError as DbError,
|
cursor::DbCursorRO, database::Database, tables, transaction::DbTx, DatabaseError as DbError,
|
||||||
};
|
};
|
||||||
use reth_primitives::stage::StageCheckpoint;
|
use reth_primitives::{fs, stage::StageCheckpoint};
|
||||||
use reth_stages::{
|
use reth_stages::{
|
||||||
stages::{AccountHashingStage, SeedOpts},
|
stages::{AccountHashingStage, SeedOpts},
|
||||||
test_utils::TestStageDB,
|
test_utils::TestStageDB,
|
||||||
@ -61,7 +61,7 @@ fn generate_testdata_db(num_blocks: u64) -> (PathBuf, StageRange) {
|
|||||||
|
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
// create the dirs
|
// create the dirs
|
||||||
std::fs::create_dir_all(&path).unwrap();
|
fs::create_dir_all(&path).unwrap();
|
||||||
println!("Account Hashing testdata not found, generating to {:?}", path.display());
|
println!("Account Hashing testdata not found, generating to {:?}", path.display());
|
||||||
let db = TestStageDB::new(&path);
|
let db = TestStageDB::new(&path);
|
||||||
let provider = db.factory.provider_rw().unwrap();
|
let provider = db.factory.provider_rw().unwrap();
|
||||||
|
|||||||
@ -13,7 +13,7 @@ use reth_interfaces::test_utils::{
|
|||||||
random_eoa_account_range,
|
random_eoa_account_range,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use reth_primitives::{Account, Address, SealedBlock, B256, U256};
|
use reth_primitives::{fs, Account, Address, SealedBlock, B256, U256};
|
||||||
use reth_stages::{
|
use reth_stages::{
|
||||||
stages::{AccountHashingStage, StorageHashingStage},
|
stages::{AccountHashingStage, StorageHashingStage},
|
||||||
test_utils::TestStageDB,
|
test_utils::TestStageDB,
|
||||||
@ -102,7 +102,7 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> PathBuf {
|
|||||||
|
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
// create the dirs
|
// create the dirs
|
||||||
std::fs::create_dir_all(&path).unwrap();
|
fs::create_dir_all(&path).unwrap();
|
||||||
println!("Transactions testdata not found, generating to {:?}", path.display());
|
println!("Transactions testdata not found, generating to {:?}", path.display());
|
||||||
let db = TestStageDB::new(&path);
|
let db = TestStageDB::new(&path);
|
||||||
|
|
||||||
|
|||||||
@ -157,6 +157,7 @@ pub mod test_utils {
|
|||||||
database::Database,
|
database::Database,
|
||||||
database_metrics::{DatabaseMetadata, DatabaseMetadataValue, DatabaseMetrics},
|
database_metrics::{DatabaseMetadata, DatabaseMetadataValue, DatabaseMetrics},
|
||||||
};
|
};
|
||||||
|
use reth_primitives::fs;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
/// Error during database open
|
/// Error during database open
|
||||||
@ -179,7 +180,7 @@ pub mod test_utils {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(db) = self.db.take() {
|
if let Some(db) = self.db.take() {
|
||||||
drop(db);
|
drop(db);
|
||||||
let _ = std::fs::remove_dir_all(&self.path);
|
let _ = fs::remove_dir_all(&self.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,6 +261,7 @@ mod tests {
|
|||||||
version::{db_version_file_path, DatabaseVersionError},
|
version::{db_version_file_path, DatabaseVersionError},
|
||||||
};
|
};
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
|
use reth_primitives::fs;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -280,8 +282,7 @@ mod tests {
|
|||||||
|
|
||||||
// Database is not empty, version file is malformed
|
// Database is not empty, version file is malformed
|
||||||
{
|
{
|
||||||
std::fs::write(path.path().join(db_version_file_path(&path)), "invalid-version")
|
fs::write(path.path().join(db_version_file_path(&path)), "invalid-version").unwrap();
|
||||||
.unwrap();
|
|
||||||
let db = init_db(&path, None);
|
let db = init_db(&path, None);
|
||||||
assert!(db.is_err());
|
assert!(db.is_err());
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
@ -292,7 +293,7 @@ mod tests {
|
|||||||
|
|
||||||
// Database is not empty, version file contains not matching version
|
// Database is not empty, version file contains not matching version
|
||||||
{
|
{
|
||||||
std::fs::write(path.path().join(db_version_file_path(&path)), "0").unwrap();
|
fs::write(path.path().join(db_version_file_path(&path)), "0").unwrap();
|
||||||
let db = init_db(&path, None);
|
let db = init_db(&path, None);
|
||||||
assert!(db.is_err());
|
assert!(db.is_err());
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
|
|||||||
Reference in New Issue
Block a user