electrs
electrs copied to clipboard
Bug: unable to load electrs after compiling (Error: electrs failed) error
Describe the bug I am running Debian 12 with Bitcoin Core (version 26.0 and I recently switched to 24.2 to see if this can fix the error). Bitcoin Core is up and running, fully sycned, has inbound and outbound connections, and I am able to connect to it with Sparrow from a different computer on my network. Bitcoin Core is running with no issues.
I compiled and ran electrs. The compiling process went without issues. When I tried running it, I get the following error:
Caused by: 0: bitcoind RPC polling failed 1: daemon not available 2: JSON-RPC error: transport error: unexpected HTTP code: 401
Bitcoin Core has RPC Server enabled along with the following:
rpcbind=127.0.0.1
rpcbind=192.168.x.x
Electrs version v.0.10.2
I am getting the same error JSON-RPC error: transport error: unexpected HTTP code: 411
. Electrs v0.10.2, Bitcoin Core v23.0 (trying with v26.0 also).
I don't understand why it fails because curl
works.
But my setup is not the standard, I have access tot the Bitcoin P2P and RPC ports on localhost, the ~/.bitcoin/.cookie
is valid but the ~/.bitcoin
data dir is remote.
Anyway, I enabled debug=rpc
in Core and I can see the request to the command getblockchaininfo
when made with curl, but not when made with ElectRS, so I guess it never authenticates.
curl --user $(cat ~/.bitcoin/.cookie) --data-binary '{"jsonrpc": "1.1", "id": "curltest", "method": "getblockchaininfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:8332/
{
"result": {
"chain": "main",
"blocks": 829338,
"headers": 829338,
"bestblockhash": "00000000000000000002caa0211eb1f45af4fd0de275cffa91cee7231b52d1c1",
"difficulty": 75502165623893.72,
"time": 1707297846,
"mediantime": 1707294426,
"verificationprogress": 0.999998525973853,
"initialblockdownload": false,
"chainwork": "0000000000000000000000000000000000000000692098c477df7323edb400e0",
"size_on_disk": 621358053410,
"pruned": false,
"warnings": ""
},
"error": null,
"id": "curltest"
}
$ cat ~/.electrs/config.toml
log_filters = "TRACE"
#timestamp = true
network = "bitcoin"
db_dir = "/home/user/.electrs/db"
cookie_file = "/home/user/.bitcoin/.cookie"
daemon_rpc_addr = "127.0.0.1:8332"
daemon_p2p_addr = "127.0.0.1:8333"
electrum_rpc_addr = "127.0.0.1:50001"
$ electrs --conf ~/.electrs/config.toml
Starting electrs 0.10.2 on x86_64 linux with Config { network: Bitcoin, db_path: "/home/user/.electrs/db/bitcoin", daemon_dir: "/home/user/.bitcoin", daemon_auth: CookieFile("/home/user/.bitcoin/.cookie"), daemon_rpc_addr: 127.0.0.1:8332, daemon_p2p_addr: 127.0.0.1:8333, electrum_rpc_addr: 127.0.0.1:50001, monitoring_addr: 127.0.0.1:4224, wait_duration: 10s, jsonrpc_timeout: 15s, index_batch_size: 10, index_lookup_limit: None, reindex_last_blocks: 0, auto_reindex: true, ignore_mempool: false, sync_once: false, skip_block_download_wait: false, disable_electrum_rpc: false, server_banner: "Welcome to electrs 0.10.2 (Electrum Rust Server)!", signet_magic: f9beb4d9, args: [] }
[DEBUG electrs::metrics::metrics_fake] metrics collection is disabled
[INFO electrs::server] serving Electrum RPC on 127.0.0.1:50001
[INFO electrs::db] "/home/user/.electrs/db/bitcoin": 2 SST files, 0.000002032 GB, 0.000000002 Grows
[DEBUG electrs::db] DB Some(Config { compacted: false, format: 0 })
[DEBUG bitcoincore_rpc] JSON-RPC request: getblockchaininfo []
[DEBUG bitcoincore_rpc] JSON-RPC failed parsing reply of getblockchaininfo: JsonRpc(Transport(HttpErrorCode(401)))
[INFO electrs::db] closing DB at /home/user/.electrs/db/bitcoin
Error: electrs failed
Caused by:
0: bitcoind RPC polling failed
1: daemon not available
2: JSON-RPC error: transport error: unexpected HTTP code: 401
I figured it out. My cookie file was incorrect. I created it using the following command:
echo "RPCUsername:RPCPassword" > auth.cookie
And entered my RPC Username and Password in the above line.
I copied the auth.cookie to .cookie and I was good to go :)
echo "RPCUsername:RPCPassword" > auth.cookie
Thanks, this gave me a hint. The problem is that echo and some editors adds a new line characters at the end of the line automatically, thus Electrs fails to read the cookie. Using printf AUTH | tee ~/.bitcoin/.cookie
or echo -n AUTH | tee ~/.bitcoin/.cookie
solves the issue.