Line data Source code
1 : #define _GNU_SOURCE
2 : #include "fd_config.h"
3 : #include "fd_auto_net.h"
4 : #include "fd_config_private.h"
5 :
6 : #include "../platform/fd_net_util.h"
7 : #include "../platform/fd_sys_util.h"
8 : #include "../../util/tile/fd_tile_private.h"
9 : #include "../../ballet/toml/fd_toml.h"
10 : #include "../../disco/genesis/fd_genesis_cluster.h"
11 : #include "../../discof/genesis/fd_genesi_tile.h"
12 : #include "../../disco/net/fd_net_tile.h"
13 : #include "../../disco/net/fd_linux_bond.h"
14 : #include "../../disco/net/iavf/fd_iavf.h"
15 : #include "../../disco/pack/fd_pack_cost.h"
16 : #include "../../disco/pack/fd_microblock.h"
17 : #include "../../ballet/shred/fd_shred.h"
18 : #include "../../ballet/txn/fd_txn.h"
19 : #include "../../discof/restore/utils/fd_ssarchive.h"
20 : #include "../../discof/restore/utils/fd_wfs.h"
21 : #include "../../flamenco/accdb/fd_accdb_shmem.h"
22 : #include "../../util/fd_boolau.h"
23 :
24 : #include <unistd.h>
25 : #include <fcntl.h>
26 : #include <errno.h>
27 : #include <stdlib.h> /* strtoul */
28 : #include <sys/utsname.h>
29 : #include <sys/mman.h>
30 :
31 : /* TODO: Rewrite this ... */
32 :
33 : static inline void
34 : replace( char * in,
35 : const char * pat,
36 0 : const char * sub ) {
37 0 : char * replace = strstr( in, pat );
38 0 : if( FD_LIKELY( replace ) ) {
39 0 : ulong pat_len = strlen( pat );
40 0 : ulong sub_len = strlen( sub );
41 0 : ulong in_len = strlen( in );
42 0 : if( FD_UNLIKELY( pat_len > in_len ) ) return;
43 :
44 0 : ulong total_len = in_len - pat_len + sub_len;
45 0 : if( FD_UNLIKELY( total_len >= PATH_MAX ) )
46 0 : FD_LOG_ERR(( "configuration scratch directory path too long: `%s`", in ));
47 :
48 0 : uchar after[PATH_MAX] = {0};
49 0 : fd_memcpy( after, replace + pat_len, strlen( replace + pat_len ) );
50 0 : fd_memcpy( replace, sub, sub_len );
51 0 : ulong after_len = strlen( ( const char * ) after );
52 0 : fd_memcpy( replace + sub_len, after, after_len );
53 0 : in[ total_len ] = '\0';
54 0 : }
55 0 : }
56 :
57 :
58 : FD_FN_CONST static inline int
59 0 : parse_log_level( char const * level ) {
60 0 : if( FD_UNLIKELY( !strcmp( level, "DEBUG" ) ) ) return 0;
61 0 : if( FD_UNLIKELY( !strcmp( level, "INFO" ) ) ) return 1;
62 0 : if( FD_UNLIKELY( !strcmp( level, "NOTICE" ) ) ) return 2;
63 0 : if( FD_UNLIKELY( !strcmp( level, "WARNING" ) ) ) return 3;
64 0 : if( FD_UNLIKELY( !strcmp( level, "ERR" ) ) ) return 4;
65 0 : if( FD_UNLIKELY( !strcmp( level, "CRIT" ) ) ) return 5;
66 0 : if( FD_UNLIKELY( !strcmp( level, "ALERT" ) ) ) return 6;
67 0 : if( FD_UNLIKELY( !strcmp( level, "EMERG" ) ) ) return 7;
68 0 : return -1;
69 0 : }
70 :
71 : FD_FN_CONST static inline int
72 0 : parse_core_dump_level( char const * level ) {
73 0 : if( FD_UNLIKELY( !strcmp( level, "disabled" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_DISABLED;
74 0 : if( FD_UNLIKELY( !strcmp( level, "minimal" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_MINIMAL;
75 0 : if( FD_UNLIKELY( !strcmp( level, "regular" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_REGULAR;
76 0 : if( FD_UNLIKELY( !strcmp( level, "full" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_FULL;
77 0 : return -1;
78 0 : }
79 :
80 : void
81 : fd_config_load_buf( fd_config_t * out,
82 : char const * buf,
83 : ulong sz,
84 0 : char const * path ) {
85 0 : static uchar pod_mem[ 1UL<<26 ];
86 0 : uchar * pod = fd_pod_join( fd_pod_new( pod_mem, sizeof(pod_mem) ) );
87 :
88 0 : fd_toml_err_info_t toml_err[1];
89 0 : uchar scratch[ 4096 ];
90 0 : int toml_errc = fd_toml_parse( buf, sz, pod, scratch, sizeof(scratch), toml_err );
91 0 : if( FD_UNLIKELY( toml_errc!=FD_TOML_SUCCESS ) ) {
92 0 : switch( toml_errc ) {
93 0 : case FD_TOML_ERR_POD:
94 0 : FD_LOG_ERR(( "Failed to parse config file (%s): ran out of buffer space while parsing", path ));
95 0 : break;
96 0 : case FD_TOML_ERR_SCRATCH:
97 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: ran out of scratch space while parsing", path, toml_err->line ));
98 0 : break;
99 0 : case FD_TOML_ERR_KEY:
100 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: oversize key", path, toml_err->line ));
101 0 : break;
102 0 : case FD_TOML_ERR_DUP:
103 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: duplicate key", path, toml_err->line ));
104 0 : break;
105 0 : case FD_TOML_ERR_RANGE:
106 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: invalid value for key", path, toml_err->line ));
107 0 : break;
108 0 : case FD_TOML_ERR_PARSE:
109 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu", path, toml_err->line ));
110 0 : break;
111 0 : default:
112 0 : FD_LOG_ERR(( "Failed to parse config file (%s): %s", path, fd_toml_strerror( toml_errc ) ));
113 0 : break;
114 0 : }
115 0 : }
116 :
117 0 : if( FD_UNLIKELY( !fd_config_extract_pod( pod, out ) ) ) FD_LOG_ERR(( "Failed to parse config file (%s): there are unrecognized keys logged above", path ));
118 :
119 0 : fd_pod_delete( fd_pod_leave( pod ) );
120 0 : }
121 :
122 : static void
123 0 : fd_config_fillf( fd_config_t * config ) {
124 0 : if( FD_UNLIKELY( strcmp( config->firedancer.layout.mode, "performance" ) && strcmp( config->firedancer.layout.mode, "efficient" ) ) )
125 0 : FD_LOG_ERR(( "[layout.mode] %s not recognized", config->firedancer.layout.mode ));
126 :
127 0 : if( FD_UNLIKELY( strcmp( config->paths.accounts, "" ) ) ) {
128 0 : replace( config->paths.accounts, "{user}", config->user );
129 0 : replace( config->paths.accounts, "{name}", config->name );
130 0 : } else {
131 0 : FD_TEST( fd_cstr_printf_check( config->paths.accounts, sizeof(config->paths.accounts), NULL, "%s/accounts.db", config->paths.base ) );
132 0 : }
133 :
134 0 : if( FD_UNLIKELY( strcmp( config->paths.stake_delegations, "" ) ) ) {
135 0 : replace( config->paths.stake_delegations, "{user}", config->user );
136 0 : replace( config->paths.stake_delegations, "{name}", config->name );
137 0 : } else {
138 0 : FD_TEST( fd_cstr_printf_check( config->paths.stake_delegations, sizeof(config->paths.stake_delegations), NULL, "%s/stakedelegations.db", config->paths.base ) );
139 0 : }
140 :
141 0 : if( FD_UNLIKELY( strcmp( config->paths.epoch_credits, "" ) ) ) {
142 0 : replace( config->paths.epoch_credits, "{user}", config->user );
143 0 : replace( config->paths.epoch_credits, "{name}", config->name );
144 0 : } else {
145 0 : FD_TEST( fd_cstr_printf_check( config->paths.epoch_credits, sizeof(config->paths.epoch_credits), NULL, "%s/epochcredits.db", config->paths.base ) );
146 0 : }
147 :
148 0 : if( FD_UNLIKELY( strcmp( config->paths.cost_tracker, "" ) ) ) {
149 0 : replace( config->paths.cost_tracker, "{user}", config->user );
150 0 : replace( config->paths.cost_tracker, "{name}", config->name );
151 0 : } else {
152 0 : FD_TEST( fd_cstr_printf_check( config->paths.cost_tracker, sizeof(config->paths.cost_tracker), NULL, "%s/costtracker.db", config->paths.base ) );
153 0 : }
154 :
155 0 : if( FD_UNLIKELY( strcmp( config->paths.vote_stakes, "" ) ) ) {
156 0 : replace( config->paths.vote_stakes, "{user}", config->user );
157 0 : replace( config->paths.vote_stakes, "{name}", config->name );
158 0 : } else {
159 0 : FD_TEST( fd_cstr_printf_check( config->paths.vote_stakes, sizeof(config->paths.vote_stakes), NULL, "%s/votestakes.db", config->paths.base ) );
160 0 : }
161 :
162 0 : if( FD_UNLIKELY( strcmp( config->paths.txncache, "" ) ) ) {
163 0 : replace( config->paths.txncache, "{user}", config->user );
164 0 : replace( config->paths.txncache, "{name}", config->name );
165 0 : } else {
166 0 : FD_TEST( fd_cstr_printf_check( config->paths.txncache, sizeof(config->paths.txncache), NULL, "%s/txncache.db", config->paths.base ) );
167 0 : }
168 :
169 0 : if( FD_UNLIKELY( strcmp( config->paths.shredb, "" ) ) ) {
170 0 : replace( config->paths.shredb, "{user}", config->user );
171 0 : replace( config->paths.shredb, "{name}", config->name );
172 0 : } else {
173 0 : FD_TEST( fd_cstr_printf_check( config->paths.shredb, sizeof(config->paths.shredb), NULL, "%s/shreds.db", config->paths.base ) );
174 0 : }
175 :
176 0 : if( FD_UNLIKELY( strcmp( config->paths.guidb, "" ) ) ) {
177 0 : replace( config->paths.guidb, "{user}", config->user );
178 0 : replace( config->paths.guidb, "{name}", config->name );
179 0 : } else {
180 0 : FD_TEST( fd_cstr_printf_check( config->paths.guidb, sizeof(config->paths.guidb), NULL, "%s/gui.db", config->paths.base ) );
181 0 : }
182 :
183 0 : if( FD_UNLIKELY( strcmp( config->paths.vote_history, "" ) ) ) {
184 0 : replace( config->paths.vote_history, "{user}", config->user );
185 0 : replace( config->paths.vote_history, "{name}", config->name );
186 0 : } else {
187 0 : fd_cstr_ncpy( config->paths.vote_history, config->paths.base, sizeof(config->paths.vote_history) );
188 0 : }
189 :
190 0 : for( ulong i=0UL; i<config->firedancer.paths.authorized_voter_paths_cnt; i++ ) {
191 0 : replace( config->firedancer.paths.authorized_voter_paths[ i ], "{user}", config->user );
192 0 : replace( config->firedancer.paths.authorized_voter_paths[ i ], "{name}", config->name );
193 0 : }
194 0 : }
195 :
196 : static void
197 0 : fd_config_fill_net( fd_config_t * config ) {
198 0 : if( FD_UNLIKELY( !strcmp( config->net.interface, "" ) ) ) {
199 0 : uint ifindex;
200 0 : int result = fd_net_util_internet_ifindex( &ifindex );
201 0 : if( FD_UNLIKELY( -1==result && errno!=ENODEV ) ) FD_LOG_ERR(( "could not get network device index (%i-%s)", errno, fd_io_strerror( errno ) ));
202 0 : else if( FD_UNLIKELY( -1==result ) )
203 0 : FD_LOG_ERR(( "no network device found which routes to 8.8.8.8. If no network "
204 0 : "interface is specified in the configuration file, Firedancer "
205 0 : "tries to use the first network interface found which routes to "
206 0 : "8.8.8.8. You can see what this is by running `ip route get 8.8.8.8` "
207 0 : "You can fix this error by specifying a network interface to bind to in "
208 0 : "your configuration file under [net.interface]" ));
209 :
210 0 : if( FD_UNLIKELY( !if_indextoname( ifindex, config->net.interface ) ) )
211 0 : FD_LOG_ERR(( "could not get name of interface with index %u", ifindex ));
212 0 : }
213 :
214 0 : if( FD_UNLIKELY( !if_nametoindex( config->net.interface ) ) )
215 0 : FD_LOG_ERR(( "configuration specifies network interface `%s` which does not exist", config->net.interface ));
216 :
217 0 : char driver[ NAME_SZ ];
218 0 : fd_net_get_driver( driver, sizeof(driver), config->net.interface );
219 0 : if( !strcmp( config->net.provider, "mlx5" ) && FD_UNLIKELY( strcmp( driver, "mlx5_core" ) ) ) {
220 0 : FD_LOG_ERR(( "[net.provider] is set to \"mlx5\" but the network interface in use is not using the "
221 0 : "mlx5_core driver. Please ensure you are using a Mellanox ConnectX NIC of version 4 "
222 0 : "or newer. interface `%s` uses `%s`", config->net.interface, driver ));
223 0 : }
224 :
225 0 : if( 0==strcmp( config->net.provider, "iavf" ) ) {
226 0 : char members[ FD_IAVF_MEMBER_MAX ][ 16 ];
227 0 : ulong member_cnt;
228 0 : if( FD_UNLIKELY( -1==fd_iavf_member_interfaces( config->net.interface, members, &member_cnt ) ) ) {
229 0 : int err = errno;
230 0 : if( err==EOPNOTSUPP && fd_bonding_is_active_backup( config->net.interface ) ) {
231 0 : FD_LOG_ERR(( "IAVF does not support bond `%s` in active-backup mode. "
232 0 : "Only 802.3ad (LACP) bonds are currently supported.", config->net.interface ));
233 0 : }
234 0 : FD_LOG_ERR(( "IAVF requires ice or i40e PFs on a physical interface or 802.3ad bond (%i-%s)", err, fd_io_strerror( err ) ));
235 0 : }
236 0 : }
237 :
238 0 : uint iface_ip;
239 0 : if( FD_UNLIKELY( -1==fd_net_util_if_addr( config->net.interface, &iface_ip ) ) )
240 0 : FD_LOG_ERR(( "could not get IP address for interface `%s`", config->net.interface ));
241 :
242 0 : if( FD_UNLIKELY( strcmp( config->firedancer.gossip.host, "" ) ) ) {
243 0 : uint gossip_ip_addr = iface_ip;
244 0 : int has_gossip_ip4 = 0;
245 0 : if( FD_UNLIKELY( strlen( config->firedancer.gossip.host )<=15UL ) ) {
246 : /* Only sets gossip_ip_addr if it's a valid IPv4 address, otherwise assume it's a DNS name */
247 0 : has_gossip_ip4 = fd_cstr_to_ip4_addr( config->firedancer.gossip.host, &gossip_ip_addr );
248 0 : }
249 0 : if( FD_UNLIKELY( !fd_ip4_addr_is_public( gossip_ip_addr ) && config->is_live_cluster && has_gossip_ip4 ) )
250 0 : FD_LOG_ERR(( "Trying to use [gossip.host] " FD_IP4_ADDR_FMT " for listening to incoming "
251 0 : "transactions, but it is part of a private network and will not be routable "
252 0 : "for other Solana network nodes.", FD_IP4_ADDR_FMT_ARGS( gossip_ip_addr ) ));
253 0 : } else if( FD_UNLIKELY( !fd_ip4_addr_is_public( iface_ip ) && config->is_live_cluster ) ) {
254 0 : FD_LOG_ERR(( "Trying to use network interface `%s` for listening to incoming transactions, "
255 0 : "but it has IPv4 address " FD_IP4_ADDR_FMT " which is part of a private network "
256 0 : "and will not be routable for other Solana network nodes. If you are running "
257 0 : "behind a NAT and this interface is publicly reachable, you can continue by "
258 0 : "manually specifying the IP address to advertise in your configuration under "
259 0 : "[gossip.host].", config->net.interface, FD_IP4_ADDR_FMT_ARGS( iface_ip ) ));
260 0 : }
261 :
262 0 : config->net.ip_addr = iface_ip;
263 0 : }
264 :
265 : void
266 0 : fd_config_validate_consensus( fd_config_t const * config ) {
267 0 : int has_bank_hash = !!strcmp( config->firedancer.consensus.wait_for_supermajority_with_bank_hash, "" );
268 0 : int has_slot = !!config->firedancer.consensus.wait_for_supermajority_at_slot;
269 :
270 0 : if( FD_UNLIKELY( has_bank_hash && !has_slot ) ) {
271 0 : FD_LOG_ERR(( "[consensus.wait_for_supermajority_with_bank_hash] is set but "
272 0 : "[consensus.wait_for_supermajority_at_slot] is 0 (disabled). "
273 0 : "Both must be configured together." ));
274 0 : }
275 0 : if( FD_UNLIKELY( has_slot && !has_bank_hash ) ) {
276 0 : FD_LOG_ERR(( "[consensus.wait_for_supermajority_at_slot] is set but "
277 0 : "[consensus.wait_for_supermajority_with_bank_hash] is empty. "
278 0 : "Both must be configured together." ));
279 0 : }
280 : /* Makes string-empty and byte-zero hash_is_zero agree (fd_wfs.h).
281 : Canonical base58 makes this the only all-zeros encoding. */
282 0 : if( FD_UNLIKELY( has_bank_hash && !strcmp( config->firedancer.consensus.wait_for_supermajority_with_bank_hash,
283 0 : "11111111111111111111111111111111" ) ) ) {
284 0 : FD_LOG_ERR(( "[consensus.wait_for_supermajority_with_bank_hash] decodes to all zeros, "
285 0 : "which is not a valid bank hash." ));
286 0 : }
287 0 : if( FD_UNLIKELY( has_bank_hash && !config->consensus.expected_shred_version ) ) {
288 0 : FD_LOG_ERR(( "[consensus.wait_for_supermajority_with_bank_hash] requires "
289 0 : "[consensus.expected_shred_version] to be nonzero." ));
290 0 : }
291 0 : if( FD_UNLIKELY( config->firedancer.consensus.wait_for_supermajority_at_slot==ULONG_MAX ) ) {
292 0 : FD_LOG_ERR(( "[consensus.wait_for_supermajority_at_slot] is ULONG_MAX. "
293 0 : "No boot slot could ever match it." ));
294 0 : }
295 0 : int wfs_configured = fd_wfs_configured( config->firedancer.consensus.wait_for_supermajority_at_slot,
296 0 : !has_bank_hash,
297 0 : (ulong)config->consensus.expected_shred_version );
298 0 : if( FD_UNLIKELY( wfs_configured && config->consensus.wait_for_vote_to_start_leader==FD_BOOLAU_TRUE ) ) {
299 0 : FD_LOG_ERR(( "wait-for-supermajority is configured, which requires "
300 0 : "[consensus.wait_for_vote_to_start_leader] to be false or \"auto\"." ));
301 0 : }
302 0 : }
303 :
304 : void
305 : fd_config_fill( fd_config_t * config,
306 : int is_local_cluster,
307 0 : int dev ) {
308 0 : struct utsname utsname;
309 0 : if( FD_UNLIKELY( -1==uname( &utsname ) ) )
310 0 : FD_LOG_ERR(( "could not get uname (%i-%s)", errno, fd_io_strerror( errno ) ));
311 0 : fd_cstr_ncpy( config->hostname, utsname.nodename, sizeof(config->hostname) ); /* Just truncate the name if it's too long to fit */
312 :
313 0 : ulong cluster = fd_genesis_cluster_identify( config->consensus.expected_genesis_hash );
314 0 : config->is_live_cluster = cluster!=FD_CLUSTER_UNKNOWN;
315 0 : strcpy( config->cluster, fd_genesis_cluster_name( cluster ) );
316 :
317 0 : if( FD_UNLIKELY( !strcmp( config->user, "" ) ) ) {
318 0 : const char * user = fd_sys_util_login_user();
319 0 : if( FD_UNLIKELY( !user ) ) FD_LOG_ERR(( "could not automatically determine a user to run Firedancer as. You must specify a [user] in your configuration TOML file." ));
320 0 : if( FD_UNLIKELY( strlen( user )>=sizeof( config->user ) ) ) FD_LOG_ERR(( "user name `%s` is too long", user ));
321 0 : strncpy( config->user, user, sizeof(config->user) );
322 0 : }
323 :
324 0 : if( FD_UNLIKELY( -1==fd_sys_util_user_to_uid( config->user, &config->uid, &config->gid ) ) ) FD_LOG_ERR(( "configuration file wants firedancer to run as user `%s` but it does not exist", config->user ));
325 0 : if( FD_UNLIKELY( !config->uid || !config->gid ) ) FD_LOG_ERR(( "firedancer cannot run as root. please specify a non-root user in the configuration file" ));
326 0 : if( FD_UNLIKELY( getuid()!=0U && config->uid!=getuid() ) ) FD_LOG_ERR(( "running as uid %u, but config specifies uid %u", getuid(), config->uid ));
327 0 : if( FD_UNLIKELY( getgid()!=0U && config->gid!=getgid() ) ) FD_LOG_ERR(( "running as gid %u, but config specifies gid %u", getgid(), config->gid ));
328 :
329 0 : FD_TEST( fd_cstr_printf_check( config->hugetlbfs.gigantic_page_mount_path,
330 0 : sizeof(config->hugetlbfs.gigantic_page_mount_path),
331 0 : NULL,
332 0 : "%s/.gigantic",
333 0 : config->hugetlbfs.mount_path ) );
334 0 : FD_TEST( fd_cstr_printf_check( config->hugetlbfs.huge_page_mount_path,
335 0 : sizeof(config->hugetlbfs.huge_page_mount_path),
336 0 : NULL,
337 0 : "%s/.huge",
338 0 : config->hugetlbfs.mount_path ) );
339 :
340 0 : ulong max_page_sz = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
341 0 : if( FD_UNLIKELY( max_page_sz!=FD_SHMEM_HUGE_PAGE_SZ && max_page_sz!=FD_SHMEM_GIGANTIC_PAGE_SZ ) ) FD_LOG_ERR(( "[hugetlbfs.max_page_size] must be \"huge\" or \"gigantic\"" ));
342 :
343 0 : replace( config->log.path, "{user}", config->user );
344 0 : replace( config->log.path, "{name}", config->name );
345 :
346 0 : if( FD_LIKELY( !strcmp( "auto", config->log.colorize ) ) ) config->log.colorize1 = 2;
347 0 : else if( FD_LIKELY( !strcmp( "true", config->log.colorize ) ) ) config->log.colorize1 = 1;
348 0 : else if( FD_LIKELY( !strcmp( "false", config->log.colorize ) ) ) config->log.colorize1 = 0;
349 0 : else FD_LOG_ERR(( "[log.colorize] must be one of \"auto\", \"true\", or \"false\"" ));
350 :
351 0 : if( FD_LIKELY( 2==config->log.colorize1 ) ) {
352 0 : config->log.colorize1 = fd_log_should_colorize();
353 0 : }
354 :
355 0 : config->log.level_logfile1 = parse_log_level( config->log.level_logfile );
356 0 : config->log.level_stderr1 = parse_log_level( config->log.level_stderr );
357 0 : if( FD_UNLIKELY( !strcmp( config->log.level_flush, "NONE" ) ) ) config->log.level_flush1 = 8;
358 0 : else config->log.level_flush1 = parse_log_level( config->log.level_flush );
359 0 : if( FD_UNLIKELY( -1==config->log.level_logfile1 ) ) FD_LOG_ERR(( "unrecognized [log.level_logfile] `%s`", config->log.level_logfile ));
360 0 : if( FD_UNLIKELY( -1==config->log.level_stderr1 ) ) FD_LOG_ERR(( "unrecognized [log.level_stderr] `%s`", config->log.level_stderr ));
361 0 : if( FD_UNLIKELY( -1==config->log.level_flush1 ) ) FD_LOG_ERR(( "unrecognized [log.level_flush] `%s`", config->log.level_flush ));
362 :
363 0 : config->development.core_dump_level = parse_core_dump_level( config->development.core_dump );
364 0 : if( FD_UNLIKELY( -1==config->development.core_dump_level ) ) FD_LOG_ERR(( "unrecognized [development.core_dump] `%s`", config->development.core_dump ));
365 :
366 0 : replace( config->paths.base, "{user}", config->user );
367 0 : replace( config->paths.base, "{name}", config->name );
368 :
369 0 : if( FD_UNLIKELY( !strcmp( config->paths.identity_key, "" ) ) ) {
370 : /* Development binaries generate an identity key on boot. */
371 0 : if( FD_UNLIKELY( config->is_live_cluster && !dev ) ) FD_LOG_ERR(( "configuration file must specify [paths.identity_key] when joining a live cluster" ));
372 :
373 0 : FD_TEST( fd_cstr_printf_check( config->paths.identity_key,
374 0 : sizeof(config->paths.identity_key),
375 0 : NULL,
376 0 : "%s/identity.json",
377 0 : config->paths.base ) );
378 0 : } else {
379 0 : replace( config->paths.identity_key, "{user}", config->user );
380 0 : replace( config->paths.identity_key, "{name}", config->name );
381 0 : }
382 :
383 0 : replace( config->paths.vote_account, "{user}", config->user );
384 0 : replace( config->paths.vote_account, "{name}", config->name );
385 :
386 0 : if( FD_UNLIKELY( strcmp( config->paths.snapshots, "" ) ) ) {
387 0 : replace( config->paths.snapshots, "{user}", config->user );
388 0 : replace( config->paths.snapshots, "{name}", config->name );
389 0 : } else {
390 0 : FD_TEST( fd_cstr_printf_check( config->paths.snapshots, sizeof(config->paths.snapshots), NULL, "%s/snapshots", config->paths.base ) );
391 0 : }
392 :
393 0 : if( FD_UNLIKELY( strcmp( config->paths.genesis, "" ) ) ) {
394 0 : replace( config->paths.genesis, "{user}", config->user );
395 0 : replace( config->paths.genesis, "{name}", config->name );
396 0 : } else {
397 0 : FD_TEST( fd_cstr_printf_check( config->paths.genesis, sizeof(config->paths.genesis), NULL, "%s/genesis.bin", config->paths.base ) );
398 0 : }
399 :
400 0 : long ts = -fd_log_wallclock();
401 0 : config->is_dev = dev;
402 :
403 0 : config->tick_per_ns_mu = dev ? fd_tempo_tick_per_ns_dev( &config->tick_per_ns_sigma )
404 0 : : fd_tempo_tick_per_ns ( &config->tick_per_ns_sigma );
405 0 : FD_LOG_INFO(( "calibrating fd_tempo tick_per_ns took %ld ms", (fd_log_wallclock()+ts)/(1000L*1000L) ));
406 :
407 0 : if( 0!=strcmp( config->net.bind_address, "" ) ) {
408 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( config->net.bind_address, &config->net.bind_address_parsed ) ) ) {
409 0 : FD_LOG_ERR(( "`net.bind_address` is not a valid IPv4 address" ));
410 0 : }
411 0 : }
412 :
413 0 : if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "perf" ) ) ) config->tiles.pack.schedule_strategy_enum = 0;
414 0 : else if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "balanced" ) ) ) config->tiles.pack.schedule_strategy_enum = 1;
415 0 : else if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "revenue" ) ) ) {
416 0 : FD_LOG_ERR(( "the revenue scheduler has been removed. Please update [tiles.pack.schedule_strategy]" ));
417 0 : }
418 0 : else if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "auction" ) ) ) config->tiles.pack.schedule_strategy_enum = 2;
419 0 : else FD_LOG_ERR(( "[tiles.pack.schedule_strategy] %s not recognized", config->tiles.pack.schedule_strategy ));
420 :
421 0 : fd_config_fill_net( config );
422 0 : fd_config_fillf( config );
423 :
424 0 : fd_auto_net( config );
425 0 : if( FD_UNLIKELY( !strcmp( config->net.provider, "auto" ) ) ) {
426 0 : FD_LOG_ERR(( "failed to resolve automatic network provider" ));
427 0 : }
428 0 : fd_config_validate( config );
429 :
430 0 : config->limits.max_cost_per_block = fd_ulong_if( !!config->development.bench.max_cost_per_block, config->development.bench.max_cost_per_block, FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND );
431 0 : config->limits.max_shreds_per_block = fd_ulong_if( !!config->development.bench.max_shreds_per_block, config->development.bench.max_shreds_per_block, FD_SHRED_BLK_MAX );
432 0 : config->limits.max_txn_per_slot = fd_ulong_min( config->limits.max_cost_per_block/FD_PACK_MIN_TXN_COST,
433 0 : (config->limits.max_shreds_per_block*FD_SHRED_DATA_PAYLOAD_MAX - 65UL*sizeof(fd_entry_batch_header_t))/FD_TXN_MIN_SERIALIZED_SZ ); /* 64 ticks + one giant microblock */
434 0 : if( FD_LIKELY( !config->development.bench.max_cost_per_block && !config->development.bench.max_shreds_per_block ) ) FD_TEST( config->limits.max_txn_per_slot==FD_MAX_TXN_PER_SLOT );
435 :
436 0 : if( FD_LIKELY( config->is_live_cluster) ) {
437 0 : if( FD_UNLIKELY( !config->development.sandbox ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration disables the sandbox which is a development only feature" ));
438 0 : if( FD_UNLIKELY( config->development.no_clone ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration disables multiprocess which is a development only feature" ));
439 0 : if( FD_UNLIKELY( config->development.bench.max_cost_per_block ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration sets [development.bench.max_cost_per_block] which is a development only feature" ));
440 0 : if( FD_UNLIKELY( config->development.bench.max_shreds_per_block ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration sets [development.bench.max_shreds_per_block] which is a development only feature" ));
441 0 : if( FD_UNLIKELY( config->development.bench.disable_blockstore_from_slot ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration has a non-zero value for [development.bench.disable_blockstore_from_slot] which is a development only feature" ));
442 0 : if( FD_UNLIKELY( config->development.bench.disable_status_cache ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration enables [development.bench.disable_status_cache] which is a development only feature" ));
443 0 : }
444 :
445 : /* When running a local cluster, some options are overridden by default
446 : to make starting and running in development environments a little
447 : easier and less strict. */
448 0 : if( FD_UNLIKELY( is_local_cluster ) ) {
449 0 : if( FD_LIKELY( !strcmp( config->paths.vote_account, "" ) ) ) {
450 0 : FD_TEST( fd_cstr_printf_check( config->paths.vote_account,
451 0 : sizeof( config->paths.vote_account ),
452 0 : NULL,
453 0 : "%s/vote-account.json",
454 0 : config->paths.base ) );
455 0 : }
456 :
457 0 : strncpy( config->cluster, "development", sizeof(config->cluster) );
458 0 : }
459 :
460 0 : fd_config_validate_consensus( config );
461 :
462 0 : }
463 :
464 0 : #define CFG_HAS_NON_EMPTY( key ) do { \
465 0 : if( !strnlen( config->key, sizeof(config->key) ) ) { \
466 0 : FD_LOG_ERR(( "missing `%s`", #key )); \
467 0 : } \
468 0 : } while(0)
469 :
470 0 : #define CFG_HAS_NON_ZERO( key ) do { \
471 0 : if( !config->key ) { FD_LOG_ERR(( "missing `%s`", #key )); } \
472 0 : } while(0)
473 :
474 0 : #define CFG_HAS_POW2( key ) do { \
475 0 : ulong value = (ulong)( config -> key ); \
476 0 : if( !value || !fd_ulong_is_pow2( value ) ) { \
477 0 : FD_LOG_ERR(( "`%s` must be a power of 2", #key )); \
478 0 : } \
479 0 : } while(0)
480 :
481 : static void
482 0 : fd_config_validatef( fd_configf_t const * config ) {
483 0 : CFG_HAS_NON_EMPTY( layout.mode );
484 0 : CFG_HAS_NON_ZERO( layout.sign_tile_count );
485 0 : CFG_HAS_NON_ZERO( layout.resolv_tile_count );
486 0 : CFG_HAS_NON_ZERO( layout.execle_tile_count );
487 0 : CFG_HAS_NON_ZERO( layout.snapzp_tile_count );
488 0 : CFG_HAS_NON_ZERO( layout.snapsv_tile_count );
489 0 : CFG_HAS_NON_ZERO( layout.snapsv_io_worker_count );
490 0 : CFG_HAS_NON_ZERO( layout.snapdc_tile_count );
491 0 : CFG_HAS_NON_ZERO( layout.snapin_tile_count );
492 0 : if( FD_UNLIKELY( config->layout.sign_tile_count < 2 ) ) {
493 0 : FD_LOG_ERR(( "layout.sign_tile_count must be >= 2" ));
494 0 : }
495 :
496 0 : if( FD_UNLIKELY( config->snapshots.sources.gossip.allow_any && config->snapshots.sources.gossip.allow_list_cnt>0UL ) ) {
497 0 : FD_LOG_ERR(( "`snapshots.sources.gossip` has an explicit list of %lu allowed peer(s) in `allow_list` "
498 0 : "but also allows any peer with `allow_any=true`. `allow_list` has no effect and may "
499 0 : "give a false sense of security. Please modify one of the two options and restart.",
500 0 : config->snapshots.sources.gossip.allow_list_cnt ));
501 0 : }
502 0 : for( ulong i=0UL; i<config->snapshots.sources.gossip.allow_list_cnt; i++ ) {
503 0 : for( ulong j=0UL; j<config->snapshots.sources.gossip.block_list_cnt; j++ ) {
504 0 : if( FD_UNLIKELY( 0==strcmp( config->snapshots.sources.gossip.allow_list[ i ], config->snapshots.sources.gossip.block_list[ j ] ) ) ) {
505 0 : FD_LOG_ERR(( "`snapshots.sources.gossip` has repeated public key `%s` in both allow[%lu] and block[%lu] lists. "
506 0 : "Please modify one of the two options and restart.", config->snapshots.sources.gossip.allow_list[ i ], i, j ));
507 :
508 0 : }
509 0 : }
510 0 : }
511 :
512 0 : if( FD_UNLIKELY( config->snapshots.server.enabled && !config->layout.enable_snapshot_production ) ) {
513 0 : FD_LOG_ERR(( "[snapshots.server].enabled=true requires [layout].enable_snapshot_production=true" ));
514 0 : }
515 :
516 0 : CFG_HAS_NON_ZERO( snapshots.wait_for_peers_timeout_seconds );
517 0 : if( FD_UNLIKELY( config->snapshots.server.idle_timeout_millis<100UL ||
518 0 : config->snapshots.server.idle_timeout_millis>=60000UL ) ) {
519 0 : FD_LOG_ERR(( "`snapshots.server.idle_timeout_millis` must be in [100,60000)" ));
520 0 : }
521 0 : if( FD_UNLIKELY( config->snapshots.server.send_timeout_millis<100UL ||
522 0 : config->snapshots.server.send_timeout_millis>=60000UL ) ) {
523 0 : FD_LOG_ERR(( "`snapshots.server.send_timeout_millis` must be in [100,60000)" ));
524 0 : }
525 :
526 0 : if( FD_UNLIKELY( config->snapshots.max_full_snapshots_to_keep>FD_SSARCHIVE_MAX_ENTRIES ) ) {
527 0 : FD_LOG_ERR(( "`snapshots.max_full_snapshots_to_keep` is %u but must be at most %lu",
528 0 : config->snapshots.max_full_snapshots_to_keep, FD_SSARCHIVE_MAX_ENTRIES ));
529 0 : }
530 0 : if( FD_UNLIKELY( config->snapshots.max_incremental_snapshots_to_keep>FD_SSARCHIVE_MAX_ENTRIES ) ) {
531 0 : FD_LOG_ERR(( "`snapshots.max_incremental_snapshots_to_keep` is %u but must be at most %lu",
532 0 : config->snapshots.max_incremental_snapshots_to_keep, FD_SSARCHIVE_MAX_ENTRIES ));
533 0 : }
534 :
535 0 : CFG_HAS_NON_ZERO( accounts.max_accounts );
536 0 : CFG_HAS_NON_ZERO( accounts.cache_size_gib );
537 :
538 0 : CFG_HAS_NON_ZERO( development.genesis.max_file_size_mib );
539 0 : if( FD_UNLIKELY( config->development.genesis.max_file_size_mib>FD_GENESIS_MAX_FILE_SIZE_MIB ) ) {
540 0 : FD_LOG_ERR(( "`development.genesis.max_file_size_mib` must be at most %lu", FD_GENESIS_MAX_FILE_SIZE_MIB ));
541 0 : }
542 :
543 0 : CFG_HAS_NON_ZERO( runtime.program_cache_size_mib );
544 0 : CFG_HAS_NON_ZERO( runtime.transaction_cache_size_mib );
545 0 : if( FD_UNLIKELY( config->runtime.transaction_cache_size_mib>(ULONG_MAX>>20) ) ) {
546 0 : FD_LOG_ERR(( "runtime.transaction_cache_size_mib is too large: %lu", config->runtime.transaction_cache_size_mib ));
547 0 : }
548 0 : }
549 :
550 : static void
551 0 : fd_config_validate_failover( fd_config_t const * config ) {
552 0 : fd_configf_t const * f = &config->firedancer;
553 :
554 0 : if( FD_UNLIKELY( f->failover.boot_to_standby && !f->failover.enabled ) ) {
555 0 : FD_LOG_ERR(( "[failover.boot_to_standby] is true, so [failover.enabled] must be true" ));
556 0 : }
557 0 : if( FD_LIKELY( !f->failover.enabled ) ) return;
558 0 : if( FD_UNLIKELY( !f->failover.listen_port ) ) {
559 0 : FD_LOG_ERR(( "[failover.listen_port] must not be zero" ));
560 0 : }
561 0 : uint listen_addr;
562 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( f->failover.listen_address, &listen_addr ) ) ) {
563 0 : FD_LOG_ERR(( "[failover.listen_address] `%s` must be an IPv4 address, host names are not accepted", f->failover.listen_address ));
564 0 : }
565 0 : }
566 :
567 : void
568 0 : fd_config_validate( fd_config_t const * config ) {
569 0 : fd_config_validatef( &config->firedancer );
570 0 : fd_config_validate_failover( config );
571 :
572 0 : CFG_HAS_NON_ZERO( development.accdb.partition_size_gib );
573 0 : if( FD_UNLIKELY( config->development.accdb.partition_size_gib>(FD_ACCDB_FILE_SZ_MAX>>30) ) ) {
574 0 : FD_LOG_ERR(( "`development.accdb.partition_size_gib` must be at most %lu", FD_ACCDB_FILE_SZ_MAX>>30 ));
575 0 : }
576 :
577 0 : if( FD_UNLIKELY( config->tiles.gui.enabled && config->tiles.gui.db_size_gib<4UL ) )
578 0 : FD_LOG_ERR(( "invalid [tiles.gui.db_size_gib]: must be at least 4 GiB" ));
579 :
580 0 : if( FD_UNLIKELY( config->tiles.bundle.enabled && !config->tiles.pack.use_consumed_cus ) )
581 0 : FD_LOG_ERR(( "[tiles.bundle.enabled] requires [tiles.pack.use_consumed_cus]" ));
582 :
583 0 : CFG_HAS_NON_EMPTY( name );
584 0 : CFG_HAS_NON_EMPTY( paths.base );
585 :
586 0 : CFG_HAS_NON_EMPTY( log.colorize );
587 0 : CFG_HAS_NON_EMPTY( log.level_logfile );
588 0 : CFG_HAS_NON_EMPTY( log.level_stderr );
589 0 : CFG_HAS_NON_EMPTY( log.level_flush );
590 :
591 0 : CFG_HAS_NON_EMPTY( layout.affinity );
592 0 : CFG_HAS_NON_EMPTY( layout.blocklist_cores );
593 0 : CFG_HAS_NON_ZERO ( layout.net_tile_count );
594 0 : CFG_HAS_NON_ZERO ( layout.quic_tile_count );
595 0 : CFG_HAS_NON_ZERO ( layout.verify_tile_count );
596 0 : CFG_HAS_NON_ZERO ( layout.shred_tile_count );
597 :
598 0 : CFG_HAS_NON_EMPTY( hugetlbfs.mount_path );
599 0 : CFG_HAS_NON_EMPTY( hugetlbfs.max_page_size );
600 :
601 0 : CFG_HAS_NON_ZERO( net.ingress_buffer_size );
602 :
603 0 : ulong bench_cost = config->development.bench.max_cost_per_block;
604 0 : ulong bench_shreds = config->development.bench.max_shreds_per_block;
605 0 : if( FD_UNLIKELY( bench_cost && (bench_cost<FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND || bench_cost>=UINT_MAX) ) ) /* fd_pack_limits_t: [0,UINT_MAX) */
606 0 : FD_LOG_ERR(( "invalid [development.bench.max_cost_per_block]: must be 0 or in [%lu,%u)", FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND, UINT_MAX ));
607 0 : if( FD_UNLIKELY( bench_shreds && (bench_shreds%FD_SHRED_BLK_MAX || bench_shreds>FD_SHRED_BLK_MAX_RAISED) ) )
608 0 : FD_LOG_ERR(( "invalid [development.bench.max_shreds_per_block]: must be 0 or a multiple of %lu up to %lu", (ulong)FD_SHRED_BLK_MAX, FD_SHRED_BLK_MAX_RAISED ));
609 0 : if( FD_UNLIKELY( config->development.event.max_upload_rate_mbps>(ulong)LONG_MAX/125000UL ) )
610 0 : FD_LOG_ERR(( "invalid [development.event.max_upload_rate_mbps]: must be at most %lu", (ulong)LONG_MAX/125000UL ));
611 :
612 0 : if( 0==strcmp( config->net.provider, "xdp" ) ) {
613 0 : if( 0!=strcmp( config->net.xdp.xdp_mode, "skb" ) &&
614 0 : 0!=strcmp( config->net.xdp.xdp_mode, "drv" ) &&
615 0 : 0!=strcmp( config->net.xdp.xdp_mode, "auto" ) &&
616 0 : 0!=strcmp( config->net.xdp.xdp_mode, "default" ) ) {
617 0 : FD_LOG_ERR(( "invalid `net.xdp.xdp_mode`: \"%s\"; must be \"skb\", \"drv\", \"auto\" or \"default\"",
618 0 : config->net.xdp.xdp_mode ));
619 0 : }
620 :
621 0 : if( 0!=strcmp( config->net.xdp.poll_mode, "prefbusy" ) &&
622 0 : 0!=strcmp( config->net.xdp.poll_mode, "softirq" ) &&
623 0 : 0!=strcmp( config->net.xdp.poll_mode, "auto" ) ) {
624 0 : FD_LOG_ERR(( "invalid `net.xdp.poll_mode`: \"%s\"; must be \"prefbusy\", \"softirq\" or \"auto\"",
625 0 : config->net.xdp.poll_mode ));
626 0 : }
627 :
628 0 : CFG_HAS_POW2 ( net.xdp.xdp_rx_queue_size );
629 0 : CFG_HAS_POW2 ( net.xdp.xdp_tx_queue_size );
630 0 : if( 0!=strcmp( config->net.xdp.rss_queue_mode, "dedicated" ) &&
631 0 : 0!=strcmp( config->net.xdp.rss_queue_mode, "simple" ) &&
632 0 : 0!=strcmp( config->net.xdp.rss_queue_mode, "auto" ) ) {
633 0 : FD_LOG_ERR(( "invalid `net.xdp.rss_queue_mode`: \"%s\"; must be \"simple\", \"dedicated\" or \"auto\"",
634 0 : config->net.xdp.rss_queue_mode ));
635 0 : }
636 0 : } else if( 0==strcmp( config->net.provider, "mlx5" ) ) {
637 0 : CFG_HAS_POW2( net.mlx5.rx_queue_size );
638 0 : CFG_HAS_POW2( net.mlx5.tx_queue_size );
639 0 : if( FD_UNLIKELY( config->net.mlx5.rx_queue_size<=FD_MLX5_BATCH_SIZE ||
640 0 : config->net.mlx5.tx_queue_size< FD_MLX5_BATCH_SIZE ) ) {
641 0 : FD_LOG_ERR(( "invalid mlx5 queue depth: RX must exceed %u and TX must be at least %u",
642 0 : FD_MLX5_BATCH_SIZE, FD_MLX5_BATCH_SIZE ));
643 0 : }
644 0 : if( FD_UNLIKELY( config->net.mlx5.rx_queue_size>FD_MLX5_QUEUE_DEPTH_MAX ||
645 0 : config->net.mlx5.tx_queue_size>FD_MLX5_QUEUE_DEPTH_MAX ) ) {
646 0 : FD_LOG_ERR(( "invalid mlx5 queue depth: RX and TX must not exceed %u", FD_MLX5_QUEUE_DEPTH_MAX ));
647 0 : }
648 0 : } else if( 0==strcmp( config->net.provider, "iavf" ) ) {
649 0 : CFG_HAS_POW2( net.iavf.rx_queue_size );
650 0 : CFG_HAS_POW2( net.iavf.tx_queue_size );
651 0 : if( FD_UNLIKELY( config->net.iavf.rx_queue_size<=FD_IAVF_BATCH_SIZE ||
652 0 : config->net.iavf.rx_queue_size>FD_IAVF_QUEUE_DEPTH_MAX ) ) {
653 0 : FD_LOG_ERR(( "invalid iavf RX queue depth %u: must exceed %u and must not exceed %u",
654 0 : config->net.iavf.rx_queue_size, FD_IAVF_BATCH_SIZE, FD_IAVF_QUEUE_DEPTH_MAX ));
655 0 : }
656 0 : if( FD_UNLIKELY( config->net.iavf.tx_queue_size<FD_IAVF_BATCH_SIZE ||
657 0 : config->net.iavf.tx_queue_size>FD_IAVF_QUEUE_DEPTH_MAX ) ) {
658 0 : FD_LOG_ERR(( "invalid iavf TX queue depth %u: must be at least %u and must not exceed %u",
659 0 : config->net.iavf.tx_queue_size, FD_IAVF_BATCH_SIZE, FD_IAVF_QUEUE_DEPTH_MAX ));
660 0 : }
661 0 : if( FD_UNLIKELY( config->layout.net_tile_count>FD_IAVF_TILE_MAX ) ) {
662 0 : FD_LOG_ERR(( "invalid iavf net tile count %u: must be between 1 and %lu",
663 0 : config->layout.net_tile_count, FD_IAVF_TILE_MAX ));
664 0 : }
665 0 : } else if( 0==strcmp( config->net.provider, "socket" ) ) {
666 0 : CFG_HAS_NON_ZERO( net.socket.receive_buffer_size );
667 0 : CFG_HAS_NON_ZERO( net.socket.send_buffer_size );
668 0 : } else if( 0==strcmp( config->net.provider, "auto" ) ) {
669 : /* "auto" is resolved after interface discovery in fd_config_fill(). */
670 0 : } else {
671 0 : FD_LOG_ERR(( "invalid `net.provider`: \"%s\"; must be \"auto\", \"xdp\", \"socket\", \"mlx5\" or \"iavf\"",
672 0 : config->net.provider ));
673 0 : }
674 :
675 0 : CFG_HAS_NON_ZERO( tiles.netlink.max_routes );
676 0 : CFG_HAS_NON_ZERO( tiles.netlink.max_peer_routes );
677 0 : CFG_HAS_NON_ZERO( tiles.netlink.max_neighbors );
678 :
679 0 : CFG_HAS_NON_ZERO( tiles.quic.max_concurrent_connections );
680 0 : CFG_HAS_NON_ZERO( tiles.quic.txn_reassembly_count );
681 0 : CFG_HAS_NON_ZERO( tiles.quic.max_concurrent_handshakes );
682 0 : CFG_HAS_NON_ZERO( tiles.quic.idle_timeout_millis );
683 :
684 0 : CFG_HAS_NON_ZERO( tiles.verify.signature_cache_size );
685 0 : CFG_HAS_NON_ZERO( tiles.verify.receive_buffer_size );
686 :
687 0 : CFG_HAS_NON_ZERO( tiles.dedup.signature_cache_size );
688 :
689 0 : CFG_HAS_NON_ZERO( tiles.pack.max_pending_transactions );
690 :
691 0 : CFG_HAS_NON_ZERO( tiles.shred.max_pending_shred_sets );
692 :
693 0 : if( FD_UNLIKELY( config->tiles.bundle.keepalive_interval_millis < 3000 ||
694 0 : config->tiles.bundle.keepalive_interval_millis > 3600000 ) ) {
695 0 : FD_LOG_ERR(( "`tiles.bundle.keepalive_interval_millis` must be in range [3000, 3,600,000]" ));
696 0 : }
697 :
698 0 : CFG_HAS_NON_EMPTY( development.core_dump );
699 :
700 0 : CFG_HAS_NON_ZERO( development.genesis.target_tick_duration_micros );
701 0 : CFG_HAS_NON_ZERO( development.genesis.ticks_per_slot );
702 0 : CFG_HAS_NON_ZERO( development.genesis.fund_initial_accounts );
703 0 : CFG_HAS_NON_ZERO( development.genesis.fund_initial_amount_lamports );
704 :
705 0 : CFG_HAS_NON_ZERO ( development.bench.benchg_tile_count );
706 0 : CFG_HAS_NON_ZERO ( development.bench.benchs_tile_count );
707 0 : CFG_HAS_NON_EMPTY( development.bench.affinity );
708 0 : }
709 :
710 : #undef CFG_HAS_NON_EMPTY
711 : #undef CFG_HAS_NON_ZERO
712 : #undef CFG_HAS_POW2
713 :
714 : void
715 : fd_config_load( int is_local_cluster,
716 : char const * default_config,
717 : ulong default_config_sz,
718 : char const * override_config,
719 : char const * override_config_path,
720 : ulong override_config_sz,
721 : char const * user_config,
722 : ulong user_config_sz,
723 : char const * user_config_path,
724 : fd_config_t * config,
725 0 : int dev ) {
726 0 : memset( config, 0, sizeof(config_t) );
727 0 : config->boot_timestamp_nanos = fd_log_wallclock();
728 :
729 0 : FD_STATIC_ASSERT( sizeof(config->launch_cpus)==8UL*fd_cpuset_word_cnt, launch_cpus );
730 0 : if( FD_UNLIKELY( fd_cpuset_getaffinity( 0, (fd_cpuset_t *)config->launch_cpus ) ) ) memset( config->launch_cpus, 0, sizeof(config->launch_cpus) );
731 :
732 : /* Before any tile joins the cpuset isolation cgroup, which carries
733 : none of the service's limits. */
734 0 : char cgroup[ 4096 ];
735 0 : int cgroup_fd = open( "/proc/self/cgroup", O_RDONLY|O_CLOEXEC );
736 0 : long cgroup_sz = cgroup_fd<0 ? -1L : read( cgroup_fd, cgroup, sizeof(cgroup)-1UL );
737 0 : if( FD_LIKELY( cgroup_fd>=0 ) ) close( cgroup_fd );
738 0 : cgroup[ fd_long_max( cgroup_sz, 0L ) ] = '\0';
739 0 : char const * v2 = !strncmp( cgroup, "0::", 3UL ) ? cgroup : strstr( cgroup, "\n0::" );
740 0 : if( FD_LIKELY( v2 ) ) {
741 0 : v2 += v2[ 0 ]=='\n' ? 4UL : 3UL;
742 0 : ulong len = strcspn( v2, "\n" );
743 0 : FD_TEST( fd_cstr_printf_check( config->launch_cgroup, sizeof(config->launch_cgroup), NULL, "%.*s", (int)len, v2 ) );
744 0 : }
745 :
746 0 : fd_config_load_buf( config, default_config, default_config_sz, "default.toml" );
747 0 : fd_config_validate( config );
748 0 : if( FD_UNLIKELY( override_config ) ) {
749 0 : fd_config_load_buf( config, override_config, override_config_sz, override_config_path );
750 0 : fd_config_validate( config );
751 0 : }
752 0 : if( FD_LIKELY( user_config ) ) {
753 0 : fd_config_load_buf( config, user_config, user_config_sz, user_config_path );
754 0 : fd_config_validate( config );
755 0 : if( FD_UNLIKELY( user_config_sz>sizeof(config->user_config)-1UL ) ) {
756 0 : if( FD_UNLIKELY( config->telemetry && config->tiles.event.url[ 0 ] ) ) {
757 0 : FD_LOG_ERR(( "config file (%s) is too large (%lu bytes, max %lu) to report in telemetry", user_config_path, user_config_sz, sizeof(config->user_config)-1UL ));
758 0 : }
759 0 : } else {
760 0 : fd_memcpy( config->user_config, user_config, user_config_sz );
761 0 : config->user_config[ user_config_sz ] = '\0';
762 0 : config->user_config_len = user_config_sz;
763 0 : }
764 0 : }
765 :
766 0 : fd_config_fill( config, is_local_cluster, dev );
767 0 : }
768 :
769 : int
770 0 : fd_config_to_memfd( fd_config_t const * config ) {
771 0 : int config_memfd = memfd_create( "fd_config", 0 );
772 0 : if( FD_UNLIKELY( -1==config_memfd ) ) return -1;
773 0 : if( FD_UNLIKELY( -1==ftruncate( config_memfd, sizeof( config_t ) ) ) ) {
774 0 : if( FD_UNLIKELY( close( config_memfd ) ) ) FD_LOG_WARNING(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
775 0 : return -1;
776 0 : }
777 :
778 0 : uchar * bytes = mmap( NULL, sizeof( config_t ), PROT_READ|PROT_WRITE, MAP_SHARED, config_memfd, 0 );
779 0 : if( FD_UNLIKELY( bytes==MAP_FAILED ) ) {
780 0 : if( FD_UNLIKELY( close( config_memfd ) ) ) FD_LOG_WARNING(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
781 0 : return -1;
782 0 : }
783 :
784 0 : fd_memcpy( bytes, config, sizeof( config_t ) );
785 0 : if( FD_UNLIKELY( munmap( bytes, sizeof( config_t ) ) ) ) {
786 0 : FD_LOG_WARNING(( "munmap() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
787 0 : return -1;
788 0 : }
789 :
790 0 : return config_memfd;
791 0 : }
|