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