Skip to content

Commit

Permalink
Merge branch 'main' into asiegel/funk-speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
asiegel-jt committed Dec 24, 2024
2 parents 9e8110a + 2efb637 commit e596c27
Show file tree
Hide file tree
Showing 26 changed files with 483 additions and 335 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
with:
submodules: recursive

- uses: dtolnay/rust-toolchain@1.73.0
- uses: dtolnay/rust-toolchain@1.81.0

- name: Build command line args
run: |
Expand All @@ -74,11 +74,11 @@ jobs:
ARGS="$ARGS --exit-on-err"
fi
# machine
if [ "${{ inputs.machine }}" != "all" ]; then
if [ ! -z "${{ inputs.machine }}" ] && [ "${{ inputs.machine }}" != "all" ]; then
ARGS="$ARGS --machines ${{ inputs.machine }}"
fi
# gcc
if [ "${{ inputs.gcc }}" != "all" ]; then
if [ ! -z "${{ inputs.gcc }}" ] && [ "${{ inputs.gcc }}" != "all" ]; then
ARGS="$ARGS --gcc-versions ${{ inputs.gcc }}"
fi
echo "BUILD_ARGS=$ARGS" >> $GITHUB_ENV
Expand All @@ -95,7 +95,7 @@ jobs:
with:
submodules: recursive

- uses: dtolnay/rust-toolchain@1.73.0
- uses: dtolnay/rust-toolchain@1.81.0

- name: Build command line args
run: |
Expand All @@ -109,11 +109,11 @@ jobs:
ARGS="$ARGS --exit-on-err"
fi
# machine
if [ "${{ inputs.machine }}" != "all" ]; then
if [ ! -z "${{ inputs.machine }}" ] && [ "${{ inputs.machine }}" != "all" ]; then
ARGS="$ARGS --machines ${{ inputs.machine }}"
fi
# clang
if [ "${{ inputs.clang }}" != "all" ]; then
if [ ! -z "${{ inputs.clang }}" ] && [ "${{ inputs.clang }}" != "all" ]; then
ARGS="$ARGS --clang-versions ${{ inputs.clang }}"
fi
echo "BUILD_ARGS=$ARGS" >> $GITHUB_ENV
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
if: github.event.pull_request.draft == false
uses: ./.github/workflows/ledgers.yml
secrets: inherit
firedancer:
if: github.event.pull_request.draft == false
uses: ./.github/workflows/test_firedancer_localnet.yml
secrets: inherit
# firedancer:
# if: github.event.pull_request.draft == false
# uses: ./.github/workflows/test_firedancer_localnet.yml
# secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,6 @@ dump/test-vectors/txn/fixtures/programs/8134209f43c8d3dbbb861b30ee71f1f649babc5f
dump/test-vectors/txn/fixtures/programs/8162e28c300791cf553a31198cd11bad10e0b7bc_265678.fix
dump/test-vectors/txn/fixtures/programs/81696f4a9ca9e9e12c70b71407b73249d8c00575_265678.fix
dump/test-vectors/txn/fixtures/programs/8173a59ae2048da0ab0756ff088897ed73f7be15_265678.fix
dump/test-vectors/txn/fixtures/programs/81e2a423431d64b80c68120e7e1e04d5829b7bbc_2924287.fix
dump/test-vectors/txn/fixtures/programs/81e2fb1dce2a047cb9e6ed334b72e57d1759ef06_265678.fix
dump/test-vectors/txn/fixtures/programs/81fd385209eb3ab9586a2f98a96a3ac9db99f260_265678.fix
dump/test-vectors/txn/fixtures/programs/8203019e63adfb8f0ddaed3fbc558786a2f45042_265678.fix
Expand Down Expand Up @@ -2222,7 +2221,6 @@ dump/test-vectors/txn/fixtures/programs/cfbba9574fbeafc94c36fd42b41f93b6cf77fa47
dump/test-vectors/txn/fixtures/programs/cfedcab73fbc13b206765d606fac26c7044e028f_265678.fix
dump/test-vectors/txn/fixtures/programs/crash-0ae873089c62df6e15d3fc0a271485da355874c8.fix
dump/test-vectors/txn/fixtures/programs/crash-10c291c5d8f688fa03b3007887e577e636d2ea79.fix
dump/test-vectors/txn/fixtures/programs/crash-266f593b1f2314b84cfde121192e747bb57b4e6e.fix
dump/test-vectors/txn/fixtures/programs/crash-2a071a64139bf15f205d9284c323d2ed75b40a00.fix
dump/test-vectors/txn/fixtures/programs/crash-3354ca5c9ba1c2ea78c33855ec5ced47dcf9f29e.fix
dump/test-vectors/txn/fixtures/programs/crash-38b53303426b0cb17570b27f89be658a890b867d-add_new_reserved_account_keys.fix
Expand Down Expand Up @@ -2336,7 +2334,6 @@ dump/test-vectors/txn/fixtures/programs/d907c1029bcdcfb8e2cd95e40111e8328bfd9986
dump/test-vectors/txn/fixtures/programs/d90c6b78ce363076a3d2138656c05b89788b220b_265678.fix
dump/test-vectors/txn/fixtures/programs/d911d69395ca0da6d47669609a67078aa5d157a4_265678.fix
dump/test-vectors/txn/fixtures/programs/d9120943dc2f4eb9449f6835fd7cfebb42027859_265678.fix
dump/test-vectors/txn/fixtures/programs/d95760218a1283e6e0ee79f3424c133b911b5e4b_265678.fix
dump/test-vectors/txn/fixtures/programs/d95929160e4a7f7c87410cd379d1dcba23d9ccad_265678.fix
dump/test-vectors/txn/fixtures/programs/d95f082d44ddd9116d6f554aa7f42857a806ba17_265678.fix
dump/test-vectors/txn/fixtures/programs/d982991cdb8f20554b0863f33082bd8db6c4b52f_265678.fix
Expand Down
2 changes: 1 addition & 1 deletion src/app/fddev/quic_trace/fd_quic_trace.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef HEADER_fd_src_app_fddev_quic_trace_fd_quic_trace_h
#define HEADER_fd_src_app_fddev_quic_trace_fd_quic_trace_h

#include "../../../disco/topo/fd_topo.h"
#include "../../../disco/quic/fd_quic_tile.h"

/* fd_quic_trace_ctx is the relocated fd_quic_ctx_t of the target quic
Expand All @@ -23,6 +22,7 @@ struct fd_quic_trace_frame_ctx {
ulong conn_id;
uint src_ip;
ushort src_port;
uchar pkt_type;
ulong pkt_num;
};

Expand Down
14 changes: 10 additions & 4 deletions src/app/fddev/quic_trace/fd_quic_trace_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,26 @@ FRAME_STUB( handshake_done )

static ulong
fd_quic_trace_frame( fd_quic_trace_frame_ctx_t * context,
uchar const * data,
ulong data_sz ) {
uchar const * data,
ulong data_sz ) {
if( FD_UNLIKELY( data_sz<1UL ) ) return FD_QUIC_PARSE_FAIL;
(void)context;

/* Frame ID is technically a varint but it's sufficient to look at the
first byte. */
uint id = data[0];
if( !fd_quic_frame_type_allowed( context->pkt_type, id ) ) {
FD_LOG_HEXDUMP_NOTICE(( "Frame not allowed", data, data_sz ));
return FD_QUIC_PARSE_FAIL;
}

switch( id ) {
# define F(T,MID,NAME,...) \
case T: return fd_quic_trace1_##NAME##_frame( context, data, data_sz );
FD_QUIC_FRAME_TYPES(F)
# undef F
default: return FD_QUIC_PARSE_FAIL;
default:
FD_LOG_HEXDUMP_NOTICE(( "Failed to parse frame", data, data_sz ));
return FD_QUIC_PARSE_FAIL;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/app/fddev/quic_trace/fd_quic_trace_log_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ after_frag( void * _ctx FD_FN_UNUSED,
fd_stem_context_t * stem FD_FN_UNUSED ) {
fd_quic_ctx_t * ctx = &fd_quic_trace_ctx;
fd_quic_log_error_t const * error = fd_type_pun_const( ctx->buffer );
printf( "event=conn_close_quic conn_id=%016lx src_ip=%08x pktnum=%8lu close_code=0x%lx loc=%.*s(%u)\n",
printf( "event=conn_close_quic conn_id=%016lx src_ip=%08x enc=%d pktnum=%8lu close_code=0x%lx loc=%.*s(%u)\n",
error->hdr.conn_id,
fd_uint_bswap( FD_LOAD( uint, error->hdr.ip4_saddr ) ),
error->hdr.enc_level,
error->hdr.pkt_num,
error->code[0],
(int)sizeof(error->src_file),
Expand Down
125 changes: 113 additions & 12 deletions src/app/fddev/quic_trace/fd_quic_trace_rx_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "fd_quic_trace.h"
#include "../../../waltz/quic/fd_quic_private.h"
#include "../../../waltz/quic/templ/fd_quic_parse_util.h"
#include "../../../waltz/quic/fd_quic_proto.c"
#include "../../../util/net/fd_eth.h"
#include "../../../util/net/fd_ip4.h"
#include "../../../util/net/fd_udp.h"
Expand Down Expand Up @@ -44,6 +45,97 @@ during_frag( void * _ctx FD_FN_UNUSED,
fd_memcpy( ctx->buffer, (uchar const *)fd_chunk_to_laddr_const( ctx->in_mem, chunk ), sz );
}

static int
bounds_check_conn( fd_quic_t * quic,
fd_quic_conn_t * conn ) {
long conn_off = (long)((ulong)conn-(ulong)quic);
return conn_off >= (long)quic->layout.conn_map_off && conn_off < (long)quic->layout.hs_pool_off;
}

static void
fd_quic_trace_initial( void * _ctx FD_FN_UNUSED,
uchar * data,
ulong data_sz,
uint ip4_saddr,
ushort udp_sport ) {
fd_quic_ctx_t * ctx = &fd_quic_trace_ctx;
fd_quic_t * quic = ctx->quic;
fd_quic_state_t * state = fd_quic_get_state( quic );
fd_quic_conn_map_t * conn_map = translate_ptr( state->conn_map );

if( FD_UNLIKELY( data_sz < FD_QUIC_SHORTEST_PKT ) ) return;

fd_quic_initial_t initial[1] = {0};
ulong rc = fd_quic_decode_initial( initial, data, data_sz );
if( FD_UNLIKELY( rc == FD_QUIC_PARSE_FAIL ) ) {
FD_LOG_DEBUG(( "fd_quic_decode_initial failed" ));
return;
}
ulong len = (ulong)( initial->pkt_num_pnoff + initial->len );
if( FD_UNLIKELY( len > data_sz ) ) {
FD_LOG_DEBUG(( "Bogus initial packet length" ));
return;
}

fd_quic_crypto_keys_t _keys[1];
fd_quic_crypto_keys_t const * keys = NULL;
if( initial->dst_conn_id_len == FD_QUIC_CONN_ID_SZ ) {
ulong dst_conn_id = fd_ulong_load_8( initial->dst_conn_id );
fd_quic_conn_map_t * conn_entry = fd_quic_conn_map_query( conn_map, dst_conn_id, NULL );
if( conn_entry ) {
fd_quic_conn_t * conn = translate_ptr( conn_entry->conn );
if( FD_LIKELY( bounds_check_conn( quic, conn ) ) ) {
keys = translate_ptr( &conn->keys[0][0] );
}
}
}
if( !keys ) {
/* Set secrets->initial_secret */
fd_quic_crypto_secrets_t secrets[1];
fd_quic_gen_initial_secret(
secrets,
initial->dst_conn_id, initial->dst_conn_id_len );

/* Derive secrets->secret[0][0] */
fd_tls_hkdf_expand_label(
secrets->secret[0][0], FD_QUIC_SECRET_SZ,
secrets->initial_secret,
FD_QUIC_CRYPTO_LABEL_CLIENT_IN,
FD_QUIC_CRYPTO_LABEL_CLIENT_IN_LEN,
NULL, 0UL );

/* Derive decryption key */
fd_quic_gen_keys( _keys, secrets->secret[0][0] );
keys = _keys;
}

ulong pktnum_off = initial->pkt_num_pnoff;
int hdr_err = fd_quic_crypto_decrypt_hdr( data, data_sz, pktnum_off, keys );
if( hdr_err!=FD_QUIC_SUCCESS ) return;

ulong pktnum_sz = fd_quic_h0_pkt_num_len( data[0] )+1u;
ulong pktnum_comp = fd_quic_pktnum_decode( data+9UL, pktnum_sz );
ulong pktnum = pktnum_comp; /* don't bother decompressing since initial pktnum is usually low */

int crypt_err = fd_quic_crypto_decrypt( data, data_sz, pktnum_off, pktnum, keys );
if( crypt_err!=FD_QUIC_SUCCESS ) return;

ulong hdr_sz = pktnum_off + pktnum_sz;
ulong wrap_sz = hdr_sz + FD_QUIC_CRYPTO_TAG_SZ;
if( FD_UNLIKELY( data_sz<wrap_sz ) ) return;

uchar conn_id_truncated[16] = {0};
fd_memcpy( conn_id_truncated, initial->dst_conn_id, initial->dst_conn_id_len );
fd_quic_trace_frame_ctx_t frame_ctx = {
.conn_id = fd_ulong_load_8( conn_id_truncated ),
.pkt_num = pktnum,
.src_ip = ip4_saddr,
.src_port = udp_sport,
.pkt_type = FD_QUIC_PKT_TYPE_INITIAL
};
fd_quic_trace_frames( &frame_ctx, data+hdr_sz, data_sz-wrap_sz );
}

static void
fd_quic_trace_1rtt( void * _ctx FD_FN_UNUSED,
uchar * data,
Expand All @@ -61,31 +153,33 @@ fd_quic_trace_1rtt( void * _ctx FD_FN_UNUSED,
ulong dst_conn_id = fd_ulong_load_8( data+1 );
fd_quic_conn_map_t * conn_entry = fd_quic_conn_map_query( conn_map, dst_conn_id, NULL );
if( !conn_entry ) return;
fd_quic_conn_t * conn = translate_ptr( conn_entry->conn );
fd_quic_conn_t * conn = translate_ptr( conn_entry->conn );
if( FD_UNLIKELY( !bounds_check_conn( quic, conn ) ) ) return;

fd_quic_crypto_keys_t * keys = &conn->keys[ fd_quic_enc_level_appdata_id ][ 0 ];

ulong pkt_number_off = 9UL;
int hdr_err = fd_quic_crypto_decrypt_hdr( data, data_sz, pkt_number_off, keys );
ulong pktnum_off = 9UL;
int hdr_err = fd_quic_crypto_decrypt_hdr( data, data_sz, pktnum_off, keys );
if( hdr_err!=FD_QUIC_SUCCESS ) return;

ulong pkt_num_sz = fd_quic_h0_pkt_num_len( data[0] )+1u;
ulong pkt_number = fd_quic_pktnum_decode( data+9UL, pkt_num_sz );
int crypt_err = fd_quic_crypto_decrypt( data, data_sz, pkt_number_off, pkt_number, keys );
ulong pktnum_sz = fd_quic_h0_pkt_num_len( data[0] )+1u;
ulong pktnum_comp = fd_quic_pktnum_decode( data+9UL, pktnum_sz );
ulong pktnum = fd_quic_reconstruct_pkt_num( pktnum_comp, pktnum_sz, conn->exp_pkt_number[2] );
int crypt_err = fd_quic_crypto_decrypt( data, data_sz, pktnum_off, pktnum, keys );
if( crypt_err!=FD_QUIC_SUCCESS ) return;

ulong hdr_sz = pkt_number_off + pkt_num_sz;
ulong hdr_sz = pktnum_off + pktnum_sz;
ulong wrap_sz = hdr_sz + FD_QUIC_CRYPTO_TAG_SZ;
if( FD_UNLIKELY( data_sz<wrap_sz ) ) return;

fd_quic_trace_frame_ctx_t frame_ctx = {
.conn_id = dst_conn_id,
.pkt_num = pkt_number,
.pkt_num = pktnum,
.src_ip = ip4_saddr,
.src_port = udp_sport,
.pkt_type = FD_QUIC_PKT_TYPE_ONE_RTT
};
fd_quic_trace_frames( &frame_ctx, data+hdr_sz, data_sz-wrap_sz );

(void)ip4_saddr; (void)conn;
}

static void
Expand All @@ -96,8 +190,15 @@ fd_quic_trace_pkt( fd_quic_ctx_t * ctx,
ushort udp_sport ) {
/* FIXME: for now, only handle 1-RTT */
int is_long = fd_quic_h0_hdr_form( data[0] );
if( is_long ) return;
fd_quic_trace_1rtt( ctx, data, data_sz, ip4_saddr, udp_sport );
if( !is_long ) {
switch( fd_quic_h0_long_packet_type( data[0] ) ) {
case FD_QUIC_PKT_TYPE_INITIAL:
fd_quic_trace_initial( ctx, data, data_sz, ip4_saddr, udp_sport );
break;
}
} else {
fd_quic_trace_1rtt( ctx, data, data_sz, ip4_saddr, udp_sport );
}
}

static void
Expand Down
6 changes: 3 additions & 3 deletions src/app/ledger/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ init_blockstore( fd_ledger_args_t * args ) {
FD_LOG_NOTICE(( "joined blockstore" ));
} else {
ulong txn_max = 1 << 22UL;
shmem = fd_wksp_alloc_laddr( args->wksp, fd_blockstore_align(), fd_blockstore_footprint( args->shred_max, args->slot_history_max, 0, txn_max ), blockstore_tag );
shmem = fd_wksp_alloc_laddr( args->wksp, fd_blockstore_align(), fd_blockstore_footprint( args->shred_max, args->slot_history_max, 16, txn_max ), blockstore_tag );
if( shmem == NULL ) {
FD_LOG_ERR(( "failed to allocate a blockstore" ));
}
Expand Down Expand Up @@ -1094,12 +1094,12 @@ prune( fd_ledger_args_t * args ) {
}
/* Create blockstore */
fd_blockstore_t * pruned_blockstore;
void * shmem = fd_wksp_alloc_laddr( pruned_wksp, fd_blockstore_align(), fd_blockstore_footprint( args->shred_max, args->slot_history_max, 0, 1UL << 22UL ), FD_BLOCKSTORE_MAGIC );
void * shmem = fd_wksp_alloc_laddr( pruned_wksp, fd_blockstore_align(), fd_blockstore_footprint( args->shred_max, args->slot_history_max, 16, 1UL << 22UL ), FD_BLOCKSTORE_MAGIC );
if( shmem == NULL ) {
FD_LOG_ERR(( "failed to allocate a blockstore" ));
}
pruned_blockstore = fd_blockstore_join( fd_blockstore_new( shmem, 1, args->hashseed, args->shred_max,
args->slot_history_max, 0, 1UL << 22UL ) );
args->slot_history_max, 16, 1UL << 22UL ) );
if( pruned_blockstore == NULL ) {
fd_wksp_free_laddr( shmem );
FD_LOG_ERR(( "failed to allocate a blockstore" ));
Expand Down
4 changes: 2 additions & 2 deletions src/app/shredcap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ main( int argc, char ** argv ) {
FD_LOG_ERR(( "failed to join a blockstore" ));
}
} else {
shmem = fd_wksp_alloc_laddr( wksp, fd_blockstore_align(), fd_blockstore_footprint( shred_max, slot_history_max, 0, shred_max ), FD_BLOCKSTORE_MAGIC );
shmem = fd_wksp_alloc_laddr( wksp, fd_blockstore_align(), fd_blockstore_footprint( shred_max, slot_history_max, 16, shred_max ), FD_BLOCKSTORE_MAGIC );
if ( shmem == NULL ) {
FD_LOG_ERR(( "failed to allocate a blockstore" ));
}

blockstore = fd_blockstore_join( fd_blockstore_new( shmem, 1, hashseed, shred_max, slot_history_max, 0, shred_max ) );
blockstore = fd_blockstore_join( fd_blockstore_new( shmem, 1, hashseed, shred_max, slot_history_max, 16, shred_max ) );
if ( blockstore == NULL ) {
fd_wksp_free_laddr( shmem );
FD_LOG_ERR(( "failed to allocate a blockstore" ));
Expand Down
2 changes: 1 addition & 1 deletion src/ballet/ed25519/fd_curve25519_secure.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

FD_25519_INLINE void FD_FN_SENSITIVE
fd_ed25519_scalar_radix16( char secret_e[ 64 ], /* ouput: 64-entry in [-8;8] */
fd_ed25519_scalar_radix16( char secret_e[ 64 ], /* output: 64-entry in [-8;8] */
uchar const secret_a[ 32 ], /* input: 32-byte, assumes valid scalar */
char * tmp_secret_carry ) {
(*tmp_secret_carry) = 0;
Expand Down
22 changes: 22 additions & 0 deletions src/ballet/txn/fd_txn.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,28 @@ fd_txn_get_instr_data( fd_txn_instr_t const * instr,
return (uchar const *)((ulong)payload + (ulong)instr->data_off);
}

/*
* 1. has 1 or 2 signatures
* 2. is legacy message
* 3. has only one instruction
* 4. which must be a Vote instruction
*/
static inline int
fd_txn_is_simple_vote_transaction( fd_txn_t const * txn,
void const * payload,
uchar const vote_program_id[ static 32 ] ) {
fd_acct_addr_t const * addr_base = fd_txn_get_acct_addrs( txn, payload );

ulong instr_cnt = txn->instr_cnt;
ulong vote_instr_cnt = 0UL;
for( ulong i=0UL; i<txn->instr_cnt; i++ ) {
ulong prog_id_idx = (ulong)txn->instr[i].program_id;
fd_acct_addr_t const * prog_id = addr_base + prog_id_idx;
vote_instr_cnt += (ulong)(0 == memcmp(prog_id->b, vote_program_id, 32UL) );
}
return (vote_instr_cnt==1UL) && (instr_cnt==1UL) && (txn->transaction_version==FD_TXN_VLEGACY) && (txn->signature_cnt<3UL);
}

/* fd_txn_align returns the alignment in bytes required of a region of
memory to be used as a fd_txn_t. It is the same as
alignof(fd_txn_t). */
Expand Down
Loading

0 comments on commit e596c27

Please sign in to comment.