go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

blsync does not expand tilde for home

Open lightclient opened this issue 1 year ago • 5 comments

I think the following should work:

$ go run ./cmd/blsync --sepolia --beacon.api=https://xxx.io --beacon.checkpoint=$(curl -X 'GET' -H 'accept: application/json' 'https://xxx.io/eth/v1/beacon/headers/finalized' | jq -r ".data.root") --blsync.engine.api=http://localhost:8551 --blsync.jwtsecret=~/.ethereum/sepolia/geth/jwtsecret
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   667  100   667    0     0   1400      0 --:--:-- --:--:-- --:--:--  1398
Fatal: Error loading or generating JWT secret: open ~/.ethereum/sepolia/geth/jwtsecret: no such file or directory
exit status 1

lightclient avatar Aug 15 '24 12:08 lightclient

tildes are expanded by your shell, nowhere else. So it's nothing geth does or doesn't do, your shell should have expanded it before it reached us. It's out of our hands.

holiman avatar Aug 15 '24 13:08 holiman

See here:

[user@work go-ethereum]$ go run ./cmd/geth --config=~/.ethereum/sepolia/geth/jwtsecret
INFO [08-15|15:06:08.697] Starting Geth on Ethereum mainnet...
INFO [08-15|15:06:08.698] Bumping default cache on mainnet         provided=1024 updated=4096
Fatal: open ~/.ethereum/sepolia/geth/jwtsecret: no such file or directory
exit status 1
[user@work go-ethereum]$ go run ./cmd/geth --config ~/.ethereum/sepolia/geth/jwtsecret
INFO [08-15|15:06:15.676] Starting Geth on Ethereum mainnet...
INFO [08-15|15:06:15.677] Bumping default cache on mainnet         provided=1024 updated=4096
Fatal: read /home/user/.ethereum/sepolia/geth/jwtsecret: is a directory
exit status 1

If you use the =-sign, you leave it up to go. If you use a space instead, the shell expands it.

holiman avatar Aug 15 '24 13:08 holiman

Right, but this also works:

$ go run ./cmd/geth attach --datadir=~/.ethereum/sepolia

So I feel like blsync isn't consistent?

lightclient avatar Aug 15 '24 13:08 lightclient

Ah, you are right. So the datadir uses DirectoryFlag, https://github.com/ethereum/go-ethereum/blob/master/internal/flags/flags.go#L57

// DirectoryFlag is custom cli.Flag type which expand the received string to an absolute path.
// e.g. ~/.ethereum -> /home/username/.ethereum

So ok, I agree, let's change blsync.jwtsecret so that it also uses the same mechanism. I guess we need a new type, similar to DirectoryFlag, which is a FileFlag (maybe such a thing already exists)

holiman avatar Aug 20 '24 06:08 holiman

There exists an cli.PathFlag out of the box, but it doesn't expand tildes.

holiman avatar Aug 20 '24 07:08 holiman

FYI, cli v3 dropped the path flag.

karalabe avatar Nov 05 '24 09:11 karalabe