LCOV - code coverage report
Current view: top level - disco/pack - fd_pack_rebate_sum.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 2 4 50.0 %
Date: 2025-03-20 12:08:36 Functions: 2 99 2.0 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_ballet_pack_fd_pack_rebate_sum_h
       2             : #define HEADER_fd_src_ballet_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          42 : #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             :   int   ib_result; /* -1: IB failed, 0: not an IB, 1: IB success */
      35             :   uint  writer_cnt;
      36             : 
      37             :   fd_pack_rebate_entry_t map[ 8192UL ];
      38             :   fd_pack_rebate_entry_t * inserted[ FD_PACK_REBATE_SUM_CAPACITY ];
      39             : };
      40             : typedef struct fd_pack_rebate_sum_private fd_pack_rebate_sum_t;
      41             : 
      42             : 
      43             : struct fd_pack_rebate {
      44             :   ulong total_cost_rebate;
      45             :   ulong vote_cost_rebate;
      46             :   ulong data_bytes_rebate;
      47             :   ulong microblock_cnt_rebate;
      48             :   int   ib_result; /* -1: IB failed, 0: not an IB, 1: IB success */
      49             :   uint  writer_cnt;
      50             : 
      51             :   fd_pack_rebate_entry_t writer_rebates[ 1UL ]; /* Actually writer_cnt, up to 1637 */
      52             : };
      53             : typedef struct fd_pack_rebate fd_pack_rebate_t;
      54             : 
      55             : #define FD_PACK_REBATE_MIN_SZ (sizeof(fd_pack_rebate_t)       -sizeof(fd_pack_rebate_entry_t))
      56             : #define FD_PACK_REBATE_MAX_SZ (sizeof(fd_pack_rebate_t)+1636UL*sizeof(fd_pack_rebate_entry_t))
      57             : 
      58             : FD_STATIC_ASSERT( sizeof(fd_pack_rebate_t)+1636UL*sizeof(fd_pack_rebate_entry_t)<USHORT_MAX, rebate_depth );
      59             : 
      60             : 
      61           0 : FD_FN_PURE static inline ulong fd_pack_rebate_sum_align    ( void ) { return alignof(fd_pack_rebate_sum_t); }
      62           0 : FD_FN_PURE static inline ulong fd_pack_rebate_sum_footprint( void ) { return sizeof (fd_pack_rebate_sum_t); }
      63             : 
      64           6 : FD_FN_PURE static inline fd_pack_rebate_sum_t * fd_pack_rebate_sum_join( void * mem ) { return (fd_pack_rebate_sum_t *)mem; }
      65             : 
      66             : void * fd_pack_rebate_sum_new( void * mem );
      67             : 
      68             : /* fd_pack_rebate_sum_add_txn adds rebate information from a bundle or
      69             :    microblock to the pending summary.  This reads the EXECUTE_SUCCESS
      70             :    flag and the bank_cu field, so those must be populated in the
      71             :    transactions before this is called.
      72             : 
      73             :    s must be a valid local join. txn will be indexed txn[i] for i in [0,
      74             :    txn_cnt), and each transaction must have the previously mentioned
      75             :    fields set.  Additionally, if the transaction txn[i] loads writable
      76             :    accounts from one or more address lookup tables, addtl_writable[i]
      77             :    must point to the first writable account address that it loaded.
      78             :    adtl_writable is indexed addtl_writable[i][j] for j in
      79             :    [0, TXN(txn[i])->addr_table_adtl_writable_cnt ).  If txn[i] does not
      80             :    load any accounts writably from address lookup tables or if the
      81             :    SANITIZE_SUCCESS flag is not set, adtl_writable[i] is ignored and can
      82             :    be NULL.  txn_cnt must be in [0, MAX_TXN_PER_MICROBLOCK], where
      83             :    txn_cnt==0 is a no-op.  txn and adtl_writable can be NULL if
      84             :    txn_cnt==0.
      85             : 
      86             :    This function does not retain any read interest in txn or
      87             :    adtl_writable after returning.
      88             : 
      89             :    Returns the number of times fd_pack_rebate_sum_report must be called
      90             :    before the next call to add_txn with a non-zero txn_cnt. */
      91             : ulong
      92             : fd_pack_rebate_sum_add_txn( fd_pack_rebate_sum_t         * s,
      93             :                             fd_txn_p_t     const         * txn,
      94             :                             fd_acct_addr_t const * const * adtl_writable,
      95             :                             ulong                          txn_cnt );
      96             : 
      97             : /* fd_pack_rebate_sum_report generates a rebate report from the state of
      98             :    the current rebate information.  s must point to a valid local join.
      99             :    out must point to a region of memory with at least USHORT_MAX bytes
     100             :    of capacity.  Returns the number of bytes that were written, which
     101             :    will be in [0, USHORT_MAX].  Updates the state of s so that
     102             :    subsequent calls to this function will write new information. */
     103             : ulong
     104             : fd_pack_rebate_sum_report( fd_pack_rebate_sum_t * s,
     105             :                            fd_pack_rebate_t     * out );
     106             : 
     107             : /* fd_pack_rebate_sum_clear clears the state of any pending rebates.
     108             :    Requires that s is a valid local join.  Given that, it's faster but
     109             :    equivalent to calling leave, delete, new, then join. */
     110             : void
     111             : fd_pack_rebate_sum_clear( fd_pack_rebate_sum_t * s );
     112             : 
     113             : #endif /* HEADER_fd_src_ballet_pack_fd_pack_rebate_sum_h */

Generated by: LCOV version 1.14