Line data Source code
1 : #ifndef HEADER_fd_src_discof_replay_fd_exec_h 2 : #define HEADER_fd_src_discof_replay_fd_exec_h 3 : 4 : #include "../../flamenco/fd_flamenco_base.h" 5 : #include "../../flamenco/runtime/context/fd_exec_slot_ctx.h" 6 : #include "../../flamenco/runtime/fd_runtime_public.h" 7 : #include "../../flamenco/stakes/fd_stakes.h" 8 : #include "../../flamenco/runtime/sysvar/fd_sysvar_epoch_schedule.h" 9 : 10 : /* Replay tile msg link formatting. The following take a pointer into 11 : a dcache region and formats it as a specific message type. */ 12 : 13 : static inline ulong 14 : generate_stake_weight_msg( fd_exec_slot_ctx_t * slot_ctx, 15 : fd_spad_t * runtime_spad, 16 : ulong epoch, 17 0 : ulong * stake_weight_msg_out ) { 18 : 19 0 : fd_stake_weight_msg_t * stake_weight_msg = (fd_stake_weight_msg_t *)fd_type_pun( stake_weight_msg_out ); 20 0 : fd_stake_weight_t * stake_weights = (fd_stake_weight_t *)&stake_weight_msg_out[5]; 21 0 : fd_vote_accounts_global_t const * vote_accounts = fd_bank_epoch_stakes_locking_query( slot_ctx->bank ); 22 0 : ulong stake_weight_idx = fd_stake_weights_by_node( vote_accounts, 23 0 : stake_weights, 24 0 : runtime_spad ); 25 0 : fd_bank_epoch_stakes_end_locking_query( slot_ctx->bank ); 26 : 27 0 : fd_epoch_schedule_t const * epoch_schedule = fd_bank_epoch_schedule_query( slot_ctx->bank ); 28 : 29 0 : stake_weight_msg->epoch = epoch; 30 0 : stake_weight_msg->staked_cnt = stake_weight_idx; /* staked_cnt */ 31 0 : stake_weight_msg->start_slot = fd_epoch_slot0( epoch_schedule, stake_weight_msg_out[0] ); /* start_slot */ 32 0 : stake_weight_msg->slot_cnt = epoch_schedule->slots_per_epoch; /* slot_cnt */ 33 0 : stake_weight_msg->excluded_stake = 0UL; /* excluded stake */ 34 : 35 0 : return 5*sizeof(ulong) + (stake_weight_idx * sizeof(fd_stake_weight_t)); 36 0 : } 37 : 38 : static inline void 39 : generate_hash_bank_msg( ulong task_infos_gaddr, 40 : ulong lt_hash_gaddr, 41 : ulong start_idx, 42 : ulong end_idx, 43 : ulong curr_slot, 44 0 : fd_runtime_public_hash_bank_msg_t * hash_msg_out ) { 45 0 : hash_msg_out->task_infos_gaddr = task_infos_gaddr; 46 0 : hash_msg_out->lthash_gaddr = lt_hash_gaddr; 47 0 : hash_msg_out->start_idx = start_idx; 48 0 : hash_msg_out->end_idx = end_idx; 49 0 : hash_msg_out->slot = curr_slot; 50 0 : } 51 : 52 : /* Execution tracking helpers */ 53 : 54 : struct fd_slice_exec { 55 : uchar * buf; /* Pointer to the memory region sized for max sz of a block. */ 56 : ulong wmark; /* Offset into slice where previous bytes have been executed, and following bytes have not. Will be on a transaction or microblock boundary. */ 57 : ulong sz; /* Total bytes this slice occupies in mbatch memory. New slices are placed at this offset */ 58 : ulong mblks_rem; /* Number of microblocks remaining in the current batch iteration. */ 59 : ulong txns_rem; /* Number of txns remaining in current microblock iteration. */ 60 : 61 : ulong last_mblk_off; /* Stored offset to the last microblock header seen. Updated during block execution. */ 62 : int last_batch; /* Signifies last batch execution. */ 63 : }; 64 : typedef struct fd_slice_exec fd_slice_exec_t; 65 : 66 : /* Note the current usage of slice_exec is that it is embedded directly 67 : in replay_tile_ctx_t, so there's no need for (_new) currently. */ 68 : 69 : fd_slice_exec_t * 70 : fd_slice_exec_join( void * slmem ); 71 : 72 : void 73 : fd_slice_exec_txn_parse( fd_slice_exec_t * slice_exec_ctx, 74 : fd_txn_p_t * txn_p_out ); 75 : 76 : void 77 : fd_slice_exec_microblock_parse( fd_slice_exec_t * slice_exec_ctx ); 78 : 79 : void 80 : fd_slice_exec_reset( fd_slice_exec_t * slice_exec_ctx ); 81 : 82 : void 83 : fd_slice_exec_begin( fd_slice_exec_t * slice_exec_ctx, 84 : ulong slice_sz, 85 : int last_batch ); 86 : 87 : static inline int 88 0 : fd_slice_exec_txn_ready( fd_slice_exec_t * slice_exec_ctx ) { 89 0 : return slice_exec_ctx->txns_rem > 0UL; 90 0 : } 91 : 92 : static inline int 93 0 : fd_slice_exec_microblock_ready( fd_slice_exec_t * slice_exec_ctx ) { 94 0 : return slice_exec_ctx->txns_rem == 0 && slice_exec_ctx->mblks_rem > 0UL; 95 0 : } 96 : 97 : static inline int 98 0 : fd_slice_exec_slice_ready( fd_slice_exec_t * slice_exec_ctx ) { 99 0 : return slice_exec_ctx->txns_rem == 0 && slice_exec_ctx->mblks_rem == 0UL; 100 0 : } 101 : 102 : static inline int 103 0 : fd_slice_exec_slot_complete( fd_slice_exec_t * slice_exec_ctx ) { 104 0 : return slice_exec_ctx->last_batch && slice_exec_ctx->mblks_rem == 0 && slice_exec_ctx->txns_rem == 0; 105 0 : } 106 : 107 : #endif /* HEADER_fd_src_discof_replay_fd_exec_h */