Skip to content

feat: use chain-specific data dirs#2495

Merged
gakonst merged 14 commits intomainfrom
dan/separate-dirs
May 2, 2023
Merged

feat: use chain-specific data dirs#2495
gakonst merged 14 commits intomainfrom
dan/separate-dirs

Conversation

@Rjected
Copy link
Member

@Rjected Rjected commented May 1, 2023

WIP attempt at changing the reth directory structure to revolve around a data directory with chain-specific directories for all other node data.

The new structure will revolve around the --datadir command line argument, which will set up folders for chains by either their chain ID, or name (e.g. mainnet), depending on whether or not we have specific names for the chain being run.

Fixes #2179

TODO:

  • make it compile
  • s/--data-dir/--datadir

@Rjected Rjected changed the title wip: use chain-specific data dirs feat: use chain-specific data dirs May 1, 2023
@Rjected
Copy link
Member Author

Rjected commented May 1, 2023

tree output now:

dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> tree /Users/dan/Library/Application\ Support/reth/
/Users/dan/Library/Application Support/reth/
├── mainnet
│   ├── db
│   │   ├── mdbx.dat
│   │   └── mdbx.lck
│   ├── jwtsecret
│   │   └── jwt.hex
│   ├── net
│   │   └── known_peers.json
│   └── p2p
│       └── secret
└── reth.toml

6 directories, 6 files

@Rjected Rjected marked this pull request as ready for review May 1, 2023 21:27
@Rjected Rjected requested a review from onbjerg as a code owner May 1, 2023 21:27
@Rjected Rjected requested a review from gakonst May 1, 2023 21:28
@codecov-commenter
Copy link

codecov-commenter commented May 1, 2023

Codecov Report

Merging #2495 (3c70582) into main (a887557) will decrease coverage by 0.07%.
The diff coverage is 26.11%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #2495      +/-   ##
==========================================
- Coverage   71.68%   71.61%   -0.07%     
==========================================
  Files         488      489       +1     
  Lines       60828    61100     +272     
==========================================
+ Hits        43603    43758     +155     
- Misses      17225    17342     +117     
Flag Coverage Δ
integration-tests 17.98% <0.00%> (-0.07%) ⬇️
unit-tests 66.64% <26.11%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
bin/reth/src/args/network_args.rs 3.50% <0.00%> (-1.76%) ⬇️
bin/reth/src/args/rpc_server_args.rs 41.15% <0.00%> (+0.16%) ⬆️
bin/reth/src/args/secret_key.rs 0.00% <0.00%> (ø)
bin/reth/src/config.rs 6.25% <0.00%> (+0.36%) ⬆️
bin/reth/src/dump_stage/execution.rs 0.00% <0.00%> (ø)
bin/reth/src/dump_stage/hashing_account.rs 0.00% <0.00%> (ø)
bin/reth/src/dump_stage/hashing_storage.rs 0.00% <0.00%> (ø)
bin/reth/src/dump_stage/merkle.rs 0.00% <0.00%> (ø)
bin/reth/src/stage/mod.rs 1.78% <7.14%> (-1.82%) ⬇️
bin/reth/src/dump_stage/mod.rs 5.35% <9.09%> (-2.06%) ⬇️
... and 8 more

... and 56 files with indirect coverage changes

@Rjected
Copy link
Member Author

Rjected commented May 1, 2023

tree output when setting the datadir:

dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> cargo run -- node --debug.tip 0xdc2d938e4cd0a149681e9e04352953ef5ab399d59bcd5b0357f6c0797470a524 --datadir ~/temp-reth-datadir
..... syncing logs
dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> tree ~/temp-reth-datadir/
/Users/dan/temp-reth-datadir/
├── db
│   ├── mdbx.dat
│   └── mdbx.lck
├── jwtsecret
│   └── jwt.hex
└── p2p
    └── secret

4 directories, 4 files

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some ideas to simplify further per my comment in the original issue. also we want reth.toml to also follow the datadir, vs being left hanging outside of it. NO file should be outside of the datadir.

@Rjected
Copy link
Member Author

Rjected commented May 1, 2023

Ok, now:

dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> cargo run -- node --debug.tip 0xdc2d938e4cd0a149681e9e04352953ef5ab399d59bcd5b0357f6c0797470a524
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
     Running `target/debug/reth node --debug.tip 0xdc2d938e4cd0a149681e9e04352953ef5ab399d59bcd5b0357f6c0797470a524`
2023-05-01T22:10:34.912767Z  INFO reth 0.1.0 starting
2023-05-01T22:10:34.918184Z  INFO Configuration loaded path="/Users/dan/Library/Application Support/reth/mainnet/reth.toml"
2023-05-01T22:10:34.918214Z  INFO Opening database path="/Users/dan/Library/Application Support/reth/mainnet/db"
...rest of syncing logs
dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> tree /Users/dan/Library/Application\ Support/reth/
/Users/dan/Library/Application Support/reth/
└── mainnet
    ├── db
    │   ├── mdbx.dat
    │   └── mdbx.lck
    ├── jwtsecret
    │   └── jwt.hex
    ├── p2p
    │   └── secret
    └── reth.toml

5 directories, 5 files

With custom dir:

dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs) [1]> cargo run -- node --debug.tip 0xdc2d938e4cd0a149681e9e04352953ef5ab399d59bcd5b0357f6c0797470a524 --datadir ~/temp-reth-datadir
   Compiling reth v0.1.0 (/Users/dan/projects/reth/bin/reth)
    Finished dev [unoptimized + debuginfo] target(s) in 10.48s
     Running `target/debug/reth node --debug.tip 0xdc2d938e4cd0a149681e9e04352953ef5ab399d59bcd5b0357f6c0797470a524 --datadir /Users/dan/temp-reth-datadir`
2023-05-01T22:06:17.296553Z  INFO reth 0.1.0 starting
2023-05-01T22:06:17.301951Z  INFO Configuration loaded path="/Users/dan/temp-reth-datadir/reth.toml"
2023-05-01T22:06:17.301979Z  INFO Opening database path="/Users/dan/temp-reth-datadir/db"
... rest of syncing logs
dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> tree ~/temp-reth-datadir/
/Users/dan/temp-reth-datadir/
├── db
│   ├── mdbx.dat
│   └── mdbx.lck
├── jwtsecret
│   └── jwt.hex
├── p2p
│   └── secret
└── reth.toml

4 directories, 5 files

@Rjected
Copy link
Member Author

Rjected commented May 1, 2023

removing the extra dirs next

@Rjected
Copy link
Member Author

Rjected commented May 1, 2023

New structure:

dan@Dans-MacBook-Pro ~/p/reth (dan/separate-dirs)> tree /Users/dan/Library/Application\ Support/reth/
/Users/dan/Library/Application Support/reth/
└── mainnet
    ├── db
    │   ├── mdbx.dat
    │   └── mdbx.lck
    ├── discovery-secret
    ├── jwt.hex
    ├── known-peers.json
    └── reth.toml

3 directories, 6 files

@Rjected Rjected requested a review from gakonst May 2, 2023 14:44
Comment on lines +24 to +27
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove in follow-up, open issue and we can have 3rd party close it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #2528

Comment on lines +32 to 36
/// The path to the database folder. If not specified, it will be set in the data dir for the
/// chain being used.
#[arg(long, value_name = "PATH", verbatim_doc_comment)]
db: Option<PathBuf>,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm

Comment on lines +251 to 276

/// Returns the path to the db directory for this chain.
pub fn db_path(&self) -> PathBuf {
self.0.join("db").into()
}

/// Returns the path to the reth p2p secret key for this chain.
pub fn p2p_secret_path(&self) -> PathBuf {
self.0.join("discovery-secret").into()
}

/// Returns the path to the known peers file for this chain.
pub fn known_peers_path(&self) -> PathBuf {
self.0.join("known-peers.json").into()
}

/// Returns the path to the config file for this chain.
pub fn config_path(&self) -> PathBuf {
self.0.join("reth.toml").into()
}

/// Returns the path to the jwtsecret file for this chain.
pub fn jwt_path(&self) -> PathBuf {
self.0.join("jwt.hex").into()
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

@gakonst gakonst merged commit ecc7ae9 into main May 2, 2023
@gakonst gakonst deleted the dan/separate-dirs branch May 2, 2023 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use an explicit root data dir to contain all reth data

3 participants