How to enable RPC for Zebra 1.0.0 stable release?

Since upgrading zebra from the RC releases to the 1.0.0 stable release, I can’t get RPC on port 8232 to work anymore. I’ve been following the steps at Hosting Zcash litewalletd via Zebra – JMPInline (nerdbank.net) (in fact, I wrote that blog) for some time, but now with 1.0.0, port 8232 appears to be closed.

I’m running zebra via its docker image. When I run bash within the docker container (while zebra is running) and run curl, I get this:

# curl --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockchaininfo", "params": [] }' -H 'content-type: application/json' http://127.0.0.1:8232/
curl: (7) Failed to connect to 127.0.0.1 port 8232: Connection refused

The zebrad.toml file I created includes this:

[rpc]
listen_addr = '0.0.0.0:8232'

But when I start the container, it rewrites the file and removes that section. This is the whole content of the rewritten file:

[network]
network = "Mainnet"
listen_addr = "0.0.0.0"

[state]
cache_dir = "/var/cache/zebrad-cache"

[metrics]
#endpoint_addr = "0.0.0.0:9999"

Why is zebra rewriting my config file? How do I enable JSON-RPC calls into it?

3 Likes

Thank you for reporting this. I’ll have a look at it as we recently made changes to Docker, including an entrypoint for the runtime build: zebra/docker/runtime-entrypoint.sh at main · ZcashFoundation/zebra · GitHub

This is a great post by the way Hosting Zcash litewalletd via Zebra – JMPInline, we might consider including the Healthcheck in our image :grimacing:

2 Likes

We rewrote our Dockerfile for the stable release, so specifying the RPC port manually in your config in the Docker volume won’t work anymore. You can now pass the RPC port when building the image (--build-arg RPC_PORT=8232) or when starting the container (--env "RPC_PORT=8232"), and Zebra will pick it up. Here’s the relevant Dockerfile part when building the image: zebra/docker/Dockerfile at 40d697a66c3a732502a99994d0d2692c3ebf3e08 · ZcashFoundation/zebra · GitHub, and here’s the relevant part of the script that starts Zebra in the container: zebra/docker/runtime-entrypoint.sh at 40d697a66c3a732502a99994d0d2692c3ebf3e08 · ZcashFoundation/zebra · GitHub. Please note that the Docker API might change soon. You can track the status of those updates here Inconsistent management of ports in the Dockerfile · Issue #6759 · ZcashFoundation/zebra · GitHub.

5 Likes

Thanks. I like the changes. I added this to my docker-compose.yml file:

    environment:
    - RPC_PORT=8232

And removed the external volume I had previously had to setup in order to set up the config file.
It seems to be working now. :slight_smile:

5 Likes

Great, these are very recent changes. We’ll have them documented in the Zebra book together with other Docker config options at some point.

Happy shielding.

4 Likes

Thanks for the great blog post!

Here’s some things you might be interested in tweaking:

With zcashd, we could use the included zcash-cli tool, but that tool is not included in the zebra image. I suspect it would be incompatible anyway

zcash-cli is compatible with zebrad, we’ve used it in some of our manual RPC testing. Feel free to copy it across from the zcashd Docker image, and use it with zebrad.

HEALTHCHECK --interval=15s --start-period=3m CMD curl --data-binary ‘{“jsonrpc”: “1.0”, “id”:“curltest”, “method”: “getblockchaininfo”, “params”: }’ -H ‘content-type: application/json’ http://127.0.0.1:8232/

If you use the getinfo method, it could be slightly faster, because it has a smaller RPC response, and it doesn’t query the chain tip. It’s unlikely to make any practical difference though!

3 Likes

Did not know this, very neat!

Screenshot_2023-06-19_20-06-30

5 Likes