LCOV - code coverage report
Current view: top level - flamenco/runtime - fd_txn_account.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 3 3 100.0 %
Date: 2026-01-12 05:12:51 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 "../accdb/fd_accdb_sync.h"
       5             : #include "../types/fd_types.h"
       6             : #include "../../funk/fd_funk_rec.h"
       7             : 
       8             : struct fd_acc_mgr;
       9             : typedef struct fd_acc_mgr fd_acc_mgr_t;
      10             : 
      11             : /* fd_txn_account_t is a wrapper around a database record. It is used to
      12             :    provide an interface for an account during transaction execution
      13             :    along with reference counting semantics. The fd_txn_account_t object
      14             :    is initialized with a pointer to the account's metadata and data, the
      15             :    wksp that the data belongs to, its pubkey, and if the transaction
      16             :    account is mutable.
      17             : 
      18             :    fd_txn_account_t is NOT thread-safe and only supports a single join
      19             :    at a given time.
      20             : 
      21             :    TODO: Consider changing the meta/data boundary to make it more
      22             :    explicit that the caller passes in a contigious region of memory
      23             :    which has to correspond to the meta/data layout.
      24             : 
      25             :    TODO: Consider making the fd_txn_account struct private */
      26             : 
      27             : struct __attribute__((aligned(8UL))) fd_txn_account {
      28             :   ulong                           magic;
      29             : 
      30             :   fd_pubkey_t                     pubkey[1];
      31             : 
      32             :   fd_account_meta_t *             meta;
      33             :   uchar *                         data;
      34             : 
      35             :   int                             is_mutable;
      36             :   long                            meta_soff;
      37             : };
      38             : typedef struct fd_txn_account fd_txn_account_t;
      39           3 : #define FD_TXN_ACCOUNT_FOOTPRINT (sizeof(fd_txn_account_t))
      40           3 : #define FD_TXN_ACCOUNT_ALIGN     (8UL)
      41          42 : #define FD_TXN_ACCOUNT_MAGIC     (0xF15EDF1C51F51AA1UL)
      42             : 
      43             : FD_PROTOTYPES_BEGIN
      44             : 
      45             : /* fd_txn_account_new lays out the memory required for a
      46             :    fd_txn_account object. The caller should only use the struct
      47             :    after it has been joined. fd_txn_account_t makes the assumption
      48             :    that the account data is laid out directly after the account meta.
      49             :    After a successful call to fd_txn_account_new, the object will now
      50             :    own the account's metadata and data. */
      51             : 
      52             : void *
      53             : fd_txn_account_new( void *              mem,
      54             :                     fd_pubkey_t const * pubkey,
      55             :                     fd_account_meta_t * meta,
      56             :                     int                 is_mutable );
      57             : 
      58             : /* fd_txn_account_join joins a thread with an indepedent address space
      59             :    to the memory region allocated by fd_txn_account_new. There can be
      60             :    only ONE valid join per fd_txn_account_t object. If a _join is called
      61             :    from one thread, it is implied that the object is no longer valid
      62             :    on other threads.
      63             : 
      64             :    TODO: When the new db is introduced, the wksp argument should be
      65             :    removed in favor of using offsets into other data structures. */
      66             : 
      67             : fd_txn_account_t *
      68             : fd_txn_account_join( void * mem );
      69             : 
      70             : /* fd_txn_account_leave leaves a current local join and returns a
      71             :    pointer to the underlying shared memory region. The fd_txn_account_t
      72             :    will still own the account's metadata and data. */
      73             : 
      74             : void *
      75             : fd_txn_account_leave( fd_txn_account_t * acct );
      76             : 
      77             : /* fd_txn_account_delete removes the memory layout for the
      78             :    fd_txn_account_t object. It returns a pointer to the underlying
      79             :    shared struct. Any attempts to join after a call to
      80             :    fd_txn_account_delete will fail. The account's metadata and data
      81             :    will be owned by the caller after the delete is called.  */
      82             : 
      83             : void *
      84             : fd_txn_account_delete( void * mem );
      85             : 
      86             : /* Factory constructors from funk.
      87             :    TODO: These need to be removed when a new db is introduced and either
      88             :    replaced with a new factory constructor or removed entirely in favor
      89             :    of the generic constructors defined above. */
      90             : 
      91             : /* fd_txn_account_init_from_funk_mutable initializes a fd_txn_account_t
      92             :    object with a mutable handle into its funk record.
      93             : 
      94             :    IMPORTANT: Cannot be called in the executor tile. */
      95             : 
      96             : fd_account_meta_t *
      97             : fd_txn_account_init_from_funk_mutable( fd_txn_account_t *        acct,
      98             :                                        fd_pubkey_t const *       pubkey,
      99             :                                        fd_accdb_user_t *         accdb,
     100             :                                        fd_funk_txn_xid_t const * xid,
     101             :                                        int                       do_create,
     102             :                                        ulong                     min_data_sz,
     103             :                                        fd_funk_rec_prepare_t *   prepare_out );
     104             : 
     105             : /* Publishes the record contents of a mutable fd_txn_account_t object
     106             :    obtained from fd_txn_account_init_from_funk_mutable into funk
     107             :    if the record does not yet exist in the current funk txn.
     108             :    ie. the record was created / cloned from an ancestor funk txn
     109             :    by fd_txn_account_init_from_funk_mutable. */
     110             : 
     111             : void
     112             : fd_txn_account_mutable_fini( fd_txn_account_t *        acct,
     113             :                              fd_accdb_user_t *         funk,
     114             :                              fd_funk_rec_prepare_t *   prepare );
     115             : 
     116             : /* Simple accesssors and mutators. */
     117             : 
     118             : fd_pubkey_t const *
     119             : fd_txn_account_get_owner( fd_txn_account_t const * acct );
     120             : 
     121             : fd_account_meta_t const *
     122             : fd_txn_account_get_meta( fd_txn_account_t const * acct );
     123             : 
     124             : uchar const *
     125             : fd_txn_account_get_data( fd_txn_account_t const * acct );
     126             : 
     127             : uchar *
     128             : fd_txn_account_get_data_mut( fd_txn_account_t const * acct );
     129             : 
     130             : ulong
     131             : fd_txn_account_get_data_len( fd_txn_account_t const * acct );
     132             : 
     133             : int
     134             : fd_txn_account_is_executable( fd_txn_account_t const * acct );
     135             : 
     136             : ulong
     137             : fd_txn_account_get_lamports( fd_txn_account_t const * acct );
     138             : 
     139             : void
     140             : fd_txn_account_set_meta( fd_txn_account_t * acct, fd_account_meta_t * meta );
     141             : 
     142             : void
     143             : fd_txn_account_set_executable( fd_txn_account_t * acct, int is_executable );
     144             : 
     145             : void
     146             : fd_txn_account_set_owner( fd_txn_account_t * acct, fd_pubkey_t const * owner );
     147             : 
     148             : void
     149             : fd_txn_account_set_lamports( fd_txn_account_t * acct, ulong lamports );
     150             : 
     151             : int
     152             : fd_txn_account_checked_add_lamports( fd_txn_account_t * acct, ulong lamports );
     153             : 
     154             : int
     155             : fd_txn_account_checked_sub_lamports( fd_txn_account_t * acct, ulong lamports );
     156             : 
     157             : void
     158             : fd_txn_account_set_data( fd_txn_account_t * acct,
     159             :                          void const *       data,
     160             :                          ulong              data_sz );
     161             : 
     162             : void
     163             : fd_txn_account_set_data_len( fd_txn_account_t * acct, ulong data_len );
     164             : 
     165             : void
     166             : fd_txn_account_set_slot( fd_txn_account_t * acct,
     167             :                          ulong              slot );
     168             : 
     169             : void
     170             : fd_txn_account_clear_owner( fd_txn_account_t * acct );
     171             : 
     172             : void
     173             : fd_txn_account_resize( fd_txn_account_t * acct, ulong dlen );
     174             : 
     175             : int
     176             : fd_txn_account_is_mutable( fd_txn_account_t const * acct );
     177             : 
     178             : int
     179             : fd_txn_account_is_readonly( fd_txn_account_t const * acct );
     180             : 
     181             : void
     182             : fd_txn_account_set_readonly( fd_txn_account_t * acct );
     183             : 
     184             : void
     185             : fd_txn_account_set_mutable( fd_txn_account_t * acct );
     186             : 
     187             : FD_PROTOTYPES_END
     188             : 
     189             : #endif /* HEADER_fd_src_flamenco_runtime_fd_txn_account_h */

Generated by: LCOV version 1.14