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 /// The number of threads used to process RPC requests and responses.
50 ///
51 /// This field is deprecated and could be removed in a future release.
52 /// We keep it just for backward compatibility but it actually do nothing.
53 /// It was something configurable when the RPC server was based in the jsonrpc-core crate,
54 /// not anymore since we migrated to jsonrpsee.
55 // TODO: Prefix this field name with an underscore so it's clear that it's now unused, and
56 // use serde(rename) to continue successfully deserializing old configs.
57 pub parallel_cpu_threads: usize,
58
59 /// Test-only option that makes Zebra say it is at the chain tip,
60 /// no matter what the estimated height or local clock is.
61 pub debug_force_finished_sync: bool,
62
63 /// The directory where Zebra stores RPC cookies.
64 pub cookie_dir: PathBuf,
65
66 /// Enable cookie-based authentication for RPCs.
67 pub enable_cookie_auth: bool,
68}
69
70// This impl isn't derivable because it depends on features.
71#[allow(clippy::derivable_impls)]
72impl Default for Config {
73 fn default() -> Self {
74 Self {
75 // Disable RPCs by default.
76 listen_addr: None,
77
78 // Disable indexer RPCs by default.
79 indexer_listen_addr: None,
80
81 // Use multiple threads, because we pause requests during getblocktemplate long polling
82 parallel_cpu_threads: 0,
83
84 // Debug options are always off by default.
85 debug_force_finished_sync: false,
86
87 // Use the default cache dir for the auth cookie.
88 cookie_dir: default_cache_dir(),
89
90 // Enable cookie-based authentication by default.
91 enable_cookie_auth: true,
92 }
93 }
94}