Line data Source code
1 : #define _GNU_SOURCE
2 : #include "run.h"
3 :
4 : #include "../../../util/net/fd_ip4.h"
5 : #include "../../../util/tile/fd_tile_private.h"
6 :
7 : #include <sched.h>
8 : #include <pthread.h>
9 : #include <sys/wait.h>
10 :
11 : #define NAME "run-agave"
12 :
13 : extern void fd_ext_validator_main( const char ** args );
14 :
15 : extern int * fd_log_private_shared_lock;
16 :
17 : static void
18 0 : clone_labs_memory_space_tiles( config_t * const config ) {
19 : /* preload shared memory for all the agave tiles at once */
20 0 : for( ulong i=0; i<config->topo.wksp_cnt; i++ ) {
21 0 : fd_topo_wksp_t * wksp = &config->topo.workspaces[ i ];
22 0 : if( FD_LIKELY( !strcmp( wksp->name, "pack_bank" ) ||
23 0 : !strcmp( wksp->name, "shred_store" ) ) ) {
24 0 : fd_topo_join_workspace( &config->topo, wksp, FD_SHMEM_JOIN_MODE_READ_ONLY );
25 0 : } else if( FD_LIKELY( !strcmp( wksp->name, "bank_poh" ) ||
26 0 : !strcmp( wksp->name, "bank_busy" ) ||
27 0 : !strcmp( wksp->name, "poh_shred" ) ||
28 0 : !strcmp( wksp->name, "gossip_dedup" ) ||
29 0 : !strcmp( wksp->name, "stake_out" ) ||
30 0 : !strcmp( wksp->name, "metric_in" ) ||
31 0 : !strcmp( wksp->name, "bank" ) ||
32 0 : !strcmp( wksp->name, "poh" ) ||
33 0 : !strcmp( wksp->name, "store" ) ) ) {
34 0 : fd_topo_join_workspace( &config->topo, wksp, FD_SHMEM_JOIN_MODE_READ_WRITE );
35 0 : }
36 0 : }
37 :
38 0 : fd_topo_run_single_process( &config->topo, 1, config->uid, config->gid, fdctl_tile_run, NULL );
39 0 : }
40 :
41 : static int _fd_ext_larger_max_cost_per_block, _fd_ext_larger_shred_limits_per_block, _fd_ext_disable_status_cache;
42 :
43 0 : int fd_ext_larger_max_cost_per_block ( void ) { return _fd_ext_larger_max_cost_per_block; }
44 0 : int fd_ext_larger_shred_limits_per_block( void ) { return _fd_ext_larger_shred_limits_per_block; }
45 0 : int fd_ext_disable_status_cache ( void ) { return _fd_ext_disable_status_cache; }
46 :
47 : void
48 0 : agave_boot( config_t * config ) {
49 0 : uint idx = 0;
50 0 : char * argv[ 128 ];
51 0 : uint bufidx = 0;
52 0 : char buffer[ 32 ][ 16 ];
53 0 : #define ADD1( arg ) do { argv[ idx++ ] = arg; } while( 0 )
54 0 : #define ADD( arg, val ) do { argv[ idx++ ] = arg; argv[ idx++ ] = val; } while( 0 )
55 0 : #define ADDU( arg, val ) do { argv[ idx++ ] = arg; FD_TEST( fd_cstr_printf_check( buffer[ bufidx ], 16, NULL, "%u", val ) ); argv[ idx++ ] = buffer[ bufidx++ ]; } while( 0 )
56 0 : #define ADDH( arg, val ) do { argv[ idx++ ] = arg; FD_TEST( fd_cstr_printf_check( buffer[ bufidx ], 16, NULL, "%hu", val ) ); argv[ idx++ ] = buffer[ bufidx++ ]; } while( 0 )
57 :
58 0 : ADD1( "fdctl" );
59 0 : ADD( "--log", "-" );
60 :
61 0 : if( FD_UNLIKELY( strcmp( config->dynamic_port_range, "" ) ) )
62 0 : ADD( "--dynamic-port-range", config->dynamic_port_range );
63 :
64 0 : ADDU( "--firedancer-tpu-port", config->tiles.quic.regular_transaction_listen_port );
65 0 : ADDU( "--firedancer-tvu-port", config->tiles.shred.shred_listen_port );
66 :
67 : /* consensus */
68 0 : ADD( "--identity", config->consensus.identity_path );
69 0 : if( strcmp( config->consensus.vote_account_path, "" ) )
70 0 : ADD( "--vote-account", config->consensus.vote_account_path );
71 0 : for( ulong i=0UL; i<config->consensus.authorized_voter_paths_cnt; i++ )
72 0 : ADD( "--authorized-voter", config->consensus.authorized_voter_paths[ i ] );
73 0 : if( !config->consensus.snapshot_fetch ) ADD1( "--no-snapshot-fetch" );
74 0 : if( !config->consensus.genesis_fetch ) ADD1( "--no-genesis-fetch" );
75 0 : if( !config->consensus.poh_speed_test ) ADD1( "--no-poh-speed-test" );
76 0 : if( strcmp( config->consensus.expected_genesis_hash, "" ) )
77 0 : ADD( "--expected-genesis-hash", config->consensus.expected_genesis_hash );
78 0 : if( config->consensus.wait_for_supermajority_at_slot ) {
79 0 : ADDU( "--wait-for-supermajority", config->consensus.wait_for_supermajority_at_slot );
80 0 : if( strcmp( config->consensus.expected_bank_hash, "" ) )
81 0 : ADD( "--expected-bank-hash", config->consensus.expected_bank_hash );
82 0 : }
83 0 : if( config->consensus.expected_shred_version )
84 0 : ADDH( "--expected-shred-version", config->consensus.expected_shred_version );
85 0 : if( !config->consensus.wait_for_vote_to_start_leader )
86 0 : ADD1( "--no-wait-for-vote-to-start-leader");
87 0 : for( uint * p = config->consensus.hard_fork_at_slots; *p; p++ ) ADDU( "--hard-fork", *p );
88 0 : for( ulong i=0; i<config->consensus.known_validators_cnt; i++ )
89 0 : ADD( "--known-validator", config->consensus.known_validators[ i ] );
90 :
91 0 : ADD( "--snapshot-archive-format", config->ledger.snapshot_archive_format );
92 0 : if( FD_UNLIKELY( config->ledger.require_tower ) ) ADD1( "--require-tower" );
93 :
94 0 : if( FD_UNLIKELY( !config->consensus.os_network_limits_test ) )
95 0 : ADD1( "--no-os-network-limits-test" );
96 :
97 : /* ledger */
98 0 : ADD( "--ledger", config->ledger.path );
99 0 : ADDU( "--limit-ledger-size", config->ledger.limit_size );
100 0 : if( strcmp( "", config->ledger.accounts_path ) )
101 0 : ADD( "--accounts", config->ledger.accounts_path );
102 0 : if( strcmp( "", config->ledger.accounts_index_path ) )
103 0 : ADD( "--accounts-index-path", config->ledger.accounts_index_path );
104 0 : if( strcmp( "", config->ledger.accounts_hash_cache_path ) )
105 0 : ADD( "--accounts-hash-cache-path", config->ledger.accounts_hash_cache_path );
106 0 : for( ulong i=0UL; i<config->ledger.account_indexes_cnt; i++ )
107 0 : ADD( "--account-index", config->ledger.account_indexes[ i ] );
108 0 : if( FD_LIKELY( !config->ledger.account_index_include_keys_cnt ) ) {
109 0 : for( ulong i=0UL; i<config->ledger.account_index_exclude_keys_cnt; i++ )
110 0 : ADD( "--account-index-exclude-key", config->ledger.account_index_exclude_keys[ i ] );
111 0 : } else {
112 0 : for( ulong i=0UL; i<config->ledger.account_index_include_keys_cnt; i++ )
113 0 : ADD( "--account-index-include-key", config->ledger.account_index_include_keys[ i ] );
114 0 : }
115 :
116 : /* gossip */
117 0 : for( ulong i=0UL; i<config->gossip.entrypoints_cnt; i++ ) ADD( "--entrypoint", config->gossip.entrypoints[ i ] );
118 0 : if( !config->gossip.port_check ) ADD1( "--no-port-check" );
119 0 : ADDH( "--gossip-port", config->gossip.port );
120 0 : char ip_addr[16]; /* ADD stored the address for later use, so ip_addr must be in scope */
121 0 : if( strcmp( config->gossip.host, "" ) ) {
122 0 : ADD( "--gossip-host", config->gossip.host );
123 0 : } else {
124 0 : FD_TEST( fd_cstr_printf_check( ip_addr, 16, NULL, FD_IP4_ADDR_FMT, FD_IP4_ADDR_FMT_ARGS(config->tiles.net.ip_addr) ) );
125 0 : ADD( "--gossip-host", ip_addr );
126 0 : }
127 0 : if( config->development.gossip.allow_private_address ) {
128 0 : ADD1( "--allow-private-addr" );
129 0 : }
130 :
131 : /* rpc */
132 0 : if( config->rpc.port ) ADDH( "--rpc-port", config->rpc.port );
133 0 : if( config->rpc.full_api ) ADD1( "--full-rpc-api" );
134 0 : if( config->rpc.private ) ADD1( "--private-rpc" );
135 0 : if( strcmp( config->rpc.bind_address, "" ) ) ADD( "--rpc-bind-address", config->rpc.bind_address );
136 0 : if( config->rpc.transaction_history ) ADD1( "--enable-rpc-transaction-history" );
137 0 : if( config->rpc.extended_tx_metadata_storage ) ADD1( "--enable-extended-tx-metadata-storage" );
138 0 : if( config->rpc.only_known ) ADD1( "--only-known-rpc" );
139 0 : if( config->rpc.pubsub_enable_block_subscription ) ADD1( "--rpc-pubsub-enable-block-subscription" );
140 0 : if( config->rpc.pubsub_enable_vote_subscription ) ADD1( "--rpc-pubsub-enable-vote-subscription" );
141 0 : if( config->rpc.bigtable_ledger_storage ) ADD1( "--enable-rpc-bigtable-ledger-storage" );
142 :
143 : /* snapshots */
144 0 : if( config->snapshots.enabled ) {
145 0 : if( config->snapshots.incremental_snapshots ) {
146 0 : ADDU( "--full-snapshot-interval-slots", config->snapshots.full_snapshot_interval_slots );
147 0 : ADDU( "--snapshot-interval-slots", config->snapshots.incremental_snapshot_interval_slots );
148 0 : } else {
149 0 : ADDU( "--snapshot-interval-slots", config->snapshots.full_snapshot_interval_slots );
150 0 : }
151 0 : } else {
152 0 : ADDU( "--snapshot-interval-slots", (uint)0 );
153 0 : }
154 0 : if( !config->snapshots.incremental_snapshots ) ADD1( "--no-incremental-snapshots" );
155 0 : ADD( "--snapshots", config->snapshots.path );
156 0 : if( strcmp( "", config->snapshots.incremental_path ) ) ADD( "--incremental-snapshot-archive-path", config->snapshots.incremental_path );
157 0 : ADDU( "--maximum-snapshots-to-retain", config->snapshots.maximum_full_snapshots_to_retain );
158 0 : ADDU( "--maximum-incremental-snapshots-to-retain", config->snapshots.maximum_incremental_snapshots_to_retain );
159 0 : ADDU( "--minimal-snapshot-download-speed", config->snapshots.minimum_snapshot_download_speed );
160 :
161 0 : if( config->layout.agave_unified_scheduler_handler_threads ) {
162 0 : if( FD_UNLIKELY( config->layout.agave_unified_scheduler_handler_threads>config->topo.agave_affinity_cnt ) ) {
163 0 : FD_LOG_ERR(( "Trying to spawn %u handler threads but the agave subprocess has %lu cores. "
164 0 : "Either increase the number of cores in [layout.agave_affinity] or reduce "
165 0 : "the number of threads in [layout.agave_unified_scheduler_handler_threads].",
166 0 : config->layout.agave_unified_scheduler_handler_threads, config->topo.agave_affinity_cnt ));
167 0 : }
168 0 : ADDU( "--unified-scheduler-handler-threads", config->layout.agave_unified_scheduler_handler_threads );
169 0 : } else {
170 0 : ulong num_threads = fd_ulong_max( config->topo.agave_affinity_cnt-4UL, fd_ulong_min( config->topo.agave_affinity_cnt, 4UL ) );
171 0 : ADDU( "--unified-scheduler-handler-threads", (uint)num_threads );
172 0 : }
173 :
174 0 : argv[ idx ] = NULL;
175 :
176 0 : if( FD_LIKELY( strcmp( config->reporting.solana_metrics_config, "" ) ) ) {
177 0 : if( FD_UNLIKELY( setenv( "SOLANA_METRICS_CONFIG", config->reporting.solana_metrics_config, 1 ) ) )
178 0 : FD_LOG_ERR(( "setenv() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
179 0 : }
180 :
181 0 : FD_LOG_INFO(( "Running Agave validator with the following arguments:" ));
182 0 : for( ulong j=0UL; j<idx; j++ ) FD_LOG_INFO(( "%s", argv[j] ));
183 :
184 0 : FD_CPUSET_DECL( floating_cpu_set );
185 0 : if( FD_UNLIKELY( fd_cpuset_getaffinity( 0, floating_cpu_set ) ) )
186 0 : FD_LOG_ERR(( "sched_getaffinity failed (%i-%s)", errno, fd_io_strerror( errno ) ));
187 :
188 0 : FD_CPUSET_DECL( cpu_set );
189 0 : for( ulong i=0UL; i<config->topo.agave_affinity_cnt; i++ ) {
190 0 : fd_cpuset_insert( cpu_set, config->topo.agave_affinity_cpu_idx[ i ] );
191 0 : }
192 :
193 0 : if( FD_UNLIKELY( fd_cpuset_setaffinity( 0, cpu_set ) ) ) {
194 0 : if( FD_LIKELY( errno==EINVAL ) ) {
195 0 : FD_LOG_ERR(( "Unable to set the affinity for threads created by Agave. It is likely "
196 0 : "that the affinity you have specified for Agave under [layout.agave_affinity] "
197 0 : "in the configuration file contains CPUs which do not exist on this machine." ));
198 0 : } else {
199 0 : FD_LOG_ERR(( "sched_setaffinity failed (%i-%s)", errno, fd_io_strerror( errno ) ));
200 0 : }
201 0 : }
202 :
203 : /* Consensus-breaking development-only CU and/or shred limit increase. */
204 0 : _fd_ext_larger_max_cost_per_block = config->development.bench.larger_max_cost_per_block;
205 0 : _fd_ext_larger_shred_limits_per_block = config->development.bench.larger_shred_limits_per_block;
206 : /* Consensus-breaking bench-only option to disable status cache */
207 0 : _fd_ext_disable_status_cache = config->development.bench.disable_status_cache;
208 0 : FD_COMPILER_MFENCE();
209 :
210 : /* agave_main will exit(1) if it fails, so no return code */
211 0 : fd_ext_validator_main( (const char **)argv );
212 0 : }
213 :
214 : int
215 0 : agave_main( void * args ) {
216 0 : config_t * const config = args;
217 :
218 0 : if( FD_UNLIKELY( config->development.debug_tile ) ) {
219 0 : if( FD_UNLIKELY( config->development.debug_tile==UINT_MAX ) ) {
220 0 : FD_LOG_WARNING(( "waiting for debugger to attach to tile agave pid:%lu", fd_sandbox_getpid() ));
221 0 : if( FD_UNLIKELY( -1==kill( getpid(), SIGSTOP ) ) )
222 0 : FD_LOG_ERR(( "kill(SIGSTOP) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
223 0 : fd_log_private_shared_lock[1] = 0;
224 0 : } else {
225 0 : while( FD_LIKELY( fd_log_private_shared_lock[1] ) ) FD_SPIN_PAUSE();
226 0 : }
227 0 : }
228 :
229 0 : clone_labs_memory_space_tiles( config );
230 :
231 0 : ulong pid = fd_sandbox_getpid(); /* Need to read /proc again.. we got a new PID from clone */
232 0 : fd_log_private_tid_set( pid );
233 0 : fd_log_private_stack_discover( FD_TILE_PRIVATE_STACK_SZ,
234 0 : &fd_tile_private_stack0, &fd_tile_private_stack1 );
235 0 : FD_LOG_NOTICE(( "booting agave pid:%lu", fd_log_group_id() ));
236 :
237 0 : fd_sandbox_switch_uid_gid( config->uid, config->gid );
238 :
239 0 : agave_boot( config );
240 0 : return 0;
241 0 : }
242 :
243 : void
244 : run_agave_cmd_fn( args_t * args,
245 0 : config_t * const config ) {
246 0 : (void)args;
247 :
248 0 : fd_log_thread_set( "agave" );
249 :
250 0 : void * stack = create_clone_stack();
251 :
252 : /* Also clone Agave into PID namespaces so it cannot signal
253 : other tile or the parent. */
254 0 : int flags = config->development.sandbox ? CLONE_NEWPID : 0;
255 0 : pid_t clone_pid = clone( agave_main, (uchar *)stack + FD_TILE_PRIVATE_STACK_SZ, flags, config );
256 0 : if( FD_UNLIKELY( clone_pid<0 ) ) FD_LOG_ERR(( "clone() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
257 0 : }
|