paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.78k stars 1.02k forks source link

Support DNS names in `trusted_nodes` in reth.toml #9767

Closed kousu closed 1 month ago

kousu commented 1 month ago

If I have enode://s with hostnames -- rather than IP addresses -- I am able to bootstrap reth to talk to them using --trusted-peers the command line.

Here is it working:

start.sh ```sh #!/bin/sh set -e curl -L https://raw.githubusercontent.com/berachain/beacon-kit/988cfc795108c81e30e4c98e18da36cdcfff746f/testing/networks/80084/eth-genesis.json -o ~/genesis.json openssl rand -hex 32 | tr -d '\n' > /tmp/secret.hex cat > ~/reth.toml <

This runs and peers successfully:

logs ```console $ ./start.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7232 100 7232 0 0 51410 0 --:--:-- --:--:-- --:--:-- 51657 2024-07-03T22:00:15.762067Z INFO Initialized tracing, debug log directory: /data/reth/.cache/reth/logs/80084 2024-07-03T22:00:15.763933Z INFO Starting reth version="1.0.0 (83d412d)" 2024-07-03T22:00:15.764569Z INFO Opening database path="/data/reth/db" 2024-07-03T22:00:15.907568Z INFO Saving prune config to toml file 2024-07-03T22:00:15.907756Z INFO Configuration loaded path="/data/reth/reth.toml" 2024-07-03T22:00:15.907780Z INFO Adding trusted nodes 2024-07-03T22:00:15.935638Z INFO Verifying storage consistency. 2024-07-03T22:00:15.939323Z INFO Database opened 2024-07-03T22:00:15.939335Z INFO Starting metrics endpoint addr=127.0.0.1:9001 2024-07-03T22:00:15.939552Z INFO Pre-merge hard forks (block based): - Homestead @0 - Dao @0 - Tangerine @0 - SpuriousDragon @0 - Byzantium @0 - Constantinople @0 - Petersburg @0 - Istanbul @0 - MuirGlacier @0 - Berlin @0 - London @0 - ArrowGlacier @0 - GrayGlacier @0 Merge hard forks: - Paris @0 (network is known to be merged) Post-merge hard forks (timestamp based): - Shanghai @0 - Cancun @0 2024-07-03T22:00:15.939935Z INFO Transaction pool initialized 2024-07-03T22:00:15.940060Z INFO Loading saved peers file=/data/reth/known-peers.json 2024-07-03T22:00:15.941568Z INFO StaticFileProducer initialized 2024-07-03T22:00:15.941907Z INFO Pruner initialized prune_config=PruneConfig { block_interval: 5, segments: PruneModes { sender_recovery: Some(Full), transaction_lookup: None, receipts: None, account_history: Some(Distance(10064)), storage_history: Some(Distance(10064)), receipts_log_filter: ReceiptsLogPruneConfig({}) } } 2024-07-03T22:00:15.942088Z INFO Consensus engine initialized 2024-07-03T22:00:15.942132Z INFO Engine API handler initialized 2024-07-03T22:00:15.944685Z INFO RPC auth server started url=127.0.0.1:8552 2024-07-03T22:00:15.944733Z INFO RPC IPC server started path=/tmp/reth.ipc 2024-07-03T22:00:15.944740Z INFO RPC HTTP server started url=127.0.0.1:8545 2024-07-03T22:00:15.944750Z INFO Starting consensus engine 2024-07-03T22:00:18.948572Z INFO Status connected_peers=2 freelist=1806678 latest_block=980558 ```

If I put the IPv4 addresses in to reth.toml rather than on the command line, it also peers:

--- start.sh    2024-07-03 22:01:27.727068910 +0000
+++ start.sh    2024-07-03 22:02:27.149421127 +0000
@@ -6,6 +6,11 @@
 openssl rand -hex 32 | tr -d '\n' > /tmp/secret.hex

 cat > ~/reth.toml <<EOF
+[peers]
+# A list of ENRs for trusted peers, which are peers reth will always try to connect to.
+trusted_nodes = [
+    "enode://0401e494dbd0c84c5c0f72adac5985d2f2525e08b68d448958aae218f5ac8198a80d1498e0ebec2ce38b1b18d6750f6e61a56b4614c5a6c6cf0981c39aed47dc@34.159.32.127:30303",
+]
 EOF

 /usr/local/bin/reth node \
@@ -23,18 +28,10 @@
     --authrpc.port 8552 \
     --authrpc.jwtsecret /tmp/secret.hex \
     --metrics "127.0.0.1:9001" \
-    --trusted-peers "enode://0401e494dbd0c84c5c0f72adac5985d2f2525e08b68d448958aae218f5ac8198a80d1498e0ebec2ce38b1b18d6750f6e61a56b4614c5a6c6cf0981c39aed47dc@34.159.32.127:30303,enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303" \
+    --trusted-peers "enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303" \
start.sh ```sh #!/bin/sh set -e curl -L https://raw.githubusercontent.com/berachain/beacon-kit/988cfc795108c81e30e4c98e18da36cdcfff746f/testing/networks/80084/eth-genesis.json -o ~/genesis.json openssl rand -hex 32 | tr -d '\n' > /tmp/secret.hex cat > ~/reth.toml <
logs ```console $ ./start.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7232 100 7232 0 0 146k 0 --:--:-- --:--:-- --:--:-- 147k 2024-07-03T22:03:12.205065Z INFO Initialized tracing, debug log directory: /data/reth/.cache/reth/logs/80084 2024-07-03T22:03:12.206754Z INFO Starting reth version="1.0.0 (83d412d)" 2024-07-03T22:03:12.207376Z INFO Opening database path="/data/reth/db" 2024-07-03T22:03:12.311714Z INFO Saving prune config to toml file 2024-07-03T22:03:12.311914Z INFO Configuration loaded path="/data/reth/reth.toml" 2024-07-03T22:03:12.311937Z INFO Adding trusted nodes 2024-07-03T22:03:12.341205Z INFO Verifying storage consistency. 2024-07-03T22:03:12.344997Z INFO Database opened 2024-07-03T22:03:12.345009Z INFO Starting metrics endpoint addr=127.0.0.1:9001 2024-07-03T22:03:12.345237Z INFO Pre-merge hard forks (block based): - Homestead @0 - Dao @0 - Tangerine @0 - SpuriousDragon @0 - Byzantium @0 - Constantinople @0 - Petersburg @0 - Istanbul @0 - MuirGlacier @0 - Berlin @0 - London @0 - ArrowGlacier @0 - GrayGlacier @0 Merge hard forks: - Paris @0 (network is known to be merged) Post-merge hard forks (timestamp based): - Shanghai @0 - Cancun @0 2024-07-03T22:03:12.345611Z INFO Transaction pool initialized 2024-07-03T22:03:12.345708Z INFO Loading saved peers file=/data/reth/known-peers.json 2024-07-03T22:03:12.347179Z INFO StaticFileProducer initialized 2024-07-03T22:03:12.347437Z INFO Pruner initialized prune_config=PruneConfig { block_interval: 5, segments: PruneModes { sender_recovery: Some(Full), transaction_lookup: None, receipts: None, account_history: Some(Distance(10064)), storage_history: Some(Distance(10064)), receipts_log_filter: ReceiptsLogPruneConfig({}) } } 2024-07-03T22:03:12.347608Z INFO Consensus engine initialized 2024-07-03T22:03:12.347645Z INFO Engine API handler initialized 2024-07-03T22:03:12.349878Z INFO RPC auth server started url=127.0.0.1:8552 2024-07-03T22:03:12.349925Z INFO RPC IPC server started path=/tmp/reth.ipc 2024-07-03T22:03:12.349934Z INFO RPC HTTP server started url=127.0.0.1:8545 2024-07-03T22:03:12.349942Z INFO Starting consensus engine 2024-07-03T22:03:15.354643Z INFO Status connected_peers=2 freelist=1806678 latest_block=980558 ```

But if I put the DNS name into the config file, it fails with

Error: Could not load config file "/data/reth/reth.toml"

1: Failed to parse url: invalid IPv4 address syntax

--- start.sh    2024-07-03 22:04:58.031393273 +0000
+++ start.sh    2024-07-03 22:04:27.246174805 +0000
@@ -10,6 +10,7 @@
 # A list of ENRs for trusted peers, which are peers reth will always try to connect to.
 trusted_nodes = [
     "enode://0401e494dbd0c84c5c0f72adac5985d2f2525e08b68d448958aae218f5ac8198a80d1498e0ebec2ce38b1b18d6750f6e61a56b4614c5a6c6cf0981c39aed47dc@34.159.32.127:30303",
+    "enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303",
 ]
 EOF

@@ -28,5 +29,8 @@
     --authrpc.port 8552 \
     --authrpc.jwtsecret /tmp/secret.hex \
     --metrics "127.0.0.1:9001" \
-    --trusted-peers "enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303" \
start.sh ```sh #!/bin/sh set -e curl -L https://raw.githubusercontent.com/berachain/beacon-kit/988cfc795108c81e30e4c98e18da36cdcfff746f/testing/networks/80084/eth-genesis.json -o ~/genesis.json openssl rand -hex 32 | tr -d '\n' > /tmp/secret.hex cat > ~/reth.toml <
logs ```console $ ./start.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7232 100 7232 0 0 53562 0 --:--:-- --:--:-- --:--:-- 53970 2024-07-03T22:06:02.214560Z INFO Initialized tracing, debug log directory: /data/reth/.cache/reth/logs/80084 2024-07-03T22:06:02.216271Z INFO Starting reth version="1.0.0 (83d412d)" 2024-07-03T22:06:02.216889Z INFO Opening database path="/data/reth/db" 2024-07-03T22:06:02.304013Z ERROR shutting down due to error Error: Could not load config file "/data/reth/reth.toml" Caused by: 0: Bad TOML data 1: TOML parse error at line 5, column 5 1: | 1: 5 | "enode://e9675164b5e17b9d9edf0cc2bd79e6b6f487200c74d1331c220abb5b8ee80c2eefbf18213989585e9d0960683e819542e11d4eefb5f2b4019e1e49f9fd8fff18@berav2-bootnode.staketab.org:30303", 1: | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1: Failed to parse url: invalid IPv4 address syntax Location: /reth-v1.0.0/crates/node/builder/src/launch/common.rs:90:14 ```

Version:

$ reth --version
reth Version: 1.0.0
Commit SHA: 83d412d
Build Timestamp: 2024-07-02T15:19:26.620030609Z
Build Features: jemalloc
Build Profile: release

I realize I'm using --trusted-peers instead of --bootnodes; I'm not entirely clear what the difference is, if I'm honest; also there doesn't seem to be an equivalent to --bootnodes in the config file. But regardless, please may I request DNS names in both trusted-peers and bootnodes, no matter how they are passed in.


It turns out hostnames are against spec in enode://s

The hostname can only be given as an IP address; DNS names are not allowed.

But it's super useful and you're already supporting them in one place, so maybe you would consider supporting them everywhere. Thank you!

Originally posted by @kousu in https://github.com/paradigmxyz/reth/issues/9015#issuecomment-2207421055

kousu commented 1 month ago

Also I'm not sure if there's a config file equivalent to --bootnodes? If so I'd hope they support the same feature.

loocapro commented 1 month ago

Can i take this?

kousu commented 1 week ago

I finally noticed this got merged and got around to testing it. It works great! My peers aren't cluttering up my startup script or top anymore. Thank you :)