Skip to content

Commit fdbf941

Browse files
committed
ipecho: add ipecho client, server, tile, and shred version commands
1 parent 603822d commit fdbf941

29 files changed

+1312
-7
lines changed

book/api/cli.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ $ fdctl version
142142
0.101.11814
143143
```
144144

145+
## `shred-version`
146+
Prints the current shred version of the cluster being joined, according
147+
to the entrypoints, to standard output and exits. The command writes
148+
diagnostic messages from logs to `stderr`.
149+
150+
```sh [bash]
151+
$ fdctl shred-version
152+
9065
153+
```
154+
145155
## `set-identity`
146156
Changes the identity key of a running validator. The `<keypair>`
147157
argument is required and must be the path to an Agave style

book/api/metrics-generated.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,18 @@
899899
| <span class="metrics-name">snapin_&#8203;accounts_&#8203;inserted</span> | gauge | Number of accounts inserted during snpashot loading. Might decrease if snapshot load is aborted and restarted |
900900

901901
</div>
902+
903+
## Ipecho Tile
904+
905+
<div class="metrics">
906+
907+
| Metric | Type | Description |
908+
|--------|------|-------------|
909+
| <span class="metrics-name">ipecho_&#8203;shred_&#8203;version</span> | gauge | The current shred version used by the validator |
910+
| <span class="metrics-name">ipecho_&#8203;connection_&#8203;count</span> | gauge | The number of active connections to the ipecho service |
911+
| <span class="metrics-name">ipecho_&#8203;connections_&#8203;closed_&#8203;ok</span> | counter | The number of connections to the ipecho service that have been made and closed normally |
912+
| <span class="metrics-name">ipecho_&#8203;connections_&#8203;closed_&#8203;error</span> | counter | The number of connections to the ipecho service that have been made and closed abnormally |
913+
| <span class="metrics-name">ipecho_&#8203;bytes_&#8203;read</span> | counter | The total number of bytes read from all connections to the ipecho service |
914+
| <span class="metrics-name">ipecho_&#8203;bytes_&#8203;written</span> | counter | The total number of bytes written to all connections to the ipecho service |
915+
916+
</div>

src/app/firedancer-dev/Local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $(call add-objs,commands/sim,fd_firedancer_dev)
1515
$(call add-objs,commands/backtest,fd_firedancer_dev)
1616
$(call add-objs,commands/snapshot_load,fd_firedancer_dev)
1717
$(call add-objs,commands/repair,fd_firedancer_dev)
18+
$(call add-objs,commands/ipecho_server,fd_firedancer_dev)
1819

1920
$(call make-bin,firedancer-dev,main,fd_firedancer_dev fd_firedancer fddev_shared fdctl_shared fdctl_platform fd_discof fd_disco fd_choreo fd_flamenco fd_funk fd_quic fd_tls fd_reedsol fd_waltz fd_tango fd_ballet fd_util firedancer_version,$(SECP256K1_LIBS) $(ROCKSDB_LIBS) $(OPENSSL_LIBS))
2021

src/app/firedancer-dev/commands/backtest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ backtest_cmd_topo( config_t * config ) {
350350
backtest_topo( config );
351351
}
352352

353-
args_t
353+
static args_t
354354
configure_args( void ) {
355355
args_t args = {
356356
.configure.command = CONFIGURE_CMD_INIT,
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
2+
#include "../../shared/commands/configure/configure.h"
3+
#include "../../shared/commands/run/run.h"
4+
#include "../../../disco/metrics/fd_metrics.h"
5+
#include "../../../disco/topo/fd_topob.h"
6+
7+
#include <time.h>
8+
#include <stdio.h>
9+
#include <unistd.h>
10+
11+
#define NAME "ipecho-server"
12+
13+
extern fd_topo_obj_callbacks_t * CALLBACKS[];
14+
15+
fd_topo_run_tile_t
16+
fdctl_tile_run( fd_topo_tile_t const * tile );
17+
18+
static void
19+
ipecho_topo( fd_topo_t * topo,
20+
char const * name ) {
21+
fd_topob_new( topo, name );
22+
topo->max_page_size = 1UL<<21UL;
23+
24+
fd_topob_wksp( topo, "all" );
25+
fd_topo_link_t * link = fd_topob_link( topo, "ipecho_out", "all", 4UL, 0UL, 1UL );
26+
link->permit_no_consumers = 1;
27+
fd_topo_tile_t * tile = fd_topob_tile( topo, "ipecho", "all", "all", 0UL, 0, 0 );
28+
tile->ipecho.expected_shred_version = 32;
29+
tile->ipecho.entrypoints_cnt = 0UL;
30+
tile->ipecho.bind_address = FD_IP4_ADDR(127,0,0,1);
31+
tile->ipecho.bind_port = 12008;
32+
fd_topob_tile_out( topo, "ipecho", 0UL, "ipecho_out", 0UL );
33+
34+
fd_topob_auto_layout( topo, 0 );
35+
fd_topob_finish( topo, CALLBACKS );
36+
}
37+
38+
extern int * fd_log_private_shared_lock;
39+
40+
static void
41+
ipecho_server_cmd_topo( config_t * config ) {
42+
ipecho_topo( &config->topo, config->name );
43+
}
44+
45+
static args_t
46+
configure_args( void ) {
47+
args_t args = {
48+
.configure.command = CONFIGURE_CMD_INIT,
49+
};
50+
51+
ulong stage_idx = 0UL;
52+
args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
53+
args.configure.stages[ stage_idx++ ] = NULL;
54+
55+
return args;
56+
}
57+
58+
void
59+
ipecho_server_cmd_perm( args_t * args FD_PARAM_UNUSED,
60+
fd_cap_chk_t * chk,
61+
config_t const * config ) {
62+
args_t c_args = configure_args();
63+
configure_cmd_perm( &c_args, chk, config );
64+
run_cmd_perm( NULL, chk, config );
65+
}
66+
67+
static void
68+
ipecho_server_cmd_fn( args_t * args,
69+
config_t * config ) {
70+
(void)args;
71+
72+
args_t c_args = configure_args();
73+
configure_cmd_fn( &c_args, config );
74+
75+
run_firedancer_init( config, 1 );
76+
77+
fd_log_private_shared_lock[ 1 ] = 0;
78+
fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE );
79+
fd_topo_fill( &config->topo );
80+
81+
ulong tile_idx1 = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
82+
fd_topo_tile_t * ipecho_tile1 = &config->topo.tiles[ tile_idx1 ];
83+
ulong volatile * const ipecho_metrics1 = fd_metrics_tile( ipecho_tile1->metrics );
84+
(void)ipecho_metrics1;
85+
86+
fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
87+
88+
ulong tile_idx = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
89+
FD_TEST( tile_idx!=ULONG_MAX );
90+
fd_topo_tile_t * ipecho_tile = &config->topo.tiles[ tile_idx ];
91+
92+
sleep(1);
93+
ulong volatile * const ipecho_metrics = fd_metrics_tile( ipecho_tile->metrics );
94+
95+
ulong last_conns = ULONG_MAX;
96+
ulong last_closed_ok = ULONG_MAX;
97+
ulong last_closed_error = ULONG_MAX;
98+
99+
for(;;) {
100+
ulong ipecho_conns = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( GAUGE, IPECHO, CONNECTION_COUNT ) ] );
101+
ulong ipecho_closed_ok = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONNECTIONS_CLOSED_OK ) ] );
102+
ulong ipecho_closed_error = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONNECTIONS_CLOSED_ERROR ) ] );
103+
104+
if( FD_UNLIKELY( ipecho_conns!=last_conns || ipecho_closed_ok!=last_closed_ok || ipecho_closed_error!=last_closed_error ) ) {
105+
FD_LOG_NOTICE(( "connections=%lu closed_ok=%lu closed_err=%lu", ipecho_conns, ipecho_closed_ok, ipecho_closed_error ));
106+
last_conns = ipecho_conns;
107+
last_closed_ok = ipecho_closed_ok;
108+
last_closed_error = ipecho_closed_error;
109+
}
110+
111+
nanosleep( &(struct timespec){ .tv_sec=0, .tv_nsec=1000L*1000L }, NULL );
112+
}
113+
}
114+
115+
action_t fd_action_ipecho_server = {
116+
.name = NAME,
117+
.args = NULL,
118+
.perm = ipecho_server_cmd_perm,
119+
.fn = ipecho_server_cmd_fn,
120+
.topo = ipecho_server_cmd_topo,
121+
};

src/app/firedancer-dev/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern fd_topo_run_tile_t fd_tile_benchs;
8686
extern fd_topo_run_tile_t fd_tile_bundle;
8787
extern fd_topo_run_tile_t fd_tile_pktgen;
8888
extern fd_topo_run_tile_t fd_tile_udpecho;
89+
extern fd_topo_run_tile_t fd_tile_ipecho;
8990

9091
extern fd_topo_run_tile_t fd_tile_gossip;
9192
extern fd_topo_run_tile_t fd_tile_repair;
@@ -149,6 +150,7 @@ fd_topo_run_tile_t * TILES[] = {
149150
&fd_tile_snaprd,
150151
&fd_tile_snapdc,
151152
&fd_tile_snapin,
153+
&fd_tile_ipecho,
152154
NULL,
153155
};
154156

@@ -179,6 +181,8 @@ extern action_t fd_action_sim;
179181
extern action_t fd_action_backtest;
180182
extern action_t fd_action_snapshot_load;
181183
extern action_t fd_action_repair;
184+
extern action_t fd_action_shred_version;
185+
extern action_t fd_action_ipecho_server;
182186

183187
action_t * ACTIONS[] = {
184188
&fd_action_run,
@@ -208,6 +212,8 @@ action_t * ACTIONS[] = {
208212
&fd_action_backtest,
209213
&fd_action_snapshot_load,
210214
&fd_action_repair,
215+
&fd_action_shred_version,
216+
&fd_action_ipecho_server,
211217
NULL,
212218
};
213219

src/app/firedancer/Local.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ $(call add-objs,topology,fd_firedancer)
3636
$(call add-objs,config,fd_firedancer)
3737
$(call add-objs,callbacks,fd_firedancer)
3838

39+
# commands
40+
$(call add-objs,commands/shred_version,fd_firedancer)
41+
3942
# version
4043
$(call make-lib,firedancer_version)
4144
$(call add-objs,version,firedancer_version)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "../../shared/fd_config.h"
2+
#include "../../shared/fd_action.h"
3+
4+
#include "../../../disco/topo/fd_topo.h"
5+
#include "../../../discof/ipecho/fd_ipecho_client.h"
6+
7+
#include <unistd.h>
8+
9+
void
10+
shred_version_cmd_fn( args_t * args,
11+
config_t * config ) {
12+
(void)args;
13+
14+
void * _client = aligned_alloc( FD_IPECHO_CLIENT_ALIGN, fd_ipecho_client_footprint() );
15+
FD_TEST( _client );
16+
fd_ipecho_client_t * client = fd_ipecho_client_join( fd_ipecho_client_new( _client ) );
17+
FD_TEST( client );
18+
19+
ulong tile_idx = fd_topo_find_tile( &config->topo, "gossip", 0UL );
20+
FD_TEST( tile_idx!=ULONG_MAX );
21+
22+
fd_topo_tile_t * tile = &config->topo.tiles[ tile_idx ];
23+
fd_ipecho_client_init( client, tile->gossip.entrypoints, tile->gossip.entrypoints_cnt );
24+
25+
for(;;) {
26+
ushort shred_version = 0;
27+
int _charge_busy;
28+
int err = fd_ipecho_client_poll( client, &shred_version, &_charge_busy );
29+
if( FD_UNLIKELY( -1==err ) ) FD_LOG_ERR(( "couldn't get shred version" ));
30+
if( FD_UNLIKELY( !err) ) {
31+
FD_LOG_STDOUT(( "%hu\n", shred_version ));
32+
break;
33+
}
34+
}
35+
}
36+
37+
action_t fd_action_shred_version = {
38+
.name = "shred-version",
39+
.fn = shred_version_cmd_fn,
40+
.description = "Retrieve the current shred version from the entrypoints",
41+
};

src/app/firedancer/config/default.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,14 @@ user = ""
349349
# The shred version is a small hash of the genesis block and any
350350
# subsequent hard forks. The validator client uses it to filter
351351
# out any shred traffic from validators that disagree with this
352-
# validator on the genesis hash or the set of hard forks. If
353-
# nonzero, ignore any shreds that have a different shred version
354-
# than this value. If zero, the expected shred version is
355-
# automatically determined by copying the shred version that the
356-
# entrypoint validator is using.
352+
# validator on the genesis hash or the set of hard forks.
353+
#
354+
# If set to zero, the expected shred version is automatically
355+
# determined at startup by requesting the shred version from the
356+
# gossip entrypoints. If set to a nonzero value, the validator will
357+
# still request the shred version from the gossip entrypoints, but
358+
# if the shred version is not equal to this value, the validator
359+
# will abort with an error.
357360
expected_shred_version = 0
358361

359362
# This section configures the "funk" account database. Currently, funk

src/app/firedancer/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern fd_topo_run_tile_t fd_tile_poh;
8484
extern fd_topo_run_tile_t fd_tile_send;
8585
extern fd_topo_run_tile_t fd_tile_tower;
8686
extern fd_topo_run_tile_t fd_tile_rpcserv;
87+
extern fd_topo_run_tile_t fd_tile_ipecho;
8788

8889
fd_topo_run_tile_t * TILES[] = {
8990
&fd_tile_net,
@@ -110,6 +111,7 @@ fd_topo_run_tile_t * TILES[] = {
110111
&fd_tile_send,
111112
&fd_tile_tower,
112113
&fd_tile_rpcserv,
114+
&fd_tile_ipecho,
113115
NULL,
114116
};
115117

@@ -124,6 +126,7 @@ extern action_t fd_action_netconf;
124126
extern action_t fd_action_set_identity;
125127
extern action_t fd_action_help;
126128
extern action_t fd_action_version;
129+
extern action_t fd_action_shred_version;
127130

128131
action_t * ACTIONS[] = {
129132
&fd_action_run,
@@ -137,6 +140,7 @@ action_t * ACTIONS[] = {
137140
&fd_action_set_identity,
138141
&fd_action_help,
139142
&fd_action_version,
143+
&fd_action_shred_version,
140144
NULL,
141145
};
142146

0 commit comments

Comments
 (0)