Skip to content

Commit 1e9971b

Browse files
address comments
1 parent 11274c7 commit 1e9971b

File tree

8 files changed

+93
-85
lines changed

8 files changed

+93
-85
lines changed

src/flamenco/runtime/context/fd_exec_instr_ctx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fd_exec_instr_ctx_delete( void * mem ) {
8484
int
8585
fd_exec_instr_ctx_find_idx_of_instr_account( fd_exec_instr_ctx_t const * ctx,
8686
fd_pubkey_t const * pubkey ) {
87-
for( int i = 0; i < ctx->instr->acct_cnt; i++ ) {
87+
for( int i=0; i<ctx->instr->acct_cnt; i++ ) {
8888
if( memcmp( pubkey->uc, ctx->instr->acct_pubkeys[i].uc, sizeof(fd_pubkey_t) )==0 ) {
8989
return i;
9090
}
@@ -120,7 +120,7 @@ fd_exec_instr_ctx_try_borrow_instr_account( fd_exec_instr_ctx_t const * ctx,
120120
fd_borrowed_account_t * account ) {
121121
/* Return a NotEnoughAccountKeys error if the idx is out of bounds.
122122
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L603 */
123-
if( FD_UNLIKELY( idx >= ctx->instr->acct_cnt ) ) {
123+
if( FD_UNLIKELY( idx>=ctx->instr->acct_cnt ) ) {
124124
return FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS;
125125
}
126126

@@ -140,7 +140,7 @@ int
140140
fd_exec_instr_ctx_try_borrow_instr_account_with_key( fd_exec_instr_ctx_t const * ctx,
141141
fd_pubkey_t const * pubkey,
142142
fd_borrowed_account_t * account ) {
143-
for( ulong i = 0; i < ctx->instr->acct_cnt; i++ ) {
143+
for( ulong i=0; i<ctx->instr->acct_cnt; i++ ) {
144144
if( memcmp( pubkey->uc, ctx->instr->acct_pubkeys[i].uc, sizeof(fd_pubkey_t) )==0 ) {
145145
return fd_exec_instr_ctx_try_borrow_instr_account( ctx, i, account );
146146
}

src/flamenco/runtime/context/fd_exec_txn_ctx.c

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ fd_exec_txn_ctx_get_account_at_index( fd_exec_txn_ctx_t * ctx,
9595
fd_txn_account_t * txn_account = &ctx->accounts[idx];
9696
*account = txn_account;
9797

98-
if( condition != NULL ) {
99-
if( FD_UNLIKELY( !condition( ctx, idx, *account ) ) )
98+
if( FD_LIKELY( condition != NULL ) ) {
99+
if( FD_UNLIKELY( !condition( ctx, idx, *account ) ) ) {
100100
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT;
101+
}
101102
}
102103

103104
return FD_ACC_MGR_SUCCESS;
@@ -134,14 +135,15 @@ fd_exec_txn_ctx_get_executable_account( fd_exec_txn_ctx_t * ctx,
134135
return FD_ACC_MGR_SUCCESS;
135136
}
136137

137-
for( ulong i = 0; i < ctx->executable_cnt; i++ ) {
138+
for( ulong i=0; i<ctx->executable_cnt; i++ ) {
138139
if( memcmp( pubkey->uc, ctx->executable_accounts[i].pubkey->uc, sizeof(fd_pubkey_t) )==0 ) {
139140
fd_txn_account_t * txn_account = &ctx->executable_accounts[i];
140141
*account = txn_account;
141142

142-
if( condition != NULL ) {
143-
if( FD_UNLIKELY( !condition( ctx, (int)i, *account ) ) )
143+
if( FD_LIKELY( condition != NULL ) ) {
144+
if( FD_UNLIKELY( !condition( ctx, (int)i, *account ) ) ) {
144145
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT;
146+
}
145147
}
146148

147149
return FD_ACC_MGR_SUCCESS;
@@ -152,99 +154,99 @@ fd_exec_txn_ctx_get_executable_account( fd_exec_txn_ctx_t * ctx,
152154
}
153155

154156
void
155-
fd_exec_txn_ctx_setup_basic( fd_exec_txn_ctx_t * txn_ctx ) {
156-
txn_ctx->compute_unit_limit = 200000;
157-
txn_ctx->compute_unit_price = 0;
158-
txn_ctx->compute_meter = 200000;
159-
txn_ctx->prioritization_fee_type = FD_COMPUTE_BUDGET_PRIORITIZATION_FEE_TYPE_DEPRECATED;
160-
txn_ctx->custom_err = UINT_MAX;
161-
162-
txn_ctx->instr_stack_sz = 0;
163-
txn_ctx->accounts_cnt = 0UL;
164-
txn_ctx->executable_cnt = 0UL;
165-
txn_ctx->paid_fees = 0UL;
166-
txn_ctx->heap_size = FD_VM_HEAP_DEFAULT;
167-
txn_ctx->loaded_accounts_data_size_limit = FD_VM_LOADED_ACCOUNTS_DATA_SIZE_LIMIT;
168-
txn_ctx->loaded_accounts_data_size = 0UL;
169-
txn_ctx->accounts_resize_delta = 0UL;
170-
txn_ctx->collected_rent = 0UL;
171-
172-
txn_ctx->num_instructions = 0;
173-
memset( txn_ctx->return_data.program_id.key, 0, sizeof(fd_pubkey_t) );
174-
txn_ctx->return_data.len = 0;
175-
176-
txn_ctx->dirty_vote_acc = 0;
177-
txn_ctx->dirty_stake_acc = 0;
178-
txn_ctx->failed_instr = NULL;
179-
txn_ctx->instr_err_idx = INT_MAX;
180-
txn_ctx->capture_ctx = NULL;
181-
182-
txn_ctx->instr_info_cnt = 0UL;
183-
txn_ctx->cpi_instr_info_cnt = 0UL;
184-
txn_ctx->instr_trace_length = 0UL;
185-
186-
txn_ctx->exec_err = 0;
187-
txn_ctx->exec_err_kind = FD_EXECUTOR_ERR_KIND_NONE;
157+
fd_exec_txn_ctx_setup_basic( fd_exec_txn_ctx_t * ctx ) {
158+
ctx->compute_unit_limit = 200000;
159+
ctx->compute_unit_price = 0;
160+
ctx->compute_meter = 200000;
161+
ctx->prioritization_fee_type = FD_COMPUTE_BUDGET_PRIORITIZATION_FEE_TYPE_DEPRECATED;
162+
ctx->custom_err = UINT_MAX;
163+
164+
ctx->instr_stack_sz = 0;
165+
ctx->accounts_cnt = 0UL;
166+
ctx->executable_cnt = 0UL;
167+
ctx->paid_fees = 0UL;
168+
ctx->heap_size = FD_VM_HEAP_DEFAULT;
169+
ctx->loaded_accounts_data_size_limit = FD_VM_LOADED_ACCOUNTS_DATA_SIZE_LIMIT;
170+
ctx->loaded_accounts_data_size = 0UL;
171+
ctx->accounts_resize_delta = 0UL;
172+
ctx->collected_rent = 0UL;
173+
174+
ctx->num_instructions = 0;
175+
memset( ctx->return_data.program_id.key, 0, sizeof(fd_pubkey_t) );
176+
ctx->return_data.len = 0;
177+
178+
ctx->dirty_vote_acc = 0;
179+
ctx->dirty_stake_acc = 0;
180+
ctx->failed_instr = NULL;
181+
ctx->instr_err_idx = INT_MAX;
182+
ctx->capture_ctx = NULL;
183+
184+
ctx->instr_info_cnt = 0UL;
185+
ctx->cpi_instr_info_cnt = 0UL;
186+
ctx->instr_trace_length = 0UL;
187+
188+
ctx->exec_err = 0;
189+
ctx->exec_err_kind = FD_EXECUTOR_ERR_KIND_NONE;
188190
}
189191

190192
void
191-
fd_exec_txn_ctx_setup( fd_exec_txn_ctx_t * txn_ctx,
193+
fd_exec_txn_ctx_setup( fd_exec_txn_ctx_t * ctx,
192194
fd_txn_t const * txn_descriptor,
193195
fd_rawtxn_b_t const * txn_raw ) {
194-
fd_exec_txn_ctx_setup_basic( txn_ctx );
195-
txn_ctx->txn_descriptor = txn_descriptor;
196-
txn_ctx->_txn_raw->raw = txn_raw->raw;
197-
txn_ctx->_txn_raw->txn_sz = txn_raw->txn_sz;
196+
fd_exec_txn_ctx_setup_basic( ctx );
197+
ctx->txn_descriptor = txn_descriptor;
198+
ctx->_txn_raw->raw = txn_raw->raw;
199+
ctx->_txn_raw->txn_sz = txn_raw->txn_sz;
198200
}
199201

200202
void
201-
fd_exec_txn_ctx_teardown( fd_exec_txn_ctx_t * txn_ctx ) {
202-
(void)txn_ctx;
203+
fd_exec_txn_ctx_teardown( fd_exec_txn_ctx_t * ctx ) {
204+
(void)ctx;
203205
}
204206

205207
void
206208
fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx,
207-
fd_exec_txn_ctx_t * txn_ctx,
209+
fd_exec_txn_ctx_t * ctx,
208210
fd_wksp_t const * funk_wksp,
209211
fd_wksp_t const * runtime_pub_wksp,
210212
ulong funk_txn_gaddr,
211213
ulong acc_mgr_gaddr,
212214
ulong sysvar_cache_gaddr,
213215
ulong funk_gaddr ) {
214216

215-
txn_ctx->runtime_pub_wksp = (fd_wksp_t *)runtime_pub_wksp;
217+
ctx->runtime_pub_wksp = (fd_wksp_t *)runtime_pub_wksp;
216218

217-
txn_ctx->funk_txn = fd_wksp_laddr( funk_wksp, funk_txn_gaddr );
218-
if( FD_UNLIKELY( !txn_ctx->funk_txn ) ) {
219+
ctx->funk_txn = fd_wksp_laddr( funk_wksp, funk_txn_gaddr );
220+
if( FD_UNLIKELY( !ctx->funk_txn ) ) {
219221
FD_LOG_ERR(( "Could not find valid funk transaction" ));
220222
}
221223

222-
txn_ctx->acc_mgr = fd_wksp_laddr( runtime_pub_wksp, acc_mgr_gaddr );
223-
if( FD_UNLIKELY( !txn_ctx->acc_mgr ) ) {
224+
ctx->acc_mgr = fd_wksp_laddr( runtime_pub_wksp, acc_mgr_gaddr );
225+
if( FD_UNLIKELY( !ctx->acc_mgr ) ) {
224226
FD_LOG_ERR(( "Could not find valid account manager" ));
225227
}
226-
txn_ctx->acc_mgr->funk = fd_wksp_laddr( funk_wksp, funk_gaddr );
228+
ctx->acc_mgr->funk = fd_wksp_laddr( funk_wksp, funk_gaddr );
227229

228-
txn_ctx->sysvar_cache = fd_wksp_laddr( runtime_pub_wksp, sysvar_cache_gaddr );
230+
ctx->sysvar_cache = fd_wksp_laddr( runtime_pub_wksp, sysvar_cache_gaddr );
229231

230-
txn_ctx->features = slot_ctx->epoch_ctx->features;
231-
txn_ctx->status_cache = slot_ctx->status_cache;
232+
ctx->features = slot_ctx->epoch_ctx->features;
233+
ctx->status_cache = slot_ctx->status_cache;
232234

233-
txn_ctx->bank_hash_cmp = slot_ctx->epoch_ctx->bank_hash_cmp;
235+
ctx->bank_hash_cmp = slot_ctx->epoch_ctx->bank_hash_cmp;
234236

235-
txn_ctx->prev_lamports_per_signature = slot_ctx->prev_lamports_per_signature;
236-
txn_ctx->enable_exec_recording = slot_ctx->enable_exec_recording;
237-
txn_ctx->total_epoch_stake = slot_ctx->epoch_ctx->total_epoch_stake;
237+
ctx->prev_lamports_per_signature = slot_ctx->prev_lamports_per_signature;
238+
ctx->enable_exec_recording = slot_ctx->enable_exec_recording;
239+
ctx->total_epoch_stake = slot_ctx->epoch_ctx->total_epoch_stake;
238240

239-
txn_ctx->slot = slot_ctx->slot_bank.slot;
240-
txn_ctx->fee_rate_governor = slot_ctx->slot_bank.fee_rate_governor;
241-
txn_ctx->block_hash_queue = slot_ctx->slot_bank.block_hash_queue; /* MAKE GLOBAL */
241+
ctx->slot = slot_ctx->slot_bank.slot;
242+
ctx->fee_rate_governor = slot_ctx->slot_bank.fee_rate_governor;
243+
ctx->block_hash_queue = slot_ctx->slot_bank.block_hash_queue; /* MAKE GLOBAL */
242244

243245
fd_epoch_bank_t const * epoch_bank = fd_exec_epoch_ctx_epoch_bank_const( slot_ctx->epoch_ctx );
244-
txn_ctx->schedule = epoch_bank->epoch_schedule;
245-
txn_ctx->rent = epoch_bank->rent;
246-
txn_ctx->slots_per_year = epoch_bank->slots_per_year;
247-
txn_ctx->stakes = epoch_bank->stakes;
246+
ctx->schedule = epoch_bank->epoch_schedule;
247+
ctx->rent = epoch_bank->rent;
248+
ctx->slots_per_year = epoch_bank->slots_per_year;
249+
ctx->stakes = epoch_bank->stakes;
248250

249251
}
250252

@@ -255,19 +257,19 @@ fd_exec_txn_ctx_reset_return_data( fd_exec_txn_ctx_t * txn_ctx ) {
255257

256258
/* https://github.com/anza-xyz/agave/blob/v2.1.1/sdk/program/src/message/versions/v0/loaded.rs#L162 */
257259
int
258-
fd_txn_account_is_demotion( fd_exec_txn_ctx_t const * txn_ctx, int idx )
260+
fd_txn_account_is_demotion( fd_exec_txn_ctx_t const * ctx, int idx )
259261
{
260262
uint is_program = 0U;
261-
for( ulong j=0UL; j<txn_ctx->txn_descriptor->instr_cnt; j++ ) {
262-
if( txn_ctx->txn_descriptor->instr[j].program_id == idx ) {
263+
for( ulong j=0UL; j<ctx->txn_descriptor->instr_cnt; j++ ) {
264+
if( ctx->txn_descriptor->instr[j].program_id == idx ) {
263265
is_program = 1U;
264266
break;
265267
}
266268
}
267269

268270
uint bpf_upgradeable_in_txn = 0U;
269-
for( ulong j = 0; j < txn_ctx->accounts_cnt; j++ ) {
270-
const fd_pubkey_t * acc = &txn_ctx->account_keys[j];
271+
for( ulong j=0; j<ctx->accounts_cnt; j++ ) {
272+
const fd_pubkey_t * acc = &ctx->account_keys[j];
271273
if ( memcmp( acc->uc, fd_solana_bpf_loader_upgradeable_program_id.key, sizeof(fd_pubkey_t) ) == 0 ) {
272274
bpf_upgradeable_in_txn = 1U;
273275
break;

src/flamenco/runtime/context/fd_exec_txn_ctx.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ fd_exec_txn_ctx_delete( void * mem );
217217
/* Sets up a basic transaction ctx without a txn descriptor or txn raw. Useful
218218
for mocking transaction context objects for instructions. */
219219
void
220-
fd_exec_txn_ctx_setup_basic( fd_exec_txn_ctx_t * txn_ctx );
220+
fd_exec_txn_ctx_setup_basic( fd_exec_txn_ctx_t * ctx );
221221

222222
void
223-
fd_exec_txn_ctx_setup( fd_exec_txn_ctx_t * txn_ctx,
223+
fd_exec_txn_ctx_setup( fd_exec_txn_ctx_t * ctx,
224224
fd_txn_t const * txn_descriptor,
225225
fd_rawtxn_b_t const * txn_raw );
226226

227227
void
228228
fd_exec_txn_ctx_from_exec_slot_ctx( fd_exec_slot_ctx_t const * slot_ctx,
229-
fd_exec_txn_ctx_t * txn_ctx,
229+
fd_exec_txn_ctx_t * ctx,
230230
fd_wksp_t const * funk_wksp,
231231
fd_wksp_t const * runtime_pub_wksp,
232232
ulong funk_txn_gaddr,
@@ -291,7 +291,7 @@ fd_exec_txn_ctx_get_executable_account( fd_exec_txn_ctx_t * ctx,
291291
fd_txn_account_condition_fn_t * condition );
292292

293293
void
294-
fd_exec_txn_ctx_reset_return_data( fd_exec_txn_ctx_t * txn_ctx );
294+
fd_exec_txn_ctx_reset_return_data( fd_exec_txn_ctx_t * ctx );
295295

296296
/* In agave, the writable accounts cache is populated by this below function.
297297
This cache is then referenced to determine if a transaction account is
@@ -307,7 +307,7 @@ fd_exec_txn_ctx_reset_return_data( fd_exec_txn_ctx_t * txn_ctx );
307307
/* https://github.com/anza-xyz/agave/blob/v2.1.1/sdk/program/src/message/versions/v0/loaded.rs#L137-L150 */
308308

309309
int
310-
fd_exec_txn_ctx_account_is_writable_idx( fd_exec_txn_ctx_t const * txn_ctx, int idx );
310+
fd_exec_txn_ctx_account_is_writable_idx( fd_exec_txn_ctx_t const * ctx, int idx );
311311

312312
/* Account pre-condition filtering functions
313313

src/flamenco/runtime/fd_borrowed_account.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ fd_borrowed_account_is_signer( fd_borrowed_account_t const * borrowed_acct ) {
305305
fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx;
306306
fd_instr_info_t const * instr = instr_ctx->instr;
307307

308+
/* The index in instruction is 1-indexed for instruction accounts, with the program account
309+
occupying index 0. */
308310
if( FD_UNLIKELY( borrowed_acct->index_in_instruction > instr_ctx->instr->acct_cnt ) ) {
309311
return 0;
310312
}
@@ -334,6 +336,8 @@ fd_borrowed_account_is_writable( fd_borrowed_account_t const * borrowed_acct ) {
334336
fd_exec_instr_ctx_t const * instr_ctx = borrowed_acct->instr_ctx;
335337
fd_instr_info_t const * instr = instr_ctx->instr;
336338

339+
/* The index in instruction is 1-indexed for instruction accounts, with the program account
340+
occupying index 0. */
337341
if( FD_UNLIKELY( borrowed_acct->index_in_instruction > instr_ctx->instr->acct_cnt ) ) {
338342
return 0;
339343
}

src/flamenco/runtime/fd_executor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ fd_executor_load_transaction_accounts( fd_exec_txn_ctx_t * txn_ctx ) {
444444
/* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/account_loader.rs#L429-L443 */
445445
for( ulong i=0UL; i<txn_ctx->accounts_cnt; i++ ) {
446446
fd_txn_account_t * acct = &txn_ctx->accounts[i];
447-
uchar unknown_acc = !!( fd_exec_txn_ctx_get_account_at_index( txn_ctx, (uchar)i, &acct, fd_txn_account_exists ) ||
448-
acct->const_meta->info.lamports==0UL );
447+
uchar unknown_acc = !!(fd_exec_txn_ctx_get_account_at_index( txn_ctx, (uchar)i, &acct, fd_txn_account_exists ) ||
448+
acct->const_meta->info.lamports==0UL);
449449
ulong acc_size = unknown_acc ? 0UL : acct->const_meta->dlen;
450450
uchar is_writable = !!( fd_exec_txn_ctx_account_is_writable_idx( txn_ctx, (int)i ) );
451451

src/flamenco/runtime/program/fd_bpf_loader_program.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,9 @@ fd_bpf_loader_program_execute( fd_exec_instr_ctx_t * ctx ) {
18391839
/* https://github.com/anza-xyz/agave/blob/v2.1.14/programs/bpf_loader/src/lib.rs#L403-L404 */
18401840
fd_guarded_borrowed_account_t program_account;
18411841
int err = fd_exec_instr_ctx_try_borrow_last_program_account( ctx, &program_account );
1842-
if( FD_UNLIKELY( err ) ) return err;
1842+
if( FD_UNLIKELY( err ) ) {
1843+
return err;
1844+
}
18431845

18441846
fd_pubkey_t const * program_id = &ctx->instr->program_id_pubkey;
18451847

src/flamenco/runtime/sysvar/fd_sysvar_instructions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fd_sysvar_instructions_serialize_account( fd_exec_txn_ctx_t * txn_ctx,
4343
&fd_sysvar_instructions_id,
4444
&rec,
4545
fd_txn_account_exists );
46-
if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS && rec == NULL ) ) {
46+
if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS && rec==NULL ) ) {
4747
/* The way we use this, this should NEVER hit since the borrowed accounts should be set up
4848
before this is called, and this is only called if the sysvar instructions account is in
4949
the borrowed accounts list. */
@@ -140,7 +140,7 @@ fd_sysvar_instructions_update_current_instr_idx( fd_exec_txn_ctx_t * txn_ctx,
140140
&fd_sysvar_instructions_id,
141141
&rec,
142142
NULL );
143-
if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) {
143+
if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) {
144144
/* https://github.com/anza-xyz/agave/blob/v2.2.0/svm/src/message_processor.rs#L40 */
145145
return FD_RUNTIME_TXN_ERR_INVALID_ACCOUNT_INDEX;
146146
}

src/flamenco/runtime/tests/fd_exec_instr_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ __wrap_fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
23002300
break;
23012301
}
23022302

2303-
/* Now borrow with is_writable check */
2303+
/* Now get account with is_writable check */
23042304
int err = fd_exec_txn_ctx_get_account_at_index( txn_ctx,
23052305
idx_in_txn,
23062306
/* Do not reallocate if data is not going to be modified */

0 commit comments

Comments
 (0)