LCOV - code coverage report
Current view: top level - disco/verify - fd_verify_tile.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 32 34 94.1 %
Date: 2026-02-13 06:06:24 Functions: 1 3 33.3 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_verify_fd_verify_tile_h
       2             : #define HEADER_fd_src_disco_verify_fd_verify_tile_h
       3             : 
       4             : /* The verify tile verifies that the cryptographic signatures of
       5             :    incoming transactions match the data being signed.  Transactions with
       6             :    invalid signatures are filtered out of the frag stream. */
       7             : 
       8             : #include "../topo/fd_topo.h"
       9             : #include "../metrics/generated/fd_metrics_enums.h"
      10             : 
      11          21 : #define FD_TXN_VERIFY_SUCCESS  0
      12          21 : #define FD_TXN_VERIFY_FAILED  -1
      13          15 : #define FD_TXN_VERIFY_DEDUP   -2
      14             : 
      15             : extern fd_topo_run_tile_t fd_tile_verify;
      16             : 
      17             : /* fd_verify_in_ctx_t is a context object for each in (producer) mcache
      18             :    connected to the verify tile. */
      19             : 
      20             : typedef struct {
      21             :   fd_wksp_t * mem;
      22             :   ulong       chunk0;
      23             :   ulong       wmark;
      24             : } fd_verify_in_ctx_t;
      25             : 
      26             : typedef struct {
      27             :   /* TODO switch to fd_sha512_batch_t? */
      28             :   fd_sha512_t * sha[ FD_TXN_ACTUAL_SIG_MAX ];
      29             : 
      30             :   int   bundle_failed;
      31             :   ulong bundle_id;
      32             : 
      33             :   ulong round_robin_idx;
      34             :   ulong round_robin_cnt;
      35             : 
      36             :   ulong   tcache_depth;
      37             :   ulong   tcache_map_cnt;
      38             :   ulong * tcache_sync;
      39             :   ulong * tcache_ring;
      40             :   ulong * tcache_map;
      41             : 
      42             :   ulong              in_kind[ 32 ];
      43             :   fd_verify_in_ctx_t in[ 32 ];
      44             : 
      45             :   fd_wksp_t * out_mem;
      46             :   ulong       out_chunk0;
      47             :   ulong       out_wmark;
      48             :   ulong       out_chunk;
      49             : 
      50             :   ulong       hashmap_seed;
      51             : 
      52             :   struct {
      53             :     ulong verify_tile_result[ FD_METRICS_ENUM_VERIFY_TILE_RESULT_CNT ];
      54             :     ulong gossiped_votes_cnt;
      55             :   } metrics;
      56             : } fd_verify_ctx_t;
      57             : 
      58             : static inline int
      59             : fd_txn_verify( fd_verify_ctx_t * ctx,
      60             :                uchar const *     udp_payload,
      61             :                ushort const      payload_sz,
      62             :                fd_txn_t const *  txn,
      63             :                int               dedup,
      64          57 :                ulong *           opt_sig ) {
      65             : 
      66             :   /* We do not want to deref any non-data field from the txn struct more than once */
      67          57 :   uchar  signature_cnt = txn->signature_cnt;
      68          57 :   ushort signature_off = txn->signature_off;
      69          57 :   ushort acct_addr_off = txn->acct_addr_off;
      70          57 :   ushort message_off   = txn->message_off;
      71             : 
      72          57 :   uchar const * signatures = udp_payload + signature_off;
      73          57 :   uchar const * pubkeys = udp_payload + acct_addr_off;
      74          57 :   uchar const * msg = udp_payload + message_off;
      75          57 :   ulong msg_sz = (ulong)payload_sz - message_off;
      76             : 
      77             :   /* The first signature is the transaction id, i.e. a unique identifier.
      78             :      So use this to do a quick dedup of ha traffic. */
      79             : 
      80          57 :   ulong ha_dedup_tag = fd_hash( ctx->hashmap_seed, signatures, 64UL );
      81          57 :   int ha_dup = 0;
      82          57 :   if( FD_LIKELY( dedup ) ) {
      83          48 :     FD_FN_UNUSED ulong tcache_map_idx = 0; /* ignored */
      84          48 :     FD_TCACHE_QUERY( ha_dup, tcache_map_idx, ctx->tcache_map, ctx->tcache_map_cnt, ha_dedup_tag );
      85          48 :     if( FD_UNLIKELY( ha_dup ) ) {
      86          15 :       return FD_TXN_VERIFY_DEDUP;
      87          15 :     }
      88          48 :   }
      89             : 
      90             :   /* Verify signatures */
      91          42 :   int res = fd_ed25519_verify_batch_single_msg( msg, msg_sz, signatures, pubkeys, ctx->sha, signature_cnt );
      92          42 :   if( FD_UNLIKELY( res != FD_ED25519_SUCCESS ) ) {
      93          21 :     return FD_TXN_VERIFY_FAILED;
      94          21 :   }
      95             : 
      96             :   /* Insert into the tcache to dedup ha traffic.
      97             :      The dedup check is repeated to guard against duped txs verifying signatures at the same time */
      98          21 :   if( FD_LIKELY( dedup ) ) {
      99          15 :     FD_TCACHE_INSERT( ha_dup, *ctx->tcache_sync, ctx->tcache_ring, ctx->tcache_depth, ctx->tcache_map, ctx->tcache_map_cnt, ha_dedup_tag );
     100          15 :     if( FD_UNLIKELY( ha_dup ) ) {
     101           0 :       return FD_TXN_VERIFY_DEDUP;
     102           0 :     }
     103          15 :   }
     104             : 
     105          21 :   *opt_sig = ha_dedup_tag;
     106          21 :   return FD_TXN_VERIFY_SUCCESS;
     107          21 : }
     108             : 
     109             : #endif /* HEADER_fd_src_disco_verify_fd_verify_tile_h */

Generated by: LCOV version 1.14