LCOV - code coverage report
Current view: top level - flamenco/runtime/tests - fd_solfuzz_private.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 27 53 50.9 %
Date: 2026-03-19 18:19:27 Functions: 4 35 11.4 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h
       2             : #define HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h
       3             : 
       4             : /* fd_solfuzz_private.h contains internal components for the solfuzz
       5             :    Protobuf shim. */
       6             : 
       7             : #include "fd_solfuzz.h"
       8             : #include "../../features/fd_features.h"
       9             : #include "../../../ballet/nanopb/pb_encode.h"
      10             : #include "../../../ballet/nanopb/pb_decode.h"
      11             : #include "generated/context.pb.h"
      12             : 
      13             : #if FD_HAS_FLATCC
      14             : #include "flatcc/flatcc_builder.h"
      15             : #include "flatbuffers/generated/context_reader.h"
      16             : #endif
      17             : 
      18             : FD_PROTOTYPES_BEGIN
      19             : 
      20             : #undef ns
      21       22206 : #define SOL_COMPAT_NS(x) FLATBUFFERS_WRAP_NAMESPACE(fd_org_solana_sealevel_v2, x)
      22             : 
      23         950 : #define SOL_COMPAT_V2_SUCCESS (0)
      24             : #define SOL_COMPAT_V2_FAILURE (-1)
      25             : 
      26             : /* Creates / overwrites an account in funk given an input account state.
      27             :    On success, loads the account into acc.  Optionally, reject any
      28             :    zero-lamport accounts from being loaded in. */
      29             : int
      30             : fd_solfuzz_pb_load_account( fd_runtime_t *                    runtime,
      31             :                             fd_accdb_user_t *                 accdb,
      32             :                             fd_funk_txn_xid_t const *         xid,
      33             :                             fd_exec_test_acct_state_t const * state,
      34             :                             ulong                             acc_idx );
      35             : 
      36             : /* Restores the fee rate governor in the bank from the given protobuf
      37             :    fee rate governor. */
      38             : void
      39             : fd_solfuzz_pb_restore_fee_rate_governor( fd_bank_t *                              bank,
      40             :                                          fd_exec_test_fee_rate_governor_t const * fee_rate_governor );
      41             : 
      42             : /* Restores the epoch schedule in the bank from the given protobuf
      43             :    epoch schedule. */
      44             : void
      45             : fd_solfuzz_pb_restore_epoch_schedule( fd_bank_t *                           bank,
      46             :                                       fd_exec_test_epoch_schedule_t const * epoch_schedule );
      47             : 
      48             : /* Restores the rent parameters in the bank from the given protobuf
      49             :    rent. */
      50             : void
      51             : fd_solfuzz_pb_restore_rent( fd_bank_t *                 bank,
      52             :                             fd_exec_test_rent_t const * rent );
      53             : 
      54             : /* Initializes the blockhash queue in the bank from the given protobuf
      55             :    blockhash queue entries. */
      56             : void
      57             : fd_solfuzz_pb_restore_blockhash_queue( fd_bank_t *                                    bank,
      58             :                                        fd_exec_test_blockhash_queue_entry_t const *   entries,
      59             :                                        ulong                                          entries_cnt );
      60             : 
      61             : /* Retrieves the slot number from the clock sysvar account within the
      62             :    given account states list.  Throws FD_LOG_ERR if the clock sysvar
      63             :    is not found or is malformed. */
      64             : ulong
      65             : fd_solfuzz_pb_get_slot( fd_exec_test_acct_state_t const * acct_states,
      66             :                         ulong                             acct_states_cnt );
      67             : 
      68             : /* Activates features in the runtime given an input feature set.  Fails
      69             :    if a passed-in feature is unknown / not supported. */
      70             : int
      71             : fd_solfuzz_pb_restore_features( fd_features_t *                    features,
      72             :                                 fd_exec_test_feature_set_t const * feature_set );
      73             : 
      74             : #if FD_HAS_FLATCC
      75             : /* Flatbuffers variant of the above. This function call should never
      76             :    fail (all passed in features should be supported). Throws FD_LOG_ERR
      77             :    if any unsupported features are inputted. */
      78             : void
      79             : fd_solfuzz_fb_restore_features( fd_features_t *                   features,
      80             :                                 SOL_COMPAT_NS(FeatureSet_table_t) feature_set );
      81             : #endif
      82             : 
      83             : typedef ulong( exec_test_run_pb_fn_t )( fd_solfuzz_runner_t *,
      84             :                                         void const *,
      85             :                                         void **,
      86             :                                         void *,
      87             :                                         ulong );
      88             : 
      89             : static inline void
      90             : fd_solfuzz_pb_execute_wrapper( fd_solfuzz_runner_t *   runner,
      91             :                                void const *            input,
      92             :                                void **                 output,
      93       30037 :                                exec_test_run_pb_fn_t * exec_test_run_fn ) {
      94       30037 :   ulong out_bufsz = 100000000;  /* 100 MB */
      95       30037 :   void * out0 = fd_spad_alloc( runner->spad, 1UL, out_bufsz );
      96       30037 :   FD_TEST( out_bufsz <= fd_spad_alloc_max( runner->spad, 1UL ) );
      97             : 
      98       30037 :   ulong out_used = exec_test_run_fn( runner, input, output, out0, out_bufsz );
      99       30037 :   if( FD_UNLIKELY( !out_used ) ) {
     100           0 :     *output = NULL;
     101           0 :   }
     102       30037 : }
     103             : 
     104             : typedef int( exec_test_run_fb_fn_t )( fd_solfuzz_runner_t *, void const * );
     105             : 
     106             : #if FD_HAS_FLATCC
     107             : /* Returns SOL_COMPAT_V2_SUCCESS on success and SOL_COMPAT_V2_FAILURE on
     108             :    failure */
     109             : static inline int
     110             : fd_solfuzz_fb_execute_wrapper( fd_solfuzz_runner_t *   runner,
     111             :                                void const *            input,
     112         949 :                                exec_test_run_fb_fn_t * exec_test_run_fn ) {
     113         949 :   FD_SPAD_FRAME_BEGIN( runner->spad ) {
     114         949 :     flatcc_builder_reset( runner->fb_builder );
     115         949 :     return exec_test_run_fn( runner, input );
     116         949 :   } FD_SPAD_FRAME_END;
     117           0 : }
     118             : #endif /* FD_HAS_FLATCC */
     119             : 
     120             : /* Utils */
     121             : 
     122             : static FD_FN_UNUSED void *
     123             : sol_compat_decode_lenient( void *               decoded,
     124             :                            uchar const *        in,
     125             :                            ulong                in_sz,
     126       30037 :                            pb_msgdesc_t const * decode_type ) {
     127       30037 :   pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
     128       30037 :   int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
     129       30037 :   if( !decode_ok ) {
     130           0 :     pb_release( decode_type, decoded );
     131           0 :     return NULL;
     132           0 :   }
     133       30037 :   return decoded;
     134       30037 : }
     135             : 
     136             : static FD_FN_UNUSED void *
     137             : sol_compat_decode( void *               decoded,
     138             :                    uchar const *        in,
     139             :                    ulong                in_sz,
     140           0 :                    pb_msgdesc_t const * decode_type ) {
     141           0 :   pb_istream_t istream = pb_istream_from_buffer( in, in_sz );
     142           0 :   int decode_ok = pb_decode_ex( &istream, decode_type, decoded, PB_DECODE_NOINIT );
     143           0 :   if( !decode_ok ) {
     144           0 :     pb_release( decode_type, decoded );
     145           0 :     return NULL;
     146           0 :   }
     147           0 :   ulong size;
     148           0 :   if( FD_UNLIKELY( !pb_get_encoded_size( &size, decode_type, decoded ) ) ) {
     149           0 :     pb_release( decode_type, decoded );
     150           0 :     return NULL;
     151           0 :   }
     152           0 :   if( FD_UNLIKELY( size != in_sz ) ) {
     153           0 :     pb_release( decode_type, decoded );
     154           0 :     return NULL;
     155           0 :   }
     156           0 :   return decoded;
     157           0 : }
     158             : 
     159             : static FD_FN_UNUSED void const *
     160             : sol_compat_encode( uchar *              out,
     161             :                    ulong *              out_sz,
     162             :                    void const *         to_encode,
     163       49746 :                    pb_msgdesc_t const * encode_type ) {
     164       49746 :   pb_ostream_t ostream = pb_ostream_from_buffer( out, *out_sz );
     165       49746 :   int encode_ok = pb_encode( &ostream, encode_type, to_encode );
     166       49746 :   if( !encode_ok ) {
     167           0 :     return NULL;
     168           0 :   }
     169       49746 :   *out_sz = ostream.bytes_written;
     170       49746 :   return to_encode;
     171       49746 : }
     172             : 
     173             : FD_PROTOTYPES_END
     174             : 
     175             : #endif /* HEADER_fd_src_flamenco_runtime_tests_fd_solfuzz_private_h */

Generated by: LCOV version 1.14