Line data Source code
1 : #include "fd_cost_harness.h" 2 : #include "fd_solfuzz_private.h" 3 : #include "fd_txn_harness.h" 4 : 5 : #include "../fd_cost_tracker.h" 6 : #include "../program/fd_compute_budget_program.h" 7 : 8 : int 9 : fd_solfuzz_pb_cost_run( fd_solfuzz_runner_t * runner, 10 : fd_exec_test_cost_context_t const * input, 11 0 : fd_exec_test_cost_result_t * output ) { 12 0 : if( FD_UNLIKELY( !input->has_tx || !input->has_features ) ) return 0; 13 : 14 0 : int ok = 0; 15 : 16 0 : fd_banks_clear_bank( runner->banks, runner->bank, 64UL ); 17 0 : runner->bank->f.slot = 1UL; 18 0 : FD_TEST( fd_solfuzz_pb_restore_features( &runner->bank->f.features, &input->features ) ); 19 : 20 0 : fd_txn_p_t * txn_p = fd_spad_alloc( runner->spad, alignof(fd_txn_p_t), sizeof(fd_txn_p_t) ); 21 0 : ulong txn_sz = fd_solfuzz_pb_txn_serialize( txn_p->payload, &input->tx ); 22 0 : if( FD_UNLIKELY( txn_sz==ULONG_MAX ) ) return 0; 23 : 24 0 : txn_p->payload_sz = txn_sz; 25 0 : if( FD_UNLIKELY( !fd_txn_parse( txn_p->payload, txn_p->payload_sz, TXN( txn_p ), NULL ) ) ) { 26 0 : return 0; 27 0 : } 28 : 29 0 : fd_txn_in_t txn_in = {0}; 30 0 : txn_in.txn = txn_p; 31 : 32 0 : fd_txn_out_t txn_out = {0}; 33 0 : fd_compute_budget_details_new( &txn_out.details.compute_budget ); 34 0 : txn_out.details.loaded_accounts_data_size = txn_out.details.compute_budget.loaded_accounts_data_size_limit; 35 0 : txn_out.details.is_simple_vote = fd_txn_is_simple_vote_transaction( TXN( txn_p ), txn_p->payload ); 36 : 37 0 : int err = fd_executor_compute_budget_program_execute_instructions( runner->bank, &txn_in, &txn_out ); 38 0 : if( FD_LIKELY( !err ) ) err = fd_sanitize_compute_unit_limits( &txn_out ); 39 0 : if( FD_UNLIKELY( err ) ) return 0; 40 : 41 0 : if( input->mode==FD_EXEC_TEST_TXN_COST_MODE_ACTUAL ) { 42 0 : ulong actual_cost = input->actual_programs_execution_cost; 43 0 : ulong limit = txn_out.details.compute_budget.compute_unit_limit; 44 0 : txn_out.details.compute_budget.compute_meter = fd_ulong_sat_sub( limit, fd_ulong_min( actual_cost, limit ) ); 45 0 : txn_out.details.loaded_accounts_data_size = (ulong)input->actual_loaded_accounts_data_size_bytes; 46 0 : } else { 47 0 : txn_out.details.loaded_accounts_data_size = txn_out.details.compute_budget.loaded_accounts_data_size_limit; 48 0 : } 49 : 50 0 : fd_cost_tracker_calculate_cost( runner->bank, &txn_in, &txn_out ); 51 : 52 0 : *output = (fd_exec_test_cost_result_t)FD_EXEC_TEST_COST_RESULT_INIT_ZERO; 53 0 : output->has_cost = 1; 54 0 : if( txn_out.details.txn_cost.type==FD_TXN_COST_TYPE_TRANSACTION ) { 55 0 : output->signature_cost = txn_out.details.txn_cost.transaction.signature_cost; 56 0 : output->write_lock_cost = txn_out.details.txn_cost.transaction.write_lock_cost; 57 0 : output->data_bytes_cost = txn_out.details.txn_cost.transaction.data_bytes_cost; 58 0 : output->programs_execution_cost = txn_out.details.txn_cost.transaction.programs_execution_cost; 59 0 : output->loaded_accounts_data_size_cost = txn_out.details.txn_cost.transaction.loaded_accounts_data_size_cost; 60 0 : output->allocated_accounts_data_size = txn_out.details.txn_cost.transaction.allocated_accounts_data_size; 61 0 : } else { 62 0 : output->signature_cost = FD_PACK_COST_PER_SIGNATURE; 63 0 : output->write_lock_cost = FD_WRITE_LOCK_UNITS * 2UL; 64 0 : output->data_bytes_cost = 0UL; 65 0 : output->programs_execution_cost = 0UL; 66 0 : output->loaded_accounts_data_size_cost = 8UL; 67 0 : output->allocated_accounts_data_size = 0UL; 68 0 : } 69 0 : output->total_cost = output->signature_cost + output->write_lock_cost + output->data_bytes_cost + output->programs_execution_cost + output->loaded_accounts_data_size_cost; 70 0 : ok = 1; 71 : 72 0 : return ok; 73 0 : }