1515#include "../../flamenco/runtime/fd_bank.h"
1616#include "../../flamenco/runtime/fd_exec_stack.h"
1717
18+ struct fd_bank_out {
19+ ulong idx ;
20+ fd_wksp_t * mem ;
21+ ulong chunk0 ;
22+ ulong wmark ;
23+ ulong chunk ;
24+ };
25+
26+ typedef struct fd_bank_out fd_bank_out_t ;
27+
1828typedef struct {
1929 ulong kind_id ;
2030
@@ -32,16 +42,11 @@ typedef struct {
3242 ulong pack_in_chunk0 ;
3343 ulong pack_in_wmark ;
3444
35- fd_wksp_t * out_mem ;
36- ulong out_chunk0 ;
37- ulong out_wmark ;
38- ulong out_chunk ;
45+ fd_bank_out_t out_poh [1 ];
46+ fd_bank_out_t out_pack [1 ];
3947
40- fd_wksp_t * rebate_mem ;
41- ulong rebate_chunk0 ;
42- ulong rebate_wmark ;
43- ulong rebate_chunk ;
44- ulong rebates_for_slot ;
48+ ulong rebates_for_slot ;
49+ int enable_rebates ;
4550 fd_pack_rebate_sum_t rebater [ 1 ];
4651
4752 fd_banks_t * banks ;
@@ -112,9 +117,8 @@ during_frag( fd_bank_ctx_t * ctx,
112117 ulong chunk ,
113118 ulong sz ,
114119 ulong ctl FD_PARAM_UNUSED ) {
115-
116120 uchar * src = (uchar * )fd_chunk_to_laddr ( ctx -> pack_in_mem , chunk );
117- uchar * dst = (uchar * )fd_chunk_to_laddr ( ctx -> out_mem , ctx -> out_chunk );
121+ uchar * dst = (uchar * )fd_chunk_to_laddr ( ctx -> out_poh -> mem , ctx -> out_poh -> chunk );
118122
119123 if ( FD_UNLIKELY ( chunk < ctx -> pack_in_chunk0 || chunk > ctx -> pack_in_wmark || sz > USHORT_MAX ) )
120124 FD_LOG_ERR (( "chunk %lu %lu corrupt, not in range [%lu,%lu]" , chunk , sz , ctx -> pack_in_chunk0 , ctx -> pack_in_wmark ));
@@ -155,7 +159,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
155159 ulong sz ,
156160 ulong begin_tspub ,
157161 fd_stem_context_t * stem ) {
158- uchar * dst = (uchar * )fd_chunk_to_laddr ( ctx -> out_mem , ctx -> out_chunk );
162+ uchar * dst = (uchar * )fd_chunk_to_laddr ( ctx -> out_poh -> mem , ctx -> out_poh -> chunk );
159163
160164 ulong slot = fd_disco_poh_sig_slot ( sig );
161165 ulong txn_cnt = (sz - sizeof (fd_microblock_bank_trailer_t ))/sizeof (fd_txn_p_t );
@@ -198,7 +202,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
198202
199203 if ( FD_UNLIKELY ( !txn_ctx -> err .is_committable ) ) {
200204 FD_TEST ( !txn_ctx -> err .is_fees_only );
201- fd_pack_rebate_sum_add_txn ( ctx -> rebater , txn , NULL , 1UL );
205+ if ( FD_LIKELY ( ctx -> enable_rebates ) ) fd_pack_rebate_sum_add_txn ( ctx -> rebater , txn , NULL , 1UL );
202206 ctx -> metrics .txn_landed [ FD_METRICS_ENUM_TRANSACTION_LANDED_V_UNLANDED_IDX ]++ ;
203207 ctx -> metrics .txn_result [ fd_bank_err_from_runtime_err ( txn_ctx -> err .exec_err ) ]++ ;
204208 continue ;
@@ -269,7 +273,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
269273 alt accounts, and finally the read-only alt accounts. */
270274 fd_txn_t * txn_descriptor = TXN ( & txn_ctx -> txn );
271275 fd_acct_addr_t const * writable_alt = fd_type_pun_const ( txn_ctx -> accounts .account_keys + txn_descriptor -> acct_addr_cnt );
272- fd_pack_rebate_sum_add_txn ( ctx -> rebater , txn , & writable_alt , 1UL );
276+ if ( FD_LIKELY ( ctx -> enable_rebates ) ) fd_pack_rebate_sum_add_txn ( ctx -> rebater , txn , & writable_alt , 1UL );
273277
274278 /* The VM will stop executing and fail an instruction immediately if
275279 it exceeds its requested CUs. A transaction which requests less
@@ -329,8 +333,8 @@ handle_microblock( fd_bank_ctx_t * ctx,
329333 transactions so the PoH tile can keep an accurate count of microblocks
330334 it has seen. */
331335 ulong new_sz = txn_cnt * sizeof (fd_txn_p_t ) + sizeof (fd_microblock_trailer_t );
332- fd_stem_publish ( stem , 0UL , bank_sig , ctx -> out_chunk , new_sz , 0UL , (ulong )fd_frag_meta_ts_comp ( microblock_start_ticks ), (ulong )fd_frag_meta_ts_comp ( tickcount ) );
333- ctx -> out_chunk = fd_dcache_compact_next ( ctx -> out_chunk , new_sz , ctx -> out_chunk0 , ctx -> out_wmark );
336+ fd_stem_publish ( stem , ctx -> out_poh -> idx , bank_sig , ctx -> out_poh -> chunk , new_sz , 0UL , (ulong )fd_frag_meta_ts_comp ( microblock_start_ticks ), (ulong )fd_frag_meta_ts_comp ( tickcount ) );
337+ ctx -> out_poh -> chunk = fd_dcache_compact_next ( ctx -> out_poh -> chunk , new_sz , ctx -> out_poh -> chunk0 , ctx -> out_poh -> wmark );
334338}
335339
336340static inline void
@@ -341,7 +345,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
341345 ulong begin_tspub ,
342346 fd_stem_context_t * stem ) {
343347
344- fd_txn_p_t * txns = (fd_txn_p_t * )fd_chunk_to_laddr ( ctx -> out_mem , ctx -> out_chunk );
348+ fd_txn_p_t * txns = (fd_txn_p_t * )fd_chunk_to_laddr ( ctx -> out_poh -> mem , ctx -> out_poh -> chunk );
345349
346350 ulong slot = fd_disco_poh_sig_slot ( sig );
347351 ulong txn_cnt = (sz - sizeof (fd_microblock_bank_trailer_t ))/sizeof (fd_txn_p_t );
@@ -432,7 +436,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
432436 }
433437 }
434438
435- fd_pack_rebate_sum_add_txn ( ctx -> rebater , txns , writable_alt , txn_cnt );
439+ if ( FD_LIKELY ( ctx -> enable_rebates ) ) fd_pack_rebate_sum_add_txn ( ctx -> rebater , txns , writable_alt , txn_cnt );
436440
437441 /* Indicate to pack tile we are done processing the transactions so
438442 it can pack new microblocks using these accounts. */
@@ -447,7 +451,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
447451 }
448452
449453 for ( ulong i = 0UL ; i < txn_cnt ; i ++ ) {
450- uchar * dst = (uchar * )fd_chunk_to_laddr ( ctx -> out_mem , ctx -> out_chunk );
454+ uchar * dst = (uchar * )fd_chunk_to_laddr ( ctx -> out_poh -> mem , ctx -> out_poh -> chunk );
451455 fd_memcpy ( dst , bundle_txn_temp + i , sizeof (fd_txn_p_t ) );
452456
453457 fd_microblock_trailer_t * trailer = (fd_microblock_trailer_t * )( dst + sizeof (fd_txn_p_t ) );
@@ -472,8 +476,8 @@ handle_bundle( fd_bank_ctx_t * ctx,
472476 trailer -> txn_preload_end_pct = (uchar )(((double )(tx_preload_end_ticks - microblock_start_ticks ) * (double )UCHAR_MAX ) / (double )microblock_duration_ticks );
473477
474478 ulong new_sz = sizeof (fd_txn_p_t ) + sizeof (fd_microblock_trailer_t );
475- fd_stem_publish ( stem , 0UL , bank_sig , ctx -> out_chunk , new_sz , 0UL , (ulong )fd_frag_meta_ts_comp ( microblock_start_ticks ), (ulong )fd_frag_meta_ts_comp ( tickcount ) );
476- ctx -> out_chunk = fd_dcache_compact_next ( ctx -> out_chunk , new_sz , ctx -> out_chunk0 , ctx -> out_wmark );
479+ fd_stem_publish ( stem , ctx -> out_poh -> idx , bank_sig , ctx -> out_poh -> chunk , new_sz , 0UL , (ulong )fd_frag_meta_ts_comp ( microblock_start_ticks ), (ulong )fd_frag_meta_ts_comp ( tickcount ) );
480+ ctx -> out_poh -> chunk = fd_dcache_compact_next ( ctx -> out_poh -> chunk , new_sz , ctx -> out_poh -> chunk0 , ctx -> out_poh -> wmark );
477481 }
478482
479483 metrics_write ( ctx );
@@ -494,7 +498,7 @@ after_frag( fd_bank_ctx_t * ctx,
494498 if ( FD_UNLIKELY ( slot != ctx -> rebates_for_slot ) ) {
495499 /* If pack has already moved on to a new slot, the rebates are no
496500 longer useful. */
497- fd_pack_rebate_sum_clear ( ctx -> rebater );
501+ if ( FD_LIKELY ( ctx -> enable_rebates ) ) fd_pack_rebate_sum_clear ( ctx -> rebater );
498502 ctx -> rebates_for_slot = slot ;
499503 }
500504
@@ -503,14 +507,39 @@ after_frag( fd_bank_ctx_t * ctx,
503507
504508 /* TODO: Use fancier logic to coalesce rebates e.g. and move this to
505509 after_credit */
506- ulong written_sz = 0UL ;
507- while ( 0UL != (written_sz = fd_pack_rebate_sum_report ( ctx -> rebater , fd_chunk_to_laddr ( ctx -> rebate_mem , ctx -> rebate_chunk ) )) ) {
508- ulong tspub = (ulong )fd_frag_meta_ts_comp ( fd_tickcount () );
509- fd_stem_publish ( stem , 1UL , slot , ctx -> rebate_chunk , written_sz , 0UL , tsorig , tspub );
510- ctx -> rebate_chunk = fd_dcache_compact_next ( ctx -> rebate_chunk , written_sz , ctx -> rebate_chunk0 , ctx -> rebate_wmark );
510+ if ( FD_LIKELY ( ctx -> enable_rebates ) ) {
511+ ulong written_sz = 0UL ;
512+ while ( 0UL != (written_sz = fd_pack_rebate_sum_report ( ctx -> rebater , fd_chunk_to_laddr ( ctx -> out_pack -> mem , ctx -> out_pack -> chunk ) )) ) {
513+ ulong tspub = (ulong )fd_frag_meta_ts_comp ( fd_tickcount () );
514+ fd_stem_publish ( stem , ctx -> out_pack -> idx , slot , ctx -> out_pack -> chunk , written_sz , 0UL , tsorig , tspub );
515+ ctx -> out_pack -> chunk = fd_dcache_compact_next ( ctx -> out_pack -> chunk , written_sz , ctx -> out_pack -> chunk0 , ctx -> out_pack -> wmark );
516+ }
511517 }
512518}
513519
520+ static inline fd_bank_out_t
521+ out1 ( fd_topo_t const * topo ,
522+ fd_topo_tile_t const * tile ,
523+ char const * name ) {
524+ ulong idx = ULONG_MAX ;
525+
526+ for ( ulong i = 0UL ; i < tile -> out_cnt ; i ++ ) {
527+ fd_topo_link_t const * link = & topo -> links [ tile -> out_link_id [ i ] ];
528+ if ( !strcmp ( link -> name , name ) ) {
529+ if ( FD_UNLIKELY ( idx != ULONG_MAX ) ) FD_LOG_ERR (( "tile %s:%lu had multiple output links named %s but expected one" , tile -> name , tile -> kind_id , name ));
530+ idx = i ;
531+ }
532+ }
533+
534+ if ( FD_UNLIKELY ( idx == ULONG_MAX ) ) return (fd_bank_out_t ){ .idx = ULONG_MAX , .mem = NULL , .chunk0 = 0 , .wmark = 0 , .chunk = 0 };
535+
536+ void * mem = topo -> workspaces [ topo -> objs [ topo -> links [ tile -> out_link_id [ idx ] ].dcache_obj_id ].wksp_id ].wksp ;
537+ ulong chunk0 = fd_dcache_compact_chunk0 ( mem , topo -> links [ tile -> out_link_id [ idx ] ].dcache );
538+ ulong wmark = fd_dcache_compact_wmark ( mem , topo -> links [ tile -> out_link_id [ idx ] ].dcache , topo -> links [ tile -> out_link_id [ idx ] ].mtu );
539+
540+ return (fd_bank_out_t ){ .idx = idx , .mem = mem , .chunk0 = chunk0 , .wmark = wmark , .chunk = chunk0 };
541+ }
542+
514543static void
515544unprivileged_init ( fd_topo_t * topo ,
516545 fd_topo_tile_t * tile ) {
@@ -580,16 +609,10 @@ unprivileged_init( fd_topo_t * topo,
580609 ctx -> pack_in_chunk0 = fd_dcache_compact_chunk0 ( ctx -> pack_in_mem , topo -> links [ tile -> in_link_id [ 0UL ] ].dcache );
581610 ctx -> pack_in_wmark = fd_dcache_compact_wmark ( ctx -> pack_in_mem , topo -> links [ tile -> in_link_id [ 0UL ] ].dcache , topo -> links [ tile -> in_link_id [ 0UL ] ].mtu );
582611
583- ctx -> out_mem = topo -> workspaces [ topo -> objs [ topo -> links [ tile -> out_link_id [ 0 ] ].dcache_obj_id ].wksp_id ].wksp ;
584- ctx -> out_chunk0 = fd_dcache_compact_chunk0 ( ctx -> out_mem , topo -> links [ tile -> out_link_id [ 0 ] ].dcache );
585- ctx -> out_wmark = fd_dcache_compact_wmark ( ctx -> out_mem , topo -> links [ tile -> out_link_id [ 0 ] ].dcache , topo -> links [ tile -> out_link_id [ 0 ] ].mtu );
586- ctx -> out_chunk = ctx -> out_chunk0 ;
587-
612+ * ctx -> out_poh = out1 ( topo , tile , "bank_poh" ); FD_TEST ( ctx -> out_poh -> idx != ULONG_MAX );
613+ * ctx -> out_pack = out1 ( topo , tile , "bank_pack" );
588614
589- ctx -> rebate_mem = topo -> workspaces [ topo -> objs [ topo -> links [ tile -> out_link_id [ 1 ] ].dcache_obj_id ].wksp_id ].wksp ;
590- ctx -> rebate_chunk0 = fd_dcache_compact_chunk0 ( ctx -> rebate_mem , topo -> links [ tile -> out_link_id [ 1 ] ].dcache );
591- ctx -> rebate_wmark = fd_dcache_compact_wmark ( ctx -> rebate_mem , topo -> links [ tile -> out_link_id [ 1 ] ].dcache , topo -> links [ tile -> out_link_id [ 1 ] ].mtu );
592- ctx -> rebate_chunk = ctx -> rebate_chunk0 ;
615+ ctx -> enable_rebates = ctx -> out_pack -> idx != ULONG_MAX ;
593616}
594617
595618static ulong
0 commit comments