Skip to content

Commit 3eb8920

Browse files
wip
1 parent c54cf3e commit 3eb8920

19 files changed

+129
-123
lines changed

src/discof/bank/fd_bank_tile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ handle_microblock( fd_bank_ctx_t * ctx,
267267
that first the non-alt accounts are laid out, then the writable
268268
alt accounts, and finally the read-only alt accounts. */
269269
fd_txn_t * txn_descriptor = TXN( &txn_ctx->txn );
270-
fd_acct_addr_t const * writable_alt = fd_type_pun_const( txn_ctx->account_keys+txn_descriptor->acct_addr_cnt );
270+
fd_acct_addr_t const * writable_alt = fd_type_pun_const( txn_ctx->accounts.account_keys+txn_descriptor->acct_addr_cnt );
271271
fd_pack_rebate_sum_add_txn( ctx->rebater, txn, &writable_alt, 1UL );
272272

273273
/* The VM will stop executing and fail an instruction immediately if
@@ -377,7 +377,7 @@ handle_bundle( fd_bank_ctx_t * ctx,
377377
continue;
378378
}
379379

380-
writable_alt[i] = fd_type_pun_const( txn_ctx->account_keys+TXN( &txn_ctx->txn )->acct_addr_cnt );
380+
writable_alt[i] = fd_type_pun_const( txn_ctx->accounts.account_keys+TXN( &txn_ctx->txn )->acct_addr_cnt );
381381
}
382382

383383
/* If all of the transactions in the bundle executed successfully, we

src/flamenco/log_collector/fd_log_collector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fd_log_collector_program_invoke( fd_exec_instr_ctx_t * ctx ) {
387387
return;
388388
}
389389

390-
fd_pubkey_t const * program_id_pubkey = &ctx->txn_ctx->account_keys[ ctx->instr->program_id ];
390+
fd_pubkey_t const * program_id_pubkey = &ctx->txn_ctx->accounts.account_keys[ ctx->instr->program_id ];
391391
/* Cache ctx->program_id_base58 */
392392
fd_base58_encode_32( program_id_pubkey->uc, NULL, ctx->program_id_base58 );
393393
/* Max msg_sz: 22 - 4 + 44 + 10 = 72 < 127 => we can use printf */

src/flamenco/runtime/context/fd_exec_instr_ctx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fd_exec_instr_ctx_find_idx_of_instr_account( fd_exec_instr_ctx_t const * ctx,
77
fd_pubkey_t const * pubkey ) {
88
for( int i=0; i<ctx->instr->acct_cnt; i++ ) {
99
ushort idx_in_txn = ctx->instr->accounts[ i ].index_in_transaction;
10-
if( memcmp( pubkey->uc, ctx->txn_ctx->account_keys[ idx_in_txn ].uc, sizeof(fd_pubkey_t) )==0 ) {
10+
if( memcmp( pubkey->uc, ctx->txn_ctx->accounts.account_keys[ idx_in_txn ].uc, sizeof(fd_pubkey_t) )==0 ) {
1111
return i;
1212
}
1313
}
@@ -100,7 +100,7 @@ fd_exec_instr_ctx_try_borrow_instr_account_with_key( fd_exec_instr_ctx_t const *
100100
fd_borrowed_account_t * account ) {
101101
for( ushort i=0; i<ctx->instr->acct_cnt; i++ ) {
102102
ushort idx_in_txn = ctx->instr->accounts[ i ].index_in_transaction;
103-
if( memcmp( pubkey->uc, ctx->txn_ctx->account_keys[ idx_in_txn ].uc, sizeof(fd_pubkey_t) )==0 ) {
103+
if( memcmp( pubkey->uc, ctx->txn_ctx->accounts.account_keys[ idx_in_txn ].uc, sizeof(fd_pubkey_t) )==0 ) {
104104
return fd_exec_instr_ctx_try_borrow_instr_account( ctx, i, account );
105105
}
106106
}
@@ -147,7 +147,7 @@ fd_exec_instr_ctx_any_signed( fd_exec_instr_ctx_t const * ctx,
147147
ushort idx_in_txn = ctx->instr->accounts[ j ].index_in_transaction;
148148
is_signer |=
149149
( ( !!fd_instr_acc_is_signer_idx( ctx->instr, j, NULL ) ) &
150-
( 0==memcmp( pubkey->key, ctx->txn_ctx->account_keys[ idx_in_txn ].key, sizeof(fd_pubkey_t) ) ) );
150+
( 0==memcmp( pubkey->key, ctx->txn_ctx->accounts.account_keys[ idx_in_txn ].key, sizeof(fd_pubkey_t) ) ) );
151151
}
152152
return is_signer;
153153
}

src/flamenco/runtime/context/fd_exec_txn_ctx.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ fd_exec_txn_ctx_get_account_at_index( fd_exec_txn_ctx_t * ctx,
6565
ushort idx,
6666
fd_txn_account_t * * account,
6767
fd_txn_account_condition_fn_t * condition ) {
68-
if( FD_UNLIKELY( idx>=ctx->accounts_cnt ) ) {
68+
if( FD_UNLIKELY( idx>=ctx->accounts.accounts_cnt ) ) {
6969
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT;
7070
}
7171

72-
fd_txn_account_t * txn_account = &ctx->accounts[idx];
72+
fd_txn_account_t * txn_account = &ctx->accounts.accounts[idx];
7373
*account = txn_account;
7474

7575
if( FD_LIKELY( condition != NULL ) ) {
@@ -112,9 +112,9 @@ fd_exec_txn_ctx_get_executable_account( fd_exec_txn_ctx_t * ctx,
112112
return FD_ACC_MGR_SUCCESS;
113113
}
114114

115-
for( ushort i=0; i<ctx->executable_cnt; i++ ) {
116-
if( memcmp( pubkey->uc, ctx->executable_accounts[i].pubkey->uc, sizeof(fd_pubkey_t) )==0 ) {
117-
fd_txn_account_t * txn_account = &ctx->executable_accounts[i];
115+
for( ushort i=0; i<ctx->accounts.executable_cnt; i++ ) {
116+
if( memcmp( pubkey->uc, ctx->accounts.accounts[i].pubkey->uc, sizeof(fd_pubkey_t) )==0 ) {
117+
fd_txn_account_t * txn_account = &ctx->accounts.accounts[i];
118118
*account = txn_account;
119119

120120
if( FD_LIKELY( condition != NULL ) ) {
@@ -136,20 +136,20 @@ fd_exec_txn_ctx_get_key_of_account_at_index( fd_exec_txn_ctx_t * ctx,
136136
fd_pubkey_t const * * key ) {
137137
/* Return a NotEnoughAccountKeys error if idx is out of bounds.
138138
https://github.com/anza-xyz/agave/blob/v2.1.14/sdk/src/transaction_context.rs#L218 */
139-
if( FD_UNLIKELY( idx>=ctx->accounts_cnt ) ) {
139+
if( FD_UNLIKELY( idx>=ctx->accounts.accounts_cnt ) ) {
140140
return FD_EXECUTOR_INSTR_ERR_NOT_ENOUGH_ACC_KEYS;
141141
}
142142

143-
*key = &ctx->account_keys[ idx ];
143+
*key = &ctx->accounts.account_keys[ idx ];
144144
return FD_EXECUTOR_INSTR_SUCCESS;
145145
}
146146

147147
void
148148
fd_exec_txn_ctx_setup_basic( fd_exec_txn_ctx_t * ctx ) {
149149
fd_compute_budget_details_new( &ctx->compute_budget_details );
150150
ctx->instr_stack_sz = 0;
151-
ctx->accounts_cnt = 0UL;
152-
ctx->executable_cnt = 0UL;
151+
ctx->accounts.accounts_cnt = 0UL;
152+
ctx->accounts.executable_cnt = 0UL;
153153
ctx->programs_to_reverify_cnt = 0UL;
154154

155155
ctx->loaded_accounts_data_size = 0UL;
@@ -213,10 +213,10 @@ fd_txn_account_has_bpf_loader_upgradeable( const fd_pubkey_t * account_keys,
213213
https://github.com/anza-xyz/agave/blob/v2.1.11/sdk/program/src/message/sanitized.rs#L38-L47 */
214214
int
215215
fd_exec_txn_ctx_account_is_writable_idx( fd_exec_txn_ctx_t const * txn_ctx, ushort idx ) {
216-
uint bpf_upgradeable = fd_txn_account_has_bpf_loader_upgradeable( txn_ctx->account_keys, txn_ctx->accounts_cnt );
216+
uint bpf_upgradeable = fd_txn_account_has_bpf_loader_upgradeable( txn_ctx->accounts.account_keys, txn_ctx->accounts.accounts_cnt );
217217
return fd_exec_txn_account_is_writable_idx_flat( fd_bank_slot_get( txn_ctx->bank ),
218218
idx,
219-
&txn_ctx->account_keys[idx],
219+
&txn_ctx->accounts.account_keys[idx],
220220
TXN( &txn_ctx->txn ),
221221
fd_bank_features_query( txn_ctx->bank ),
222222
bpf_upgradeable );

src/flamenco/runtime/context/fd_exec_txn_ctx.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ struct fd_exec_txn_ctx {
7171
Nonetheless, when Agave prepares a sanitized batch for execution and tries to lock accounts, a lower limit is enforced:
7272
https://github.com/anza-xyz/agave/blob/838c1952595809a31520ff1603a13f2c9123aa51/accounts-db/src/account_locks.rs#L118
7373
That is the limit we are going to use here. */
74-
ulong accounts_cnt; /* Number of account pubkeys accessed by this transaction. */
75-
fd_pubkey_t account_keys[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of account pubkeys accessed by this transaction. */
76-
fd_txn_account_t accounts[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of borrowed accounts accessed by this transaction. */
77-
ulong executable_cnt; /* Number of BPF upgradeable loader accounts. */
78-
fd_txn_account_t executable_accounts[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of BPF upgradeable loader program data accounts */
74+
75+
struct {
76+
ulong accounts_cnt; /* Number of account pubkeys accessed by this transaction. */
77+
fd_pubkey_t account_keys[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of account pubkeys accessed by this transaction. */
78+
fd_txn_account_t accounts[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of borrowed accounts accessed by this transaction. */
79+
ulong executable_cnt; /* Number of BPF upgradeable loader accounts. */
80+
fd_txn_account_t executable_accounts[ MAX_TX_ACCOUNT_LOCKS ]; /* Array of BPF upgradeable loader program data accounts */
81+
} accounts;
7982

8083
/* When a program is deployed or upgraded, we must queue it to be
8184
updated in the program cache (if it exists already) so that
@@ -235,8 +238,8 @@ fd_exec_txn_ctx_teardown( fd_exec_txn_ctx_t * txn_ctx );
235238
static inline int
236239
fd_exec_txn_ctx_find_index_of_account( fd_exec_txn_ctx_t const * ctx,
237240
fd_pubkey_t const * pubkey ) {
238-
for( ulong i=ctx->accounts_cnt; i>0UL; i-- ) {
239-
if( 0==memcmp( pubkey, &ctx->account_keys[ i-1UL ], sizeof(fd_pubkey_t) ) ) {
241+
for( ulong i=ctx->accounts.accounts_cnt; i>0UL; i-- ) {
242+
if( 0==memcmp( pubkey, &ctx->accounts.account_keys[ i-1UL ], sizeof(fd_pubkey_t) ) ) {
240243
return (int)(i-1UL);
241244
}
242245
}

src/flamenco/runtime/fd_cost_tracker.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,10 @@ would_fit( fd_cost_tracker_t const * cost_tracker,
384384
account_cost_map_t const * map = fd_type_pun_const(((cost_tracker_outer_t const *)cost_tracker)+1UL);
385385
account_cost_t const * pool = fd_type_pun_const( (void*)((ulong)cost_tracker + ((cost_tracker_outer_t const *)cost_tracker)->pool_offset) );
386386

387-
for( ulong i=0UL; i<txn_ctx->accounts_cnt; i++ ) {
387+
for( ulong i=0UL; i<txn_ctx->accounts.accounts_cnt; i++ ) {
388388
if( !fd_exec_txn_ctx_account_is_writable_idx( txn_ctx, (ushort)i ) ) continue;
389389

390-
fd_pubkey_t const * writable_acc = &txn_ctx->account_keys[i];
390+
fd_pubkey_t const * writable_acc = &txn_ctx->accounts.account_keys[i];
391391

392392
account_cost_t const * chained_cost = account_cost_map_ele_query_const( map, writable_acc, NULL, pool );
393393
if( FD_UNLIKELY( chained_cost && fd_ulong_sat_add( chained_cost->cost, cost )>cost_tracker->account_cost_limit ) ) {
@@ -408,10 +408,10 @@ add_transaction_execution_cost( fd_cost_tracker_t * _cost_tracker,
408408
account_cost_map_t * map = fd_type_pun( cost_tracker+1UL );
409409
account_cost_t * pool = fd_type_pun( (void*)((ulong)cost_tracker+cost_tracker->pool_offset) );
410410

411-
for( ulong i=0UL; i<txn_ctx->accounts_cnt; i++ ) {
411+
for( ulong i=0UL; i<txn_ctx->accounts.accounts_cnt; i++ ) {
412412
if( FD_LIKELY( !fd_exec_txn_ctx_account_is_writable_idx( txn_ctx, (ushort)i ) ) ) continue;
413413

414-
fd_pubkey_t const * writable_acc = &txn_ctx->account_keys[i];
414+
fd_pubkey_t const * writable_acc = &txn_ctx->accounts.account_keys[i];
415415

416416
account_cost_t * account_cost = account_cost_map_ele_query( map, writable_acc, NULL, pool );
417417
if( FD_UNLIKELY( !account_cost ) ) {

0 commit comments

Comments
 (0)