Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/discof/replay/fd_replay_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "../../flamenco/fd_flamenco_base.h"
#include "../../flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h"

#include "../../flamenco/runtime/tests/fd_dump_pb.h"

#include <errno.h>

/* Replay concepts:
Expand Down Expand Up @@ -358,6 +360,9 @@ struct fd_replay_tile {

fd_replay_out_link_t stake_out[1];

/* For dumping blocks to protobuf. */
fd_block_dump_ctx_t * block_dump_ctx;

struct {
fd_histf_t store_read_wait[ 1 ];
fd_histf_t store_read_work[ 1 ];
Expand All @@ -379,7 +384,6 @@ FD_FN_CONST static inline ulong
scratch_align( void ) {
return 128UL;
}

FD_FN_PURE static inline ulong
scratch_footprint( fd_topo_tile_t const * tile ) {
ulong chain_cnt = fd_block_id_map_chain_cnt_est( tile->replay.max_live_slots );
Expand All @@ -394,7 +398,13 @@ scratch_footprint( fd_topo_tile_t const * tile ) {
l = FD_LAYOUT_APPEND( l, fd_vote_tracker_align(), fd_vote_tracker_footprint() );
l = FD_LAYOUT_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
l = FD_LAYOUT_APPEND( l, fd_spad_align(), fd_spad_footprint( tile->replay.heap_size_gib<<30 ) );
l = FD_LAYOUT_FINI ( l, scratch_align() );

if( FD_UNLIKELY( tile->replay.dump_block_to_pb ) ) {
l = FD_LAYOUT_APPEND( l, fd_block_dump_context_align(), fd_block_dump_context_footprint() );
}

l = FD_LAYOUT_FINI( l, scratch_align() );

return l;
}

Expand Down Expand Up @@ -847,6 +857,13 @@ replay_block_finalize( fd_replay_tile_t * ctx,
though we could technically do this before the hash cmp and vote
tower stuff. */
publish_slot_completed( ctx, stem, bank, 0 );

/* If enabled, dump the block to a file and reset the dumping
context state */
if( FD_UNLIKELY( ctx->capture_ctx && ctx->capture_ctx->dump_block_to_pb ) ) {
fd_dump_block_to_protobuf( ctx->block_dump_ctx, ctx->banks, bank, ctx->funk, ctx->capture_ctx );
fd_block_dump_context_reset( ctx->block_dump_ctx );
}
}

/**********************************************************************/
Expand Down Expand Up @@ -1446,6 +1463,11 @@ dispatch_task( fd_replay_tile_t * ctx,
fd_funk_txn_xid_t xid = { .ul = { task->txn_exec->slot, task->txn_exec->slot } };
fd_runtime_update_program_cache( bank, ctx->funk, &xid, txn_p, ctx->runtime_spad );

/* Add the transaction to the block dumper if necessary */
if( FD_UNLIKELY( ctx->capture_ctx && ctx->capture_ctx->dump_block_to_pb ) ) {
fd_dump_block_to_protobuf_collect_tx( ctx->block_dump_ctx, txn_p );
}

bank->refcnt++;

if( FD_UNLIKELY( !bank->first_transaction_scheduled_nanos ) ) bank->first_transaction_scheduled_nanos = fd_log_wallclock();
Expand Down Expand Up @@ -2120,6 +2142,10 @@ unprivileged_init( fd_topo_t * topo,
void * vote_tracker_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_vote_tracker_align(), fd_vote_tracker_footprint() );
void * _capture_ctx = FD_SCRATCH_ALLOC_APPEND( l, fd_capture_ctx_align(), fd_capture_ctx_footprint() );
void * spad_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_spad_align(), fd_spad_footprint( tile->replay.heap_size_gib<<30 ) );
void * block_dump_ctx = NULL;
if( FD_UNLIKELY( tile->replay.dump_block_to_pb ) ) {
block_dump_ctx = FD_SCRATCH_ALLOC_APPEND( l, fd_block_dump_context_align(), fd_block_dump_context_footprint() );
}

ulong store_obj_id = fd_pod_query_ulong( topo->props, "store", ULONG_MAX );
FD_TEST( store_obj_id!=ULONG_MAX );
Expand Down Expand Up @@ -2191,6 +2217,12 @@ unprivileged_init( fd_topo_t * topo,
if( FD_LIKELY( tile->replay.dump_block_to_pb ) ) ctx->capture_ctx->dump_block_to_pb = tile->replay.dump_block_to_pb;
}

if( FD_UNLIKELY( tile->replay.dump_block_to_pb ) ) {
ctx->block_dump_ctx = fd_block_dump_context_join( fd_block_dump_context_new( block_dump_ctx ) );
} else {
ctx->block_dump_ctx = NULL;
}

ctx->exec_cnt = fd_topo_tile_name_cnt( topo, "exec" );

if( FD_UNLIKELY( ctx->exec_cnt>FD_PACK_MAX_BANK_TILES ) ) FD_LOG_ERR(( "replay tile has too many exec tiles %lu", ctx->exec_cnt ));
Expand Down
2 changes: 0 additions & 2 deletions src/flamenco/runtime/fd_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
#include "../features/fd_features.h"
#include "context/fd_capture_ctx.h"
#include "context/fd_exec_txn_ctx.h"
#include "info/fd_runtime_block_info.h"
#include "info/fd_instr_info.h"
#include "../../disco/pack/fd_microblock.h"
#include "info/fd_microblock_info.h"
#include "../../ballet/sbpf/fd_sbpf_loader.h"
#include "../vm/fd_vm_base.h"

Expand Down
4 changes: 0 additions & 4 deletions src/flamenco/runtime/info/Local.mk
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
ifdef FD_HAS_INT128
$(call add-hdrs,fd_runtime_block_info.h)
$(call add-hdrs,fd_instr_info.h)
$(call add-hdrs,fd_microblock_batch_info.h)
$(call add-hdrs,fd_microblock_info.h)

$(call add-objs,fd_instr_info,fd_flamenco)
endif
39 changes: 0 additions & 39 deletions src/flamenco/runtime/info/fd_microblock_batch_info.h

This file was deleted.

41 changes: 0 additions & 41 deletions src/flamenco/runtime/info/fd_microblock_info.h

This file was deleted.

24 changes: 0 additions & 24 deletions src/flamenco/runtime/info/fd_runtime_block_info.h

This file was deleted.

76 changes: 17 additions & 59 deletions src/flamenco/runtime/tests/fd_block_harness.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "../fd_runtime.h"
#include "../fd_system_ids.h"
#include "../fd_txn_account.h"
#include "../info/fd_runtime_block_info.h"
#include "../program/fd_stake_program.h"
#include "../program/fd_vote_program.h"
#include "../sysvar/fd_sysvar_epoch_schedule.h"
Expand Down Expand Up @@ -166,9 +165,10 @@ fd_runtime_fuzz_block_ctx_destroy( fd_solfuzz_runner_t * runner ) {

/* Sets up block execution context from an input test case to execute against the runtime.
Returns block_info on success and NULL on failure. */
static fd_runtime_block_info_t *
static fd_txn_p_t *
fd_runtime_fuzz_block_ctx_create( fd_solfuzz_runner_t * runner,
fd_exec_test_block_context_t const * test_ctx ) {
fd_exec_test_block_context_t const * test_ctx,
ulong * out_txn_cnt ) {
fd_funk_t * funk = runner->funk;
fd_bank_t * bank = runner->bank;
fd_banks_t * banks = runner->banks;
Expand Down Expand Up @@ -370,32 +370,7 @@ fd_runtime_fuzz_block_ctx_create( fd_solfuzz_runner_t * runner,
fd_sysvar_cache_restore_fuzz( bank, funk, xid );

/* Prepare raw transaction pointers and block / microblock infos */
ulong txn_cnt = test_ctx->txns_count;

// For fuzzing, we're using a single microblock batch that contains a single microblock containing all transactions
fd_runtime_block_info_t * block_info = fd_spad_alloc( runner->spad, alignof(fd_runtime_block_info_t), sizeof(fd_runtime_block_info_t) );
fd_microblock_batch_info_t * batch_info = fd_spad_alloc( runner->spad, alignof(fd_microblock_batch_info_t), sizeof(fd_microblock_batch_info_t) );
fd_microblock_info_t * microblock_info = fd_spad_alloc( runner->spad, alignof(fd_microblock_info_t), sizeof(fd_microblock_info_t) );
fd_memset( block_info, 0, sizeof(fd_runtime_block_info_t) );
fd_memset( batch_info, 0, sizeof(fd_microblock_batch_info_t) );
fd_memset( microblock_info, 0, sizeof(fd_microblock_info_t) );

block_info->microblock_batch_cnt = 1UL;
block_info->microblock_cnt = 1UL;
block_info->microblock_batch_infos = batch_info;

batch_info->microblock_cnt = 1UL;
batch_info->microblock_infos = microblock_info;

ulong batch_signature_cnt = 0UL;
ulong batch_txn_cnt = 0UL;
ulong batch_account_cnt = 0UL;
ulong signature_cnt = 0UL;
ulong account_cnt = 0UL;

fd_microblock_hdr_t * microblock_hdr = fd_spad_alloc( runner->spad, alignof(fd_microblock_hdr_t), sizeof(fd_microblock_hdr_t) );
fd_memset( microblock_hdr, 0, sizeof(fd_microblock_hdr_t) );

ulong txn_cnt = test_ctx->txns_count;
fd_txn_p_t * txn_ptrs = fd_spad_alloc( runner->spad, alignof(fd_txn_p_t), txn_cnt * sizeof(fd_txn_p_t) );
for( ulong i=0UL; i<txn_cnt; i++ ) {
fd_txn_p_t * txn = &txn_ptrs[i];
Expand All @@ -411,35 +386,20 @@ fd_runtime_fuzz_block_ctx_create( fd_solfuzz_runner_t * runner,
if( FD_UNLIKELY( !fd_txn_parse( txn->payload, msg_sz, TXN( txn ), NULL ) ) ) {
return NULL;
}

signature_cnt += TXN( txn )->signature_cnt;
account_cnt += fd_txn_account_cnt( TXN( txn ), FD_TXN_ACCT_CAT_ALL );
}

microblock_hdr->txn_cnt = txn_cnt;
microblock_info->microblock.raw = (uchar *)microblock_hdr;

microblock_info->signature_cnt = signature_cnt;
microblock_info->account_cnt = account_cnt;
microblock_info->txns = txn_ptrs;

batch_signature_cnt += signature_cnt;
batch_txn_cnt += txn_cnt;
batch_account_cnt += account_cnt;

block_info->signature_cnt = batch_info->signature_cnt = batch_signature_cnt;
block_info->txn_cnt = batch_info->txn_cnt = batch_txn_cnt;
block_info->account_cnt = batch_info->account_cnt = batch_account_cnt;

return block_info;
*out_txn_cnt = txn_cnt;
return txn_ptrs;
}

/* Takes in a block_info created from `fd_runtime_fuzz_block_ctx_create()`
and executes it against the runtime. Returns the execution result. */
/* Takes in a list of txn_p_t created from
fd_runtime_fuzz_block_ctx_create and executes it against the runtime.
Returns the execution result. */
static int
fd_runtime_fuzz_block_ctx_exec( fd_solfuzz_runner_t * runner,
fd_funk_txn_xid_t const * xid,
fd_runtime_block_info_t * block_info ) {
fd_runtime_fuzz_block_ctx_exec( fd_solfuzz_runner_t * runner,
fd_funk_txn_xid_t const * xid,
fd_txn_p_t * txn_ptrs,
ulong txn_cnt ) {
int res = 0;

// Prepare. Execute. Finalize.
Expand Down Expand Up @@ -468,9 +428,6 @@ fd_runtime_fuzz_block_ctx_exec( fd_solfuzz_runner_t * runner,
return res;
}

fd_txn_p_t * txn_ptrs = block_info->microblock_batch_infos[0].microblock_infos[0].txns;
ulong txn_cnt = block_info->microblock_batch_infos[0].txn_cnt;

/* Sequential transaction execution */
for( ulong i=0UL; i<txn_cnt; i++ ) {
fd_txn_p_t * txn = &txn_ptrs[i];
Expand Down Expand Up @@ -521,16 +478,17 @@ fd_solfuzz_block_run( fd_solfuzz_runner_t * runner,

FD_SPAD_FRAME_BEGIN( runner->spad ) {
/* Set up the block execution context */
fd_runtime_block_info_t * block_info = fd_runtime_fuzz_block_ctx_create( runner, input );
if( block_info==NULL ) {
ulong txn_cnt;
fd_txn_p_t * txn_ptrs = fd_runtime_fuzz_block_ctx_create( runner, input, &txn_cnt );
if( txn_ptrs==NULL ) {
fd_runtime_fuzz_block_ctx_destroy( runner );
return 0;
}

fd_funk_txn_xid_t xid = { .ul = { fd_bank_slot_get( runner->bank ), fd_bank_slot_get( runner->bank ) } };

/* Execute the constructed block against the runtime. */
int res = fd_runtime_fuzz_block_ctx_exec( runner, &xid, block_info );
int res = fd_runtime_fuzz_block_ctx_exec( runner, &xid, txn_ptrs, txn_cnt );

/* Start saving block exec results */
FD_SCRATCH_ALLOC_INIT( l, output_buf );
Expand Down
Loading
Loading