sui_config/
rpc_config.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::net::SocketAddr;
5
6#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
7#[serde(rename_all = "kebab-case")]
8pub struct RpcConfig {
9    /// Enable indexing of transactions and objects
10    ///
11    /// This enables indexing of transactions and objects which allows for a slightly richer rpc
12    /// api. There are some APIs which will be disabled/enabled based on this config while others
13    /// (eg GetTransaction) will still be enabled regardless of this config but may return slight
14    /// less data (eg GetTransaction won't return the checkpoint that includes the requested
15    /// transaction).
16    ///
17    /// Defaults to `false`, with indexing and APIs which require indexes being disabled
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub enable_indexing: Option<bool>,
20
21    /// Configure the address to listen on for https
22    ///
23    /// Defaults to `0.0.0.0:9443` if not specified.
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub https_address: Option<SocketAddr>,
26
27    /// TLS configuration to use for https.
28    ///
29    /// If not provided then the node will not create an https service.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub tls: Option<RpcTlsConfig>,
32
33    /// Maxumum budget for rendering a Move value into JSON.
34    ///
35    /// This sets the numbers of bytes that we are willing to spend on rendering field names and
36    /// values when rendering a Move value into a JSON value.
37    ///
38    /// Defaults to `1MiB` if not specified.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub max_json_move_value_size: Option<usize>,
41
42    /// Configuration for RPC index initialization and bulk loading
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub index_initialization: Option<RpcIndexInitConfig>,
45
46    /// Enable indexing of authenticated events
47    ///
48    /// This controls whether authenticated events are indexed and whether the authenticated
49    /// events API endpoints are available. When disabled, authenticated events are not indexed
50    /// and API calls will return an unsupported error.
51    ///
52    /// Defaults to `false`, with authenticated events indexing and API disabled
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub authenticated_events_indexing: Option<bool>,
55}
56
57impl RpcConfig {
58    pub fn enable_indexing(&self) -> bool {
59        self.enable_indexing.unwrap_or(false)
60    }
61
62    pub fn https_address(&self) -> SocketAddr {
63        self.https_address
64            .unwrap_or_else(|| SocketAddr::from(([0, 0, 0, 0], 9443)))
65    }
66
67    pub fn tls_config(&self) -> Option<&RpcTlsConfig> {
68        self.tls.as_ref()
69    }
70
71    pub fn max_json_move_value_size(&self) -> usize {
72        self.max_json_move_value_size.unwrap_or(1024 * 1024)
73    }
74
75    pub fn index_initialization_config(&self) -> Option<&RpcIndexInitConfig> {
76        self.index_initialization.as_ref()
77    }
78
79    pub fn authenticated_events_indexing(&self) -> bool {
80        self.authenticated_events_indexing.unwrap_or(false)
81    }
82}
83
84#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
85#[serde(rename_all = "kebab-case")]
86pub struct RpcTlsConfig {
87    /// File path to a PEM formatted TLS certificate chain
88    cert: String,
89    /// File path to a PEM formatted TLS private key
90    key: String,
91}
92
93impl RpcTlsConfig {
94    pub fn cert(&self) -> &str {
95        &self.cert
96    }
97
98    pub fn key(&self) -> &str {
99        &self.key
100    }
101}
102
103/// Configuration for RPC index initialization and bulk loading
104#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
105#[serde(rename_all = "kebab-case")]
106pub struct RpcIndexInitConfig {
107    /// Override for RocksDB's set_db_write_buffer_size during bulk indexing.
108    /// This is the total memory budget for all column families' memtables.
109    ///
110    /// Defaults to 90% of system RAM if not specified.
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub db_write_buffer_size: Option<usize>,
113
114    /// Override for each column family's write buffer size during bulk indexing.
115    ///
116    /// Defaults to 25% of system RAM divided by max_write_buffer_number if not specified.
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub cf_write_buffer_size: Option<usize>,
119
120    /// Override for the maximum number of write buffers per column family during bulk indexing.
121    /// This value is capped at 32 as an upper bound.
122    ///
123    /// Defaults to a dynamic value based on system RAM if not specified.
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub cf_max_write_buffer_number: Option<i32>,
126
127    /// Override for the number of background jobs during bulk indexing.
128    ///
129    /// Defaults to the number of CPU cores if not specified.
130    #[serde(skip_serializing_if = "Option::is_none")]
131    pub max_background_jobs: Option<i32>,
132
133    /// Override for the batch size limit during bulk indexing.
134    /// This controls how much data is accumulated in memory before flushing to disk.
135    ///
136    /// Defaults to half the write buffer size or 128MB, whichever is smaller.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub batch_size_limit: Option<usize>,
139}