go-ethereum
go-ethereum copied to clipboard
cmd/geth, cmd/utils: geth attach with custom headers
This PR makes it possible to set custom headers. Example:
$ source setheaders && go run . attach -H "CF-Access-Client-Id: $CFID" -H "CF-Access-Client-Secret: $CFSEC" https://rpc.mainnet.ethpandaops.io
Welcome to the Geth JavaScript console!
instance: erigon/2022.09.1/linux-amd64/go1.18.5
Error handlng:
go run . attach -H "a bad header" https://rpc.mainnet.ethpandaops.io
Fatal: invalid http header directive: "a bad header"
Follow-up, this now also works with geth db <subcommand> --remotedb
.
source ~/.headers && geth db get --remotedb https://geth.mainnet.ethpandaops.io -H "CF-Access-Client-Id: $CFID" -H "CF-Access-Client-Secret: $CFSEC" SnapshotRoot
INFO [09-20|11:42:31.873] Maximum peer count ETH=50 LES=0 total=50
INFO [09-20|11:42:31.882] Set global gas cap cap=50,000,000
INFO [09-20|11:42:31.882] Using remote db url=https://geth.mainnet.ethpandaops.io headers=2
INFO [09-20|11:42:32.237] Get operation failed key=0x536e617073686f74526f6f74 error="the method debug_dbGet does not exist/is not available"
the method debug_dbGet does not exist/is not available
It seems the debug
module was not available
instance: Geth/v1.10.23-stable-d901d853/linux-amd64/go1.18.5
at block: 15573889 (Tue Sep 20 2022 11:45:59 GMT+0200 (CEST))
modules: eth:1.0 net:1.0 rpc:1.0 web3:1.0
However, the flag is really wonky. I suspect this is a bug in urfave
.
geth db get --remotedb -H "a: a" -H "b: b" -> two headers, a, and b
geth --remotedb -H "a: a" -H "b: b" db get -> one headerstring "[a: a, b: b]"
I'll investigate this a bit more
With the debug
api enabled:
[user@work go-ethereum]$ source ~/.headers && geth db get --remotedb https://geth.mainnet.ethpandaops.io -H "CF-Access-Client-Id: $CFID" -H "CF-Access-Client-Secret: $CFSEC" SnapshotRoot
INFO [09-20|12:15:26.196] Maximum peer count ETH=50 LES=0 total=50
INFO [09-20|12:15:26.205] Set global gas cap cap=50,000,000
INFO [09-20|12:15:26.205] Using remote db url=https://geth.mainnet.ethpandaops.io headers=2
key 0x536e617073686f74526f6f74: 0xd918b5caf52f50738a2caca54182cf824da8886f743912313f032f5f457c68c0
[user@work go-ethereum]$ source ~/.headers && geth db metadata --remotedb https://geth.mainnet.ethpandaops.io -H "CF-Access-Client-Id: $CFID" -H "CF-Access-Client-Secret: $CFSEC"
INFO [09-20|12:15:59.160] Maximum peer count ETH=50 LES=0 total=50
INFO [09-20|12:15:59.164] Set global gas cap cap=50,000,000
INFO [09-20|12:15:59.164] Using remote db url=https://geth.mainnet.ethpandaops.io headers=2
+-------------------------+--------------------------------------------------------------------+
| FIELD | VALUE |
+-------------------------+--------------------------------------------------------------------+
| databaseVersion | 8 (0x8) |
| headBlockHash | 0x9a63371c36059fe56f0882d148946d2663290fcb1140a74f102ee6437e13b9bb |
| headFastBlockHash | 0x9a63371c36059fe56f0882d148946d2663290fcb1140a74f102ee6437e13b9bb |
| headHeaderHash | 0x9a63371c36059fe56f0882d148946d2663290fcb1140a74f102ee6437e13b9bb |
| headBlock.Hash | 0x9a63371c36059fe56f0882d148946d2663290fcb1140a74f102ee6437e13b9bb |
| headBlock.Root | 0x070ed50879b2311360da6c702bce70b396201c812e62e314957d9a3cb0ac0926 |
| headBlock.Number | 15574038 (0xeda416) |
| headHeader.Hash | 0x9a63371c36059fe56f0882d148946d2663290fcb1140a74f102ee6437e13b9bb |
| headHeader.Root | 0x070ed50879b2311360da6c702bce70b396201c812e62e314957d9a3cb0ac0926 |
| headHeader.Number | 15574038 (0xeda416) |
| frozen | 15484036 items |
| lastPivotNumber | 15410664 (0xeb25e8) |
| len(snapshotSyncStatus) | 286 bytes |
| snapshotGenerator | Done: true, Accounts: 0, |
| | Slots: 0, Storage: 0, Marker: |
| snapshotDisabled | false |
| snapshotJournal | 5978335 bytes |
| snapshotRecoveryNumber | <nil> |
| snapshotRoot | 0x6995fd875d7fe7dc28e7d272c1c75237178b344b623034f0cfb626c6af639c0e |
| txIndexTail | 13224039 (0xc9c867) |
| fastTxLookupLimit | 2350000 (0x23dbb0) |
+-------------------------+--------------------------------------------------------------------+
ht @barnabasbusa
However, the flag is really wonky. I suspect this is a bug in urfave.
Fix: https://github.com/ethereum/go-ethereum/pull/25830
Re-test after latest changes:
$ source ~/.headers && geth db get --remotedb https://geth.mainnet.ethpandaops.io -H "CF-Access-Client-Id: $CFID" -H "CF-Access-Client-Secret: $CFSEC" SnapshotRoot
INFO [09-20|15:19:55.457] Maximum peer count ETH=50 LES=0 total=50
INFO [09-20|15:19:55.467] Set global gas cap cap=50,000,000
INFO [09-20|15:19:55.467] Using remote db url=https://geth.mainnet.ethpandaops.io headers=2
key 0x536e617073686f74526f6f74: 0x809bc95750a8c633e559a44f77e76ed88b31664e920ff26f9353909eab808836
$ source ~/.headers && geth attach -H "CF-Access-Client-Id: $CFID" -H "CF-Access-Client-Secret: $CFSEC" https://geth.mainnet.ethpandaops.io
Welcome to the Geth JavaScript console!
instance: Geth/v1.10.25-stable-69568c55/linux-amd64/go1.18.6
at block: 15574951 (Tue Sep 20 2022 15:21:11 GMT+0200 (CEST))
datadir: /data