LCOV - code coverage report
Current view: top level - funk - fd_funk.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 37 39 94.9 %
Date: 2025-09-18 04:41:32 Functions: 39 2622 1.5 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_funk_fd_funk_h
       2             : #define HEADER_fd_src_funk_fd_funk_h
       3             : 
       4             : /* Funk is a hybrid of a database and version control system designed
       5             :    for ultra high performance blockchain applications.
       6             : 
       7             :    The data model is a flat table of records.  A record is a xid/key-val
       8             :    pair and records are fast O(1) indexable by their xid/key.  xid is
       9             :    short for "transaction id" and xids have a compile time fixed size
      10             :    (e.g. 16 bytes).  keys also have a compile time fixed size (e.g.
      11             :    40 bytes).  Record values can vary in length from zero to a compile
      12             :    time maximum size.  The xid of all zeros is reserved for the "root"
      13             :    transaction described below.  Outside this, there are no
      14             :    restrictions on what a record xid, key or val can be.  Individual
      15             :    records can be created, updated, and deleted arbitrarily.  They are
      16             :    just binary data as far as funk is concerned.
      17             : 
      18             :    The maximum number of records is practically only limited by the size
      19             :    of the workspace memory backing it.  At present, each record requires
      20             :    128 bytes of metadata (this includes records that are published and
      21             :    records that are in the process of being updated).  In other words,
      22             :    about 13 GiB record metadata per hundred million records.  The
      23             :    maximum number of records that can be held by a funk instance is set
      24             :    when that it was created (given the persistent and relocatable
      25             :    properties described below though, it is straightforward to resize
      26             :    this).
      27             : 
      28             :    The transaction model is richer than what is found in a regular
      29             :    database.  A transaction is a xid-"updates to parent transaction"
      30             :    pair and transactions are fast O(1) indexable by xid.  There is no
      31             :    limitation on the number of updates in a transaction.  Updates to the
      32             :    record value are represented as the complete value record to make it
      33             :    trivial to apply cryptographic operations like hashing to all updated
      34             :    values in a transaction with file I/O, operating system calls, memory
      35             :    data marshalling overhead, etc.
      36             : 
      37             :    Like records, the maximum number of transactions in preparation is
      38             :    practically only limited by the size of the workspace memory backing
      39             :    it.  At present, a transaction requires 96 bytes of memory.  As such,
      40             :    it is practical to track a large number of forks during an extended
      41             :    period of time of consensus failure in a block chain application
      42             :    without using much workspace memory at all.  The maximum number of
      43             :    transactions that can be in preparation at any given time by a funk
      44             :    instance is set when that it was created (as before, given the
      45             :    persistent and relocatable properties described below, it is
      46             :    straightforward to resize this).
      47             : 
      48             :    That is, a transaction is a compact representation of the entire
      49             :    history of _all_ the database records up to that transaction.  We can
      50             :    trace a transaction's ancestors back to the "root" give the complete
      51             :    history of all database records up to that transaction.  The “root”
      52             :    transaction is the ancestor of all transactions.  The transaction
      53             :    history is linear from the root transaction until the "last
      54             :    published" transaction and cannot be modified.
      55             : 
      56             :    To start "preparing" a new transaction, we pick the new transaction's
      57             :    xid (ideally unique among all transactions thus far) and fork off a
      58             :    "parent" transaction.  This operation virtually clones all database
      59             :    records in the parent transaction, even if the parent itself has not
      60             :    yet been "published".  Given the above, the parent transaction can be
      61             :    the last published transaction or another in-preparation transaction.
      62             : 
      63             :    Record inserts, reads, removes take place within the context
      64             :    of a transaction, effectively isolating them to a private view of the
      65             :    world.  If a transaction is "cancelled", the changes to a record are
      66             :    harmlessly discarded.  Records in a transaction that has children
      67             :    cannot be changed ("frozen").
      68             : 
      69             :    As such, it is not possible to modify the records in transactions
      70             :    strictly before the last published transaction.  However, it is
      71             :    possible to modify the records of the last published transaction if
      72             :    there is no transactions in preparation.  This is useful, for
      73             :    example, loading up a transaction from a checkpointed state on
      74             :    startup.  A common idiom at start of a block though is to fork the
      75             :    potential transaction of that block from its parent (freezing its
      76             :    parent) and then fork a child of the potential transaction that will
      77             :    hold updates to the block that are incrementally "merged" into the
      78             :    potential transaction as block processing progresses.
      79             : 
      80             :    Critically, in-preparation transactions form a tree of dependent and
      81             :    competing histories.  This model matches blockchains, where
      82             :    speculative work can proceed on several blocks at once long before
      83             :    the blocks are finalized.  When a transaction is published, all its
      84             :    ancestors are also published, any competing histories are
      85             :    cancelled, leaving only a linear history up to the published
      86             :    transaction.  There is no practical limitation on the complexity of
      87             :    this tree.
      88             : 
      89             :    Under the hood, the database state is stored in NUMA and TLB
      90             :    optimized shared memory (i.e. fd_wksp) such that various database
      91             :    operations can be used concurrently by multiple threads distributed
      92             :    arbitrarily over multiple processes zero copy.
      93             : 
      94             :    Database operations are at algorithmic minimums with reasonably high
      95             :    performance implementations.  Most are fast O(1) time and all are
      96             :    small O(1) space (e.g. in complex transaction tree operations, there
      97             :    is no use of dynamic allocation to hold temporaries and no use of
      98             :    recursion to bound stack utilization at trivial levels).  Further,
      99             :    there are no explicit operating system calls and, given a well
     100             :    optimized workspace (i.e. the wksp pages fit within a core's TLBs) no
     101             :    implicit operating system calls.  Critical operations (e.g. those
     102             :    that actually might impact transaction history) are fortified against
     103             :    memory corruption (e.g. robust against DoS attack by corrupting
     104             :    transaction metadata to create loops in transaction trees or going
     105             :    out of bounds in memory).  Outside of record values, all memory used
     106             :    is preallocated.  And record values are O(1) lockfree concurrent
     107             :    allocated via fd_alloc using the same wksp as funk (the
     108             :    implementation is structured in layers that are straightforward to
     109             :    retarget for particular applications as might be necessary).
     110             : 
     111             :    The shared memory used by a funk instance is within a workspace such
     112             :    that it is also persistent and remotely inspectable.  For example, a
     113             :    process attached to a funk instance can be terminated and a new
     114             :    process can resume exactly where the original process left off
     115             :    instantly (e.g. no file I/O).  Or a real-time monitor could be
     116             :    visualizing the ongoing activity in a database non-invasively (e.g.
     117             :    forks in flight, records updated by forks, etc).  Or an auxiliary
     118             :    process could be lazily and non-invasively writing all published
     119             :    records to permanent storage in the background in parallel with
     120             :    on-going operations.
     121             : 
     122             :    The records are further stored in the workspace memory relocatably.
     123             :    For example, workspace memory could just be committed to a persistent
     124             :    memory as is (or backed by NVMe or such directly), copied to a
     125             :    different host, and processes on the new host could resume (indeed,
     126             :    though it wouldn't be space efficient, the shared memory region is
     127             :    usable as is as an on-disk checkpoint file).  Or the workspace could
     128             :    be resized and what not to handle large needs than when the database
     129             :    was initially created and it all "just works".
     130             : 
     131             :    Limited concurrent (multithreaded) access is supported. As a
     132             :    general rule, transaction level operations
     133             :    (e.g. fd_funk_txn_cancel and fd_funk_txn_publish) have to be
     134             :    single-threaded. In this case, no other access is allowed at the
     135             :    same time. Purely record level operations are thread safe and can
     136             :    be arbitrarily interleaved across multiple cpus. Specifically,
     137             :    these are:
     138             :      fd_funk_rec_query_try
     139             :      fd_funk_rec_query_test
     140             :      fd_funk_rec_query_try_global
     141             :      fd_funk_rec_prepare
     142             :      fd_funk_rec_publish
     143             :      fd_funk_rec_cancel
     144             :      fd_funk_rec_remove
     145             : */
     146             : 
     147             : //#include "fd_funk_base.h" /* Includes ../util/fd_util.h */
     148             : //#include "fd_funk_txn.h"  /* Includes fd_funk_base.h */
     149             : //#include "fd_funk_rec.h"  /* Includes fd_funk_txn.h */
     150             : #include "fd_funk_val.h"    /* Includes fd_funk_rec.h */
     151             : 
     152             : /* FD_FUNK_ALIGN describe the alignment needed
     153             :    for a funk.  ALIGN should be a positive integer power of 2.
     154             :    The footprint is dynamic depending on map sizes. */
     155             : 
     156         153 : #define FD_FUNK_ALIGN (4096UL)
     157             : 
     158             : /* The details of a fd_funk_shmem_private are exposed here to facilitate
     159             :    inlining various operations. */
     160             : 
     161      412755 : #define FD_FUNK_MAGIC (0xf17eda2ce7fc2c02UL) /* firedancer funk version 2 */
     162             : 
     163             : struct __attribute__((aligned(FD_FUNK_ALIGN))) fd_funk_shmem_private {
     164             : 
     165             :   /* Metadata */
     166             : 
     167             :   ulong magic;      /* ==FD_FUNK_MAGIC */
     168             :   ulong funk_gaddr; /* wksp gaddr of this in the backing wksp, non-zero gaddr */
     169             :   ulong wksp_tag;   /* Tag to use for wksp allocations, positive */
     170             :   ulong seed;       /* Seed for various hashing function used under the hood, arbitrary */
     171             :   ulong cycle_tag;  /* Next cycle_tag to use, used internally for various data integrity checks */
     172             : 
     173             :   /* The funk transaction map stores the details about transactions
     174             :      in preparation and their relationships to each other.  This is a
     175             :      fd_map_chain_para/fd_pool_para and more details are given in
     176             :      fd_funk_txn.h
     177             : 
     178             :      txn_max is the maximum number of transactions that can be in
     179             :      preparation.  Due to the use of compressed map indices to reduce
     180             :      workspace memory footprint required, txn_max is at most
     181             :      FD_FUNK_TXN_IDX_NULL (currently ~4B).  This should be more than
     182             :      ample for anticipated uses cases ... e.g. every single validator in
     183             :      a pool of tens of thousands Solana validator had its own fork and
     184             :      with no consensus ever being achieved, a funk with txn_max at the
     185             :      limits of a compressed index will be chug along for days to weeks
     186             :      before running out of indexing space.  But if ever needing to
     187             :      support more, it is straightforward to change the code to not use
     188             :      index compression.  Then, a funk (with a planet sized workspace
     189             :      backing it) would survive a similar scenario for millions of years.
     190             :      Presumably, if such a situation arose, in the weeks to eons while
     191             :      there was consensus, somebody would notice and care enough to
     192             :      intervene (if not it is probably irrelevant to the real world
     193             :      anyway).
     194             : 
     195             :      txn_map_gaddr is the wksp gaddr of the fd_funk_txn_map_t used by
     196             :      this funk.
     197             : 
     198             :      child_{head,tail}_cidx are compressed txn map indices.  After
     199             :      decompression, they give the txn map index of the {oldest,youngest}
     200             :      child of funk (i.e. an in-preparation transaction whose parent
     201             :      transaction id is last_publish).  FD_FUNK_TXN_IDX_NULL indicates
     202             :      the funk is childless.  Thus, if head/tail is FD_FUNK_TXN_IDX_NULL,
     203             :      tail/head will be too. funk is "frozen" if it has children.
     204             : 
     205             :      last_publish is the ID of the last published transaction.  It will
     206             :      be the root transaction if no transactions have been published.
     207             :      Will be the root transaction immediately after construction. */
     208             : 
     209             :   ulong txn_max;         /* In [0,FD_FUNK_TXN_IDX_NULL] */
     210             :   ulong txn_map_gaddr;   /* Non-zero wksp gaddr with tag wksp_tag
     211             :                             seed   ==fd_funk_txn_map_seed   (txn_map)
     212             :                             txn_max==fd_funk_txn_map_key_max(txn_map) */
     213             :   ulong txn_pool_gaddr;
     214             :   ulong txn_ele_gaddr;
     215             : 
     216             :   uint  child_head_cidx; /* After decompression, in [0,txn_max) or FD_FUNK_TXN_IDX_NULL, FD_FUNK_TXN_IDX_NULL if txn_max 0 */
     217             :   uint  child_tail_cidx; /* " */
     218             : 
     219             :   /* Padding to FD_FUNK_TXN_XID_ALIGN here */
     220             : 
     221             :   fd_funk_txn_xid_t root[1];         /* Always equal to the root transaction */
     222             :   fd_funk_txn_xid_t last_publish[1]; /* Root transaction immediately after construction, not root thereafter */
     223             : 
     224             :   /* The funk record map stores the details about all the records in
     225             :      the funk, including all those in the last published transaction and
     226             :      all those getting updated in an in-preparation translation.  This
     227             :      is a fd_map_chain_para/fd_pool_para and more details are given in
     228             :      fd_funk_rec.h
     229             : 
     230             :      rec_max is the maximum number of records that can exist in this
     231             :      funk.
     232             : 
     233             :      rec_map_gaddr is the wksp gaddr of the fd_funk_rec_map_t used by
     234             :      this funk. */
     235             : 
     236             :   uint rec_max;
     237             :   ulong rec_map_gaddr; /* Non-zero wksp gaddr with tag wksp_tag
     238             :                           seed   ==fd_funk_rec_map_seed   (rec_map)
     239             :                           rec_max==fd_funk_rec_map_key_max(rec_map) */
     240             :   ulong rec_pool_gaddr;
     241             :   ulong rec_ele_gaddr;
     242             : 
     243             :   /* The funk alloc is used for allocating wksp resources for record
     244             :      values.  This is a fd_alloc and more details are given in
     245             :      fd_funk_val.h.  Allocations from this allocator will be tagged with
     246             :      wksp_tag and operations on this allocator will use concurrency
     247             :      group 0.
     248             : 
     249             :      TODO: Consider letting user just pass a join of alloc (and maybe
     250             :      the cgroup_idx to give the funk), inferring the wksp, cgroup from
     251             :      that and allocating exclusively from that? */
     252             : 
     253             :   ulong alloc_gaddr; /* Non-zero wksp gaddr with tag wksp tag */
     254             :   uchar lock;        /* lock for synchronizing modifications to funk object */
     255             : 
     256             :   /* Padding to FD_FUNK_ALIGN here */
     257             : };
     258             : 
     259             : /* The details of a fd_funk_private are exposed here to facilitate
     260             :    inlining various operations. */
     261             : 
     262             : #define FD_FUNK_JOIN_ALIGN 64
     263             : 
     264             : struct __attribute__((aligned(FD_FUNK_JOIN_ALIGN))) fd_funk_private {
     265             : 
     266             :   fd_funk_shmem_t *  shmem;
     267             : 
     268             :   fd_funk_txn_map_t  txn_map[1];
     269             :   fd_funk_txn_pool_t txn_pool[1];
     270             : 
     271             :   fd_funk_rec_map_t  rec_map[1];
     272             :   fd_funk_rec_pool_t rec_pool[1];
     273             : 
     274             :   fd_wksp_t *  wksp;
     275             :   fd_alloc_t * alloc;
     276             : 
     277             : };
     278             : 
     279             : FD_PROTOTYPES_BEGIN
     280             : 
     281             : /* Constructors */
     282             : 
     283             : /* fd_funk_align return FD_FUNK_ALIGN. */
     284             : 
     285             : FD_FN_CONST ulong
     286             : fd_funk_align( void );
     287             : 
     288             : /* fd_funk_footprint returns the size need for funk and all
     289             :    auxiliary data structures. Note that only record valus are
     290             :    allocated dynamically. */
     291             : 
     292             : FD_FN_CONST ulong
     293             : fd_funk_footprint( ulong txn_max,
     294             :                    ulong rec_max );
     295             : 
     296             : /* fd_funk_new formats an unused wksp allocation with the appropriate
     297             :    alignment and footprint as a funk.  Caller is not joined on return.
     298             :    Returns shmem on success and NULL on failure (shmem NULL, shmem
     299             :    misaligned, zero wksp_tag, shmem is not backed by a wksp ...  logs
     300             :    details).  A workspace can be used by multiple funks concurrently.
     301             :    They will dynamically share the underlying workspace (along with any
     302             :    other non-funk usage) but will otherwise act as completely separate
     303             :    non-conflicting funks.  To help with various diagnostics, garbage
     304             :    collection and what not, all allocations to the underlying wksp are
     305             :    tagged with the given tag (positive).  Ideally, the tag used here
     306             :    should be distinct from all other tags used by this workspace but
     307             :    this is not required. */
     308             : 
     309             : void *
     310             : fd_funk_new( void * shmem,
     311             :              ulong  wksp_tag,
     312             :              ulong  seed,
     313             :              ulong  txn_max,
     314             :              ulong  rec_max );
     315             : 
     316             : /* fd_funk_join joins the caller to a funk instance.  ljoin points to a
     317             :    fd_funk_t compatible memory region in the caller's address space,
     318             :    shfunk points to the first byte of the memory region backing the funk
     319             :    in the caller's address space.  Returns an handle to the caller's
     320             :    local join on success (join has ownership of the ljoin region) and
     321             :    NULL on failure (NULL ljoin, NULL shfunk, misaligned shfunk, shfunk
     322             :    is not backed by a wksp, bad magic, ... logs details).  Every
     323             :    successful join should have a matching leave.  The lifetime of the
     324             :    join is until the matching leave or the thread group is terminated
     325             :    (joins are local to a thread group). */
     326             : 
     327             : fd_funk_t *
     328             : fd_funk_join( fd_funk_t * ljoin,
     329             :               void *      shfunk );
     330             : 
     331             : /* fd_funk_purify attempts to clean up a possibly corrupt funk
     332             :    instance. The shfunk argument is what would normally be passed to
     333             :    join, and purify should be used BEFORE calling join. As a side
     334             :    effect, all pending transactions are aborted. Important note:
     335             :    purify is very expensive. Do not use this API indiscriminately. It
     336             :    is meant to be used after a process crash. An error is returned if
     337             :    purify fails. */
     338             : int
     339             : fd_funk_purify( void * shfunk );
     340             : 
     341             : /* fd_funk_leave leaves a funk join.  Returns the memory region used for
     342             :    join on success (caller has ownership on return and the caller is no
     343             :    longer joined) and NULL on failure (logs details).  Sets *opt_shfunk
     344             :    a pointer to the funk shm region if opt_shfunk!=NULL. */
     345             : 
     346             : void *
     347             : fd_funk_leave( fd_funk_t * funk,
     348             :                void **     opt_shfunk );
     349             : 
     350             : /* fd_funk_delete unformats a wksp allocation used as a funk
     351             :    (additionally frees all wksp allocations used by that funk).  Assumes
     352             :    nobody is or will be joined to the funk.  Returns shmem on success
     353             :    and NULL on failure (logs details).  Reasons for failure include
     354             :    shfunk is NULL, misaligned shfunk, shfunk is not backed by a
     355             :    workspace, etc. */
     356             : 
     357             : void *
     358             : fd_funk_delete( void * shfunk );
     359             : 
     360             : /* fd_funk_delete_fast is an optimized verison of fd_funk_delete.
     361             :    Unlike fd_funk_delete, makes an additional assumption that this funk
     362             :    was created with a wksp_tag (see fd_funk_new) that is distinct from
     363             :    all other tags in the workspace.  Also unlike fd_funk_delete, frees
     364             :    wksp allocation backing the funk instance itself.
     365             : 
     366             :    WARNING: Using this function frees all wksp allocations matching the
     367             :    funk's wksp_tag. */
     368             : 
     369             : void
     370             : fd_funk_delete_fast( void * shfunk );
     371             : 
     372             : /* Accessors */
     373             : 
     374             : /* fd_funk_wksp returns the local join to the wksp backing the funk.
     375             :    The lifetime of the returned pointer is at least as long as the
     376             :    lifetime of the local join.  Assumes funk is a current local join. */
     377             : 
     378        2193 : FD_FN_PURE static inline fd_wksp_t * fd_funk_wksp( fd_funk_t const * funk ) { return funk->wksp; }
     379             : 
     380             : /* fd_funk_wksp_tag returns the workspace allocation tag used by the
     381             :    funk for its wksp allocations.  Will be positive.  Assumes funk is a
     382             :    current local join. */
     383             : 
     384          15 : FD_FN_PURE static inline ulong fd_funk_wksp_tag( fd_funk_t * funk ) { return funk->shmem->wksp_tag; }
     385             : 
     386             : /* fd_funk_seed returns the hash seed used by the funk for various hash
     387             :    functions.  Arbitrary value.  Assumes funk is a current local join.
     388             :    TODO: consider renaming hash_seed? */
     389             : 
     390           3 : FD_FN_PURE static inline ulong fd_funk_seed( fd_funk_t * funk ) { return funk->shmem->seed; }
     391             : 
     392             : /* fd_funk_txn_max returns maximum number of in-preparations the funk
     393             :    can support.  Assumes funk is a current local join.  Return in
     394             :    [0,FD_FUNK_TXN_IDX_NULL]. */
     395             : 
     396           3 : FD_FN_PURE static inline ulong fd_funk_txn_max( fd_funk_t * funk ) { return funk->txn_pool->ele_max; }
     397             : 
     398             : /* fd_funk_txn_map returns the funk's transaction map join. This
     399             :    join can copied by value and is generally stored as a stack variable. */
     400             : 
     401    20589510 : FD_FN_PURE static inline fd_funk_txn_map_t * fd_funk_txn_map( fd_funk_t * funk ) { return funk->txn_map; }
     402             : 
     403             : /* fd_funk_txn_pool returns the funk's transaction pool join. This
     404             :    join can copied by value and is generally stored as a stack variable. */
     405             : 
     406      102009 : FD_FN_PURE static inline fd_funk_txn_pool_t * fd_funk_txn_pool( fd_funk_t * funk ) { return funk->txn_pool; }
     407             : 
     408             : /* fd_funk_last_publish_child_{head,tail} returns a pointer in the
     409             :    caller's address space to {oldest,young} transaction child of root, NULL if
     410             :    funk is childless.  All pointers are in the caller's address space.
     411             :    These are all a fast O(1) but not fortified against memory data
     412             :    corruption. */
     413             : 
     414             : FD_FN_PURE static inline fd_funk_txn_t *
     415             : fd_funk_last_publish_child_head( fd_funk_t *          funk,
     416        5538 :                                  fd_funk_txn_pool_t * pool ) {
     417        5538 :   ulong idx = fd_funk_txn_idx( funk->shmem->child_head_cidx );
     418        5538 :   if( fd_funk_txn_idx_is_null( idx ) ) return NULL; /* TODO: Consider branchless? */
     419        5538 :   return pool->ele + idx;
     420        5538 : }
     421             : 
     422             : FD_FN_PURE static inline fd_funk_txn_t *
     423             : fd_funk_last_publish_child_tail( fd_funk_t *          funk,
     424        5538 :                                  fd_funk_txn_pool_t * pool ) {
     425        5538 :   ulong idx = fd_funk_txn_idx( funk->shmem->child_tail_cidx );
     426        5538 :   if( fd_funk_txn_idx_is_null( idx ) ) return NULL; /* TODO: Consider branchless? */
     427        5538 :   return pool->ele + idx;
     428        5538 : }
     429             : 
     430             : /* fd_funk_root returns a pointer in the caller's address space to the
     431             :    transaction id of the root transaction.  Assumes funk is a current
     432             :    local join.  Lifetime of the returned pointer is the lifetime of the
     433             :    current local join.  The value at this pointer will always be the
     434             :    root transaction id. */
     435             : 
     436      206373 : FD_FN_CONST static inline fd_funk_txn_xid_t const * fd_funk_root( fd_funk_t * funk ) { return funk->shmem->root; }
     437             : 
     438             : /* fd_funk_last_publish returns a pointer in the caller's address space
     439             :    to transaction id of the last published transaction.  Assumes funk is
     440             :    a current local join.  Lifetime of the returned pointer is the
     441             :    lifetime of the current local join.  The value at this pointer will
     442             :    be constant until the next transaction is published. */
     443             : 
     444     3145734 : FD_FN_CONST static inline fd_funk_txn_xid_t const * fd_funk_last_publish( fd_funk_t * funk ) { return funk->shmem->last_publish; }
     445             : 
     446             : /* fd_funk_is_frozen returns 1 if the records of the last published
     447             :    transaction are frozen (i.e. the funk has children) and 0 otherwise
     448             :    (i.e. the funk is childless).  Assumes funk is a current local join. */
     449             : 
     450             : FD_FN_PURE static inline int
     451    10697268 : fd_funk_last_publish_is_frozen( fd_funk_t const * funk ) {
     452    10697268 :   return fd_funk_txn_idx( funk->shmem->child_head_cidx )!=FD_FUNK_TXN_IDX_NULL;
     453    10697268 : }
     454             : 
     455             : /* fd_funk_rec_max returns maximum number of records that can be held
     456             :    in the funk.  This includes both records of the last published
     457             :    transaction and records for transactions that are in-flight. */
     458             : 
     459           0 : FD_FN_PURE static inline ulong fd_funk_rec_max( fd_funk_t * funk ) { return funk->rec_pool->ele_max; }
     460             : 
     461             : /* fd_funk_rec_map returns the funk's record map join. This
     462             :    join can copied by value and is generally stored as a stack variable. */
     463             : 
     464          39 : FD_FN_PURE static inline fd_funk_rec_map_t * fd_funk_rec_map( fd_funk_t * funk ) { return funk->rec_map; }
     465             : 
     466             : /* fd_funk_rec_pool returns the funk's record pool join. This
     467             :    join can copied by value and is generally stored as a stack variable. */
     468             : 
     469           0 : FD_FN_PURE static inline fd_funk_rec_pool_t * fd_funk_rec_pool( fd_funk_t * funk ) { return funk->rec_pool; }
     470             : 
     471             : /* fd_funk_alloc returns a pointer in the caller's address space to
     472             :    the funk's allocator. */
     473             : 
     474     1256985 : FD_FN_PURE static inline fd_alloc_t * fd_funk_alloc( fd_funk_t * funk ) { return funk->alloc; }
     475             : 
     476             : /* fd_funk_rec_is_full returns 1 if no more records can be allocated
     477             :    and 0 otherwise. */
     478             : 
     479             : static inline int
     480    24223038 : fd_funk_rec_is_full( fd_funk_t * funk ) {
     481    24223038 :   return fd_funk_rec_pool_is_empty( funk->rec_pool );
     482    24223038 : }
     483             : 
     484             : /* fd_funk_txn_is_full returns true if the transaction map is
     485             :    full. No more in-preparation transactions are allowed. */
     486             : 
     487             : static inline int
     488      836880 : fd_funk_txn_is_full( fd_funk_t * funk ) {
     489      836880 :   return fd_funk_txn_pool_is_empty( funk->txn_pool );
     490      836880 : }
     491             : 
     492             : /* fd_begin_crit and fd_end_crit are used to mark the beginning and end of a critical section.
     493             :    They indicate that funk is in a state where fd_funk_purify doesn't work. */
     494             : 
     495             : static inline void
     496      206358 : fd_begin_crit(fd_funk_t * funk) {
     497      206358 :    funk->shmem->magic = FD_FUNK_MAGIC+1;
     498      206358 : }
     499             : 
     500             : static inline void
     501      206358 : fd_end_crit(fd_funk_t * funk) {
     502      206358 :    funk->shmem->magic = FD_FUNK_MAGIC;
     503      206358 : }
     504             : 
     505             : /* Misc */
     506             : 
     507             : /* fd_funk_verify verifies the integrity of funk.  Returns
     508             :    FD_FUNK_SUCCESS if funk appears to be intact and FD_FUNK_ERR_INVAL
     509             :    otherwise (logs details).  Assumes funk is a current local join (NULL
     510             :    returns FD_FUNK_ERR_INVAL and logs details.) */
     511             : 
     512             : int
     513             : fd_funk_verify( fd_funk_t * funk );
     514             : 
     515             : FD_PROTOTYPES_END
     516             : 
     517             : #endif /* HEADER_fd_src_funk_fd_funk_h */

Generated by: LCOV version 1.14