Line data Source code
1 : #ifndef HEADER_fd_src_disco_pack_fd_pack_rebate_sum_h 2 : #define HEADER_fd_src_disco_pack_fd_pack_rebate_sum_h 3 : 4 : #include "../fd_disco_base.h" 5 : #include "fd_microblock.h" 6 : 7 : 8 : /* Pack schedules transactions assuming they consume all the CUs they 9 : request in order to accommodate the worst case. However, 10 : transactions frequently consume fewer CUs than they request. If the 11 : bank tiles notify pack of how many CUs can be rebated, pack can use 12 : that information to schedule additional transactions. 13 : 14 : fd_pack_rebate_sum_t digests microblocks and produces 0-3 15 : fd_pack_rebate_t messages which summarizes what rebates are needed. 16 : From the bank tiles's perspective, fd_pack_rebate_t is an opaque 17 : type, but pack reads its internals. */ 18 : 19 : FD_STATIC_ASSERT( MAX_TXN_PER_MICROBLOCK*FD_TXN_ACCT_ADDR_MAX<4096UL, map_size ); 20 : 21 0 : #define FD_PACK_REBATE_SUM_CAPACITY (5UL*1024UL) 22 : 23 : typedef struct { 24 : fd_acct_addr_t key; /* account address */ 25 : ulong rebate_cus; 26 : } fd_pack_rebate_entry_t; 27 : 28 : 29 : struct fd_pack_rebate_sum_private { 30 : ulong total_cost_rebate; 31 : ulong vote_cost_rebate; 32 : ulong data_bytes_rebate; 33 : ulong microblock_cnt_rebate; 34 : ulong alloc_rebate; 35 : int ib_result; /* -1: IB failed, 0: not an IB, 1: IB success */ 36 : uint writer_cnt; 37 : 38 : fd_pack_rebate_entry_t map[ 8192UL ]; 39 : fd_pack_rebate_entry_t * inserted[ FD_PACK_REBATE_SUM_CAPACITY ]; 40 : }; 41 : typedef struct fd_pack_rebate_sum_private fd_pack_rebate_sum_t; 42 : 43 : 44 : struct fd_pack_rebate { 45 : ulong total_cost_rebate; 46 : ulong vote_cost_rebate; 47 : ulong data_bytes_rebate; 48 : ulong microblock_cnt_rebate; 49 : ulong alloc_rebate; 50 : int ib_result; /* -1: IB failed, 0: not an IB, 1: IB success */ 51 : uint writer_cnt; 52 : 53 : fd_pack_rebate_entry_t writer_rebates[ 1UL ]; /* Actually writer_cnt, up to 1637 */ 54 : }; 55 : typedef struct fd_pack_rebate fd_pack_rebate_t; 56 : 57 : #define FD_PACK_REBATE_MIN_SZ (sizeof(fd_pack_rebate_t) -sizeof(fd_pack_rebate_entry_t)) 58 : #define FD_PACK_REBATE_MAX_SZ (sizeof(fd_pack_rebate_t)+1636UL*sizeof(fd_pack_rebate_entry_t)) 59 : 60 : FD_STATIC_ASSERT( sizeof(fd_pack_rebate_t)+1636UL*sizeof(fd_pack_rebate_entry_t)<USHORT_MAX, rebate_depth ); 61 : 62 : 63 0 : FD_FN_PURE static inline ulong fd_pack_rebate_sum_align ( void ) { return alignof(fd_pack_rebate_sum_t); } 64 0 : FD_FN_PURE static inline ulong fd_pack_rebate_sum_footprint( void ) { return sizeof (fd_pack_rebate_sum_t); } 65 : 66 0 : FD_FN_PURE static inline fd_pack_rebate_sum_t * fd_pack_rebate_sum_join( void * mem ) { return (fd_pack_rebate_sum_t *)mem; } 67 : 68 : void * fd_pack_rebate_sum_new( void * mem ); 69 : 70 : /* fd_pack_rebate_sum_add_txn adds rebate information from a bundle or 71 : microblock to the pending summary. This reads the EXECUTE_SUCCESS 72 : flag and the execle_cu field, so those must be populated in the 73 : transactions before this is called. 74 : 75 : s must be a valid local join. txn will be indexed txn[i] for i in [0, 76 : txn_cnt), and each transaction must have the previously mentioned 77 : fields set. 78 : 79 : Additionally, if the transaction txn[i] loads writable accounts 80 : from one or more address lookup tables, addtl_writable[i] must 81 : either be NULL or point to the first writable account address that 82 : it loaded. When not NULL, adtl_writable is indexed 83 : addtl_writable[i][j] for j in [0, TXN(txn[i])->addr_table_adtl_writable_cnt ). 84 : If adtl_writable[i] is NULL, ALT account rebates are skipped (this can 85 : happen if the transaction doesn't load any writable accounts from address 86 : lookup tables or if the resolved addresses are not available). 87 : txn_cnt must be in [0, MAX_TXN_PER_MICROBLOCK], where txn_cnt==0 is 88 : a no-op. txn and adtl_writable can be NULL if txn_cnt==0. 89 : 90 : This function does not retain any read interest in txn or 91 : adtl_writable after returning. 92 : 93 : Returns the number of times fd_pack_rebate_sum_report must be called 94 : before the next call to add_txn with a non-zero txn_cnt. */ 95 : ulong 96 : fd_pack_rebate_sum_add_txn( fd_pack_rebate_sum_t * s, 97 : fd_txn_p_t const * txn, 98 : fd_acct_addr_t const * const * adtl_writable, 99 : ulong txn_cnt ); 100 : 101 : /* fd_pack_rebate_sum_report generates a rebate report from the state of 102 : the current rebate information. s must point to a valid local join. 103 : out must point to a region of memory with at least USHORT_MAX bytes 104 : of capacity. Returns the number of bytes that were written, which 105 : will be in [0, USHORT_MAX]. Updates the state of s so that 106 : subsequent calls to this function will write new information. */ 107 : ulong 108 : fd_pack_rebate_sum_report( fd_pack_rebate_sum_t * s, 109 : fd_pack_rebate_t * out ); 110 : 111 : /* fd_pack_rebate_sum_clear clears the state of any pending rebates. 112 : Requires that s is a valid local join. Given that, it's faster but 113 : equivalent to calling leave, delete, new, then join. */ 114 : void 115 : fd_pack_rebate_sum_clear( fd_pack_rebate_sum_t * s ); 116 : 117 : #endif /* HEADER_fd_src_disco_pack_fd_pack_rebate_sum_h */