Skip to content

Commit 11a7ced

Browse files
committed
flamenco: dedup update_hash_bank code
1 parent 41bdb2f commit 11a7ced

File tree

4 files changed

+43
-65
lines changed

4 files changed

+43
-65
lines changed

src/discof/replay/fd_replay_tile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,10 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx,
22152215

22162216
ulong snapshot_slot = ctx->slot_ctx->slot_bank.slot;
22172217
if( FD_UNLIKELY( !snapshot_slot ) ) {
2218+
/* Genesis-specific setup. */
2219+
/* FIXME: This branch does not set up a new block exec ctx
2220+
properly. Needs to do whatever prepare_new_block_execution
2221+
does, but just hacking that in breaks stuff. */
22182222
fd_runtime_update_leaders( ctx->slot_ctx,
22192223
ctx->slot_ctx->slot_bank.slot,
22202224
ctx->runtime_spad );

src/flamenco/runtime/fd_hashes.c

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,15 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
615615

616616
fd_collect_modified_accounts( slot_ctx, task_data, runtime_spad );
617617

618-
ulong wcnt = fd_tpool_worker_cnt( tpool );
618+
ulong wcnt = 0UL;
619+
620+
/* Handle non-tpool case in a single-threaded manner */
621+
if( FD_LIKELY( tpool ) ){
622+
wcnt = fd_tpool_worker_cnt( tpool );
623+
} else {
624+
wcnt = 1UL;
625+
}
626+
619627

620628
fd_lthash_value_t * lt_hashes = fd_spad_alloc( runtime_spad,
621629
FD_LTHASH_VALUE_ALIGN,
@@ -624,18 +632,31 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
624632
fd_lthash_zero( &lt_hashes[i] );
625633
}
626634

627-
ulong cnt_per_worker = task_data->info_sz / (wcnt-1UL);
628-
for( ulong worker_idx=1UL; worker_idx<wcnt; worker_idx++ ) {
629-
ulong start_idx = (worker_idx-1UL) * cnt_per_worker;
630-
ulong end_idx = worker_idx!=wcnt-1 ? start_idx + cnt_per_worker - 1 : task_data->info_sz - 1;
631-
fd_tpool_exec( tpool, worker_idx, fd_account_hash_task,
632-
task_data, start_idx, end_idx,
633-
&lt_hashes[worker_idx], 0UL, 0UL,
634-
0UL, 0UL, worker_idx, 0UL, 0UL, 0UL );
635-
}
635+
if( FD_LIKELY( tpool ) ){
636+
ulong cnt_per_worker = task_data->info_sz / (wcnt-1UL);
637+
for( ulong worker_idx=1UL; worker_idx<wcnt; worker_idx++ ) {
638+
ulong start_idx = (worker_idx-1UL) * cnt_per_worker;
639+
ulong end_idx = worker_idx!=wcnt-1 ? start_idx + cnt_per_worker - 1 : task_data->info_sz - 1;
640+
fd_tpool_exec( tpool, worker_idx, fd_account_hash_task,
641+
task_data, start_idx, end_idx,
642+
&lt_hashes[worker_idx], 0UL, 0UL,
643+
0UL, 0UL, worker_idx, 0UL, 0UL, 0UL );
644+
}
636645

637-
for( ulong worker_idx=1UL; worker_idx<wcnt; worker_idx++ ) {
638-
fd_tpool_wait( tpool, worker_idx );
646+
for( ulong worker_idx=1UL; worker_idx<wcnt; worker_idx++ ) {
647+
fd_tpool_wait( tpool, worker_idx );
648+
}
649+
650+
} else {
651+
for( ulong i=0UL; i<task_data->info_sz; i++ ) {
652+
fd_accounts_hash_task_info_t * task_info = &task_data->info[i];
653+
fd_account_hash( slot_ctx->funk,
654+
slot_ctx->funk_txn,
655+
task_info,
656+
&lt_hashes[ 0 ],
657+
slot_ctx->slot_bank.slot,
658+
&slot_ctx->epoch_ctx->features );
659+
}
639660
}
640661

641662
return fd_update_hash_bank_exec_hash( slot_ctx,
@@ -649,46 +670,6 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
649670
runtime_spad );
650671
}
651672

652-
int
653-
fd_update_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
654-
fd_capture_ctx_t * capture_ctx,
655-
fd_hash_t * hash,
656-
ulong signature_cnt,
657-
fd_spad_t * runtime_spad ) {
658-
659-
/* Collect list of changed accounts to be added to bank hash */
660-
fd_accounts_hash_task_data_t * task_data = fd_spad_alloc( runtime_spad,
661-
alignof(fd_accounts_hash_task_data_t),
662-
sizeof(fd_accounts_hash_task_data_t) );
663-
664-
fd_collect_modified_accounts( slot_ctx, task_data, runtime_spad );
665-
666-
fd_lthash_value_t * lt_hash = fd_spad_alloc( runtime_spad,
667-
FD_LTHASH_VALUE_ALIGN,
668-
FD_LTHASH_VALUE_FOOTPRINT );
669-
fd_lthash_zero( lt_hash );
670-
671-
for( ulong i=0UL; i<task_data->info_sz; i++ ) {
672-
fd_accounts_hash_task_info_t * task_info = &task_data->info[i];
673-
fd_account_hash( slot_ctx->funk,
674-
slot_ctx->funk_txn,
675-
task_info,
676-
lt_hash,
677-
slot_ctx->slot_bank.slot,
678-
&slot_ctx->epoch_ctx->features );
679-
}
680-
681-
return fd_update_hash_bank_exec_hash( slot_ctx,
682-
hash,
683-
capture_ctx,
684-
task_data,
685-
1UL,
686-
lt_hash,
687-
1UL,
688-
signature_cnt,
689-
runtime_spad );
690-
}
691-
692673
void const *
693674
fd_hash_account( uchar hash[ static 32 ],
694675
fd_lthash_value_t * lthash,

src/flamenco/runtime/fd_hashes.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
110110
fd_tpool_t * tpool,
111111
fd_spad_t * runtime_spad );
112112

113-
/* Single threaded version of fd_update_hash_bank_tpool
114-
TODO: Use parallel execution APIs in fd_runtime_public */
115-
int
116-
fd_update_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
117-
fd_capture_ctx_t * capture_ctx,
118-
fd_hash_t * hash,
119-
ulong signature_cnt,
120-
fd_spad_t * runtime_spad );
121113

122114
/* fd_hash_account is the method to compute the account
123115
hash. It includes the following content:

src/flamenco/runtime/fd_runtime.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,11 +3653,12 @@ fd_runtime_process_genesis_block( fd_exec_slot_ctx_t * slot_ctx,
36533653
fd_runtime_freeze( slot_ctx, runtime_spad );
36543654

36553655
/* sort and update bank hash */
3656-
int result = fd_update_hash_bank( slot_ctx,
3657-
capture_ctx,
3658-
&slot_ctx->slot_bank.banks_hash,
3659-
slot_ctx->signature_cnt,
3660-
runtime_spad );
3656+
int result = fd_update_hash_bank_tpool( slot_ctx,
3657+
capture_ctx,
3658+
&slot_ctx->slot_bank.banks_hash,
3659+
slot_ctx->signature_cnt,
3660+
NULL,
3661+
runtime_spad );
36613662
if( FD_UNLIKELY( result != FD_EXECUTOR_INSTR_SUCCESS ) ) {
36623663
FD_LOG_ERR(( "Failed to update bank hash with error=%d", result ));
36633664
}

0 commit comments

Comments
 (0)