LCOV - code coverage report
Current view: top level - discof/repair - fd_repair.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 91 0.0 %
Date: 2025-10-27 04:40:00 Functions: 0 8 0.0 %

          Line data    Source code
       1             : #include "fd_repair.h"
       2             : #include "../../ballet/sha256/fd_sha256.h"
       3             : #include "../../disco/keyguard/fd_keyguard_client.h"
       4             : 
       5             : void *
       6           0 : fd_repair_new( void * shmem, fd_pubkey_t * identity_key ) {
       7             : 
       8           0 :   if( FD_UNLIKELY( !shmem ) ) {
       9           0 :     FD_LOG_WARNING(( "NULL mem" ));
      10           0 :     return NULL;
      11           0 :   }
      12             : 
      13           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)shmem, fd_repair_align() ) ) ) {
      14           0 :     FD_LOG_WARNING(( "misaligned mem" ));
      15           0 :     return NULL;
      16           0 :   }
      17             : 
      18           0 :   ulong footprint = fd_repair_footprint();
      19           0 :   fd_memset( shmem, 0, footprint );
      20             : 
      21           0 :   fd_repair_t * repair = (fd_repair_t *)shmem;
      22           0 :   repair->identity_key = *identity_key;
      23             : 
      24           0 :   return shmem;
      25           0 : }
      26             : 
      27             : fd_repair_t *
      28           0 : fd_repair_join( void * shrepair ) {
      29           0 :   fd_repair_t * repair = (fd_repair_t *)shrepair;
      30             : 
      31           0 :   if( FD_UNLIKELY( !repair ) ) {
      32           0 :     FD_LOG_WARNING(( "NULL repair" ));
      33           0 :     return NULL;
      34           0 :   }
      35             : 
      36           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned((ulong)repair, fd_repair_align() ) ) ) {
      37           0 :     FD_LOG_WARNING(( "misaligned repair" ));
      38           0 :     return NULL;
      39           0 :   }
      40             : 
      41           0 :   fd_wksp_t * wksp = fd_wksp_containing( repair );
      42           0 :   if( FD_UNLIKELY( !wksp ) ) {
      43           0 :     FD_LOG_WARNING(( "repair must be part of a workspace" ));
      44           0 :     return NULL;
      45           0 :   }
      46             : 
      47           0 :   return repair;
      48           0 : }
      49             : 
      50             : void *
      51           0 : fd_repair_leave( fd_repair_t const * repair ) {
      52             : 
      53           0 :   if( FD_UNLIKELY( !repair ) ) {
      54           0 :     FD_LOG_WARNING(( "NULL repair" ));
      55           0 :     return NULL;
      56           0 :   }
      57             : 
      58           0 :   return (void *)repair;
      59           0 : }
      60             : 
      61             : void *
      62           0 : fd_repair_delete( void * repair ) {
      63             : 
      64           0 :   if( FD_UNLIKELY( !repair ) ) {
      65           0 :     FD_LOG_WARNING(( "NULL repair" ));
      66           0 :     return NULL;
      67           0 :   }
      68             : 
      69           0 :   if( FD_UNLIKELY( !fd_ulong_is_aligned((ulong)repair, fd_repair_align() ) ) ) {
      70           0 :     FD_LOG_WARNING(( "misaligned repair" ));
      71           0 :     return NULL;
      72           0 :   }
      73             : 
      74           0 :   return repair;
      75           0 : }
      76             : 
      77             : fd_repair_msg_t *
      78           0 : fd_repair_pong( fd_repair_t * repair, fd_hash_t * ping_token ) {
      79           0 :   uchar pre_image[FD_REPAIR_PONG_PREIMAGE_SZ];
      80           0 :   memcpy( pre_image, "SOLANA_PING_PONG", 16UL );
      81           0 :   memcpy( pre_image+16UL, ping_token->uc, 32UL);
      82             : 
      83             :   /* Generate response hash token */
      84           0 :   fd_sha256_hash( pre_image, FD_REPAIR_PONG_PREIMAGE_SZ, &repair->msg.pong.hash );
      85             : 
      86           0 :   repair->msg.kind      = FD_REPAIR_KIND_PONG;
      87           0 :   repair->msg.pong.from = repair->identity_key;
      88           0 :   return &repair->msg;
      89           0 : }
      90             : 
      91             : fd_repair_msg_t *
      92             : fd_repair_shred( fd_repair_t *     repair,
      93             :                  fd_pubkey_t const * to,
      94             :                  ulong             ts,
      95             :                  uint              nonce,
      96             :                  ulong             slot,
      97           0 :                  ulong             shred_idx ) {
      98           0 :   memset(&repair->msg, 0, sizeof(fd_repair_msg_t));
      99           0 :   repair->msg.kind            = FD_REPAIR_KIND_SHRED;
     100           0 :   repair->msg.shred.from      = repair->identity_key;
     101           0 :   repair->msg.shred.to        = *to;
     102           0 :   repair->msg.shred.ts        = ts;
     103           0 :   repair->msg.shred.nonce     = nonce;
     104           0 :   repair->msg.shred.slot      = slot;
     105           0 :   repair->msg.shred.shred_idx = shred_idx;
     106           0 :   return &repair->msg;
     107           0 : }
     108             : 
     109             : fd_repair_msg_t *
     110             : fd_repair_highest_shred( fd_repair_t *     repair,
     111             :                          fd_pubkey_t const * to,
     112             :                          ulong             ts,
     113             :                          uint              nonce,
     114             :                          ulong             slot,
     115           0 :                          ulong             shred_idx ) {
     116           0 :   memset(&repair->msg, 0, sizeof(fd_repair_msg_t));
     117           0 :   repair->msg.kind                    = FD_REPAIR_KIND_HIGHEST_SHRED;
     118           0 :   repair->msg.highest_shred.from      = repair->identity_key;
     119           0 :   repair->msg.highest_shred.to        = *to;
     120           0 :   repair->msg.highest_shred.ts        = ts;
     121           0 :   repair->msg.highest_shred.nonce     = nonce;
     122           0 :   repair->msg.highest_shred.slot      = slot;
     123           0 :   repair->msg.highest_shred.shred_idx = shred_idx;
     124           0 :   return &repair->msg;
     125           0 : }
     126             : 
     127             : fd_repair_msg_t *
     128             : fd_repair_orphan( fd_repair_t *     repair,
     129             :                   fd_pubkey_t const * to,
     130             :                   ulong             ts,
     131             :                   uint              nonce,
     132           0 :                   ulong             slot ) {
     133           0 :   memset(&repair->msg, 0, sizeof(fd_repair_msg_t));
     134           0 :   repair->msg.kind         = FD_REPAIR_KIND_ORPHAN;
     135           0 :   repair->msg.orphan.from  = repair->identity_key;
     136           0 :   repair->msg.orphan.to    = *to;
     137           0 :   repair->msg.orphan.ts    = ts;
     138           0 :   repair->msg.orphan.nonce = nonce;
     139           0 :   repair->msg.orphan.slot  = slot;
     140           0 :   return &repair->msg;
     141           0 : }

Generated by: LCOV version 1.14