Skip to content

Commit 9f04233

Browse files
riptlripatel-fd
authored andcommitted
restore: initial vinyl integration
1 parent 41d584b commit 9f04233

File tree

22 files changed

+1229
-53
lines changed

22 files changed

+1229
-53
lines changed

src/app/firedancer-dev/Local.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $(call add-objs,commands/ipecho_server,fd_firedancer_dev)
1919
$(call add-objs,commands/gossip_dump,fd_firedancer_dev)
2020

2121
ifdef FD_HAS_SSE
22-
$(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))
22+
$(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_vinyl fd_funk fd_quic fd_tls fd_reedsol fd_waltz fd_tango fd_ballet fd_util firedancer_version,$(SECP256K1_LIBS) $(ROCKSDB_LIBS) $(OPENSSL_LIBS))
2323
endif
2424

2525
# $(call make-integration-test,test_fddev,tests/test_fddev,fd_fddev fd_fdctl 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, $(SECP256K1_LIBS))

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ backtest_topo( config_t * config ) {
4949
ulong exec_tile_cnt = config->firedancer.layout.exec_tile_count;
5050

5151
int disable_snap_loader = !config->gossip.entrypoints_cnt;
52+
int snap_vinyl = !!config->firedancer.vinyl.enabled;
5253
int solcap_enabled = strlen( config->capture.solcap_capture )>0;
5354

5455
fd_topo_t * topo = { fd_topob_new( &config->topo, config->name ) };
@@ -88,6 +89,10 @@ backtest_topo( config_t * config ) {
8889
config->firedancer.runtime.program_cache.heap_size_mib<<20 );
8990
fd_topob_tile_uses( topo, replay_tile, progcache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
9091

92+
if( snap_vinyl ) {
93+
setup_topo_vinyl( topo, &config->firedancer );
94+
}
95+
9196
/**********************************************************************/
9297
/* Add the executor tiles to topo */
9398
/**********************************************************************/
@@ -276,7 +281,15 @@ backtest_topo( config_t * config ) {
276281
fd_ulong_pow2_up( FD_PACK_MAX_TXNCACHE_TXN_PER_SLOT ) );
277282
fd_topob_tile_uses( topo, replay_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
278283
if( FD_LIKELY( !disable_snap_loader ) ) {
279-
fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "snapin", 0UL ) ], txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
284+
fd_topob_tile_uses( topo, snapin_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
285+
if( snap_vinyl ) {
286+
ulong vinyl_map_obj_id = fd_pod_query_ulong( topo->props, "vinyl.meta_map", ULONG_MAX ); FD_TEST( vinyl_map_obj_id !=ULONG_MAX );
287+
ulong vinyl_pool_obj_id = fd_pod_query_ulong( topo->props, "vinyl.meta_pool", ULONG_MAX ); FD_TEST( vinyl_pool_obj_id!=ULONG_MAX );
288+
fd_topo_obj_t * vinyl_map_obj = &topo->objs[ vinyl_map_obj_id ];
289+
fd_topo_obj_t * vinyl_pool_obj = &topo->objs[ vinyl_pool_obj_id ];
290+
fd_topob_tile_uses( topo, snapin_tile, vinyl_map_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
291+
fd_topob_tile_uses( topo, snapin_tile, vinyl_pool_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
292+
}
280293
}
281294
for( ulong i=0UL; i<exec_tile_cnt; i++ ) {
282295
fd_topob_tile_uses( topo, &topo->tiles[ fd_topo_find_tile( topo, "exec", i ) ], txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ snapshot_load_topo( config_t * config,
4343
config->firedancer.funk.max_database_transactions,
4444
config->firedancer.funk.heap_size_gib );
4545

46+
if( config->firedancer.vinyl.enabled ) {
47+
setup_topo_vinyl( topo, &config->firedancer );
48+
}
49+
4650
static ushort tile_to_cpu[ FD_TILE_MAX ] = {0};
4751
if( args->snapshot_load.tile_cpus[0] ) {
4852
ulong cpu_cnt = fd_tile_private_cpus_parse( args->snapshot_load.tile_cpus, tile_to_cpu );
@@ -105,6 +109,16 @@ snapshot_load_topo( config_t * config,
105109
fd_topob_tile_uses( topo, snapin_tile, txncache_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
106110
snapin_tile->snapin.funk_obj_id = funk_obj->id;
107111
snapin_tile->snapin.txncache_obj_id = txncache_obj->id;
112+
if( config->firedancer.vinyl.enabled ) {
113+
ulong vinyl_map_obj_id = fd_pod_query_ulong( topo->props, "vinyl.meta_map", ULONG_MAX ); FD_TEST( vinyl_map_obj_id !=ULONG_MAX );
114+
ulong vinyl_pool_obj_id = fd_pod_query_ulong( topo->props, "vinyl.meta_pool", ULONG_MAX ); FD_TEST( vinyl_pool_obj_id!=ULONG_MAX );
115+
116+
fd_topo_obj_t * vinyl_map_obj = &topo->objs[ vinyl_map_obj_id ];
117+
fd_topo_obj_t * vinyl_pool_obj = &topo->objs[ vinyl_pool_obj_id ];
118+
119+
fd_topob_tile_uses( topo, snapin_tile, vinyl_map_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
120+
fd_topob_tile_uses( topo, snapin_tile, vinyl_pool_obj, FD_SHMEM_JOIN_MODE_READ_WRITE );
121+
}
108122

109123
snapin_tile->snapin.max_live_slots = config->firedancer.runtime.max_live_slots;
110124

src/app/firedancer-dev/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ extern fd_topo_obj_callbacks_t fd_obj_cb_banks;
2525
extern fd_topo_obj_callbacks_t fd_obj_cb_funk;
2626
extern fd_topo_obj_callbacks_t fd_obj_cb_bank_hash_cmp;
2727

28+
extern fd_topo_obj_callbacks_t fd_obj_cb_vinyl_meta;
29+
extern fd_topo_obj_callbacks_t fd_obj_cb_vinyl_meta_ele;
30+
2831
fd_topo_obj_callbacks_t * CALLBACKS[] = {
2932
&fd_obj_cb_mcache,
3033
&fd_obj_cb_dcache,
@@ -42,6 +45,8 @@ fd_topo_obj_callbacks_t * CALLBACKS[] = {
4245
&fd_obj_cb_banks,
4346
&fd_obj_cb_funk,
4447
&fd_obj_cb_bank_hash_cmp,
48+
&fd_obj_cb_vinyl_meta,
49+
&fd_obj_cb_vinyl_meta_ele,
4550
NULL,
4651
};
4752

src/app/firedancer/Local.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ $(OBJDIR)/obj/app/firedancer/version.d: src/app/firedancer/version.h
3434
# firedancer core
3535
$(call add-objs,topology,fd_firedancer)
3636
$(call add-objs,config,fd_firedancer)
37-
$(call add-objs,callbacks,fd_firedancer)
37+
$(call add-objs,callbacks callbacks_vinyl,fd_firedancer)
3838

3939
# commands
4040
$(call add-objs,commands/shred_version,fd_firedancer)
41+
$(call add-objs,commands/configure/vinyl,fd_firedancer)
4142

4243
# version
4344
$(call make-lib,firedancer_version)
4445
$(call add-objs,version,firedancer_version)
4546

4647
ifdef FD_HAS_SSE
47-
$(call make-bin,firedancer,main,fd_firedancer 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) $(OPENSSL_LIBS))
48+
$(call make-bin,firedancer,main,fd_firedancer fdctl_shared fdctl_platform fd_discof fd_disco fd_choreo fd_flamenco fd_vinyl fd_funk fd_quic fd_tls fd_reedsol fd_waltz fd_tango fd_ballet fd_util firedancer_version,$(SECP256K1_LIBS) $(OPENSSL_LIBS))
4849
endif
4950

5051
else

src/app/firedancer/callbacks.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,34 @@ fd_topo_obj_callbacks_t fd_obj_cb_funk = {
101101
.new = funk_new,
102102
};
103103

104+
/* cnc: a tile admin message queue */
105+
106+
static ulong
107+
cnc_align( fd_topo_t const * topo,
108+
fd_topo_obj_t const * obj ) {
109+
(void)topo; (void)obj;
110+
return fd_cnc_align();
111+
}
112+
113+
static ulong
114+
cnc_footprint( fd_topo_t const * topo,
115+
fd_topo_obj_t const * obj ) {
116+
return fd_cnc_footprint( VAL("app_sz") );
117+
}
118+
119+
static void
120+
cnc_new( fd_topo_t const * topo,
121+
fd_topo_obj_t const * obj ) {
122+
FD_TEST( fd_cnc_new( fd_topo_obj_laddr( topo, obj->id ), VAL("app_sz"), VAL("type"), fd_log_wallclock() ) );
123+
}
124+
125+
fd_topo_obj_callbacks_t fd_obj_cb_cnc = {
126+
.name = "cnc",
127+
.footprint = cnc_footprint,
128+
.align = cnc_align,
129+
.new = cnc_new,
130+
};
131+
104132
static ulong
105133
fec_sets_footprint( fd_topo_t const * topo,
106134
fd_topo_obj_t const * obj ) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include "../../vinyl/fd_vinyl.h"
2+
#include "../../disco/topo/fd_topo.h"
3+
#include "../../util/pod/fd_pod_format.h"
4+
5+
#define VAL(name) (__extension__({ \
6+
ulong __x = fd_pod_queryf_ulong( topo->props, ULONG_MAX, "obj.%lu.%s", obj->id, name ); \
7+
if( FD_UNLIKELY( __x==ULONG_MAX ) ) FD_LOG_ERR(( "obj.%lu.%s was not set", obj->id, name )); \
8+
__x; }))
9+
10+
11+
/* vinyl_meta: a shared memory separately chained hash map */
12+
13+
static ulong
14+
vinyl_meta_align( fd_topo_t const * topo,
15+
fd_topo_obj_t const * obj ) {
16+
(void)topo; (void)obj;
17+
return fd_vinyl_meta_align();
18+
}
19+
20+
static ulong
21+
vinyl_meta_footprint( fd_topo_t const * topo,
22+
fd_topo_obj_t const * obj ) {
23+
return fd_vinyl_meta_footprint( VAL("ele_max"), VAL("lock_cnt"), VAL("probe_max") );
24+
}
25+
26+
static void
27+
vinyl_meta_new( fd_topo_t const * topo,
28+
fd_topo_obj_t const * obj ) {
29+
FD_TEST( fd_vinyl_meta_new( fd_topo_obj_laddr( topo, obj->id ), VAL("ele_max"), VAL("lock_cnt"), VAL("probe_max"), VAL("seed") ) );
30+
}
31+
32+
fd_topo_obj_callbacks_t fd_obj_cb_vinyl_meta = {
33+
.name = "vinyl_meta",
34+
.footprint = vinyl_meta_footprint,
35+
.align = vinyl_meta_align,
36+
.new = vinyl_meta_new,
37+
};
38+
39+
/* vinyl_meta_ele: hash map elements of vinyl_meta */
40+
41+
static ulong
42+
vinyl_meta_ele_align( fd_topo_t const * topo,
43+
fd_topo_obj_t const * obj ) {
44+
(void)topo; (void)obj;
45+
return fd_ulong_max( alignof(fd_vinyl_meta_ele_t), 128UL );
46+
}
47+
48+
static ulong
49+
vinyl_meta_ele_footprint( fd_topo_t const * topo,
50+
fd_topo_obj_t const * obj ) {
51+
return fd_ulong_align_up( sizeof(fd_vinyl_meta_ele_t) * VAL("cnt"), vinyl_meta_ele_align( topo, obj ) );
52+
}
53+
54+
static void
55+
vinyl_meta_ele_new( fd_topo_t const * topo,
56+
fd_topo_obj_t const * obj ) {
57+
/* On Zen 4:
58+
- non-temporal wide stores are fastest
59+
- scattering 8 byte writes is slower
60+
- memset is slowest */
61+
62+
# if FD_HAS_AVX512
63+
uchar * m0 = fd_topo_obj_laddr( topo, obj->id );
64+
uchar * m1 = m0 + vinyl_meta_ele_footprint( topo, obj );
65+
__m512i zero = _mm512_setzero_si512();
66+
for( uchar * m=m0; m<m1; m+=64 ) {
67+
_mm512_stream_si512( (__m512i *)m, zero );
68+
}
69+
_mm_sfence();
70+
# else
71+
fd_vinyl_meta_ele_t * ele = fd_topo_obj_laddr( topo, obj->id );
72+
ulong cnt = VAL("cnt");
73+
for( ulong i=0UL; i<cnt; i++ ) {
74+
ele[ i ].phdr.ctl = 0UL;
75+
}
76+
# endif
77+
}
78+
79+
fd_topo_obj_callbacks_t fd_obj_cb_vinyl_meta_ele = {
80+
.name = "vinyl_meta_e",
81+
.footprint = vinyl_meta_ele_footprint,
82+
.align = vinyl_meta_ele_align,
83+
.new = vinyl_meta_ele_new,
84+
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "../../../shared/commands/configure/configure.h"
2+
#include "../../../platform/fd_file_util.h"
3+
4+
#include <errno.h>
5+
#include <fcntl.h> /* open */
6+
#include <unistd.h> /* fchown, close */
7+
#include <sys/stat.h> /* fchmod */
8+
9+
static int
10+
enabled( config_t const * config ) {
11+
return !!config->firedancer.vinyl.enabled;
12+
}
13+
14+
static void
15+
init( config_t const * config ) {
16+
if( FD_UNLIKELY( -1==fd_file_util_mkdir_all( config->paths.accounts, config->uid, config->gid, 0 ) ) ) {
17+
FD_LOG_ERR(( "fd_file_util_mkdir_all(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
18+
}
19+
20+
int vinyl_fd = open( config->paths.accounts, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, S_IRUSR|S_IWUSR );
21+
if( FD_UNLIKELY( vinyl_fd<0 ) ) {
22+
FD_LOG_ERR(( "open(`%s`,O_RDWR|O_CREAT|O_CLOEXEC,S_IRUSR|S_IWUSR) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
23+
}
24+
25+
if( FD_UNLIKELY( fchown( vinyl_fd, config->uid, config->gid )<0 ) ) {
26+
FD_LOG_ERR(( "chown(`%s`,%u:%u) failed (%i-%s)", config->paths.accounts, config->uid, config->gid, errno, fd_io_strerror( errno ) ));
27+
}
28+
29+
if( FD_UNLIKELY( fchmod( vinyl_fd, S_IRUSR|S_IWUSR )<0 ) ) {
30+
FD_LOG_ERR(( "chmod(`%s`,S_IRUSR|S_IWUSR) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
31+
}
32+
33+
ulong bstream_sz = config->firedancer.vinyl.file_size_gib<<30;
34+
if( FD_UNLIKELY( 0!=ftruncate( vinyl_fd, (long)bstream_sz ) ) ) {
35+
FD_LOG_ERR(( "ftruncate(`%s`,%lu bytes) failed (%i-%s)", config->paths.accounts, bstream_sz, errno, fd_io_strerror( errno ) ));
36+
}
37+
38+
if( FD_UNLIKELY( close( vinyl_fd )<0 ) ) {
39+
FD_LOG_ERR(( "close(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
40+
}
41+
}
42+
43+
static int
44+
fini( config_t const * config,
45+
int pre_init ) {
46+
(void)pre_init;
47+
if( FD_UNLIKELY( unlink( config->paths.accounts )<0 ) ) {
48+
FD_LOG_ERR(( "unlink(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) ));
49+
}
50+
return 1;
51+
}
52+
53+
static configure_result_t
54+
check( config_t const * config ) {
55+
struct stat st;
56+
if( FD_UNLIKELY( 0!=stat( config->paths.accounts, &st ) ) ) {
57+
if( errno==ENOENT ) NOT_CONFIGURED( "`%s` does not exist", config->paths.accounts );
58+
else NOT_CONFIGURED( "stat(`%s`) failed (%i-%s)", config->paths.accounts, errno, fd_io_strerror( errno ) );
59+
}
60+
61+
ulong bstream_sz = config->firedancer.vinyl.file_size_gib<<30;
62+
if( FD_UNLIKELY( (ulong)st.st_size!=bstream_sz ) )
63+
NOT_CONFIGURED( "`%s` needs to be resized (have %lu bytes, want %lu bytes)", config->paths.accounts, (ulong)st.st_size, bstream_sz );
64+
65+
CHECK( check_file( config->paths.accounts, config->uid, config->gid, S_IFREG | S_IRUSR | S_IWUSR ) );
66+
CONFIGURE_OK();
67+
}
68+
69+
configure_stage_t fd_cfg_stage_vinyl = {
70+
.name = "vinyl",
71+
.enabled = enabled,
72+
.init = init,
73+
.fini = fini,
74+
.check = check,
75+
};

src/app/firedancer/config/default.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ user = ""
155155
# Firedancer instance.
156156
genesis = ""
157157

158+
# Absolute path to the file backing the vinyl account database.
159+
# Only used if [vinyl.enabled] is set.
160+
accounts = ""
161+
158162
# Firedancer logs to two places by default: stderr and a logfile.
159163
# stdout is not used for logging, and will only be used to print command
160164
# output or boot errors. Messages to "stderr" are abbreviated and not
@@ -466,6 +470,8 @@ user = ""
466470
# This section configures the "funk" account database. Currently, funk
467471
# stores all Solana accounts. In future versions of Firedancer, most
468472
# accounts will be offloaded to the "groove" database.
473+
#
474+
# FIXME rename 'funk' to human-readable name like 'accounts.live_db'
469475
[funk]
470476
# The size of the funk heap in gigabytes. This value must be large
471477
# enough to store all Solana accounts uncompressed.
@@ -486,6 +492,12 @@ user = ""
486492
# setting.
487493
max_database_transactions = 2048
488494

495+
# FIXME rename 'vinyl' to human-readable name like 'accounts.root_db'
496+
[vinyl]
497+
enabled = false
498+
max_account_records = 30_000_000
499+
file_size_gib = 16
500+
489501
[runtime]
490502
max_vote_accounts = 2000000
491503

src/app/firedancer/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ fd_topo_obj_callbacks_t * CALLBACKS[] = {
4343
NULL,
4444
};
4545

46+
extern configure_stage_t fd_cfg_stage_vinyl;
47+
4648
configure_stage_t * STAGES[] = {
4749
&fd_cfg_stage_hugetlbfs,
4850
&fd_cfg_stage_sysctl,
4951
&fd_cfg_stage_ethtool_channels,
5052
&fd_cfg_stage_ethtool_offloads,
5153
&fd_cfg_stage_ethtool_loopback,
5254
&fd_cfg_stage_snapshots,
55+
&fd_cfg_stage_vinyl,
5356
NULL,
5457
};
5558

0 commit comments

Comments
 (0)