LCOV - code coverage report
Current view: top level - flamenco/runtime/program/vote - fd_vote_common.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 43 0.0 %
Date: 2026-01-27 05:09:45 Functions: 0 5 0.0 %

          Line data    Source code
       1             : #include "fd_vote_common.h"
       2             : #include "../fd_vote_program.h"
       3             : #include "../fd_program_util.h"
       4             : 
       5             : int
       6             : fd_vote_verify_authorized_signer( fd_pubkey_t const * authorized,
       7           0 :                                   fd_pubkey_t const * signers[static FD_TXN_SIG_MAX] ) {
       8             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/programs/vote/src/vote_state/mod.rs#L989
       9           0 :   return fd_signers_contains( signers, authorized ) ?
      10           0 :     FD_EXECUTOR_INSTR_SUCCESS :
      11           0 :     FD_EXECUTOR_INSTR_ERR_MISSING_REQUIRED_SIGNATURE;
      12           0 : }
      13             : 
      14             : int
      15             : fd_vote_signature_verify( fd_pubkey_t *       epoch_authorized_voter,
      16             :                           int                 authorized_withdrawer_signer,
      17           0 :                           fd_pubkey_t const * signers[static FD_TXN_SIG_MAX] ) {
      18           0 :   return authorized_withdrawer_signer ? 0 : fd_vote_verify_authorized_signer( epoch_authorized_voter, signers );
      19           0 : }
      20             : 
      21             : uchar
      22           0 : fd_vote_compute_vote_latency( ulong voted_for_slot, ulong current_slot ) {
      23           0 :   return (uchar)fd_ulong_min( fd_ulong_sat_sub( current_slot, voted_for_slot ), UCHAR_MAX );
      24           0 : }
      25             : 
      26             : ulong
      27             : fd_vote_credits_for_vote_at_index( fd_landed_vote_t const * votes,
      28           0 :                                    ulong                    index ) {
      29             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L679
      30           0 :   fd_landed_vote_t const * landed_vote = deq_fd_landed_vote_t_peek_index_const( votes, index );
      31           0 :   ulong                    latency     = landed_vote == NULL ? 0 : landed_vote->latency;
      32             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L683
      33           0 :   ulong                    max_credits =  VOTE_CREDITS_MAXIMUM_PER_SLOT;
      34             : 
      35             :   /* If latency is 0, this means that the Lockout was created and stored
      36             :      from a software version that did not store vote latencies; in this
      37             :      case, 1 credit is awarded.
      38             :      https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L691 */
      39           0 :   if( FD_UNLIKELY( latency==0UL ) ) {
      40           0 :     return 1;
      41           0 :   }
      42             : 
      43           0 :   ulong diff = 0;
      44           0 :   int   cf   = fd_ulong_checked_sub( latency, VOTE_CREDITS_GRACE_SLOTS, &diff );
      45           0 :   if( cf || diff==0UL ) {
      46             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L697
      47           0 :     return max_credits;
      48           0 :   }
      49             : 
      50           0 :   ulong credits = 0;
      51           0 :   cf = fd_ulong_checked_sub( max_credits, diff, &credits );
      52           0 :   if( cf != 0 || credits == 0 ) {
      53             :     // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L705
      54           0 :     return 1;
      55           0 :   }
      56             :   // https://github.com/anza-xyz/agave/blob/v2.0.1/sdk/program/src/vote/state/mod.rs#L707
      57           0 :   return credits;
      58           0 : }
      59             : 
      60             : int
      61             : fd_vote_contains_slot( fd_landed_vote_t const * votes,
      62           0 :                        ulong                    slot ) {
      63             :   /* Logic is copied from slice::binary_search_by() in Rust. While not fully optimized,
      64             :      it aims to achieve fuzzing conformance for both sorted and unsorted inputs. */
      65           0 :   ulong size = deq_fd_landed_vote_t_cnt( votes );
      66           0 :   if( FD_UNLIKELY( size==0UL ) ) return 0;
      67             : 
      68           0 :   ulong base = 0UL;
      69           0 :   while( size>1UL ) {
      70           0 :     ulong half = size / 2UL;
      71           0 :     ulong mid = base + half;
      72           0 :     ulong mid_slot = deq_fd_landed_vote_t_peek_index_const( votes, mid )->lockout.slot;
      73           0 :     base = (slot<mid_slot) ? base : mid;
      74           0 :     size -= half;
      75           0 :   }
      76             : 
      77           0 :   return deq_fd_landed_vote_t_peek_index_const( votes, base )->lockout.slot==slot;
      78           0 : }

Generated by: LCOV version 1.14