Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lidatong committed Jul 25, 2023
1 parent 1788e0d commit 05ab26b
Show file tree
Hide file tree
Showing 23 changed files with 638 additions and 219 deletions.
2 changes: 1 addition & 1 deletion ffi/rust/firedancer-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn main() {
.clang_arg(format!("-I{prefix}/"))
.header(&format!("wrapper_{lib}.h"))
.blocklist_type("schar|uchar|ushort|uint|ulong")
.blocklist_item("SORT_QUICK_ORDER_STYLE|SORT_MERGE_THRESH|SORT_QUICK_THRESH|SORT_QUICK_ORDER_STYLE|SORT_QUICK_SWAP_MINIMIZE");
.blocklist_item("SORT_QUICK_ORDER_STYLE|SORT_MERGE_THRESH|SORT_QUICK_THRESH|SORT_QUICK_ORDER_STYLE|SORT_QUICK_SWAP_MINIMIZE|MAP_MEMOIZE|MAP_QUERY_OPT|MAP_KEY_EQUAL_IS_SLOW");

// Well this is a complete mess. We want to only include, say, functions
// declared in the `ballet` directory in the ballet bindgen output. If
Expand Down
2 changes: 2 additions & 0 deletions ffi/rust/firedancer-sys/src/tango/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod fseq;
mod mcache;
mod tcache;
mod xdp;
mod stake;

pub use cnc::*;
pub use dcache::*;
Expand All @@ -13,3 +14,4 @@ pub use fseq::*;
pub use mcache::*;
pub use tcache::*;
pub use xdp::*;
pub use stake::*;
10 changes: 10 additions & 0 deletions ffi/rust/firedancer-sys/src/tango/stake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub use crate::generated::{
fd_stake_t,
fd_stake_align,
fd_stake_footprint,
fd_stake_join,
fd_stake_new,
fd_stake_version,
fd_stake_update,
FD_STAKE_ALIGN
};
2 changes: 2 additions & 0 deletions src/app/fdctl/src/commands/configure/frank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ fn step(config: &mut Config) {
let xsk = run!("{bin}/fd_xdp_ctl new-xsk {workspace} 2048 {} {}", config.tiles.quic.xdp_rx_queue_size, config.tiles.quic.xdp_tx_queue_size);
run!("{bin}/fd_xdp_ctl bind-xsk {xsk} {name} {interface} {i}");
let xsk_aio = run!("{bin}/fd_xdp_ctl new-xsk-aio {workspace} {} {}", config.tiles.quic.xdp_tx_queue_size, config.tiles.quic.xdp_aio_depth);
let stake = run!("{bin}/fd_tango_ctl new-stake {workspace} {}", 16); /* FIXME hardcode */

run!("{bin}/fd_pod_ctl
insert {pod} cstr {prefix}.quic.quic{i}.cnc {cnc} \
insert {pod} cstr {prefix}.quic.quic{i}.mcache {mcache} \
insert {pod} cstr {prefix}.quic.quic{i}.dcache {dcache} \
insert {pod} cstr {prefix}.quic.quic{i}.fseq {fseq} \
insert {pod} cstr {prefix}.quic.quic{i}.quic {quic} \
insert {pod} cstr {prefix}.quic.quic{i}.stake {stake} \
insert {pod} cstr {prefix}.quic.quic{i}.xsk {xsk} \
insert {pod} cstr {prefix}.quic.quic{i}.xsk_aio {xsk_aio}",
mcache=verify_mcache,
Expand Down
12 changes: 10 additions & 2 deletions src/app/frank/fd_frank_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ fd_frank_quic_task( int argc,
fd_quic_t * quic = fd_quic_join( fd_wksp_pod_map( quic_pod, "quic" ) );
if( FD_UNLIKELY( !quic ) ) FD_LOG_ERR(( "fd_quic_join failed" ));

// FD_LOG_INFO(( "loading %s.quic.%s.qos", cfg_path, quic_name ));
// fd_quic_qos_t * qos = fd_quic_qos_join( fd_wksp_pod_map( quic_pod, "qos" ) );
// if( FD_UNLIKELY( !qos ) ) FD_LOG_ERR(( "fd_quic_qos_join failed" ));

FD_LOG_INFO(( "loading %s.quic.%s.stake", cfg_path, quic_name ));
fd_stake_t * stake = fd_stake_join( fd_wksp_pod_map( quic_pod, "stake" ) );
if( FD_UNLIKELY( !stake ) ) FD_LOG_ERR(( "fd_stake_join failed" ));

FD_LOG_INFO(( "loading %s.quic.%s.xsk", cfg_path, quic_name ));
fd_xsk_t * xsk = preload_xsks[ idx ];
if( FD_UNLIKELY( !xsk ) ) FD_LOG_ERR(( "fd_xsk_join failed" ));
Expand Down Expand Up @@ -114,7 +122,7 @@ fd_frank_quic_task( int argc,

FD_LOG_INFO(( "creating scratch" ));
ulong footprint = fd_quic_tile_scratch_footprint( fd_mcache_depth( mcache ) );
if( FD_UNLIKELY( !footprint ) ) FD_LOG_ERR(( "fd_quic_tile_scratch_footprint failed" ));
if( FD_UNLIKELY( !footprint ) ) FD_LOG_ERR(( "fd_quic_tile_scratch_footprint failed" ));
void * scratch = fd_alloca( FD_QUIC_TILE_SCRATCH_ALIGN, footprint );
if( FD_UNLIKELY( !scratch ) ) FD_LOG_ERR(( "fd_alloca failed" ));

Expand Down Expand Up @@ -155,7 +163,7 @@ fd_frank_quic_task( int argc,
/* Start serving */

FD_LOG_INFO(( "%s run", quic_name ));
int err = fd_quic_tile( cnc, quic, xsk_aio, mcache, dcache, lazy, rng, scratch );
int err = fd_quic_tile( cnc, quic, /* qos , */ stake, xsk_aio, mcache, dcache, lazy, rng, scratch );
if( FD_UNLIKELY( err ) ) FD_LOG_ERR(( "fd_quic_tile failed (%i)", err ));

/* Clean up */
Expand Down
18 changes: 10 additions & 8 deletions src/disco/quic/fd_quic.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ FD_FN_CONST ulong
fd_quic_tile_scratch_footprint( ulong depth );

int
fd_quic_tile( fd_cnc_t * cnc, /* Local join to the tile's command-and-control */
fd_quic_t * quic, /* QUIC without active join */
fd_xsk_aio_t * xsk_aio, /* Local join to QUIC XSK aio */
fd_frag_meta_t * mcache, /* Local join to the tile's txn output mcache */
uchar * dcache, /* Local join to the tile's txn output dcache */
long lazy, /* Laziness, <=0 means use a reasonable default */
fd_rng_t * rng, /* Local join to the rng this tile should use */
void * scratch ); /* Tile scratch memory */
fd_quic_tile( fd_cnc_t * cnc, /* Local join to the tile's command-and-control */
fd_quic_t * quic, /* QUIC without active join */
// fd_quic_qos_t * qos, /* Local join to QoS */
fd_stake_t * stake,
fd_xsk_aio_t * xsk_aio, /* Local join to QUIC XSK aio */
fd_frag_meta_t * mcache, /* Local join to the tile's txn output mcache */
uchar * dcache, /* Local join to the tile's txn output dcache */
long lazy, /* Laziness, <=0 means use a reasonable default */
fd_rng_t * rng, /* Local join to the rng this tile should use */
void * scratch ); /* Tile scratch memory */

FD_PROTOTYPES_END

Expand Down
67 changes: 59 additions & 8 deletions src/disco/quic/fd_quic_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ fd_quic_tile_scratch_footprint( ulong depth ) {
}

int
fd_quic_tile( fd_cnc_t * cnc,
fd_quic_t * quic,
fd_xsk_aio_t * xsk_aio,
fd_frag_meta_t * mcache,
uchar * dcache,
long lazy,
fd_rng_t * rng,
void * scratch ) {
fd_quic_tile( fd_cnc_t * cnc,
fd_quic_t * quic,
// fd_quic_qos_t * qos,
fd_stake_t * stake,
fd_xsk_aio_t * xsk_aio,
fd_frag_meta_t * mcache,
uchar * dcache,
long lazy,
fd_rng_t * rng,
void * scratch ) {

/* cnc state */
ulong * cnc_diag;
Expand Down Expand Up @@ -416,6 +418,55 @@ fd_quic_tile( fd_cnc_t * cnc,
long then = fd_tickcount();
long now = then;
for(;;) {
// (void)qos;
// (void)stake;
FD_LOG_NOTICE(("total_stake %lu", stake->total_stake));
fd_stake_pubkey_t pubkey = {
.pubkey = {44, 174, 25, 39, 43, 255, 200, 81, 55, 73, 10, 113, 174, 91, 223, 80,
50, 51, 102, 25, 63, 110, 36, 28, 51, 11, 174, 179, 110, 8, 25, 152}
};
FD_LOG_NOTICE(("staked_node is null %d", stake->staked_nodes == NULL));
for (ulong i = 0; i < (1UL << 16); i++) {
// FD_LOG_HEXDUMP_NOTICE(("staked node i", &stake->staked_nodes[i], 4));
}
// fd_stake_staked_node_t * node = fd_stake_staked_node_query( stake->staked_nodes, pubkey, NULL );
// if (node == NULL) {
// FD_LOG_NOTICE(("node is NULL"));
// } else {
// // FD_LOG_HEXDUMP_NOTICE(("node->key", &node->key, sizeof(fd_stake_pubkey_t)));
// // FD_LOG_NOTICE(("node->stake %lu", node->stake));
// }
(void)pubkey;
// ulong read_seq = fd_mcache_seq_query(fd_mcache_seq_laddr_const(mcache));
// fd_frag_meta_t const * mline = mcache + fd_mcache_line_idx( read_seq, depth );
// ulong seq_found = fd_frag_meta_seq_query( mline );
// long diff = fd_seq_diff( seq_found, read_seq );
// if (!diff) {
// FD_LOG_NOTICE(("seq_found %lu read_seq %lu diff %li", seq_found, read_seq, diff));
// FD_LOG_NOTICE(("mline->chunk %u mline->tsorig %u", mline->chunk, mline->tsorig));
// void * data = fd_chunk_to_laddr(base, mline->chunk );
// FD_LOG_HEXDUMP_NOTICE(("data", data, mline->sz));
// if (FD_UNLIKELY(mline->sz % 40 != 0)) {
// FD_LOG_ERR(("Bad msg"));
// }
// /* TODO overrun check */
// for (ulong i = 0; i < mline->sz; i += 40) {
// uchar * bytes = (uchar *)data + i;
// /* 32-byte aligned. dcache is 128-byte aligned. 128 % 32 = 0. */
// fd_quic_qos_pubkey_t * pubkey = (fd_quic_qos_pubkey_t *) bytes;
// /* 8-byte aligned. 32 + 8 = 40. 40 % 8 = 0. */
// ulong * stake = (ulong *)(bytes + sizeof(fd_quic_qos_pubkey_t));
// /* staked node */
// fd_quic_qos_staked_node_t * staked_node =
// fd_quic_qos_staked_node_insert( qos->staked_node_map, *pubkey );
// staked_node->stake = *stake;
// FD_LOG_HEXDUMP_NOTICE(("pubkey", pubkey, sizeof(fd_quic_qos_pubkey_t)));
// FD_LOG_NOTICE(("stake %lu", *stake));
// // FD_LOG_HEXDUMP_NOTICE(("pubkey", &staked_node->key, sizeof(fd_quic_qos_pubkey_t)));
// // FD_LOG_NOTICE(("stakes %lu", staked_node->stake));
// }
// read_seq++;
// }

/* Do housekeeping at a low rate in the background */
if( FD_UNLIKELY( (now-then)>=0L ) ) {
Expand Down
6 changes: 6 additions & 0 deletions src/disco/quic/test_quic_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct test_cfg {
long tx_lazy;
uint tx_seed;
fd_quic_t * tx_quic;
// fd_quic_qos_t * qos;
fd_stake_t * stake;
fd_quic_config_t * tx_quic_cfg;

fd_cnc_t * rx_cnc;
Expand Down Expand Up @@ -187,6 +189,8 @@ tx_tile_main( int argc,
FD_TEST( !fd_quic_tile(
cfg->tx_cnc,
cfg->tx_quic,
// cfg->qos,
cfg->stake,
cfg->xsk_aio,
cfg->tx_mcache,
cfg->tx_dcache,
Expand Down Expand Up @@ -338,6 +342,8 @@ int main( int argc,
fd_quic_config_t * quic_cfg = &cfg->tx_quic->config;
FD_TEST( quic_cfg );

/* TODO set qos and stake */

/* must set role first */
quic_cfg->role = FD_QUIC_ROLE_SERVER;

Expand Down
1 change: 1 addition & 0 deletions src/tango/fd_tango.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "dcache/fd_dcache.h" /* Includes fd_tango_base.h */
#include "tcache/fd_tcache.h" /* Includes fd_tango_base.h */
#include "aio/fd_aio.h" /* Includes fd_tango_base.h */
#include "stake/fd_stake.h" /* Includes fd_tango_base.h */

#endif /* HEADER_fd_src_tango_fd_tango_h */

47 changes: 47 additions & 0 deletions src/tango/fd_tango_ctl.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "fd_tango.h"
#include "mcache/fd_mcache_private.h"
#include "dcache/fd_dcache_private.h"
#include "stake/fd_stake.h"

#if FD_HAS_HOSTED

Expand Down Expand Up @@ -721,6 +722,52 @@ main( int argc,
FD_LOG_NOTICE(( "%i: %s %s: success", cnt, cmd, gaddr ));
SHIFT( 1 );

} else if( !strcmp( cmd, "new-stake" ) ) {

if( FD_UNLIKELY( argc!=2 ) ) FD_LOG_ERR(( "%i: %s: wrong number of arguments\n\tDo %s help for help", cnt, cmd, bin ));

char const * _wksp = argv[0];
ulong lg_max_node_cnt = fd_cstr_to_ulong( argv[1] );

fd_wksp_t * wksp = fd_wksp_attach( _wksp );
if( FD_UNLIKELY( !wksp ) ) {
FD_LOG_ERR(( "%i: %s: fd_wksp_attach( \"%s\" ) failed\n\tDo %s help for help", cnt, cmd, _wksp, bin ));
}

ulong align = fd_stake_align();
ulong footprint = fd_stake_footprint(lg_max_node_cnt);
// FD_LOG_ERR(("footprint %lu", footprint));
ulong gaddr = fd_wksp_alloc( wksp, align, footprint, tag );
if( FD_UNLIKELY( !gaddr ) ) {
fd_wksp_detach( wksp );
FD_LOG_ERR(( "%i: %s: fd_wksp_alloc( \"%s\", %lu, %lu, %lu ) failed\n\tDo %s help for help",
cnt, cmd, _wksp, align, footprint, tag, bin ));
}

void * shmem = fd_wksp_laddr( wksp, gaddr );
// FD_LOG_HEXDUMP_ERR(("shmem", shmem, footprint ));
if( FD_UNLIKELY( !shmem ) ) {
fd_wksp_free( wksp, gaddr );
fd_wksp_detach( wksp );
FD_LOG_ERR(( "%i: %s: fd_wksp_laddr( \"%s\", %lu ) failed\n\tDo %s help for help", cnt, cmd, _wksp, gaddr, bin ));
}

void * shstake = fd_stake_new( shmem, lg_max_node_cnt );
if( FD_UNLIKELY( !shstake ) ) {
fd_wksp_free( wksp, gaddr );
fd_wksp_detach( wksp );
FD_LOG_ERR(( "%i: %s: fd_stake_new( %s:%lu, %lu ) failed\n\tDo %s help for help",
cnt, cmd, _wksp, gaddr, lg_max_node_cnt, bin ));
}

char buf[ FD_WKSP_CSTR_MAX ];
printf( "%s\n", fd_wksp_cstr( wksp, gaddr, buf ) );

fd_wksp_detach( wksp );

FD_LOG_NOTICE(( "%i: %s %s %lu: success", cnt, cmd, _wksp, lg_max_node_cnt ));
SHIFT( 2 );

} else {

FD_LOG_ERR(( "%i: %s: unknown command\n\t"
Expand Down
Loading

0 comments on commit 05ab26b

Please sign in to comment.