zebra_rpc/config/rpc.rs
1//! RPC config
2
3use std::{net::SocketAddr, path::PathBuf};
4
5use serde::{Deserialize, Serialize};
6
7use zebra_chain::common::default_cache_dir;
8
9/// RPC configuration section.
10#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
11#[serde(deny_unknown_fields, default)]
12pub struct Config {
13 /// IP address and port for the RPC server.
14 ///
15 /// Note: The RPC server is disabled by default.
16 /// To enable the RPC server, set a listen address in the config:
17 /// ```toml
18 /// [rpc]
19 /// listen_addr = '127.0.0.1:8232'
20 /// ```
21 ///
22 /// The recommended ports for the RPC server are:
23 /// - Mainnet: 127.0.0.1:8232
24 /// - Testnet: 127.0.0.1:18232
25 ///
26 /// # Security
27 ///
28 /// If you bind Zebra's RPC port to a public IP address,
29 /// anyone on the internet can send transactions via your node.
30 /// They can also query your node's state.
31 pub listen_addr: Option<SocketAddr>,
32
33 /// IP address and port for the indexer RPC server.
34 ///
35 /// Note: The indexer RPC server is disabled by default.
36 /// To enable the indexer RPC server, compile `zebrad` with the
37 /// `indexer` feature flag and set a listen address in the config:
38 /// ```toml
39 /// [rpc]
40 /// indexer_listen_addr = '127.0.0.1:8230'
41 /// ```
42 ///
43 /// # Security
44 ///
45 /// If you bind Zebra's indexer RPC port to a public IP address,
46 /// anyone on the internet can query your node's state.
47 pub indexer_listen_addr: Option<SocketAddr>,
48
49 /// IP address and port for the lightwalletd-compatible gRPC server.
50 ///
51 /// Note: The lightwalletd gRPC server is disabled by default.
52 /// To enable it, set a listen address in the config:
53 /// ```toml
54 /// [rpc]
55 /// lightwalletd_listen_addr = '127.0.0.1:9067'
56 /// ```
57 ///
58 /// This server implements the lightwalletd `CompactTxStreamer` service, so
59 /// Zcash light clients can connect directly to Zebra.
60 ///
61 /// This server is experimental: its behaviour and configuration may change
62 /// in any release, including in ways that break clients.
63 ///
64 /// # Security
65 ///
66 /// The port serves plaintext HTTP/2, with no TLS and no authentication —
67 /// cookie authentication does not apply to it. Anyone who can reach the
68 /// port can query your node's state and send transactions through it, and
69 /// anyone on the network path can read and modify the traffic, including
70 /// the addresses a light client is querying. Terminate TLS in a reverse
71 /// proxy, and bind Zebra to a loopback or private address.
72 ///
73 /// Run this on infrastructure you operate, not on end users' machines: a
74 /// loopback port is reachable by any local process, and by web pages
75 /// loaded in a browser on that machine.
76 pub lightwalletd_listen_addr: Option<SocketAddr>,
77
78 /// The number of threads used to process RPC requests and responses.
79 ///
80 /// This field is deprecated and could be removed in a future release.
81 /// We keep it just for backward compatibility but it actually do nothing.
82 /// It was something configurable when the RPC server was based in the jsonrpc-core crate,
83 /// not anymore since we migrated to jsonrpsee.
84 // TODO: Prefix this field name with an underscore so it's clear that it's now unused, and
85 // use serde(rename) to continue successfully deserializing old configs.
86 pub parallel_cpu_threads: usize,
87
88 /// Test-only option that makes Zebra say it is at the chain tip,
89 /// no matter what the estimated height or local clock is.
90 pub debug_force_finished_sync: bool,
91
92 /// The directory where Zebra stores RPC cookies.
93 pub cookie_dir: PathBuf,
94
95 /// Enable cookie-based authentication for RPCs.
96 pub enable_cookie_auth: bool,
97
98 /// The maximum size of the response body in bytes.
99 pub max_response_body_size: u32,
100}
101
102// This impl isn't derivable because it depends on features.
103#[allow(clippy::derivable_impls)]
104impl Default for Config {
105 fn default() -> Self {
106 Self {
107 // Disable RPCs by default.
108 listen_addr: None,
109
110 // Disable indexer RPCs by default.
111 indexer_listen_addr: None,
112
113 // Disable the lightwalletd gRPC server by default.
114 lightwalletd_listen_addr: None,
115
116 // Use multiple threads, because we pause requests during getblocktemplate long polling
117 parallel_cpu_threads: 0,
118
119 // Debug options are always off by default.
120 debug_force_finished_sync: false,
121
122 // Use the default cache dir for the auth cookie.
123 cookie_dir: default_cache_dir(),
124
125 // Enable cookie-based authentication by default.
126 enable_cookie_auth: true,
127
128 // 50 MiB
129 max_response_body_size: 52_428_800,
130 }
131 }
132}