From b6c3b76bd1f0bfc223fc0a4b86f90d85974cd815 Mon Sep 17 00:00:00 2001 From: ibhatt-jumptrading Date: Wed, 31 Jul 2024 15:08:07 +0000 Subject: [PATCH] better rent epoch handling for LUT accounts and accounts that DNE --- src/flamenco/runtime/fd_acc_mgr.c | 5 ++- src/flamenco/runtime/fd_borrowed_account.c | 3 ++ src/flamenco/runtime/fd_executor.c | 45 ++++++++-------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/flamenco/runtime/fd_acc_mgr.c b/src/flamenco/runtime/fd_acc_mgr.c index c27ffc1691..6f7699c362 100644 --- a/src/flamenco/runtime/fd_acc_mgr.c +++ b/src/flamenco/runtime/fd_acc_mgr.c @@ -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" )); diff --git a/src/flamenco/runtime/fd_borrowed_account.c b/src/flamenco/runtime/fd_borrowed_account.c index 51bf01d2fc..4387d9cf66 100644 --- a/src/flamenco/runtime/fd_borrowed_account.c +++ b/src/flamenco/runtime/fd_borrowed_account.c @@ -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; diff --git a/src/flamenco/runtime/fd_executor.c b/src/flamenco/runtime/fd_executor.c index adb1ba60ad..4065d812ec 100644 --- a/src/flamenco/runtime/fd_executor.c +++ b/src/flamenco/runtime/fd_executor.c @@ -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 ); @@ -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; iaccounts_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; } } }