Line data Source code
1 : #define _GNU_SOURCE
2 : #include "fd_config.h"
3 : #include "fd_config_private.h"
4 :
5 : #include "../platform/fd_net_util.h"
6 : #include "../platform/fd_sys_util.h"
7 : #include "../../ballet/toml/fd_toml.h"
8 : #include "../../disco/genesis/fd_genesis_cluster.h"
9 :
10 : #include <unistd.h>
11 : #include <errno.h>
12 : #include <stdlib.h> /* strtoul */
13 : #include <sys/utsname.h>
14 : #include <sys/mman.h>
15 :
16 : /* TODO: Rewrite this ... */
17 :
18 : static inline void
19 : replace( char * in,
20 : const char * pat,
21 0 : const char * sub ) {
22 0 : char * replace = strstr( in, pat );
23 0 : if( FD_LIKELY( replace ) ) {
24 0 : ulong pat_len = strlen( pat );
25 0 : ulong sub_len = strlen( sub );
26 0 : ulong in_len = strlen( in );
27 0 : if( FD_UNLIKELY( pat_len > in_len ) ) return;
28 :
29 0 : ulong total_len = in_len - pat_len + sub_len;
30 0 : if( FD_UNLIKELY( total_len >= PATH_MAX ) )
31 0 : FD_LOG_ERR(( "configuration scratch directory path too long: `%s`", in ));
32 :
33 0 : uchar after[PATH_MAX] = {0};
34 0 : fd_memcpy( after, replace + pat_len, strlen( replace + pat_len ) );
35 0 : fd_memcpy( replace, sub, sub_len );
36 0 : ulong after_len = strlen( ( const char * ) after );
37 0 : fd_memcpy( replace + sub_len, after, after_len );
38 0 : in[ total_len ] = '\0';
39 0 : }
40 0 : }
41 :
42 :
43 : FD_FN_CONST static inline int
44 0 : parse_log_level( char const * level ) {
45 0 : if( FD_UNLIKELY( !strcmp( level, "DEBUG" ) ) ) return 0;
46 0 : if( FD_UNLIKELY( !strcmp( level, "INFO" ) ) ) return 1;
47 0 : if( FD_UNLIKELY( !strcmp( level, "NOTICE" ) ) ) return 2;
48 0 : if( FD_UNLIKELY( !strcmp( level, "WARNING" ) ) ) return 3;
49 0 : if( FD_UNLIKELY( !strcmp( level, "ERR" ) ) ) return 4;
50 0 : if( FD_UNLIKELY( !strcmp( level, "CRIT" ) ) ) return 5;
51 0 : if( FD_UNLIKELY( !strcmp( level, "ALERT" ) ) ) return 6;
52 0 : if( FD_UNLIKELY( !strcmp( level, "EMERG" ) ) ) return 7;
53 0 : return -1;
54 0 : }
55 :
56 : FD_FN_CONST static inline int
57 0 : parse_core_dump_level( char const * level ) {
58 0 : if( FD_UNLIKELY( !strcmp( level, "disabled" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_DISABLED;
59 0 : if( FD_UNLIKELY( !strcmp( level, "minimal" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_MINIMAL;
60 0 : if( FD_UNLIKELY( !strcmp( level, "regular" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_REGULAR;
61 0 : if( FD_UNLIKELY( !strcmp( level, "full" ) ) ) return FD_TOPO_CORE_DUMP_LEVEL_FULL;
62 0 : return -1;
63 0 : }
64 :
65 : void
66 : fd_config_load_buf( fd_config_t * out,
67 : char const * buf,
68 : ulong sz,
69 0 : char const * path ) {
70 0 : static uchar pod_mem[ 1UL<<26 ];
71 0 : uchar * pod = fd_pod_join( fd_pod_new( pod_mem, sizeof(pod_mem) ) );
72 :
73 0 : fd_toml_err_info_t toml_err[1];
74 0 : uchar scratch[ 4096 ];
75 0 : int toml_errc = fd_toml_parse( buf, sz, pod, scratch, sizeof(scratch), toml_err );
76 0 : if( FD_UNLIKELY( toml_errc!=FD_TOML_SUCCESS ) ) {
77 0 : switch( toml_errc ) {
78 0 : case FD_TOML_ERR_POD:
79 0 : FD_LOG_ERR(( "Failed to parse config file (%s): ran out of buffer space while parsing", path ));
80 0 : break;
81 0 : case FD_TOML_ERR_SCRATCH:
82 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: ran out of scratch space while parsing", path, toml_err->line ));
83 0 : break;
84 0 : case FD_TOML_ERR_KEY:
85 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: oversize key", path, toml_err->line ));
86 0 : break;
87 0 : case FD_TOML_ERR_DUP:
88 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: duplicate key", path, toml_err->line ));
89 0 : break;
90 0 : case FD_TOML_ERR_RANGE:
91 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu: invalid value for key", path, toml_err->line ));
92 0 : break;
93 0 : case FD_TOML_ERR_PARSE:
94 0 : FD_LOG_ERR(( "Failed to parse config file (%s) at line %lu", path, toml_err->line ));
95 0 : break;
96 0 : default:
97 0 : FD_LOG_ERR(( "Failed to parse config file (%s): %s", path, fd_toml_strerror( toml_errc ) ));
98 0 : break;
99 0 : }
100 0 : }
101 :
102 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 ));
103 :
104 0 : fd_pod_delete( fd_pod_leave( pod ) );
105 0 : }
106 :
107 : static void
108 0 : fd_config_fillf( fd_config_t * config ) {
109 0 : if( FD_UNLIKELY( strcmp( config->paths.accounts, "" ) ) ) {
110 0 : replace( config->paths.accounts, "{user}", config->user );
111 0 : replace( config->paths.accounts, "{name}", config->name );
112 0 : } else {
113 0 : FD_TEST( fd_cstr_printf_check( config->paths.accounts, sizeof(config->paths.accounts), NULL, "%s/accounts.db", config->paths.base ) );
114 0 : }
115 :
116 0 : if( FD_UNLIKELY( strcmp( config->paths.shredb, "" ) ) ) {
117 0 : replace( config->paths.shredb, "{user}", config->user );
118 0 : replace( config->paths.shredb, "{name}", config->name );
119 0 : } else {
120 0 : FD_TEST( fd_cstr_printf_check( config->paths.shredb, sizeof(config->paths.shredb), NULL, "%s/shreds.db", config->paths.base ) );
121 0 : }
122 :
123 0 : for( ulong i=0UL; i<config->firedancer.paths.authorized_voter_paths_cnt; i++ ) {
124 0 : replace( config->firedancer.paths.authorized_voter_paths[ i ], "{user}", config->user );
125 0 : replace( config->firedancer.paths.authorized_voter_paths[ i ], "{name}", config->name );
126 0 : }
127 0 : }
128 :
129 : static void
130 0 : fd_config_fillh( fd_config_t * config ) {
131 0 : if( FD_UNLIKELY( strcmp( config->frankendancer.paths.accounts_path, "" ) ) ) {
132 0 : replace( config->frankendancer.paths.accounts_path, "{user}", config->user );
133 0 : replace( config->frankendancer.paths.accounts_path, "{name}", config->name );
134 0 : }
135 :
136 0 : if( FD_UNLIKELY( strcmp( config->frankendancer.paths.ledger, "" ) ) ) {
137 0 : replace( config->frankendancer.paths.ledger, "{user}", config->user );
138 0 : replace( config->frankendancer.paths.ledger, "{name}", config->name );
139 0 : } else {
140 0 : FD_TEST( fd_cstr_printf_check( config->frankendancer.paths.ledger, sizeof(config->frankendancer.paths.ledger), NULL, "%s/ledger", config->paths.base ) );
141 0 : }
142 :
143 0 : if( FD_UNLIKELY( strcmp( config->frankendancer.snapshots.path, "" ) ) ) {
144 0 : replace( config->frankendancer.snapshots.path, "{user}", config->user );
145 0 : replace( config->frankendancer.snapshots.path, "{name}", config->name );
146 0 : } else {
147 0 : strncpy( config->frankendancer.snapshots.path, config->frankendancer.paths.ledger, sizeof(config->frankendancer.snapshots.path) );
148 0 : }
149 :
150 0 : for( ulong i=0UL; i<config->frankendancer.paths.authorized_voter_paths_cnt; i++ ) {
151 0 : replace( config->frankendancer.paths.authorized_voter_paths[ i ], "{user}", config->user );
152 0 : replace( config->frankendancer.paths.authorized_voter_paths[ i ], "{name}", config->name );
153 0 : }
154 :
155 0 : if( FD_UNLIKELY( config->tiles.quic.quic_transaction_listen_port!=config->tiles.quic.regular_transaction_listen_port+6 ) )
156 0 : FD_LOG_ERR(( "configuration specifies invalid [tiles.quic.quic_transaction_listen_port] `%hu`. "
157 0 : "This must be 6 more than [tiles.quic.regular_transaction_listen_port] `%hu`",
158 0 : config->tiles.quic.quic_transaction_listen_port,
159 0 : config->tiles.quic.regular_transaction_listen_port ));
160 :
161 0 : char dynamic_port_range[ 32 ];
162 0 : fd_memcpy( dynamic_port_range, config->frankendancer.dynamic_port_range, sizeof(dynamic_port_range) );
163 :
164 0 : char * dash = strstr( dynamic_port_range, "-" );
165 0 : if( FD_UNLIKELY( !dash ) )
166 0 : FD_LOG_ERR(( "configuration specifies invalid [dynamic_port_range] `%s`. "
167 0 : "This must be formatted like `<min>-<max>`",
168 0 : config->frankendancer.dynamic_port_range ));
169 :
170 0 : *dash = '\0';
171 0 : char * endptr;
172 0 : ulong agave_port_min = strtoul( dynamic_port_range, &endptr, 10 );
173 0 : if( FD_UNLIKELY( *endptr != '\0' || agave_port_min > USHORT_MAX ) )
174 0 : FD_LOG_ERR(( "configuration specifies invalid [dynamic_port_range] `%s`. "
175 0 : "This must be formatted like `<min>-<max>`",
176 0 : config->frankendancer.dynamic_port_range ));
177 0 : ulong agave_port_max = strtoul( dash + 1, &endptr, 10 );
178 0 : if( FD_UNLIKELY( *endptr != '\0' || agave_port_max > USHORT_MAX ) )
179 0 : FD_LOG_ERR(( "configuration specifies invalid [dynamic_port_range] `%s`. "
180 0 : "This must be formatted like `<min>-<max>`",
181 0 : config->frankendancer.dynamic_port_range ));
182 0 : if( FD_UNLIKELY( agave_port_min > agave_port_max ) )
183 0 : FD_LOG_ERR(( "configuration specifies invalid [dynamic_port_range] `%s`. "
184 0 : "The minimum port must be less than or equal to the maximum port",
185 0 : config->frankendancer.dynamic_port_range ));
186 :
187 0 : if( FD_UNLIKELY( config->tiles.quic.regular_transaction_listen_port >= agave_port_min &&
188 0 : config->tiles.quic.regular_transaction_listen_port < agave_port_max ) )
189 0 : FD_LOG_ERR(( "configuration specifies invalid [tiles.quic.transaction_listen_port] `%hu`. "
190 0 : "This must be outside the dynamic port range `%s`",
191 0 : config->tiles.quic.regular_transaction_listen_port,
192 0 : config->frankendancer.dynamic_port_range ));
193 :
194 0 : if( FD_UNLIKELY( config->tiles.quic.quic_transaction_listen_port >= agave_port_min &&
195 0 : config->tiles.quic.quic_transaction_listen_port < agave_port_max ) )
196 0 : FD_LOG_ERR(( "configuration specifies invalid [tiles.quic.quic_transaction_listen_port] `%hu`. "
197 0 : "This must be outside the dynamic port range `%s`",
198 0 : config->tiles.quic.quic_transaction_listen_port,
199 0 : config->frankendancer.dynamic_port_range ));
200 :
201 0 : if( FD_UNLIKELY( config->tiles.shred.shred_listen_port >= agave_port_min &&
202 0 : config->tiles.shred.shred_listen_port < agave_port_max ) )
203 0 : FD_LOG_ERR(( "configuration specifies invalid [tiles.shred.shred_listen_port] `%hu`. "
204 0 : "This must be outside the dynamic port range `%s`",
205 0 : config->tiles.shred.shred_listen_port,
206 0 : config->frankendancer.dynamic_port_range ));
207 0 : }
208 :
209 : static void
210 0 : fd_config_fill_net( fd_config_t * config ) {
211 0 : if( FD_UNLIKELY( !strcmp( config->net.interface, "" ) ) ) {
212 0 : uint ifindex;
213 0 : int result = fd_net_util_internet_ifindex( &ifindex );
214 0 : if( FD_UNLIKELY( -1==result && errno!=ENODEV ) ) FD_LOG_ERR(( "could not get network device index (%i-%s)", errno, fd_io_strerror( errno ) ));
215 0 : else if( FD_UNLIKELY( -1==result ) )
216 0 : FD_LOG_ERR(( "no network device found which routes to 8.8.8.8. If no network "
217 0 : "interface is specified in the configuration file, Firedancer "
218 0 : "tries to use the first network interface found which routes to "
219 0 : "8.8.8.8. You can see what this is by running `ip route get 8.8.8.8` "
220 0 : "You can fix this error by specifying a network interface to bind to in "
221 0 : "your configuration file under [net.interface]" ));
222 :
223 0 : if( FD_UNLIKELY( !if_indextoname( ifindex, config->net.interface ) ) )
224 0 : FD_LOG_ERR(( "could not get name of interface with index %u", ifindex ));
225 0 : }
226 :
227 0 : if( FD_UNLIKELY( !if_nametoindex( config->net.interface ) ) )
228 0 : FD_LOG_ERR(( "configuration specifies network interface `%s` which does not exist", config->net.interface ));
229 0 : uint iface_ip;
230 0 : if( FD_UNLIKELY( -1==fd_net_util_if_addr( config->net.interface, &iface_ip ) ) )
231 0 : FD_LOG_ERR(( "could not get IP address for interface `%s`", config->net.interface ));
232 :
233 0 : if( FD_UNLIKELY( config->is_firedancer ) ) {
234 0 : if( FD_UNLIKELY( strcmp( config->firedancer.gossip.host, "" ) ) ) {
235 0 : uint gossip_ip_addr = iface_ip;
236 0 : int has_gossip_ip4 = 0;
237 0 : if( FD_UNLIKELY( strlen( config->firedancer.gossip.host )<=15UL ) ) {
238 : /* Only sets gossip_ip_addr if it's a valid IPv4 address, otherwise assume it's a DNS name */
239 0 : has_gossip_ip4 = fd_cstr_to_ip4_addr( config->firedancer.gossip.host, &gossip_ip_addr );
240 0 : }
241 0 : if( FD_UNLIKELY( !fd_ip4_addr_is_public( gossip_ip_addr ) && config->is_live_cluster && has_gossip_ip4 ) )
242 0 : FD_LOG_ERR(( "Trying to use [gossip.host] " FD_IP4_ADDR_FMT " for listening to incoming "
243 0 : "transactions, but it is part of a private network and will not be routable "
244 0 : "for other Solana network nodes.", FD_IP4_ADDR_FMT_ARGS( gossip_ip_addr ) ));
245 0 : } else if( FD_UNLIKELY( !fd_ip4_addr_is_public( iface_ip ) && config->is_live_cluster ) ) {
246 0 : FD_LOG_ERR(( "Trying to use network interface `%s` for listening to incoming transactions, "
247 0 : "but it has IPv4 address " FD_IP4_ADDR_FMT " which is part of a private network "
248 0 : "and will not be routable for other Solana network nodes. If you are running "
249 0 : "behind a NAT and this interface is publicly reachable, you can continue by "
250 0 : "manually specifying the IP address to advertise in your configuration under "
251 0 : "[gossip.host].", config->net.interface, FD_IP4_ADDR_FMT_ARGS( iface_ip ) ));
252 0 : }
253 0 : }
254 :
255 0 : config->net.ip_addr = iface_ip;
256 0 : }
257 :
258 : void
259 : fd_config_fill( fd_config_t * config,
260 : int is_local_cluster,
261 0 : int dev ) {
262 0 : struct utsname utsname;
263 0 : if( FD_UNLIKELY( -1==uname( &utsname ) ) )
264 0 : FD_LOG_ERR(( "could not get uname (%i-%s)", errno, fd_io_strerror( errno ) ));
265 0 : strncpy( config->hostname, utsname.nodename, sizeof(config->hostname) );
266 0 : config->hostname[ sizeof(config->hostname)-1UL ] = '\0'; /* Just truncate the name if it's too long to fit */
267 :
268 0 : ulong cluster = FD_CLUSTER_UNKNOWN;
269 0 : if( FD_UNLIKELY( !config->is_firedancer ) ) {
270 0 : cluster = fd_genesis_cluster_identify( config->frankendancer.consensus.expected_genesis_hash );
271 0 : }
272 0 : config->is_live_cluster = cluster!=FD_CLUSTER_UNKNOWN;
273 0 : strcpy( config->cluster, fd_genesis_cluster_name( cluster ) );
274 :
275 0 : if( FD_UNLIKELY( !strcmp( config->user, "" ) ) ) {
276 0 : const char * user = fd_sys_util_login_user();
277 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." ));
278 0 : if( FD_UNLIKELY( strlen( user )>=sizeof( config->user ) ) ) FD_LOG_ERR(( "user name `%s` is too long", user ));
279 0 : strncpy( config->user, user, sizeof(config->user) );
280 0 : }
281 :
282 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 ));
283 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" ));
284 0 : if( FD_UNLIKELY( getuid()!=0U && config->uid!=getuid() ) ) FD_LOG_ERR(( "running as uid %u, but config specifies uid %u", getuid(), config->uid ));
285 0 : if( FD_UNLIKELY( getgid()!=0U && config->gid!=getgid() ) ) FD_LOG_ERR(( "running as gid %u, but config specifies gid %u", getgid(), config->gid ));
286 :
287 0 : FD_TEST( fd_cstr_printf_check( config->hugetlbfs.gigantic_page_mount_path,
288 0 : sizeof(config->hugetlbfs.gigantic_page_mount_path),
289 0 : NULL,
290 0 : "%s/.gigantic",
291 0 : config->hugetlbfs.mount_path ) );
292 0 : FD_TEST( fd_cstr_printf_check( config->hugetlbfs.huge_page_mount_path,
293 0 : sizeof(config->hugetlbfs.huge_page_mount_path),
294 0 : NULL,
295 0 : "%s/.huge",
296 0 : config->hugetlbfs.mount_path ) );
297 :
298 0 : ulong max_page_sz = fd_cstr_to_shmem_page_sz( config->hugetlbfs.max_page_size );
299 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\"" ));
300 :
301 0 : replace( config->log.path, "{user}", config->user );
302 0 : replace( config->log.path, "{name}", config->name );
303 :
304 0 : if( FD_LIKELY( !strcmp( "auto", config->log.colorize ) ) ) config->log.colorize1 = 2;
305 0 : else if( FD_LIKELY( !strcmp( "true", config->log.colorize ) ) ) config->log.colorize1 = 1;
306 0 : else if( FD_LIKELY( !strcmp( "false", config->log.colorize ) ) ) config->log.colorize1 = 0;
307 0 : else FD_LOG_ERR(( "[log.colorize] must be one of \"auto\", \"true\", or \"false\"" ));
308 :
309 0 : if( FD_LIKELY( 2==config->log.colorize1 ) ) {
310 0 : config->log.colorize1 = fd_log_should_colorize();
311 0 : }
312 :
313 0 : config->log.level_logfile1 = parse_log_level( config->log.level_logfile );
314 0 : config->log.level_stderr1 = parse_log_level( config->log.level_stderr );
315 0 : config->log.level_flush1 = parse_log_level( config->log.level_flush );
316 0 : if( FD_UNLIKELY( -1==config->log.level_logfile1 ) ) FD_LOG_ERR(( "unrecognized [log.level_logfile] `%s`", config->log.level_logfile ));
317 0 : if( FD_UNLIKELY( -1==config->log.level_stderr1 ) ) FD_LOG_ERR(( "unrecognized [log.level_stderr] `%s`", config->log.level_stderr ));
318 0 : if( FD_UNLIKELY( -1==config->log.level_flush1 ) ) FD_LOG_ERR(( "unrecognized [log.level_flush] `%s`", config->log.level_flush ));
319 :
320 0 : config->development.core_dump_level = parse_core_dump_level( config->development.core_dump );
321 0 : if( FD_UNLIKELY( -1==config->development.core_dump_level ) ) FD_LOG_ERR(( "unrecognized [development.core_dump] `%s`", config->development.core_dump ));
322 :
323 0 : replace( config->paths.base, "{user}", config->user );
324 0 : replace( config->paths.base, "{name}", config->name );
325 :
326 0 : if( FD_UNLIKELY( !strcmp( config->paths.identity_key, "" ) ) ) {
327 0 : if( FD_UNLIKELY( config->is_live_cluster ) ) FD_LOG_ERR(( "configuration file must specify [consensus.identity_path] when joining a live cluster" ));
328 :
329 0 : FD_TEST( fd_cstr_printf_check( config->paths.identity_key,
330 0 : sizeof(config->paths.identity_key),
331 0 : NULL,
332 0 : "%s/identity.json",
333 0 : config->paths.base ) );
334 0 : } else {
335 0 : replace( config->paths.identity_key, "{user}", config->user );
336 0 : replace( config->paths.identity_key, "{name}", config->name );
337 0 : }
338 :
339 0 : replace( config->paths.vote_account, "{user}", config->user );
340 0 : replace( config->paths.vote_account, "{name}", config->name );
341 :
342 0 : if( FD_UNLIKELY( strcmp( config->paths.snapshots, "" ) ) ) {
343 0 : replace( config->paths.snapshots, "{user}", config->user );
344 0 : replace( config->paths.snapshots, "{name}", config->name );
345 0 : } else {
346 0 : FD_TEST( fd_cstr_printf_check( config->paths.snapshots, sizeof(config->paths.snapshots), NULL, "%s/snapshots", config->paths.base ) );
347 0 : }
348 :
349 0 : if( FD_UNLIKELY( strcmp( config->paths.genesis, "" ) ) ) {
350 0 : replace( config->paths.genesis, "{user}", config->user );
351 0 : replace( config->paths.genesis, "{name}", config->name );
352 0 : } else {
353 0 : FD_TEST( fd_cstr_printf_check( config->paths.genesis, sizeof(config->paths.genesis), NULL, "%s/genesis.bin", config->paths.base ) );
354 0 : }
355 :
356 0 : long ts = -fd_log_wallclock();
357 0 : config->tick_per_ns_mu = dev ? fd_tempo_tick_per_ns_dev( &config->tick_per_ns_sigma )
358 0 : : fd_tempo_tick_per_ns ( &config->tick_per_ns_sigma );
359 0 : FD_LOG_INFO(( "calibrating fd_tempo tick_per_ns took %ld ms", (fd_log_wallclock()+ts)/(1000L*1000L) ));
360 :
361 0 : if( 0!=strcmp( config->net.bind_address, "" ) ) {
362 0 : if( FD_UNLIKELY( !fd_cstr_to_ip4_addr( config->net.bind_address, &config->net.bind_address_parsed ) ) ) {
363 0 : FD_LOG_ERR(( "`net.bind_address` is not a valid IPv4 address" ));
364 0 : }
365 0 : }
366 :
367 0 : if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "perf" ) ) ) config->tiles.pack.schedule_strategy_enum = 0;
368 0 : else if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "balanced" ) ) ) config->tiles.pack.schedule_strategy_enum = 1;
369 0 : else if( FD_LIKELY( !strcmp( config->tiles.pack.schedule_strategy, "revenue" ) ) ) {
370 0 : FD_LOG_ERR(( "the revenue scheduler has been removed. Please update [tiles.pack.schedule_strategy]" ));
371 0 : }
372 0 : else FD_LOG_ERR(( "[tiles.pack.schedule_strategy] %s not recognized", config->tiles.pack.schedule_strategy ));
373 :
374 0 : fd_config_fill_net( config );
375 :
376 0 : if( FD_UNLIKELY( config->is_firedancer ) ) {
377 0 : fd_config_fillf( config );
378 0 : } else {
379 0 : fd_config_fillh( config );
380 0 : }
381 :
382 0 : if( FD_LIKELY( config->is_live_cluster) ) {
383 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" ));
384 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" ));
385 0 : if( FD_UNLIKELY( config->development.bench.larger_max_cost_per_block ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration enables [development.bench.larger_max_cost_per_block] which is a development only feature" ));
386 0 : if( FD_UNLIKELY( config->development.bench.larger_shred_limits_per_block ) ) FD_LOG_ERR(( "trying to join a live cluster, but configuration enables [development.bench.larger_shred_limits_per_block] which is a development only feature" ));
387 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" ));
388 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" ));
389 0 : }
390 :
391 : /* When running a local cluster, some options are overriden by default
392 : to make starting and running in development environments a little
393 : easier and less strict. */
394 0 : if( FD_UNLIKELY( is_local_cluster ) ) {
395 0 : if( FD_LIKELY( !strcmp( config->paths.vote_account, "" ) ) ) {
396 0 : FD_TEST( fd_cstr_printf_check( config->paths.vote_account,
397 0 : sizeof( config->paths.vote_account ),
398 0 : NULL,
399 0 : "%s/vote-account.json",
400 0 : config->paths.base ) );
401 0 : }
402 :
403 0 : strncpy( config->cluster, "development", sizeof(config->cluster) );
404 :
405 0 : if( FD_UNLIKELY( !config->is_firedancer ) ) {
406 : /* By default only_known is true for validators to ensure secure
407 : snapshot download, but in development it doesn't matter and
408 : often the developer does not provide known peers. */
409 0 : config->frankendancer.rpc.only_known = 0;
410 :
411 : /* When starting from a new genesis block, this needs to be off else
412 : the validator will get stuck forever. */
413 0 : config->frankendancer.consensus.wait_for_vote_to_start_leader = 0;
414 :
415 : /* We have to wait until we get a snapshot before we can join a
416 : second validator to this one, so make this smaller than the
417 : default. */
418 0 : config->frankendancer.snapshots.full_snapshot_interval_slots = fd_uint_min( config->frankendancer.snapshots.full_snapshot_interval_slots, 200U );
419 0 : }
420 0 : }
421 :
422 0 : if( FD_UNLIKELY( config->is_firedancer && strcmp( config->firedancer.consensus.wait_for_supermajority_with_bank_hash, "" ) && (!config->consensus.expected_shred_version || config->consensus.wait_for_vote_to_start_leader) ) ) {
423 0 : FD_LOG_ERR(( "Config option [consensus.wait_for_supermajority_with_bank_hash] requires consensus.expected_shred_version!=0 and consensus.wait_for_vote_to_start_leader==false." ));
424 0 : }
425 :
426 0 : if( FD_UNLIKELY( config->is_firedancer && config->is_live_cluster && cluster!=FD_CLUSTER_TESTNET ) )
427 0 : FD_LOG_ERR(( "Attempted to start against live cluster `%s`. Firedancer is not "
428 0 : "ready for production deployment, has not been tested, and is "
429 0 : "missing consensus critical functionality. Joining a live Solana "
430 0 : "cluster may destabilize the network. Please do not attempt. You "
431 0 : "can start against the testnet cluster by specifying the testnet "
432 0 : "entrypoints from https://docs.solana.com/clusters under "
433 0 : "[gossip.entrypoints] in your configuration file.", fd_genesis_cluster_name( cluster ) ));
434 0 : }
435 :
436 48 : #define CFG_HAS_NON_EMPTY( key ) do { \
437 48 : if( !strnlen( config->key, sizeof(config->key) ) ) { \
438 0 : FD_LOG_ERR(( "missing `%s`", #key )); \
439 0 : } \
440 48 : } while(0)
441 :
442 90 : #define CFG_HAS_NON_ZERO( key ) do { \
443 90 : if( !config->key ) { FD_LOG_ERR(( "missing `%s`", #key )); } \
444 90 : } while(0)
445 :
446 6 : #define CFG_HAS_POW2( key ) do { \
447 6 : ulong value = (ulong)( config -> key ); \
448 6 : if( !value || !fd_ulong_is_pow2( value ) ) { \
449 0 : FD_LOG_ERR(( "`%s` must be a power of 2", #key )); \
450 0 : } \
451 6 : } while(0)
452 :
453 : static void
454 0 : fd_config_validatef( fd_configf_t const * config ) {
455 0 : CFG_HAS_NON_ZERO( layout.sign_tile_count );
456 0 : CFG_HAS_NON_ZERO( layout.resolv_tile_count );
457 0 : CFG_HAS_NON_ZERO( layout.execle_tile_count );
458 0 : if( FD_UNLIKELY( config->layout.sign_tile_count < 2 ) ) {
459 0 : FD_LOG_ERR(( "layout.sign_tile_count must be >= 2" ));
460 0 : }
461 :
462 0 : if( FD_UNLIKELY( config->snapshots.sources.gossip.allow_any && config->snapshots.sources.gossip.allow_list_cnt>0UL ) ) {
463 0 : FD_LOG_ERR(( "`snapshots.sources.gossip` has an explicit list of %lu allowed peer(s) in `allow_list` "
464 0 : "but also allows any peer with `allow_any=true`. `allow_list` has no effect and may "
465 0 : "give a false sense of security. Please modify one of the two options and restart.",
466 0 : config->snapshots.sources.gossip.allow_list_cnt ));
467 0 : }
468 0 : for( ulong i=0UL; i<config->snapshots.sources.gossip.allow_list_cnt; i++ ) {
469 0 : for( ulong j=0UL; j<config->snapshots.sources.gossip.block_list_cnt; j++ ) {
470 0 : if( FD_UNLIKELY( 0==strcmp( config->snapshots.sources.gossip.allow_list[ i ], config->snapshots.sources.gossip.block_list[ j ] ) ) ) {
471 0 : FD_LOG_ERR(( "`snapshots.sources.gossip` has repeated public key `%s` in both allow[%lu] and block[%lu] lists. "
472 0 : "Please modify one of the two options and restart.", config->snapshots.sources.gossip.allow_list[ i ], i, j ));
473 :
474 0 : }
475 0 : }
476 0 : }
477 :
478 0 : CFG_HAS_NON_ZERO( accounts.max_accounts );
479 0 : CFG_HAS_NON_ZERO( accounts.cache_size_gib );
480 :
481 0 : CFG_HAS_NON_ZERO( runtime.program_cache.mean_cache_entry_size );
482 0 : CFG_HAS_NON_ZERO( runtime.program_cache.heap_size_mib );
483 0 : if( config->runtime.program_cache.mean_cache_entry_size < 4096 ) { FD_LOG_ERR(( "`%s` must be >= 4096", "runtime.program_cache.mean_cache_entry_size" )); }
484 0 : if( config->runtime.program_cache.heap_size_mib < 32 ) { FD_LOG_ERR(( "`%s` must be >= 32", "runtime.program_cache.heap_size_mib" )); }
485 0 : }
486 :
487 : static void
488 3 : fd_config_validateh( fd_configh_t const * config ) {
489 3 : CFG_HAS_NON_EMPTY( dynamic_port_range );
490 :
491 3 : CFG_HAS_NON_EMPTY( ledger.snapshot_archive_format );
492 :
493 3 : CFG_HAS_NON_ZERO( snapshots.full_snapshot_interval_slots );
494 3 : CFG_HAS_NON_ZERO( snapshots.incremental_snapshot_interval_slots );
495 3 : CFG_HAS_NON_ZERO( snapshots.minimum_snapshot_download_speed );
496 3 : CFG_HAS_NON_ZERO( snapshots.maximum_snapshot_download_abort );
497 :
498 3 : CFG_HAS_NON_EMPTY( layout.agave_affinity );
499 3 : CFG_HAS_NON_ZERO ( layout.resolh_tile_count );
500 3 : CFG_HAS_NON_ZERO ( layout.bank_tile_count );
501 3 : }
502 :
503 : void
504 3 : fd_config_validate( fd_config_t const * config ) {
505 3 : if( FD_LIKELY( config->is_firedancer ) ) {
506 0 : fd_config_validatef( &config->firedancer );
507 3 : } else {
508 3 : fd_config_validateh( &config->frankendancer );
509 3 : }
510 :
511 3 : CFG_HAS_NON_EMPTY( name );
512 3 : CFG_HAS_NON_EMPTY( paths.base );
513 :
514 3 : CFG_HAS_NON_EMPTY( log.colorize );
515 3 : CFG_HAS_NON_EMPTY( log.level_logfile );
516 3 : CFG_HAS_NON_EMPTY( log.level_stderr );
517 3 : CFG_HAS_NON_EMPTY( log.level_flush );
518 :
519 3 : CFG_HAS_NON_EMPTY( layout.affinity );
520 3 : CFG_HAS_NON_EMPTY( layout.blocklist_cores );
521 3 : CFG_HAS_NON_ZERO ( layout.net_tile_count );
522 3 : CFG_HAS_NON_ZERO ( layout.quic_tile_count );
523 3 : CFG_HAS_NON_ZERO ( layout.verify_tile_count );
524 3 : CFG_HAS_NON_ZERO ( layout.shred_tile_count );
525 :
526 3 : CFG_HAS_NON_EMPTY( hugetlbfs.mount_path );
527 3 : CFG_HAS_NON_EMPTY( hugetlbfs.max_page_size );
528 :
529 3 : CFG_HAS_NON_ZERO( net.ingress_buffer_size );
530 3 : if( 0==strcmp( config->net.provider, "xdp" ) ) {
531 3 : CFG_HAS_NON_EMPTY( net.xdp.xdp_mode );
532 3 : CFG_HAS_POW2 ( net.xdp.xdp_rx_queue_size );
533 3 : CFG_HAS_POW2 ( net.xdp.xdp_tx_queue_size );
534 3 : if( 0!=strcmp( config->net.xdp.rss_queue_mode, "dedicated" ) &&
535 3 : 0!=strcmp( config->net.xdp.rss_queue_mode, "simple" ) &&
536 3 : 0!=strcmp( config->net.xdp.rss_queue_mode, "auto" ) ) {
537 0 : FD_LOG_ERR(( "invalid `net.xdp.rss_queue_mode`: \"%s\"; must be \"simple\", \"dedicated\", or \"auto\"",
538 0 : config->net.xdp.rss_queue_mode ));
539 0 : }
540 3 : } else if( 0==strcmp( config->net.provider, "socket" ) ) {
541 0 : CFG_HAS_NON_ZERO( net.socket.receive_buffer_size );
542 0 : CFG_HAS_NON_ZERO( net.socket.send_buffer_size );
543 0 : } else {
544 0 : FD_LOG_ERR(( "invalid `net.provider`: must be \"xdp\" or \"socket\"" ));
545 0 : }
546 :
547 3 : CFG_HAS_NON_ZERO( tiles.netlink.max_routes );
548 3 : CFG_HAS_NON_ZERO( tiles.netlink.max_peer_routes );
549 3 : CFG_HAS_NON_ZERO( tiles.netlink.max_neighbors );
550 :
551 3 : CFG_HAS_NON_ZERO( tiles.quic.max_concurrent_connections );
552 3 : CFG_HAS_NON_ZERO( tiles.quic.txn_reassembly_count );
553 3 : CFG_HAS_NON_ZERO( tiles.quic.max_concurrent_handshakes );
554 3 : CFG_HAS_NON_ZERO( tiles.quic.idle_timeout_millis );
555 :
556 3 : CFG_HAS_NON_ZERO( tiles.verify.signature_cache_size );
557 3 : CFG_HAS_NON_ZERO( tiles.verify.receive_buffer_size );
558 :
559 3 : CFG_HAS_NON_ZERO( tiles.dedup.signature_cache_size );
560 :
561 3 : CFG_HAS_NON_ZERO( tiles.pack.max_pending_transactions );
562 :
563 3 : CFG_HAS_NON_ZERO( tiles.shred.max_pending_shred_sets );
564 :
565 3 : if( config->is_firedancer ) {
566 0 : CFG_HAS_POW2( tiles.repair.slot_max );
567 0 : }
568 :
569 3 : if( FD_UNLIKELY( config->tiles.bundle.keepalive_interval_millis < 3000 ||
570 3 : config->tiles.bundle.keepalive_interval_millis > 3600000 ) ) {
571 0 : FD_LOG_ERR(( "`tiles.bundle.keepalive_interval_millis` must be in range [3000, 3,600,000]" ));
572 0 : }
573 :
574 3 : CFG_HAS_NON_EMPTY( development.core_dump );
575 :
576 3 : CFG_HAS_NON_ZERO( development.genesis.target_tick_duration_micros );
577 3 : CFG_HAS_NON_ZERO( development.genesis.ticks_per_slot );
578 3 : CFG_HAS_NON_ZERO( development.genesis.fund_initial_accounts );
579 3 : CFG_HAS_NON_ZERO( development.genesis.fund_initial_amount_lamports );
580 :
581 3 : CFG_HAS_NON_ZERO ( development.bench.benchg_tile_count );
582 3 : CFG_HAS_NON_ZERO ( development.bench.benchs_tile_count );
583 3 : CFG_HAS_NON_EMPTY( development.bench.affinity );
584 :
585 3 : CFG_HAS_NON_ZERO( development.bundle.ssl_heap_size_mib );
586 3 : }
587 :
588 : #undef CFG_HAS_NON_EMPTY
589 : #undef CFG_HAS_NON_ZERO
590 : #undef CFG_HAS_POW2
591 :
592 : void
593 : fd_config_load( int is_firedancer,
594 : int is_local_cluster,
595 : char const * default_config,
596 : ulong default_config_sz,
597 : char const * override_config,
598 : char const * override_config_path,
599 : ulong override_config_sz,
600 : char const * user_config,
601 : ulong user_config_sz,
602 : char const * user_config_path,
603 : fd_config_t * config,
604 0 : int dev ) {
605 0 : memset( config, 0, sizeof(config_t) );
606 0 : config->is_firedancer = is_firedancer;
607 0 : config->boot_timestamp_nanos = fd_log_wallclock();
608 :
609 0 : fd_config_load_buf( config, default_config, default_config_sz, "default.toml" );
610 0 : fd_config_validate( config );
611 0 : if( FD_UNLIKELY( override_config ) ) {
612 0 : fd_config_load_buf( config, override_config, override_config_sz, override_config_path );
613 0 : fd_config_validate( config );
614 0 : }
615 0 : if( FD_LIKELY( user_config ) ) {
616 0 : fd_config_load_buf( config, user_config, user_config_sz, user_config_path );
617 0 : fd_config_validate( config );
618 0 : }
619 :
620 0 : fd_config_fill( config, is_local_cluster, dev );
621 0 : }
622 :
623 : int
624 0 : fd_config_to_memfd( fd_config_t const * config ) {
625 0 : int config_memfd = memfd_create( "fd_config", 0 );
626 0 : if( FD_UNLIKELY( -1==config_memfd ) ) return -1;
627 0 : if( FD_UNLIKELY( -1==ftruncate( config_memfd, sizeof( config_t ) ) ) ) {
628 0 : if( FD_UNLIKELY( close( config_memfd ) ) ) FD_LOG_WARNING(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
629 0 : return -1;
630 0 : }
631 :
632 0 : uchar * bytes = mmap( NULL, sizeof( config_t ), PROT_READ|PROT_WRITE, MAP_SHARED, config_memfd, 0 );
633 0 : if( FD_UNLIKELY( bytes==MAP_FAILED ) ) {
634 0 : if( FD_UNLIKELY( close( config_memfd ) ) ) FD_LOG_WARNING(( "close() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
635 0 : return -1;
636 0 : }
637 :
638 0 : fd_memcpy( bytes, config, sizeof( config_t ) );
639 0 : if( FD_UNLIKELY( munmap( bytes, sizeof( config_t ) ) ) ) {
640 0 : FD_LOG_WARNING(( "munmap() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
641 0 : return -1;
642 0 : }
643 :
644 0 : return config_memfd;
645 0 : }
|