LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_txn_account.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 4 4 100.0 %
Date: 2025-09-18 04:41:32 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_runtime_fd_txn_account_h
       2             : #define HEADER_fd_src_flamenco_runtime_fd_txn_account_h
       3             : 
       4             : #include "../../ballet/txn/fd_txn.h"
       5             : #include "../fd_flamenco_base.h"
       6             : #include "program/fd_program_util.h"
       7             : #include "fd_executor_err.h"
       8             : #include "../types/fd_types.h"
       9             : #include "../../funk/fd_funk_rec.h"
      10             : 
      11             : struct fd_acc_mgr;
      12             : typedef struct fd_acc_mgr fd_acc_mgr_t;
      13             : 
      14             : /* fd_txn_account_t is a wrapper around a database record. It is used to
      15             :    provide an interface for an account during transaction execution
      16             :    along with reference counting semantics. The fd_txn_account_t object
      17             :    is initialized with a pointer to the account's metadata and data, the
      18             :    wksp that the data belongs to, its pubkey, and if the transaction
      19             :    account is mutable.
      20             : 
      21             :    fd_txn_account_t is NOT thread-safe and only supports a single join
      22             :    at a given time.
      23             : 
      24             :    TODO: Consider changing the meta/data boundary to make it more
      25             :    explicit that the caller passes in a contigious region of memory
      26             :    which has to correspond to the meta/data layout.
      27             : 
      28             :    TODO: Consider making the fd_txn_account struct private */
      29             : 
      30             : struct __attribute__((aligned(8UL))) fd_txn_account {
      31             :   ulong                           magic;
      32             : 
      33             :   fd_pubkey_t                     pubkey[1];
      34             : 
      35             :   fd_account_meta_t *             meta;
      36             :   uchar *                         data;
      37             : 
      38             :   int                             is_mutable;
      39             : 
      40             :   ulong                           meta_gaddr;
      41             :   ulong                           data_gaddr;
      42             : 
      43             :   ulong                           starting_dlen;
      44             :   ulong                           starting_lamports;
      45             : 
      46             :   /* Provide borrowing semantics. Used for single-threaded logic only,
      47             :      thus not comparable to a data synchronization lock. */
      48             :   ushort                          refcnt_excl;
      49             : 
      50             : };
      51             : typedef struct fd_txn_account fd_txn_account_t;
      52           3 : #define FD_TXN_ACCOUNT_FOOTPRINT (sizeof(fd_txn_account_t))
      53           3 : #define FD_TXN_ACCOUNT_ALIGN     (8UL)
      54        1020 : #define FD_TXN_ACCOUNT_MAGIC     (0xF15EDF1C51F51AA1UL)
      55             : 
      56        4689 : #define FD_TXN_ACCOUNT_DECL(_x)  fd_txn_account_t _x[1];
      57             : 
      58             : FD_PROTOTYPES_BEGIN
      59             : 
      60             : /* fd_txn_account_new lays out the memory required for a
      61             :    fd_txn_account object. The caller should only use the struct
      62             :    after it has been joined. fd_txn_account_t makes the assumption
      63             :    that the account data is laid out directly after the account meta.
      64             :    After a successful call to fd_txn_account_new, the object will now
      65             :    own the account's metadata and data. */
      66             : 
      67             : void *
      68             : fd_txn_account_new( void *              mem,
      69             :                     fd_pubkey_t const * pubkey,
      70             :                     fd_account_meta_t * meta,
      71             :                     int                 is_mutable );
      72             : 
      73             : /* fd_txn_account_join joins a thread with an indepedent address space
      74             :    to the memory region allocated by fd_txn_account_new. There can be
      75             :    only ONE valid join per fd_txn_account_t object. If a _join is called
      76             :    from one thread, it is implied that the object is no longer valid
      77             :    on other threads.
      78             : 
      79             :    TODO: When the new db is introduced, the wksp argument should be
      80             :    removed in favor of using offsets into other data structures. */
      81             : 
      82             : fd_txn_account_t *
      83             : fd_txn_account_join( void * mem, fd_wksp_t * data_wksp );
      84             : 
      85             : /* fd_txn_account_leave leaves a current local join and returns a
      86             :    pointer to the underlying shared memory region. The fd_txn_account_t
      87             :    will still own the account's metadata and data. */
      88             : 
      89             : void *
      90             : fd_txn_account_leave( fd_txn_account_t * acct );
      91             : 
      92             : /* fd_txn_account_delete removes the memory layout for the
      93             :    fd_txn_account_t object. It returns a pointer to the underlying
      94             :    shared struct. Any attempts to join after a call to
      95             :    fd_txn_account_delete will fail. The account's metadata and data
      96             :    will be owned by the caller after the delete is called.  */
      97             : 
      98             : void *
      99             : fd_txn_account_delete( void * mem );
     100             : 
     101             : /* Factory constructors from funk.
     102             :    TODO: These need to be removed when a new db is introduced and either
     103             :    replaced with a new factory constructor or removed entirely in favor
     104             :    of the generic constructors defined above. */
     105             : 
     106             : /* fd_txn_account_init_from_funk_readonly initializes a fd_txn_account_t
     107             :    object with a readonly handle into its funk record.
     108             : 
     109             :    IMPORTANT: When we access the account metadata and data pointer later
     110             :    on in the execution pipeline, we assume that nothing else will change
     111             :    these.
     112             : 
     113             :    This is safe because we assume that we hold a read lock on the
     114             :    account, since we are inside a Solana transaction. */
     115             : 
     116             : int
     117             : fd_txn_account_init_from_funk_readonly( fd_txn_account_t *    acct,
     118             :                                         fd_pubkey_t const *   pubkey,
     119             :                                         fd_funk_t const *     funk,
     120             :                                         fd_funk_txn_t const * funk_txn );
     121             : 
     122             : /* fd_txn_account_init_from_funk_mutable initializes a fd_txn_account_t
     123             :    object with a mutable handle into its funk record.
     124             : 
     125             :    IMPORTANT: Cannot be called in the executor tile. */
     126             : 
     127             : int
     128             : fd_txn_account_init_from_funk_mutable( fd_txn_account_t *      acct,
     129             :                                        fd_pubkey_t const *     pubkey,
     130             :                                        fd_funk_t *             funk,
     131             :                                        fd_funk_txn_t *         funk_txn,
     132             :                                        int                     do_create,
     133             :                                        ulong                   min_data_sz,
     134             :                                        fd_funk_rec_prepare_t * prepare_out );
     135             : 
     136             : /* Publishes the record contents of a mutable fd_txn_account_t object
     137             :    obtained from fd_txn_account_init_from_funk_mutable into funk
     138             :    if the record does not yet exist in the current funk txn.
     139             :    ie. the record was created / cloned from an ancestor funk txn
     140             :    by fd_txn_account_init_from_funk_mutable. */
     141             : 
     142             : void
     143             : fd_txn_account_mutable_fini( fd_txn_account_t *      acct,
     144             :                              fd_funk_t *             funk,
     145             :                              fd_funk_txn_t *         txn,
     146             :                              fd_funk_rec_prepare_t * prepare );
     147             : 
     148             : /* Simple accesssors and mutators. */
     149             : 
     150             : fd_pubkey_t const *
     151             : fd_txn_account_get_owner( fd_txn_account_t const * acct );
     152             : 
     153             : fd_account_meta_t const *
     154             : fd_txn_account_get_meta( fd_txn_account_t const * acct );
     155             : 
     156             : uchar const *
     157             : fd_txn_account_get_data( fd_txn_account_t const * acct );
     158             : 
     159             : uchar *
     160             : fd_txn_account_get_data_mut( fd_txn_account_t const * acct );
     161             : 
     162             : ulong
     163             : fd_txn_account_get_data_len( fd_txn_account_t const * acct );
     164             : 
     165             : int
     166             : fd_txn_account_is_executable( fd_txn_account_t const * acct );
     167             : 
     168             : ulong
     169             : fd_txn_account_get_lamports( fd_txn_account_t const * acct );
     170             : 
     171             : ulong
     172             : fd_txn_account_get_rent_epoch( fd_txn_account_t const * acct );
     173             : 
     174             : void
     175             : fd_txn_account_set_meta( fd_txn_account_t * acct, fd_account_meta_t * meta );
     176             : 
     177             : void
     178             : fd_txn_account_set_executable( fd_txn_account_t * acct, int is_executable );
     179             : 
     180             : void
     181             : fd_txn_account_set_owner( fd_txn_account_t * acct, fd_pubkey_t const * owner );
     182             : 
     183             : void
     184             : fd_txn_account_set_lamports( fd_txn_account_t * acct, ulong lamports );
     185             : 
     186             : int
     187             : fd_txn_account_checked_add_lamports( fd_txn_account_t * acct, ulong lamports );
     188             : 
     189             : int
     190             : fd_txn_account_checked_sub_lamports( fd_txn_account_t * acct, ulong lamports );
     191             : 
     192             : void
     193             : fd_txn_account_set_data( fd_txn_account_t * acct,
     194             :                          void const *       data,
     195             :                          ulong              data_sz );
     196             : 
     197             : void
     198             : fd_txn_account_set_data_len( fd_txn_account_t * acct, ulong data_len );
     199             : 
     200             : void
     201             : fd_txn_account_set_slot( fd_txn_account_t * acct,
     202             :                          ulong              slot );
     203             : 
     204             : void
     205             : fd_txn_account_clear_owner( fd_txn_account_t * acct );
     206             : 
     207             : void
     208             : fd_txn_account_resize( fd_txn_account_t * acct, ulong dlen );
     209             : 
     210             : ushort
     211             : fd_txn_account_is_borrowed( fd_txn_account_t const * acct );
     212             : 
     213             : int
     214             : fd_txn_account_is_mutable( fd_txn_account_t const * acct );
     215             : 
     216             : int
     217             : fd_txn_account_is_readonly( fd_txn_account_t const * acct );
     218             : 
     219             : int
     220             : fd_txn_account_try_borrow_mut( fd_txn_account_t * acct );
     221             : 
     222             : void
     223             : fd_txn_account_drop( fd_txn_account_t * acct );
     224             : 
     225             : void
     226             : fd_txn_account_set_readonly( fd_txn_account_t * acct );
     227             : 
     228             : void
     229             : fd_txn_account_set_mutable( fd_txn_account_t * acct );
     230             : 
     231             : fd_solana_account_meta_t
     232             : fd_txn_account_get_solana_meta( fd_txn_account_t const * acct );
     233             : 
     234             : FD_PROTOTYPES_END
     235             : 
     236             : #endif /* HEADER_fd_src_flamenco_runtime_fd_txn_account_h */

Generated by: LCOV version 1.14