Line data Source code
1 : #include "fd_pack_test.h" 2 : #include "../../../ballet/pack/fd_compute_budget_program.h" 3 : 4 : ulong 5 : fd_exec_pack_cpb_test_run( fd_exec_instr_test_runner_t * _unused FD_PARAM_UNUSED, 6 : void const * input_, 7 : void ** output_, 8 : void * output_buf, 9 0 : ulong output_bufsz ){ 10 0 : fd_exec_test_pack_compute_budget_context_t const * input = fd_type_pun_const( input_ ); 11 0 : fd_exec_test_pack_compute_budget_effects_t ** output = fd_type_pun( output_ ); 12 : 13 0 : ulong output_end = (ulong) output_buf + output_bufsz; 14 0 : FD_SCRATCH_ALLOC_INIT( l, output_buf ); 15 : 16 0 : fd_exec_test_pack_compute_budget_effects_t * effects = 17 0 : FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_exec_test_pack_compute_budget_effects_t), 18 0 : sizeof (fd_exec_test_pack_compute_budget_effects_t) ); 19 0 : if( FD_UNLIKELY( _l > output_end ) ) { 20 0 : return 0UL; 21 0 : } 22 0 : *effects = (fd_exec_test_pack_compute_budget_effects_t) FD_EXEC_TEST_PACK_COMPUTE_BUDGET_EFFECTS_INIT_ZERO; 23 : 24 0 : fd_compute_budget_program_state_t cbp_state[1]; 25 0 : fd_compute_budget_program_init( cbp_state ); 26 0 : do { 27 : 28 0 : int ok = 1; 29 0 : for( ulong i=0UL; i<input->instr_datas_count; ++i ){ 30 0 : pb_bytes_array_t * instr_data = input->instr_datas[i]; 31 : // Reject if any of the instructions fail to parse 32 0 : if( !fd_compute_budget_program_parse( instr_data->bytes, instr_data->size, cbp_state ) ) { 33 0 : ok = 0; 34 0 : break; 35 0 : }; 36 0 : } 37 : 38 0 : if( !ok ) { 39 0 : effects->is_empty = 1; 40 0 : break; 41 0 : } 42 0 : ulong rewards; 43 0 : uint compute_unit_limit; 44 0 : fd_compute_budget_program_finalize( cbp_state, 45 0 : input->instr_datas_count, 46 0 : &rewards, 47 0 : &compute_unit_limit 48 0 : ); 49 0 : effects->rewards = rewards; 50 0 : effects->compute_unit_limit = compute_unit_limit; 51 : 52 : /* If not set, use defaults. See: 53 : https://github.com/firedancer-io/firedancer/blob/688cb04408cf20b0600d900900cdbebebd181e5b/src/ballet/pack/fd_compute_budget_program.h#L64-L70 54 : https://github.com/firedancer-io/agave/blob/838c1952595809a31520ff1603a13f2c9123aa51/runtime-transaction/src/compute_budget_instruction_details.rs#L49-L101 55 : */ 56 0 : effects->heap_sz = !!( cbp_state->flags & FD_COMPUTE_BUDGET_PROGRAM_FLAG_SET_HEAP ) ? cbp_state->heap_size : FD_VM_HEAP_DEFAULT; 57 0 : effects->loaded_acct_data_sz = !!( cbp_state->flags & FD_COMPUTE_BUDGET_PROGRAM_FLAG_SET_LOADED_DATA_SZ ) ? cbp_state->loaded_acct_data_sz : FD_COMPUTE_BUDGET_MAX_LOADED_DATA_SZ; 58 0 : } while(0); 59 : 60 0 : ulong actual_end = FD_SCRATCH_ALLOC_FINI( l, 1UL ); 61 : 62 0 : *output = effects; 63 0 : return actual_end - (ulong) output_buf; 64 : 65 0 : }