Skip to content

Commit

Permalink
better rent epoch handling for LUT accounts and accounts that DNE
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhatt-jumptrading committed Jul 31, 2024
1 parent 2e34a09 commit b6c3b76
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
5 changes: 3 additions & 2 deletions src/flamenco/runtime/fd_acc_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ fd_acc_mgr_modify_raw( fd_acc_mgr_t * acc_mgr,

fd_account_meta_t * ret = fd_funk_val( rec, fd_funk_wksp( funk ) );

if( do_create && ret->magic == 0 )
fd_account_meta_init(ret);
if( do_create && ret->magic==0UL ) {
fd_account_meta_init( ret );
}

if( ret->magic != FD_ACCOUNT_META_MAGIC )
FD_LOG_ERR(( "bad magic" ));
Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/runtime/fd_borrowed_account.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ fd_borrowed_account_make_modifiable( fd_borrowed_account_t * borrowed_account,
} else {
/* Account did not exist, set up metadata */
fd_account_meta_init( (fd_account_meta_t *)new_raw_data );
/* All new accounts are rent-exempt, so set it up accordingly. Currently,
this can't be done in fd_account_meta_init. */
((fd_account_meta_t *)new_raw_data)->info.rent_epoch = ULONG_MAX;
}

borrowed_account->const_meta = borrowed_account->meta = (fd_account_meta_t *)new_raw_data;
Expand Down
45 changes: 17 additions & 28 deletions src/flamenco/runtime/fd_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,13 +833,9 @@ fd_executor_setup_borrowed_accounts_for_txn( fd_exec_txn_ctx_t * txn_ctx ) {
fd_pubkey_t * acc = &txn_ctx->accounts[i];

fd_borrowed_account_t * borrowed_account = fd_borrowed_account_init( &txn_ctx->borrowed_accounts[i] );
int err = fd_acc_mgr_view( txn_ctx->acc_mgr, txn_ctx->funk_txn, acc, borrowed_account );
fd_acc_mgr_view( txn_ctx->acc_mgr, txn_ctx->funk_txn, acc, borrowed_account );
memcpy(borrowed_account->pubkey->key, acc, sizeof(*acc));

if( FD_UNLIKELY( err ) ) {
// FD_LOG_WARNING(( "fd_acc_mgr_view(%32J) failed (%d-%s)", acc->uc, err, fd_acc_mgr_strerror( err ) ));
}

if( fd_txn_account_is_writable_idx( txn_ctx, (int)i ) ) {
void * borrowed_account_data = fd_valloc_malloc( txn_ctx->valloc, 8UL, fd_borrowed_account_raw_size( borrowed_account ) );
fd_borrowed_account_make_modifiable( borrowed_account, borrowed_account_data );
Expand Down Expand Up @@ -1016,31 +1012,24 @@ fd_execute_txn_prepare_phase3( fd_exec_slot_ctx_t * slot_ctx,
}

int
fd_execute_txn_prepare_phase4( fd_exec_slot_ctx_t * slot_ctx,
fd_execute_txn_prepare_phase4( fd_exec_slot_ctx_t * FD_FN_UNUSED slot_ctx,
fd_exec_txn_ctx_t * txn_ctx ) {
/* Setup all borrowed accounts used in the transaction. */
fd_executor_setup_borrowed_accounts_for_txn( txn_ctx );
/* Update rent exempt on writable accounts if feature activated
TODO this should probably not run on executable accounts
Also iterate over LUT accounts */
if( FD_FEATURE_ACTIVE( slot_ctx, set_exempt_rent_epoch_max ) ) {
fd_pubkey_t * tx_accs = (fd_pubkey_t *)((uchar *)txn_ctx->_txn_raw->raw + txn_ctx->txn_descriptor->acct_addr_off);
for( fd_txn_acct_iter_t ctrl = fd_txn_acct_iter_init( txn_ctx->txn_descriptor, FD_TXN_ACCT_CAT_WRITABLE );
ctrl != fd_txn_acct_iter_end(); ctrl=fd_txn_acct_iter_next( ctrl ) ) {
ulong i = fd_txn_acct_iter_idx( ctrl );
if( (i == 0) || fd_pubkey_is_sysvar_id( &tx_accs[i] ) )
continue;
fd_txn_set_exempt_rent_epoch_max( txn_ctx, &tx_accs[i] );
}
}

for( ulong i = 0; i < txn_ctx->accounts_cnt; i++ ) {
txn_ctx->unknown_accounts[i] = 0;
txn_ctx->nonce_accounts[i] = 0;
if (fd_txn_is_writable(txn_ctx->txn_descriptor, (int)i)) {
FD_BORROWED_ACCOUNT_DECL(writable_new);
int err = fd_acc_mgr_view(txn_ctx->acc_mgr, txn_ctx->funk_txn, &txn_ctx->accounts[i], writable_new);
if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) {
txn_ctx->unknown_accounts[i] = 1;
/* Update rent exempt on writable accounts if feature activated. All
writable accounts that don't exist, will already be marked as being
rent exempt (rent_epoch==ULONG_MAX). */
for( ulong i=0UL; i<txn_ctx->accounts_cnt; i++ ) {
txn_ctx->unknown_accounts[ i ] = 0;
txn_ctx->nonce_accounts [ i ] = 0;
if( fd_txn_is_writable( txn_ctx->txn_descriptor, (int)i ) ) {
if( FD_UNLIKELY( i!=0UL && !fd_pubkey_is_sysvar_id( &txn_ctx->accounts[ i ] ) ) ) {
fd_txn_set_exempt_rent_epoch_max( txn_ctx, &txn_ctx->accounts[ i ] );
}
FD_BORROWED_ACCOUNT_DECL( writable_new );
int err = fd_acc_mgr_view( txn_ctx->acc_mgr, txn_ctx->funk_txn, &txn_ctx->accounts[ i ], writable_new );
if( FD_UNLIKELY( err!=FD_ACC_MGR_SUCCESS ) ) {
txn_ctx->unknown_accounts[ i ] = 1;
}
}
}
Expand Down

0 comments on commit b6c3b76

Please sign in to comment.