Line data Source code
1 : #include "fd_sysvar.h" 2 : #include "../context/fd_exec_epoch_ctx.h" 3 : #include "../context/fd_exec_slot_ctx.h" 4 : #include "fd_sysvar_rent.h" 5 : 6 : /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank.rs#L1813 */ 7 : int 8 : fd_sysvar_set( fd_exec_slot_ctx_t * slot_ctx, 9 : uchar const * owner, 10 : fd_pubkey_t const * pubkey, 11 : void const * data, 12 : ulong sz, 13 897834 : ulong slot ) { 14 : 15 897834 : fd_acc_mgr_t * acc_mgr = slot_ctx->acc_mgr; 16 897834 : fd_funk_txn_t * funk_txn = slot_ctx->funk_txn; 17 : 18 897834 : FD_BORROWED_ACCOUNT_DECL(rec); 19 : 20 897834 : int err = fd_acc_mgr_modify( acc_mgr, funk_txn, pubkey, 1, sz, rec ); 21 897834 : if( FD_UNLIKELY( err != FD_ACC_MGR_SUCCESS ) ) 22 0 : return FD_ACC_MGR_ERR_READ_FAILED; 23 : 24 897834 : fd_memcpy(rec->data, data, sz); 25 : 26 : /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank.rs#L1825 */ 27 897834 : fd_acc_lamports_t lamports_before = rec->meta->info.lamports; 28 897834 : fd_epoch_bank_t * epoch_bank = fd_exec_epoch_ctx_epoch_bank( slot_ctx->epoch_ctx ); 29 : /* https://github.com/anza-xyz/agave/blob/ae18213c19ea5335dfc75e6b6116def0f0910aff/runtime/src/bank.rs#L6184 30 : The account passed in via the updater is always the current sysvar account, so we take the max of the 31 : current account lamports and the minimum rent exempt balance needed. */ 32 897834 : fd_acc_lamports_t lamports_after = fd_ulong_max( lamports_before, fd_rent_exempt_minimum_balance( &epoch_bank->rent, sz ) ); 33 897834 : rec->meta->info.lamports = lamports_after; 34 : 35 : /* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank.rs#L1826 */ 36 897834 : if ( lamports_after > lamports_before ) { 37 65880 : slot_ctx->slot_bank.capitalization += ( lamports_after - lamports_before ); 38 831954 : } else if ( lamports_before < lamports_after ) { 39 0 : slot_ctx->slot_bank.capitalization -= ( lamports_before - lamports_after ); 40 0 : } 41 : 42 897834 : rec->meta->dlen = sz; 43 897834 : fd_memcpy(rec->meta->info.owner, owner, 32); 44 897834 : rec->meta->slot = slot; 45 897834 : return 0; 46 897834 : }