LCOV - code coverage report
Current view: top level - flamenco/types - fd_types_custom.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 19 43 44.2 %
Date: 2024-11-13 11:58:15 Functions: 2 1045 0.2 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_types_custom
       2             : #define HEADER_fd_src_flamenco_runtime_fd_types_custom
       3             : 
       4             : #include "fd_types_meta.h"
       5             : #include "fd_bincode.h"
       6             : #include "../../ballet/ed25519/fd_ed25519.h"
       7             : #include "../../ballet/txn/fd_txn.h"
       8             : #include "../../util/net/fd_ip4.h"
       9             : 
      10       27495 : #define FD_HASH_FOOTPRINT (32UL)
      11       25188 : #define FD_HASH_ALIGN (8UL)
      12       14325 : #define FD_PUBKEY_FOOTPRINT FD_HASH_FOOTPRINT
      13       13818 : #define FD_PUBKEY_ALIGN FD_HASH_ALIGN
      14             : 
      15             : /* TODO this should not have packed alignment, but it's misused everywhere */
      16             : 
      17             : union __attribute__((packed)) fd_hash {
      18             :   uchar hash[ FD_HASH_FOOTPRINT ];
      19             :   uchar key [ FD_HASH_FOOTPRINT ]; // Making fd_hash and fd_pubkey interchangeable
      20             : 
      21             :   // Generic type specific accessors
      22             :   ulong ul  [ FD_HASH_FOOTPRINT / sizeof(ulong) ];
      23             :   uint  ui  [ FD_HASH_FOOTPRINT / sizeof(uint)  ];
      24             :   uchar uc  [ FD_HASH_FOOTPRINT ];
      25             : };
      26             : 
      27             : typedef union fd_hash fd_hash_t;
      28             : typedef union fd_hash fd_pubkey_t;
      29             : 
      30             : static const fd_pubkey_t pubkey_null = { 0 };
      31             : static const fd_hash_t   hash_null   = { 0 };
      32             : 
      33             : union fd_signature {
      34             :   uchar uc[ 64 ];
      35             :   ulong ul[  8 ];
      36             : };
      37             : 
      38             : typedef union fd_signature fd_signature_t;
      39             : 
      40             : FD_PROTOTYPES_BEGIN
      41             : 
      42             : #define fd_hash_check_zero(_x) (!((_x)->ul[0] | (_x)->ul[1] | (_x)->ul[2] | (_x)->ul[3]))
      43             : #define fd_hash_set_zero(_x)   {((_x)->ul[0] = 0); ((_x)->ul[1] = 0); ((_x)->ul[2] = 0); ((_x)->ul[3] = 0);}
      44             : 
      45      394263 : #define fd_pubkey_new              fd_hash_new
      46             : #define fd_pubkey_decode           fd_hash_decode
      47       38619 : #define fd_pubkey_decode_preflight fd_hash_decode_preflight
      48      752412 : #define fd_pubkey_decode_unsafe    fd_hash_decode_unsafe
      49       47601 : #define fd_pubkey_encode           fd_hash_encode
      50             : #define fd_pubkey_decode_archival  fd_hash_decode
      51           0 : #define fd_pubkey_encode_archival  fd_hash_encode
      52      173280 : #define fd_pubkey_destroy          fd_hash_destroy
      53       47367 : #define fd_pubkey_size             fd_hash_size
      54             : #define fd_pubkey_check_zero       fd_hash_check_zero
      55             : #define fd_pubkey_set_zero         fd_hash_set_zero
      56         153 : #define fd_pubkey_walk             fd_hash_walk
      57             : 
      58             : #define fd_hash_decode_archival             fd_hash_decode
      59           0 : #define fd_hash_decode_archival_preflight   fd_hash_decode_preflight
      60           0 : #define fd_hash_decode_archival_unsafe      fd_hash_decode_unsafe
      61           0 : #define fd_hash_encode_archival             fd_hash_encode
      62           0 : #define fd_pubkey_decode_archival_preflight fd_hash_decode_preflight
      63           0 : #define fd_pubkey_decode_archival_unsafe    fd_hash_decode_unsafe
      64             : 
      65             : struct __attribute__((aligned(8UL))) fd_option_slot {
      66             :   uchar is_some;
      67             :   ulong slot;
      68             : };
      69             : typedef struct fd_option_slot fd_option_slot_t;
      70             : 
      71             : /* Index structure needed for transaction status (metadata) blocks */
      72             : struct fd_txnstatusidx {
      73             :     fd_ed25519_sig_t sig;
      74             :     ulong offset;
      75             :     ulong status_sz;
      76             : };
      77             : typedef struct fd_txnstatusidx fd_txnstatusidx_t;
      78             : 
      79             : /* IPv4 ***************************************************************/
      80             : 
      81             : typedef uint fd_gossip_ip4_addr_t;
      82             : typedef uint fd_gossip_ip4_addr_t;
      83             : 
      84             : /* IPv6 ***************************************************************/
      85             : 
      86             : union fd_gossip_ip6_addr {
      87             :   uchar  uc[ 16 ];
      88             :   ushort us[  8 ];
      89             :   uint   ul[  4 ];
      90             : };
      91             : 
      92             : typedef union fd_gossip_ip6_addr fd_gossip_ip6_addr_t;
      93             : 
      94             : /* Solana account struct for vote accounts. */
      95             : /* Encoded Size: Fixed (113 bytes) */
      96             : struct __attribute__((aligned(8UL))) fd_solana_vote_account {
      97             :   ulong lamports;
      98             :   fd_pubkey_t node_pubkey;
      99             :   long last_timestamp_ts;
     100             :   ulong last_timestamp_slot;
     101             :   fd_pubkey_t owner;
     102             :   uchar executable;
     103             :   ulong rent_epoch;
     104             : };
     105             : typedef struct fd_solana_vote_account fd_solana_vote_account_t;
     106           0 : #define FD_SOLANA_VOTE_ACCOUNT_FOOTPRINT sizeof(fd_solana_vote_account_t)
     107           0 : #define FD_SOLANA_VOTE_ACCOUNT_ALIGN (8UL)
     108             : 
     109             : void
     110             : fd_solana_vote_account_new( fd_solana_vote_account_t * self );
     111             : 
     112             : int
     113             : fd_solana_vote_account_decode( fd_solana_vote_account_t * self, fd_bincode_decode_ctx_t * ctx );
     114             : 
     115             : #define fd_solana_vote_account_decode_archival fd_solana_vote_account_decode
     116             : 
     117             : int
     118             : fd_solana_vote_account_decode_preflight( fd_bincode_decode_ctx_t * ctx );
     119             : 
     120           0 : #define fd_solana_vote_account_decode_archival_preflight fd_solana_vote_account_decode_preflight
     121             : 
     122             : void
     123             : fd_solana_vote_account_decode_unsafe( fd_solana_vote_account_t * self, fd_bincode_decode_ctx_t * ctx );
     124             : 
     125           0 : #define fd_solana_vote_account_decode_archival_unsafe fd_solana_vote_account_decode_unsafe
     126             : 
     127             : int
     128             : fd_solana_vote_account_encode( fd_solana_vote_account_t const * self, fd_bincode_encode_ctx_t * ctx );
     129             : 
     130           0 : #define fd_solana_vote_account_encode_archival fd_solana_vote_account_encode
     131             : 
     132             : void
     133             : fd_solana_vote_account_destroy( fd_solana_vote_account_t * self, fd_bincode_destroy_ctx_t * ctx );
     134             : 
     135             : void
     136             : fd_solana_vote_account_walk( void * w, fd_solana_vote_account_t const * self, fd_types_walk_fn_t fun, const char *name, uint level );
     137             : 
     138             : ulong
     139             : fd_solana_vote_account_size( fd_solana_vote_account_t const * self );
     140             : 
     141             : ulong
     142             : fd_solana_vote_account_footprint( void );
     143             : 
     144             : ulong
     145             : fd_solana_vote_account_align( void );
     146             : 
     147             : /* Transaction wrapper ************************************************/
     148             : 
     149             : /* fd_flamenco_txn_t is yet another fd_txn_t wrapper.
     150             :    This should die as soon as we have a better stubs generator. */
     151             : 
     152             : struct fd_flamenco_txn {
     153             :   union {
     154             :     uchar                  txn_buf[ FD_TXN_MAX_SZ ];
     155             :     __extension__ fd_txn_t txn[0];
     156             :   };
     157             :   uchar raw[ FD_TXN_MTU ];
     158             :   ulong raw_sz;
     159             : };
     160             : 
     161             : typedef struct fd_flamenco_txn fd_flamenco_txn_t;
     162             : 
     163             : static inline void
     164           0 : fd_flamenco_txn_new( fd_flamenco_txn_t * self FD_FN_UNUSED ) {}
     165             : 
     166             : int
     167             : fd_flamenco_txn_decode( fd_flamenco_txn_t *       self,
     168             :                         fd_bincode_decode_ctx_t * ctx );
     169             : 
     170             : int
     171             : fd_flamenco_txn_decode_preflight( fd_bincode_decode_ctx_t * ctx );
     172             : 
     173             : void
     174             : fd_flamenco_txn_decode_unsafe( fd_flamenco_txn_t *       self,
     175             :                                fd_bincode_decode_ctx_t * ctx );
     176             : 
     177             : static inline void
     178             : fd_flamenco_txn_destroy( fd_flamenco_txn_t const *  self FD_FN_UNUSED,
     179           0 :                          fd_bincode_destroy_ctx_t * ctx  FD_FN_UNUSED ) {}
     180             : 
     181             : FD_FN_CONST static inline ulong
     182           0 : fd_flamenco_txn_size( fd_flamenco_txn_t const * self FD_FN_UNUSED ) {
     183           0 :   return self->raw_sz;
     184           0 : }
     185             : 
     186             : static inline int
     187             : fd_flamenco_txn_encode( fd_flamenco_txn_t const * self,
     188           0 :                         fd_bincode_encode_ctx_t * ctx ) {
     189           0 :   return fd_bincode_bytes_encode( self->raw, self->raw_sz, ctx );
     190           0 : }
     191             : 
     192             : static inline void
     193             : fd_flamenco_txn_walk( void *                    w,
     194             :                       fd_flamenco_txn_t const * self,
     195             :                       fd_types_walk_fn_t        fun,
     196             :                       char const *              name,
     197           9 :                       uint                      level ) {
     198             : 
     199           9 :   static uchar const zero[ 64 ]={0};
     200           9 :   fd_txn_t const *   txn  = self->txn;
     201           9 :   uchar const *      sig0 = zero;
     202             : 
     203           9 :   if( FD_LIKELY( txn->signature_cnt > 0 ) )
     204           9 :     sig0 = fd_txn_get_signatures( txn, self->raw )[0];
     205             : 
     206             :   /* For now, just print the transaction's signature */
     207           9 :   fun( w, sig0, name, FD_FLAMENCO_TYPE_SIG512, "txn", level );
     208           9 : }
     209             : 
     210             : /* Represents the lamport balance associated with an account. */
     211             : typedef ulong fd_acc_lamports_t;
     212             : 
     213             : #if FD_HAS_INT128
     214             : /********************* Rewards types **************************************************/
     215             : /* TODO: move these into fd_types, but first we need to add dlist support to fd_types */
     216             : struct __attribute__((aligned(8UL))) fd_stake_reward {
     217             :   /* dlist */
     218             :   ulong prev;
     219             :   ulong next;
     220             :   /* pool */
     221             :   ulong parent;
     222             :   /* data */
     223             :   fd_pubkey_t stake_pubkey;
     224             :   ulong credits_observed;
     225             :   ulong lamports;
     226             : };
     227             : typedef struct fd_stake_reward fd_stake_reward_t;
     228             : #define FD_STAKE_REWARD_FOOTPRINT sizeof(fd_stake_reward_t)
     229             : #define FD_STAKE_REWARD_ALIGN (8UL)
     230             : 
     231             : /* Encoded Size: Fixed (42 bytes) */
     232             : struct __attribute__((aligned(8UL))) fd_vote_reward {
     233             :   fd_pubkey_t pubkey;
     234             :   ulong vote_rewards;
     235             :   uchar commission;
     236             :   uchar needs_store;
     237             : };
     238             : typedef struct fd_vote_reward fd_vote_reward_t;
     239             : #define FD_VOTE_REWARD_FOOTPRINT sizeof(fd_vote_reward_t)
     240             : #define FD_VOTE_REWARD_ALIGN (8UL)
     241             : 
     242             : #define DLIST_NAME fd_stake_reward_dlist
     243             : #define DLIST_ELE_T fd_stake_reward_t
     244             : #include "../../util/tmpl/fd_dlist.c"
     245             : #undef DLIST_NAME
     246             : #undef DLIST_ELE_T
     247             : 
     248             : #define POOL_NAME fd_stake_reward_pool
     249           0 : #define POOL_T fd_stake_reward_t
     250           0 : #define POOL_NEXT parent
     251             : #include "../../util/tmpl/fd_pool.c"
     252             : #undef POOL_NAME
     253             : #undef POOL_T
     254             : #undef POOL_NEXT
     255             : 
     256             : typedef struct fd_vote_reward_t_mapnode fd_vote_reward_t_mapnode_t;
     257             : #define REDBLK_T fd_vote_reward_t_mapnode_t
     258             : #define REDBLK_NAME fd_vote_reward_t_map
     259             : #define REDBLK_IMPL_STYLE 1
     260             : #include "../../util/tmpl/fd_redblack.c"
     261             : #undef REDBLK_T
     262             : #undef REDBLK_NAME
     263             : struct fd_vote_reward_t_mapnode {
     264             :     fd_vote_reward_t elem;
     265             :     ulong redblack_parent;
     266             :     ulong redblack_left;
     267             :     ulong redblack_right;
     268             :     int redblack_color;
     269             : };
     270             : 
     271             : /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/points.rs#L21 */
     272             : /* Encoded Size: Fixed (24 bytes) */
     273             : struct __attribute__((aligned(8UL))) fd_point_value {
     274             :   ulong rewards;
     275             :   uint128 points;
     276             : };
     277             : typedef struct fd_point_value fd_point_value_t;
     278           0 : #define FD_POINT_VALUE_FOOTPRINT sizeof(fd_point_value_t)
     279             : #define FD_POINT_VALUE_ALIGN (8UL)
     280             : 
     281             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L56 */
     282             : /* Encoded Size: Dynamic */
     283             : struct __attribute__((aligned(8UL))) fd_partitioned_stake_rewards {
     284             :   ulong partitions_len;
     285             :   fd_stake_reward_dlist_t * partitions;
     286             :   fd_stake_reward_t * pool;
     287             : };
     288             : typedef struct fd_partitioned_stake_rewards fd_partitioned_stake_rewards_t;
     289           0 : #define FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT sizeof(fd_partitioned_stake_rewards_t)
     290             : #define FD_PARTITIONED_STAKE_REWARDS_ALIGN (8UL)
     291             : 
     292             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L131 */
     293             : /* Encoded Size: Dynamic */
     294             : struct __attribute__((aligned(8UL))) fd_stake_reward_calculation_partitioned {
     295             :   fd_partitioned_stake_rewards_t partitioned_stake_rewards;
     296             :   ulong total_stake_rewards_lamports;
     297             : };
     298             : typedef struct fd_stake_reward_calculation_partitioned fd_stake_reward_calculation_partitioned_t;
     299           0 : #define FD_STAKE_REWARD_CALCULATION_PARTITIONED_FOOTPRINT sizeof(fd_stake_reward_calculation_partitioned_t)
     300             : #define FD_STAKE_REWARD_CALCULATION_PARTITIONED_ALIGN (8UL)
     301             : 
     302             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L94 */
     303             : /* Encoded Size: Dynamic */
     304             : struct __attribute__((aligned(8UL))) fd_stake_reward_calculation {
     305             :   fd_stake_reward_dlist_t stake_rewards;
     306             :   ulong stake_rewards_len;
     307             :   fd_stake_reward_t * pool;
     308             :   ulong total_stake_rewards_lamports;
     309             : };
     310             : typedef struct fd_stake_reward_calculation fd_stake_reward_calculation_t;
     311             : #define FD_STAKE_REWARD_CALCULATION_FOOTPRINT sizeof(fd_stake_reward_calculation_t)
     312             : #define FD_STAKE_REWARD_CALCULATION_ALIGN (8UL)
     313             : 
     314             : /* Encoded Size: Dynamic */
     315             : struct __attribute__((aligned(8UL))) fd_calculate_stake_vote_rewards_result {
     316             :   fd_stake_reward_calculation_t stake_reward_calculation;
     317             :   fd_vote_reward_t_mapnode_t * vote_reward_map_pool;
     318             :   fd_vote_reward_t_mapnode_t * vote_reward_map_root;
     319             : };
     320             : typedef struct fd_calculate_stake_vote_rewards_result fd_calculate_stake_vote_rewards_result_t;
     321             : #define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_stake_vote_rewards_result_t)
     322             : #define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_ALIGN (8UL)
     323             : 
     324             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L102 */
     325             : /* Encoded Size: Dynamic */
     326             : struct __attribute__((aligned(8UL))) fd_calculate_validator_rewards_result {
     327             :   fd_calculate_stake_vote_rewards_result_t calculate_stake_vote_rewards_result;
     328             :   fd_point_value_t point_value;
     329             : };
     330             : typedef struct fd_calculate_validator_rewards_result fd_calculate_validator_rewards_result_t;
     331             : #define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_validator_rewards_result_t)
     332             : #define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_ALIGN (8UL)
     333             : 
     334             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L138 */
     335             : /* Encoded Size: Dynamic */
     336             : struct __attribute__((aligned(8UL))) fd_calculate_rewards_and_distribute_vote_rewards_result {
     337             :   ulong total_rewards;
     338             :   ulong distributed_rewards;
     339             :   fd_point_value_t point_value;
     340             :   fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition;
     341             : };
     342             : typedef struct fd_calculate_rewards_and_distribute_vote_rewards_result fd_calculate_rewards_and_distribute_vote_rewards_result_t;
     343             : #define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t)
     344             : #define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_ALIGN (8UL)
     345             : 
     346             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L118 */
     347             : /* Encoded Size: Dynamic */
     348             : struct __attribute__((aligned(8UL))) fd_partitioned_rewards_calculation {
     349             :   fd_vote_reward_t_mapnode_t * vote_reward_map_pool;
     350             :   fd_vote_reward_t_mapnode_t * vote_reward_map_root;
     351             :   fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition;
     352             :   ulong old_vote_balance_and_staked;
     353             :   ulong validator_rewards;
     354             :   double validator_rate;
     355             :   double foundation_rate;
     356             :   double prev_epoch_duration_in_years;
     357             :   ulong capitalization;
     358             :   fd_point_value_t point_value;
     359             : };
     360             : typedef struct fd_partitioned_rewards_calculation fd_partitioned_rewards_calculation_t;
     361             : #define FD_PARTITIONED_REWARDS_CALCULATION_FOOTPRINT sizeof(fd_partitioned_rewards_calculation_t)
     362             : #define FD_PARTITIONED_REWARDS_CALCULATION_ALIGN (8UL)
     363             : 
     364             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L60 */
     365             : /* Encoded Size: Dynamic */
     366             : struct __attribute__((aligned(8UL))) fd_start_block_height_and_rewards {
     367             :   ulong distribution_starting_block_height;
     368             :   fd_partitioned_stake_rewards_t partitioned_stake_rewards;
     369             : };
     370             : typedef struct fd_start_block_height_and_rewards fd_start_block_height_and_rewards_t;
     371             : #define FD_START_BLOCK_HEIGHT_AND_REWARDS_FOOTPRINT sizeof(fd_start_block_height_and_rewards_t)
     372             : #define FD_START_BLOCK_HEIGHT_AND_REWARDS_ALIGN (8UL)
     373             : 
     374             : union fd_epoch_reward_status_inner {
     375             :   fd_start_block_height_and_rewards_t Active;
     376             : };
     377             : typedef union fd_epoch_reward_status_inner fd_epoch_reward_status_inner_t;
     378             : 
     379             : /* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L70 */
     380             : struct fd_epoch_reward_status {
     381             :   uint discriminant;
     382             :   fd_epoch_reward_status_inner_t inner;
     383             : };
     384             : typedef struct fd_epoch_reward_status fd_epoch_reward_status_t;
     385             : #define FD_EPOCH_REWARD_STATUS_FOOTPRINT sizeof(fd_epoch_reward_status_t)
     386             : #define FD_EPOCH_REWARD_STATUS_ALIGN (8UL)
     387             : 
     388             : enum {
     389             : fd_epoch_reward_status_enum_Active = 0,
     390             : fd_epoch_reward_status_enum_Inactive = 1,
     391             : }; 
     392             : 
     393             : /*******************************************************************************************/
     394             : #endif
     395             : 
     396             : FD_PROTOTYPES_END
     397             : 
     398             : #endif /* HEADER_fd_src_flamenco_runtime_fd_types_custom */

Generated by: LCOV version 1.14