LCOV - code coverage report
Current view: top level - flamenco/runtime/sysvar - fd_sysvar.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 18 22 81.8 %
Date: 2026-05-25 08:51:51 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "fd_sysvar.h"
       2             : #include "../fd_system_ids.h"
       3             : #include "../fd_runtime.h"
       4             : #include "../fd_accdb_svm.h"
       5             : #include "fd_sysvar_rent.h"
       6             : 
       7             : /* https://github.com/anza-xyz/agave/blob/v3.1/runtime/src/bank.rs#L2025 */
       8             : 
       9             : void
      10             : fd_sysvar_account_update( fd_bank_t *               bank,
      11             :                           fd_accdb_user_t *         accdb,
      12             :                           fd_funk_txn_xid_t const * xid,
      13             :                           fd_capture_ctx_t *        capture_ctx,
      14             :                           fd_pubkey_t const *       address,
      15             :                           void const *              data,
      16        4482 :                           ulong                     sz ) {
      17        4482 :   fd_rent_t const * rent    = &bank->f.rent;
      18             :   /* Newly created sysvar accounts get at least 1 lamport and capitalization
      19             :      increases by that amount. In Agave, adjust_sysvar_balance_for_rent()
      20             :      does max(rent_exempt_min, current_lamports), which in this case would
      21             :      yield 1 instead of 0. */
      22        4482 :   ulong     const   min_bal = fd_ulong_max( fd_rent_exempt_minimum_balance( rent, sz ), 1UL );
      23             : 
      24        4482 :   fd_accdb_svm_write(
      25        4482 :       accdb, bank, xid, capture_ctx,
      26        4482 :       address, &fd_sysvar_owner_id,
      27        4482 :       data, sz,
      28        4482 :       min_bal, 0,
      29        4482 :       FD_ACCDB_FLAG_CREATE|FD_ACCDB_FLAG_TRUNCATE
      30        4482 :   );
      31        4482 : }
      32             : 
      33             : int
      34             : fd_sysvar_instr_acct_check( fd_exec_instr_ctx_t const * ctx,
      35             :                             ulong                       idx,
      36          12 :                             fd_pubkey_t const *         addr_want ) {
      37             : 
      38          12 :   if( FD_UNLIKELY( idx >= ctx->instr->acct_cnt ) ) {
      39           0 :     return FD_EXECUTOR_INSTR_ERR_MISSING_ACC;
      40           0 :   }
      41             : 
      42          12 :   ushort idx_in_txn = ctx->instr->accounts[idx].index_in_transaction;
      43          12 :   fd_pubkey_t const * addr_have = &ctx->txn_out->accounts.keys[ idx_in_txn ];
      44          12 :   if( FD_UNLIKELY( 0!=memcmp( addr_have, addr_want, sizeof(fd_pubkey_t) ) ) ) {
      45           0 :     return FD_EXECUTOR_INSTR_ERR_INVALID_ARG;
      46           0 :   }
      47             : 
      48          12 :   return FD_EXECUTOR_INSTR_SUCCESS;
      49          12 : }

Generated by: LCOV version 1.14