Skip to content

Commit fdd822d

Browse files
committed
Block level fuzzing
1 parent eb0b05c commit fdd822d

20 files changed

+1515
-332
lines changed

src/app/fdctl/run/tiles/fd_replay.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -1310,13 +1310,11 @@ prepare_new_block_execution( fd_replay_tile_ctx_t * ctx,
13101310
fork->slot_ctx.funk_txn = fd_funk_txn_prepare(ctx->funk, fork->slot_ctx.funk_txn, &xid, 1);
13111311
fd_funk_end_write( ctx->funk );
13121312

1313-
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_block_pre_execute_process_new_epoch( &fork->slot_ctx,
1314-
ctx->tpool,
1315-
ctx->exec_spads,
1316-
ctx->exec_spad_cnt,
1317-
ctx->runtime_spad ) ) ) {
1318-
FD_LOG_ERR(( "couldn't process new epoch" ));
1319-
}
1313+
fd_runtime_block_pre_execute_process_new_epoch( &fork->slot_ctx,
1314+
ctx->tpool,
1315+
ctx->exec_spads,
1316+
ctx->exec_spad_cnt,
1317+
ctx->runtime_spad );
13201318

13211319
/* We want to push on a spad frame before we start executing a block.
13221320
Apart from allocations made at the epoch boundary, there should be no

src/app/ledger/main.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct fd_ledger_args {
7272

7373
int dump_insn_to_pb; /* instruction dumping: should insns be dumped */
7474
int dump_txn_to_pb; /* txn dumping: should txns be dumped */
75+
int dump_block_to_pb; /* block dumping: should blocks be dumped */
7576
ulong dump_proto_start_slot; /* instruction / txn dumping: what slot to start dumping*/
7677
char const * dump_proto_sig_filter; /* instruction / txn dumping: specify txn sig to dump at */
7778
char const * dump_proto_output_dir; /* instruction / txn dumping: output directory for protobuf messages */
@@ -687,7 +688,7 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) {
687688
int has_solcap = args->capture_fpath && args->capture_fpath[0] != '\0';
688689
int has_checkpt = args->checkpt_path && args->checkpt_path[0] != '\0';
689690
int has_checkpt_funk = args->checkpt_funk && args->checkpt_funk[0] != '\0';
690-
int has_dump_to_protobuf = args->dump_insn_to_pb || args->dump_txn_to_pb;
691+
int has_dump_to_protobuf = args->dump_insn_to_pb || args->dump_txn_to_pb || args->dump_block_to_pb;
691692

692693
if( has_solcap || has_checkpt || has_checkpt_funk || has_dump_to_protobuf ) {
693694
FILE * capture_file = NULL;
@@ -717,6 +718,7 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) {
717718
if( has_dump_to_protobuf ) {
718719
args->capture_ctx->dump_insn_to_pb = args->dump_insn_to_pb;
719720
args->capture_ctx->dump_txn_to_pb = args->dump_txn_to_pb;
721+
args->capture_ctx->dump_block_to_pb = args->dump_block_to_pb;
720722
args->capture_ctx->dump_proto_sig_filter = args->dump_proto_sig_filter;
721723
args->capture_ctx->dump_proto_output_dir = args->dump_proto_output_dir;
722724
args->capture_ctx->dump_proto_start_slot = args->dump_proto_start_slot;
@@ -1393,6 +1395,7 @@ initial_setup( int argc, char ** argv, fd_ledger_args_t * args ) {
13931395
int abort_on_mismatch = fd_env_strip_cmdline_int ( &argc, &argv, "--abort-on-mismatch", NULL, 1 );
13941396
int dump_insn_to_pb = fd_env_strip_cmdline_int ( &argc, &argv, "--dump-insn-to-pb", NULL, 0 );
13951397
int dump_txn_to_pb = fd_env_strip_cmdline_int ( &argc, &argv, "--dump-txn-to-pb", NULL, 0 );
1398+
int dump_block_to_pb = fd_env_strip_cmdline_int ( &argc, &argv, "--dump-block-to-pb", NULL, 0 );
13961399
ulong dump_proto_start_slot = fd_env_strip_cmdline_ulong ( &argc, &argv, "--dump-proto-start-slot", NULL, 0 );
13971400
char const * dump_proto_sig_filter = fd_env_strip_cmdline_cstr ( &argc, &argv, "--dump-proto-sig-filter", NULL, NULL );
13981401
char const * dump_proto_output_dir = fd_env_strip_cmdline_cstr ( &argc, &argv, "--dump-proto-output-dir", NULL, NULL );
@@ -1499,6 +1502,7 @@ initial_setup( int argc, char ** argv, fd_ledger_args_t * args ) {
14991502
args->abort_on_mismatch = abort_on_mismatch;
15001503
args->dump_insn_to_pb = dump_insn_to_pb;
15011504
args->dump_txn_to_pb = dump_txn_to_pb;
1505+
args->dump_block_to_pb = dump_block_to_pb;
15021506
args->dump_proto_start_slot = dump_proto_start_slot;
15031507
args->dump_proto_sig_filter = dump_proto_sig_filter;
15041508
args->dump_proto_output_dir = dump_proto_output_dir;

src/flamenco/runtime/context/fd_capture_ctx.h

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ struct __attribute__((aligned(FD_CAPTURE_CTX_ALIGN))) fd_capture_ctx {
3030

3131
/* Transaction Capture */
3232
int dump_txn_to_pb;
33+
34+
/* Block Capture */
35+
int dump_block_to_pb;
3336
};
3437
typedef struct fd_capture_ctx fd_capture_ctx_t;
3538
#define FD_CAPTURE_CTX_FOOTPRINT ( sizeof(fd_capture_ctx_t) + fd_solcap_writer_footprint() )

src/flamenco/runtime/context/fd_exec_epoch_ctx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fd_exec_epoch_ctx_leaders( fd_exec_epoch_ctx_t * ctx ) {
113113
}
114114

115115
void
116-
fd_exec_epoch_ctx_from_prev( fd_exec_epoch_ctx_t * self,
116+
fd_exec_epoch_ctx_from_prev( fd_exec_epoch_ctx_t * self,
117117
fd_exec_epoch_ctx_t * prev,
118118
fd_spad_t * runtime_spad );
119119

src/flamenco/runtime/fd_executor.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,8 @@ fd_executor_setup_accessed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx,
909909
fd_pubkey_t const * addr_lut_acc = (fd_pubkey_t *)((uchar *)txn_ctx->_txn_raw->raw + addr_lut->addr_off);
910910

911911
/* https://github.com/anza-xyz/agave/blob/368ea563c423b0a85cc317891187e15c9a321521/accounts-db/src/accounts.rs#L90-L94 */
912-
FD_BORROWED_ACCOUNT_DECL( addr_lut_rec );
913-
int err = fd_acc_mgr_view( txn_ctx->slot_ctx->acc_mgr,
914-
txn_ctx->slot_ctx->funk_txn,
915-
(fd_pubkey_t *) addr_lut_acc,
916-
addr_lut_rec );
912+
FD_BORROWED_ACCOUNT_DECL(addr_lut_rec);
913+
int err = fd_acc_mgr_view(txn_ctx->slot_ctx->acc_mgr, txn_ctx->slot_ctx->funk_txn, addr_lut_acc, addr_lut_rec);
917914
if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) {
918915
return FD_RUNTIME_TXN_ERR_ADDRESS_LOOKUP_TABLE_NOT_FOUND;
919916
}

src/flamenco/runtime/fd_runtime.c

+25-21
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,14 @@ fd_runtime_freeze( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) {
664664
rec->meta->info.lamports += fees;
665665
rec->meta->slot = slot_ctx->slot_bank.slot;
666666

667-
fd_blockstore_start_write( slot_ctx->blockstore );
668-
fd_block_t * blk = slot_ctx->block;
669-
blk->rewards.collected_fees = fees;
670-
blk->rewards.post_balance = rec->meta->info.lamports;
671-
memcpy( blk->rewards.leader.uc, leader->uc, sizeof(fd_hash_t) );
672-
fd_blockstore_end_write( slot_ctx->blockstore );
667+
if( FD_LIKELY( slot_ctx->blockstore ) ) {
668+
fd_blockstore_start_write( slot_ctx->blockstore );
669+
fd_block_t * blk = slot_ctx->block;
670+
blk->rewards.collected_fees = fees;
671+
blk->rewards.post_balance = rec->meta->info.lamports;
672+
memcpy( blk->rewards.leader.uc, leader->uc, sizeof(fd_hash_t) );
673+
fd_blockstore_end_write( slot_ctx->blockstore );
674+
}
673675
} while(0);
674676

675677
ulong old = slot_ctx->slot_bank.capitalization;
@@ -1394,7 +1396,7 @@ int
13941396
fd_runtime_block_execute_prepare( fd_exec_slot_ctx_t * slot_ctx,
13951397
fd_spad_t * runtime_spad ) {
13961398

1397-
if( slot_ctx->slot_bank.slot != 0UL ) {
1399+
if( slot_ctx->blockstore && slot_ctx->slot_bank.slot != 0UL ) {
13981400
fd_blockstore_block_height_update( slot_ctx->blockstore,
13991401
slot_ctx->slot_bank.slot,
14001402
slot_ctx->slot_bank.block_height );
@@ -2453,7 +2455,7 @@ fd_apply_builtin_program_feature_transitions( fd_exec_slot_ctx_t * slot_ctx,
24532455
}
24542456
}
24552457

2456-
} FD_SCRATCH_SCOPE_END;
2458+
} FD_SPAD_FRAME_END;
24572459
}
24582460

24592461
static void
@@ -3113,8 +3115,9 @@ fd_runtime_block_collect_txns( fd_block_info_t const * block_info,
31133115
/* Genesis */
31143116
/*******************************************************************************/
31153117

3116-
static void
3117-
fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) {
3118+
void
3119+
fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx,
3120+
fd_spad_t * runtime_spad ) {
31183121
fd_sysvar_recent_hashes_init( slot_ctx, runtime_spad );
31193122
fd_sysvar_clock_init( slot_ctx );
31203123
fd_sysvar_slot_history_init( slot_ctx, runtime_spad );
@@ -3792,7 +3795,7 @@ fd_runtime_publish_old_txns( fd_exec_slot_ctx_t * slot_ctx,
37923795
return 0;
37933796
}
37943797

3795-
static int
3798+
int
37963799
fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx,
37973800
fd_capture_ctx_t * capture_ctx,
37983801
fd_block_info_t const * block_info,
@@ -3801,6 +3804,7 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx,
38013804
ulong exec_spad_cnt,
38023805
fd_spad_t * runtime_spad ) {
38033806

3807+
uchar dump_block = capture_ctx && slot_ctx->slot_bank.slot >= capture_ctx->dump_proto_start_slot && capture_ctx->dump_block_to_pb;
38043808
if ( capture_ctx != NULL && capture_ctx->capture ) {
38053809
fd_solcap_writer_set_slot( capture_ctx->capture, slot_ctx->slot_bank.slot );
38063810
}
@@ -3812,6 +3816,10 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx,
38123816
return res;
38133817
}
38143818

3819+
if( dump_block ) {
3820+
fd_dump_block_to_protobuf( block_info, slot_ctx, capture_ctx, runtime_spad );
3821+
}
3822+
38153823
ulong txn_cnt = block_info->txn_cnt;
38163824
fd_txn_p_t * txn_ptrs = fd_spad_alloc( runtime_spad, alignof(fd_txn_p_t), txn_cnt * sizeof(fd_txn_p_t) );
38173825

@@ -3863,7 +3871,7 @@ fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx,
38633871
return FD_RUNTIME_EXECUTE_SUCCESS;
38643872
}
38653873

3866-
int
3874+
void
38673875
fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
38683876
fd_tpool_t * tpool,
38693877
fd_spad_t * * exec_spads,
@@ -3908,8 +3916,6 @@ fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
39083916
runtime_spad );
39093917
fd_funk_end_write( slot_ctx->acc_mgr->funk );
39103918
}
3911-
3912-
return FD_RUNTIME_EXECUTE_SUCCESS;
39133919
}
39143920

39153921
int
@@ -3954,13 +3960,11 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx,
39543960
fd_funk_end_write( funk );
39553961
}
39563962

3957-
if( FD_UNLIKELY( (ret = fd_runtime_block_pre_execute_process_new_epoch( slot_ctx,
3958-
tpool,
3959-
exec_spads,
3960-
exec_spad_cnt,
3961-
runtime_spad )) != FD_RUNTIME_EXECUTE_SUCCESS ) ) {
3962-
break;
3963-
}
3963+
fd_runtime_block_pre_execute_process_new_epoch( slot_ctx,
3964+
tpool,
3965+
exec_spads,
3966+
exec_spad_cnt,
3967+
runtime_spad );
39643968

39653969
/* All runtime allocations here are scoped to the end of a block. */
39663970
FD_SPAD_FRAME_BEGIN( runtime_spad ) {

src/flamenco/runtime/fd_runtime.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ fd_runtime_is_epoch_boundary( fd_epoch_bank_t * epoch_bank,
449449
that we modify when processing a new epoch need to be hashed into
450450
the bank hash.
451451
*/
452-
int
452+
void
453453
fd_runtime_block_pre_execute_process_new_epoch( fd_exec_slot_ctx_t * slot_ctx,
454454
fd_tpool_t * tpool,
455455
fd_spad_t * * exec_spads,
@@ -493,8 +493,21 @@ fd_runtime_block_eval_tpool( fd_exec_slot_ctx_t * slot_ctx,
493493
ulong spads_cnt,
494494
fd_spad_t * runtime_spad );
495495

496+
int
497+
fd_runtime_block_execute_tpool( fd_exec_slot_ctx_t * slot_ctx,
498+
fd_capture_ctx_t * capture_ctx,
499+
fd_block_info_t const * block_info,
500+
fd_tpool_t * tpool,
501+
fd_spad_t * * exec_spads,
502+
ulong exec_spad_cnt,
503+
fd_spad_t * runtime_spad );
504+
496505
/* Genesis ********************************************************************/
497506

507+
void
508+
fd_runtime_init_program( fd_exec_slot_ctx_t * slot_ctx,
509+
fd_spad_t * runtime_spad );
510+
498511
void
499512
fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
500513
char const * genesis_filepath,

src/flamenco/runtime/tests/Local.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
$(call add-hdrs,generated/context.pb.h,generated/elf.pb.h,generated/invoke.pb.h,generated/txn.pb.h,generated/vm.pb.h,generated/shred.pb.h generated/metadata.pb.h generated/pack.pb.h)
2-
$(call add-objs,generated/context.pb generated/elf.pb generated/invoke.pb generated/txn.pb generated/vm.pb generated/shred.pb generated/metadata.pb generated/pack.pb,fd_flamenco)
1+
$(call add-hdrs,generated/context.pb.h,generated/elf.pb.h,generated/invoke.pb.h,generated/txn.pb.h,generated/block.pb.h,generated/vm.pb.h,generated/shred.pb.h generated/metadata.pb.h generated/pack.pb.h)
2+
$(call add-objs,generated/context.pb generated/elf.pb generated/invoke.pb generated/txn.pb generated/block.pb generated/vm.pb generated/shred.pb generated/metadata.pb generated/pack.pb,fd_flamenco)
33

44
ifdef FD_HAS_INT128
55
ifdef FD_HAS_SECP256K1

0 commit comments

Comments
 (0)