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 : if( strcmp( "", config->ledger.accounts_path ) ) ADD( "--accounts", config->ledger.accounts_path );
100 0 : ADDU( "--limit-ledger-size", config->ledger.limit_size );
101 0 : for( ulong i=0UL; i<config->ledger.account_indexes_cnt; i++ )
102 0 : ADD( "--account-index", config->ledger.account_indexes[ i ] );
103 0 : if( FD_LIKELY( !config->ledger.account_index_include_keys_cnt ) ) {
104 0 : for( ulong i=0UL; i<config->ledger.account_index_exclude_keys_cnt; i++ )
105 0 : ADD( "--account-index-exclude-key", config->ledger.account_index_exclude_keys[ i ] );
106 0 : } else {
107 0 : for( ulong i=0UL; i<config->ledger.account_index_include_keys_cnt; i++ )
108 0 : ADD( "--account-index-include-key", config->ledger.account_index_include_keys[ i ] );
109 0 : }
110 :
111 : /* gossip */
112 0 : for( ulong i=0UL; i<config->gossip.entrypoints_cnt; i++ ) ADD( "--entrypoint", config->gossip.entrypoints[ i ] );
113 0 : if( !config->gossip.port_check ) ADD1( "--no-port-check" );
114 0 : ADDH( "--gossip-port", config->gossip.port );
115 0 : char ip_addr[16]; /* ADD stored the address for later use, so ip_addr must be in scope */
116 0 : if( strcmp( config->gossip.host, "" ) ) {
117 0 : ADD( "--gossip-host", config->gossip.host );
118 0 : } else {
119 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) ) );
120 0 : ADD( "--gossip-host", ip_addr );
121 0 : }
122 0 : if( config->development.gossip.allow_private_address ) {
123 0 : ADD1( "--allow-private-addr" );
124 0 : }
125 :
126 : /* rpc */
127 0 : if( config->rpc.port ) ADDH( "--rpc-port", config->rpc.port );
128 0 : if( config->rpc.full_api ) ADD1( "--full-rpc-api" );
129 0 : if( config->rpc.private ) ADD1( "--private-rpc" );
130 0 : if( config->rpc.transaction_history ) ADD1( "--enable-rpc-transaction-history" );
131 0 : if( config->rpc.extended_tx_metadata_storage ) ADD1( "--enable-extended-tx-metadata-storage" );
132 0 : if( config->rpc.only_known ) ADD1( "--only-known-rpc" );
133 0 : if( config->rpc.pubsub_enable_block_subscription ) ADD1( "--rpc-pubsub-enable-block-subscription" );
134 0 : if( config->rpc.pubsub_enable_vote_subscription ) ADD1( "--rpc-pubsub-enable-vote-subscription" );
135 0 : if( config->rpc.bigtable_ledger_storage ) ADD1( "--enable-rpc-bigtable-ledger-storage" );
136 :
137 : /* snapshots */
138 0 : if( !config->snapshots.incremental_snapshots ) ADD1( "--no-incremental-snapshots" );
139 0 : ADDU( "--full-snapshot-interval-slots", config->snapshots.full_snapshot_interval_slots );
140 0 : ADDU( "--incremental-snapshot-interval-slots", config->snapshots.incremental_snapshot_interval_slots );
141 0 : ADD( "--snapshots", config->snapshots.path );
142 0 : if( strcmp( "", config->snapshots.incremental_path ) ) ADD( "--incremental-snapshot-archive-path", config->snapshots.incremental_path );
143 0 : ADDU( "--maximum-snapshots-to-retain", config->snapshots.maximum_full_snapshots_to_retain );
144 0 : ADDU( "--maximum-incremental-snapshots-to-retain", config->snapshots.maximum_incremental_snapshots_to_retain );
145 0 : ADDU( "--minimal-snapshot-download-speed", config->snapshots.minimum_snapshot_download_speed );
146 :
147 0 : argv[ idx ] = NULL;
148 :
149 0 : if( FD_LIKELY( strcmp( config->reporting.solana_metrics_config, "" ) ) ) {
150 0 : if( FD_UNLIKELY( setenv( "SOLANA_METRICS_CONFIG", config->reporting.solana_metrics_config, 1 ) ) )
151 0 : FD_LOG_ERR(( "setenv() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
152 0 : }
153 :
154 0 : FD_LOG_INFO(( "Running Agave validator with the following arguments:" ));
155 0 : for( ulong j=0UL; j<idx; j++ ) FD_LOG_INFO(( "%s", argv[j] ));
156 :
157 0 : FD_CPUSET_DECL( floating_cpu_set );
158 0 : if( FD_UNLIKELY( fd_cpuset_getaffinity( 0, floating_cpu_set ) ) )
159 0 : FD_LOG_ERR(( "sched_getaffinity failed (%i-%s)", errno, fd_io_strerror( errno ) ));
160 :
161 0 : FD_CPUSET_DECL( cpu_set );
162 0 : for( ulong i=0UL; i<config->topo.agave_affinity_cnt; i++ ) {
163 0 : fd_cpuset_insert( cpu_set, config->topo.agave_affinity_cpu_idx[ i ] );
164 0 : }
165 :
166 0 : if( FD_UNLIKELY( fd_cpuset_setaffinity( 0, cpu_set ) ) ) {
167 0 : if( FD_LIKELY( errno==EINVAL ) ) {
168 0 : FD_LOG_ERR(( "Unable to set the affinity for threads created by Agave. It is likely "
169 0 : "that the affinity you have specified for Agave under [layout.agave_affinity] "
170 0 : "in the configuration file contains CPUs which do not exist on this machine." ));
171 0 : } else {
172 0 : FD_LOG_ERR(( "sched_setaffinity failed (%i-%s)", errno, fd_io_strerror( errno ) ));
173 0 : }
174 0 : }
175 :
176 : /* Consensus-breaking development-only CU and/or shred limit increase. */
177 0 : _fd_ext_larger_max_cost_per_block = config->development.bench.larger_max_cost_per_block;
178 0 : _fd_ext_larger_shred_limits_per_block = config->development.bench.larger_shred_limits_per_block;
179 : /* Consensus-breaking bench-only option to disable status cache */
180 0 : _fd_ext_disable_status_cache = config->development.bench.disable_status_cache;
181 0 : FD_COMPILER_MFENCE();
182 :
183 : /* agave_main will exit(1) if it fails, so no return code */
184 0 : fd_ext_validator_main( (const char **)argv );
185 0 : }
186 :
187 : int
188 0 : agave_main( void * args ) {
189 0 : config_t * const config = args;
190 :
191 0 : if( FD_UNLIKELY( config->development.debug_tile ) ) {
192 0 : if( FD_UNLIKELY( config->development.debug_tile==UINT_MAX ) ) {
193 0 : FD_LOG_WARNING(( "waiting for debugger to attach to tile agave pid:%lu", fd_sandbox_getpid() ));
194 0 : if( FD_UNLIKELY( -1==kill( getpid(), SIGSTOP ) ) )
195 0 : FD_LOG_ERR(( "kill(SIGSTOP) failed (%i-%s)", errno, fd_io_strerror( errno ) ));
196 0 : fd_log_private_shared_lock[1] = 0;
197 0 : } else {
198 0 : while( FD_LIKELY( fd_log_private_shared_lock[1] ) ) FD_SPIN_PAUSE();
199 0 : }
200 0 : }
201 :
202 0 : clone_labs_memory_space_tiles( config );
203 :
204 0 : ulong pid = fd_sandbox_getpid(); /* Need to read /proc again.. we got a new PID from clone */
205 0 : fd_log_private_tid_set( pid );
206 0 : fd_log_private_stack_discover( FD_TILE_PRIVATE_STACK_SZ,
207 0 : &fd_tile_private_stack0, &fd_tile_private_stack1 );
208 0 : FD_LOG_NOTICE(( "booting agave pid:%lu", fd_log_group_id() ));
209 :
210 0 : fd_sandbox_switch_uid_gid( config->uid, config->gid );
211 :
212 0 : agave_boot( config );
213 0 : return 0;
214 0 : }
215 :
216 : void
217 : run_agave_cmd_fn( args_t * args,
218 0 : config_t * const config ) {
219 0 : (void)args;
220 :
221 0 : fd_log_thread_set( "agave" );
222 :
223 0 : void * stack = create_clone_stack();
224 :
225 : /* Also clone Agave into PID namespaces so it cannot signal
226 : other tile or the parent. */
227 0 : int flags = config->development.sandbox ? CLONE_NEWPID : 0;
228 0 : pid_t clone_pid = clone( agave_main, (uchar *)stack + FD_TILE_PRIVATE_STACK_SZ, flags, config );
229 0 : if( FD_UNLIKELY( clone_pid<0 ) ) FD_LOG_ERR(( "clone() failed (%i-%s)", errno, fd_io_strerror( errno ) ));
230 0 : }
|