Skip to content

Commit

Permalink
flamenco: fix compute budget error code mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mjain-jump committed Oct 21, 2024
1 parent 9db2c8a commit 100b10e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
28998db63d8a506c7180c8d4e1dacfbdc6cf6e33
f46721d202e91423ad2c2aa2029c9e1f71c08375
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
dump/test-vectors/txn/fixtures/programs/1aef56362df9ae008fbd3d21fe0f5ca5c2bb93e8_1509242.fix
dump/test-vectors/txn/fixtures/programs/2418705d8008ed1bd58108b4e9ce43ae111a1cdc_1870939.fix
dump/test-vectors/txn/fixtures/programs/28c9bd56453eff58ad736c7ea4b8f61325a2fa5d_2050912.fix
dump/test-vectors/txn/fixtures/programs/2e6cbb44ce7014cd45620872b31af391476032a2_1684472.fix
dump/test-vectors/txn/fixtures/programs/308129c271ce81ab4b217bf262dd43e855b5b119_3709853.fix
dump/test-vectors/txn/fixtures/programs/31837b434273533d354985aa1dfdde5edf8fabe1_85273.fix
dump/test-vectors/txn/fixtures/programs/430c9cbdf850779d725e4b38340ce83f1bf59434_1313564.fix
dump/test-vectors/txn/fixtures/programs/475f33d2f9070eebe4934e34e92580b2ce0e7da1_3047163.fix
dump/test-vectors/txn/fixtures/programs/81e2a423431d64b80c68120e7e1e04d5829b7bbc_2924287.fix
dump/test-vectors/txn/fixtures/programs/871a9b0045d9a6f96f54fd5c78dad8a13b766889_437374.fix
dump/test-vectors/txn/fixtures/programs/923cbadb9bcfc4bfc32f3985b4faeade40521a38_2611281.fix
Expand Down
33 changes: 18 additions & 15 deletions src/flamenco/runtime/program/fd_compute_budget_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ sanitize_requested_heap_size( ulong bytes ) {
/* https://github.com/anza-xyz/agave/blob/16de8b75ebcd57022409b422de557dd37b1de8db/compute-budget/src/compute_budget_processor.rs#L69-L148 */
int
fd_executor_compute_budget_program_execute_instructions( fd_exec_txn_ctx_t * ctx, fd_rawtxn_b_t const * txn_raw ) {
uint has_compute_units_limit_update = 0UL;
uint has_compute_units_price_update = 0UL;
uint has_requested_heap_size = 0UL;
uint has_loaded_accounts_data_size_limit_update = 0UL;
uint has_compute_units_limit_update = 0UL;
uint has_compute_units_price_update = 0UL;
uint has_requested_heap_size = 0UL;
uint has_loaded_accounts_data_size_limit_update = 0UL;

uint num_non_compute_budget_instrs = 0U;
ushort requested_heap_size_instr_index = 0;
uint num_non_compute_budget_instrs = 0U;

uint updated_compute_unit_limit = 0U;
uint updated_requested_heap_size = 0U;
uint updated_loaded_accounts_data_size_limit = 0U;
ulong updated_compute_unit_price = 0UL;
uint updated_compute_unit_limit = 0U;
uint updated_requested_heap_size = 0U;
uint updated_loaded_accounts_data_size_limit = 0U;
ulong updated_compute_unit_price = 0UL;

uint prioritization_fee_type = FD_COMPUTE_BUDGET_PRIORITIZATION_FEE_TYPE_COMPUTE_UNIT_PRICE;

Expand Down Expand Up @@ -76,20 +77,17 @@ fd_executor_compute_budget_program_execute_instructions( fd_exec_txn_ctx_t * ctx

has_requested_heap_size = 1U;
updated_requested_heap_size = instruction.inner.request_heap_frame;
requested_heap_size_instr_index = i;

if( FD_UNLIKELY( !sanitize_requested_heap_size( updated_requested_heap_size ) ) ) {
FD_TXN_ERR_FOR_LOG_INSTR( ctx, FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA, i );
return FD_RUNTIME_TXN_ERR_INSTRUCTION_ERROR;
}
break;
}
case fd_compute_budget_program_instruction_enum_set_compute_unit_limit: {
if( FD_UNLIKELY( has_compute_units_limit_update ) ) {
return FD_RUNTIME_TXN_ERR_DUPLICATE_INSTRUCTION;
}

has_compute_units_limit_update = 1U;
updated_compute_unit_limit = instruction.inner.set_compute_unit_limit;
has_compute_units_limit_update = 1U;
updated_compute_unit_limit = instruction.inner.set_compute_unit_limit;

break;
}
Expand Down Expand Up @@ -121,7 +119,12 @@ fd_executor_compute_budget_program_execute_instructions( fd_exec_txn_ctx_t * ctx
}
}

/* https://github.com/anza-xyz/agave/blob/5535e79b8749f00d44e7d1524abcb56dad98ca75/runtime-transaction/src/compute_budget_instruction_details.rs#L51-L64 */
if( has_requested_heap_size ) {
if( FD_UNLIKELY( !sanitize_requested_heap_size( updated_requested_heap_size ) ) ) {
FD_TXN_ERR_FOR_LOG_INSTR( ctx, FD_EXECUTOR_INSTR_ERR_INVALID_INSTR_DATA, requested_heap_size_instr_index );
return FD_RUNTIME_TXN_ERR_INSTRUCTION_ERROR;
}
ctx->heap_size = updated_requested_heap_size;
}

Expand Down

0 comments on commit 100b10e

Please sign in to comment.