LCOV - code coverage report
Current view: top level - discof/sender - fd_sender_tile.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 252 0.0 %
Date: 2025-06-06 04:57:44 Functions: 0 13 0.0 %

          Line data    Source code
       1             : /* Sender tile signs and sends transactions to the current leader. Currently
       2             :    only supports transactions which require one signature. */
       3             : #define _GNU_SOURCE
       4             : 
       5             : #include "../../disco/topo/fd_topo.h"
       6             : #include "generated/fd_sender_tile_seccomp.h"
       7             : 
       8             : #include "../../flamenco/repair/fd_repair.h"
       9             : #include "../../flamenco/runtime/fd_blockstore.h"
      10             : #include "../../flamenco/leaders/fd_leaders.h"
      11             : #include "../../flamenco/fd_flamenco.h"
      12             : #include "../../choreo/fd_choreo.h"
      13             : #include "../../util/net/fd_eth.h"
      14             : #include "../../util/net/fd_ip4.h"
      15             : #include "../../util/net/fd_udp.h"
      16             : #include "../../disco/shred/fd_stake_ci.h"
      17             : #include "../../disco/keyguard/fd_keyload.h"
      18             : #include "../../disco/keyguard/fd_keyguard_client.h"
      19             : #include "../../disco/keyguard/fd_keyguard.h"
      20             : #include "../../flamenco/leaders/fd_leaders.h"
      21             : #include "../../flamenco/runtime/fd_runtime.h"
      22             : #include "../../disco/fd_disco.h"
      23             : #include "../../util/pod/fd_pod.h"
      24             : #include "../../util/net/fd_net_headers.h"
      25             : 
      26             : #include <unistd.h>
      27             : #include <arpa/inet.h>
      28             : #include <linux/unistd.h>
      29             : #include <sys/random.h>
      30             : #include <netdb.h>
      31             : #include <netinet/in.h>
      32             : #include <sys/socket.h>
      33             : 
      34           0 : #define SCRATCH_MAX    (4UL /*KiB*/ << 10)
      35           0 : #define SCRATCH_DEPTH  (4UL) /* 4 scratch frames */
      36             : 
      37             : struct fd_sender_tile_ctx {
      38             :   fd_pubkey_t identity_key[ 1 ];
      39             :   fd_pubkey_t vote_acct_addr[ 1 ];
      40             : 
      41             :   fd_stake_ci_t * stake_ci;
      42             :   ulong *         poh_slot;
      43             :   fd_shred_dest_weighted_t * new_dest_ptr;
      44             :   ulong                      new_dest_cnt;
      45             : 
      46             :   uchar txn_buf[ sizeof(fd_txn_p_t) ] __attribute__((aligned(alignof(fd_txn_p_t))));
      47             : 
      48             :   fd_gossip_peer_addr_t tpu_serve_addr;
      49             :   fd_ip4_udp_hdrs_t     packet_hdr[1];
      50             :   ushort                net_id;
      51             : 
      52             :   ulong       stake_in_idx;
      53             :   fd_wksp_t * stake_in_mem;
      54             :   ulong       stake_in_chunk0;
      55             :   ulong       stake_in_wmark;
      56             : 
      57             :   ulong       contact_in_idx;
      58             :   fd_wksp_t * contact_in_mem;
      59             :   ulong       contact_in_chunk0;
      60             :   ulong       contact_in_wmark;
      61             : 
      62             :   ulong       replay_in_idx;
      63             :   fd_wksp_t * replay_in_mem;
      64             :   ulong       replay_in_chunk0;
      65             :   ulong       replay_in_wmark;
      66             : 
      67             :   ulong       poh_in_idx;
      68             :   fd_wksp_t * poh_in_mem;
      69             :   ulong       poh_in_chunk0;
      70             :   ulong       poh_in_wmark;
      71             : 
      72             :   ulong            gossip_out_idx;
      73             :   fd_frag_meta_t * gossip_out_mcache;
      74             :   ulong *          gossip_out_sync;
      75             :   ulong            gossip_out_depth;
      76             :   ulong            gossip_out_seq;
      77             : 
      78             :   fd_wksp_t * gossip_out_mem;
      79             :   ulong       gossip_out_chunk0;
      80             :   ulong       gossip_out_wmark;
      81             :   ulong       gossip_out_chunk;
      82             : 
      83             :   ulong            dedup_out_idx;
      84             :   fd_frag_meta_t * dedup_out_mcache;
      85             :   ulong *          dedup_out_sync;
      86             :   ulong            dedup_out_depth;
      87             :   ulong            dedup_out_seq;
      88             : 
      89             :   fd_wksp_t * dedup_out_mem;
      90             :   ulong       dedup_out_chunk0;
      91             :   ulong       dedup_out_wmark;
      92             :   ulong       dedup_out_chunk;
      93             : 
      94             :   ulong            net_out_idx;
      95             :   fd_frag_meta_t * net_out_mcache;
      96             :   ulong *          net_out_sync;
      97             :   ulong            net_out_depth;
      98             :   ulong            net_out_seq;
      99             : 
     100             :   fd_wksp_t * net_out_mem;
     101             :   ulong       net_out_chunk0;
     102             :   ulong       net_out_wmark;
     103             :   ulong       net_out_chunk;
     104             : 
     105             :   ulong                sign_in_idx;
     106             :   ulong                sign_out_idx;
     107             :   fd_keyguard_client_t keyguard_client[ 1 ];
     108             : 
     109             : };
     110             : typedef struct fd_sender_tile_ctx fd_sender_tile_ctx_t;
     111             : 
     112             : 
     113             : FD_FN_CONST static inline ulong
     114           0 : scratch_align( void ) {
     115           0 :   return 128UL;
     116           0 : }
     117             : 
     118             : FD_FN_PURE static inline ulong
     119           0 : loose_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
     120           0 :   return 0UL;
     121           0 : }
     122             : 
     123             : FD_FN_PURE static inline ulong
     124           0 : scratch_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED) {
     125           0 :   ulong l = FD_LAYOUT_INIT;
     126           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_sender_tile_ctx_t), sizeof(fd_sender_tile_ctx_t) );
     127           0 :   l = FD_LAYOUT_APPEND( l, fd_stake_ci_align(), fd_stake_ci_footprint() );
     128           0 :   l = FD_LAYOUT_APPEND( l, fd_scratch_smem_align(), fd_scratch_smem_footprint( SCRATCH_MAX   ) );
     129           0 :   l = FD_LAYOUT_APPEND( l, fd_scratch_fmem_align(), fd_scratch_fmem_footprint( SCRATCH_DEPTH ) );
     130           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
     131           0 : }
     132             : 
     133             : static void
     134             : send_packet( fd_sender_tile_ctx_t * ctx,
     135             :              uint                   dst_ip_addr,
     136             :              ushort                 dst_port,
     137             :              uchar const *          payload,
     138             :              ulong                  payload_sz,
     139           0 :              ulong                  tsorig ) {
     140           0 :   uchar * packet = fd_chunk_to_laddr( ctx->net_out_mem, ctx->net_out_chunk );
     141             : 
     142           0 :   fd_ip4_udp_hdrs_t * hdr = (fd_ip4_udp_hdrs_t *)packet;
     143           0 :   *hdr = *ctx->packet_hdr;
     144             : 
     145           0 :   fd_ip4_hdr_t * ip4 = hdr->ip4;
     146           0 :   ip4->daddr  = dst_ip_addr;
     147           0 :   ip4->net_id = fd_ushort_bswap( ctx->net_id++ );
     148           0 :   ip4->check  = 0U;
     149           0 :   ip4->net_tot_len = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_ip4_hdr_t)+sizeof(fd_udp_hdr_t)) );
     150           0 :   ip4->check  = fd_ip4_hdr_check_fast( ip4 );
     151             : 
     152           0 :   fd_udp_hdr_t * udp = hdr->udp;
     153           0 :   udp->net_dport = fd_ushort_bswap( dst_port );
     154           0 :   udp->net_len   = fd_ushort_bswap( (ushort)(payload_sz + sizeof(fd_udp_hdr_t)) );
     155           0 :   fd_memcpy( packet+sizeof(fd_ip4_udp_hdrs_t), payload, payload_sz );
     156           0 :   udp->check     = 0U;
     157             : 
     158           0 :   ulong tspub     = fd_frag_meta_ts_comp( fd_tickcount() );
     159           0 :   ulong sig       = fd_disco_netmux_sig( dst_ip_addr, dst_port, dst_ip_addr, DST_PROTO_OUTGOING, sizeof(fd_ip4_udp_hdrs_t) );
     160           0 :   ulong packet_sz = payload_sz + sizeof(fd_ip4_udp_hdrs_t);
     161           0 :   fd_mcache_publish( ctx->net_out_mcache, ctx->net_out_depth, ctx->net_out_seq, sig, ctx->net_out_chunk, packet_sz, 0UL, tsorig, tspub );
     162           0 :   ctx->net_out_seq   = fd_seq_inc( ctx->net_out_seq, 1UL );
     163           0 :   ctx->net_out_chunk = fd_dcache_compact_next( ctx->net_out_chunk, packet_sz, ctx->net_out_chunk0, ctx->net_out_wmark );
     164           0 : }
     165             : 
     166             : static int
     167             : get_current_leader_tpu_vote_contact( fd_sender_tile_ctx_t *      ctx,
     168           0 :                                      fd_shred_dest_weighted_t ** out_dest ) {
     169           0 :   ulong poh_slot = fd_fseq_query( ctx->poh_slot );
     170           0 :   if( poh_slot==ULONG_MAX ) { return -1; }
     171             : 
     172           0 :   fd_epoch_leaders_t const * lsched = fd_stake_ci_get_lsched_for_slot( ctx->stake_ci, poh_slot );
     173           0 :   if( FD_UNLIKELY( !lsched      ) ) { return -1; }
     174             : 
     175           0 :   fd_pubkey_t const * slot_leader = fd_epoch_leaders_get( lsched, poh_slot );
     176           0 :   if( FD_UNLIKELY( !slot_leader ) ) { return -1 ; } /* Count this as bad slot too */
     177             : 
     178           0 :   fd_shred_dest_t * sdest = fd_stake_ci_get_sdest_for_slot( ctx->stake_ci, poh_slot );
     179           0 :   fd_shred_dest_idx_t sdest_idx = fd_shred_dest_pubkey_to_idx( sdest, slot_leader );
     180           0 :   if( FD_UNLIKELY( sdest_idx==FD_SHRED_DEST_NO_DEST ) ) {
     181           0 :     return -1;
     182           0 :   }
     183             : 
     184           0 :   *out_dest = fd_shred_dest_idx_to_dest( sdest, sdest_idx );
     185             : 
     186           0 :   return 0;
     187           0 : }
     188             : 
     189             : static inline void
     190             : handle_new_cluster_contact_info( fd_sender_tile_ctx_t * ctx,
     191             :                                  uchar const *         buf,
     192           0 :                                  ulong                 buf_sz ) {
     193           0 :   ulong const * header = (ulong const *)fd_type_pun_const( buf );
     194             : 
     195           0 :   ulong dest_cnt = buf_sz;
     196             : 
     197           0 :   if( dest_cnt >= MAX_SHRED_DESTS )
     198           0 :     FD_LOG_ERR(( "Cluster nodes had %lu destinations, which was more than the max of %lu", dest_cnt, MAX_SHRED_DESTS ));
     199             : 
     200           0 :   fd_shred_dest_wire_t const * in_dests = fd_type_pun_const( header );
     201           0 :   fd_shred_dest_weighted_t * dests = fd_stake_ci_dest_add_init( ctx->stake_ci );
     202             : 
     203           0 :   ctx->new_dest_ptr = dests;
     204           0 :   ctx->new_dest_cnt = dest_cnt;
     205             : 
     206           0 :   for( ulong i=0UL; i<dest_cnt; i++ ) {
     207           0 :     memcpy( dests[i].pubkey.uc, in_dests[i].pubkey, 32UL );
     208           0 :     dests[i].ip4  = in_dests[i].ip4_addr;
     209           0 :     dests[i].port = in_dests[i].udp_port;
     210           0 :   }
     211           0 : }
     212             : 
     213             : static inline void
     214           0 : finalize_new_cluster_contact_info( fd_sender_tile_ctx_t * ctx ) {
     215           0 :   fd_stake_ci_dest_add_fini( ctx->stake_ci, ctx->new_dest_cnt );
     216           0 : }
     217             : 
     218             : static void
     219             : during_frag( fd_sender_tile_ctx_t * ctx,
     220             :              ulong                  in_idx,
     221             :              ulong                  seq FD_PARAM_UNUSED,
     222             :              ulong                  sig FD_PARAM_UNUSED,
     223             :              ulong                  chunk,
     224             :              ulong                  sz,
     225           0 :              ulong                  ctl FD_PARAM_UNUSED ) {
     226             : 
     227           0 :   if( FD_UNLIKELY( in_idx==ctx->sign_in_idx ) ) {
     228           0 :     FD_LOG_CRIT(( "signing tile send out of band fragment" ));
     229           0 :   }
     230             : 
     231           0 :   if( FD_UNLIKELY( in_idx==ctx->stake_in_idx ) ) {
     232           0 :     if( FD_UNLIKELY( chunk<ctx->stake_in_chunk0 || chunk>ctx->stake_in_wmark ) )
     233           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz,
     234           0 :             ctx->stake_in_chunk0, ctx->stake_in_wmark ));
     235           0 :     uchar const * dcache_entry = fd_chunk_to_laddr_const( ctx->stake_in_mem, chunk );
     236           0 :     fd_stake_ci_stake_msg_init( ctx->stake_ci, dcache_entry );
     237           0 :   }
     238             : 
     239           0 :   if( FD_UNLIKELY( in_idx==ctx->contact_in_idx ) ) {
     240           0 :     if( FD_UNLIKELY( chunk<ctx->contact_in_chunk0 || chunk>ctx->contact_in_wmark ) ) {
     241           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->contact_in_chunk0, ctx->contact_in_wmark ));
     242           0 :     }
     243             : 
     244           0 :     uchar const * dcache_entry = fd_chunk_to_laddr_const( ctx->contact_in_mem, chunk );
     245           0 :     handle_new_cluster_contact_info( ctx, dcache_entry, sz );
     246           0 :   }
     247             : 
     248           0 :   if( FD_UNLIKELY( in_idx==ctx->replay_in_idx ) ) {
     249           0 :     if( FD_UNLIKELY( chunk<ctx->replay_in_chunk0 || chunk>ctx->replay_in_wmark || sz!=sizeof(fd_txn_p_t) ) ) {
     250           0 :       FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->replay_in_chunk0, ctx->replay_in_wmark ));
     251           0 :     }
     252             : 
     253           0 :     uchar const * dcache_entry = fd_chunk_to_laddr_const( ctx->replay_in_mem, chunk );
     254           0 :     memcpy( ctx->txn_buf, dcache_entry, sz );
     255           0 :   }
     256           0 : }
     257             : 
     258             : static void
     259             : after_frag( fd_sender_tile_ctx_t * ctx,
     260             :             ulong                  in_idx,
     261             :             ulong                  seq,
     262             :             ulong                  sig,
     263             :             ulong                  sz,
     264             :             ulong                  tsorig,
     265             :             ulong                  tspub,
     266           0 :             fd_stem_context_t *    stem ) {
     267           0 :   (void)seq;
     268           0 :   (void)sig;
     269           0 :   (void)sz;
     270           0 :   (void)tsorig;
     271           0 :   (void)tspub;
     272           0 :   (void)stem;
     273             : 
     274           0 :   if( FD_UNLIKELY( in_idx==ctx->contact_in_idx ) ) {
     275           0 :     finalize_new_cluster_contact_info( ctx );
     276           0 :     return;
     277           0 :   }
     278             : 
     279           0 :   if( FD_UNLIKELY( in_idx==ctx->stake_in_idx ) ) {
     280           0 :     fd_stake_ci_stake_msg_fini( ctx->stake_ci );
     281           0 :     return;
     282           0 :   }
     283             : 
     284           0 :   if( FD_UNLIKELY( in_idx==ctx->replay_in_idx ) ) {
     285           0 :     fd_txn_p_t * txn = (fd_txn_p_t *)fd_type_pun(ctx->txn_buf);
     286             : 
     287             :     /* sign the txn */
     288           0 :     uchar * signature = txn->payload + TXN(txn)->signature_off;
     289           0 :     uchar * message   = txn->payload + TXN(txn)->message_off;
     290           0 :     ulong message_sz  = txn->payload_sz - TXN(txn)->message_off;
     291           0 :     fd_keyguard_client_sign( ctx->keyguard_client, signature, message, message_sz, FD_KEYGUARD_SIGN_TYPE_ED25519 );
     292             : 
     293           0 :     uchar * msg_to_gossip = fd_chunk_to_laddr( ctx->gossip_out_mem, ctx->gossip_out_chunk );
     294           0 :     memcpy( msg_to_gossip, txn->payload, txn->payload_sz );
     295             : 
     296             :     /* send to leader */
     297           0 :     fd_shred_dest_weighted_t * leader_dest = NULL;
     298           0 :     int res = get_current_leader_tpu_vote_contact( ctx, &leader_dest );
     299             :     /* TODO: add metrics for successful votes sent and failed votes */
     300           0 :     if( res==0 ) {
     301           0 :       send_packet( ctx, leader_dest->ip4, leader_dest->port, msg_to_gossip, txn->payload_sz, 0UL );
     302           0 :     }
     303             : 
     304             :     /* send to gossip */
     305           0 :     fd_mcache_publish( ctx->gossip_out_mcache, ctx->gossip_out_depth, ctx->gossip_out_seq, 1UL, ctx->gossip_out_chunk,
     306           0 :       txn->payload_sz, 0UL, 0, 0 );
     307           0 :     ctx->gossip_out_seq   = fd_seq_inc( ctx->gossip_out_seq, 1UL );
     308           0 :     ctx->gossip_out_chunk = fd_dcache_compact_next( ctx->gossip_out_chunk, txn->payload_sz,
     309           0 :                                                     ctx->gossip_out_chunk0, ctx->gossip_out_wmark );
     310             :     /* send to dedup */
     311           0 :     uchar * msg_to_pack = fd_chunk_to_laddr( ctx->dedup_out_mem, ctx->dedup_out_chunk );
     312           0 :     memcpy( msg_to_pack, msg_to_gossip, txn->payload_sz );
     313           0 :     fd_mcache_publish( ctx->dedup_out_mcache, ctx->dedup_out_depth, ctx->dedup_out_seq, 1UL, ctx->dedup_out_chunk,
     314           0 :       txn->payload_sz, 0UL, 0, 0 );
     315           0 :     ctx->dedup_out_seq    = fd_seq_inc( ctx->dedup_out_seq, 1UL );
     316           0 :     ctx->dedup_out_chunk = fd_dcache_compact_next( ctx->dedup_out_chunk, txn->payload_sz, ctx->dedup_out_chunk0,
     317           0 :         ctx->dedup_out_wmark );
     318           0 :   }
     319           0 : }
     320             : 
     321             : static void
     322             : privileged_init( fd_topo_t *      topo,
     323           0 :                  fd_topo_tile_t * tile ) {
     324           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     325             : 
     326           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     327           0 :   fd_sender_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_sender_tile_ctx_t), sizeof(fd_sender_tile_ctx_t) );
     328             : 
     329           0 :   if( FD_UNLIKELY( !strcmp( tile->sender.identity_key_path, "" ) ) )
     330           0 :     FD_LOG_ERR(( "identity_key_path not set" ));
     331             : 
     332           0 :   ctx->identity_key[ 0 ] = *(fd_pubkey_t const *)fd_type_pun_const( fd_keyload_load( tile->sender.identity_key_path, /* pubkey only: */ 1 ) );
     333           0 : }
     334             : 
     335             : static void
     336             : unprivileged_init( fd_topo_t *      topo,
     337           0 :                    fd_topo_tile_t * tile ) {
     338           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     339             : 
     340           0 :   if( FD_UNLIKELY( !tile->out_cnt ) ) FD_LOG_ERR(( "sender has no primary output link" ));
     341             : 
     342             :   /* Scratch mem setup */
     343             : 
     344           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     345           0 :   fd_sender_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_sender_tile_ctx_t), sizeof(fd_sender_tile_ctx_t) );
     346             :   // TODO: set the lo_mark_slot to the actual snapshot slot!
     347           0 :   ctx->stake_ci = fd_stake_ci_join( fd_stake_ci_new( FD_SCRATCH_ALLOC_APPEND( l, fd_stake_ci_align(), fd_stake_ci_footprint() ), ctx->identity_key ) );
     348           0 :   void * scratch_smem        = FD_SCRATCH_ALLOC_APPEND( l, fd_scratch_smem_align(), fd_scratch_smem_footprint( SCRATCH_MAX   ) );
     349           0 :   void * scratch_fmem        = FD_SCRATCH_ALLOC_APPEND( l, fd_scratch_fmem_align(), fd_scratch_fmem_footprint( SCRATCH_DEPTH ) );
     350             : 
     351             :   /* scratch space attach */
     352           0 :   fd_scratch_attach( scratch_smem, scratch_fmem, SCRATCH_MAX, SCRATCH_DEPTH );
     353             : 
     354           0 :   ctx->net_id = (ushort)0;
     355             : 
     356           0 :   ctx->tpu_serve_addr.addr = tile->sender.ip_addr;
     357           0 :   ctx->tpu_serve_addr.port = fd_ushort_bswap( tile->sender.tpu_listen_port );
     358           0 :   fd_ip4_udp_hdr_init( ctx->packet_hdr, FD_TXN_MTU, ctx->tpu_serve_addr.addr, ctx->tpu_serve_addr.port );
     359             : 
     360           0 :   ulong poh_slot_obj_id = fd_pod_query_ulong( topo->props, "poh_slot", ULONG_MAX );
     361           0 :   FD_TEST( poh_slot_obj_id!=ULONG_MAX );
     362           0 :   ctx->poh_slot = fd_fseq_join( fd_topo_obj_laddr( topo, poh_slot_obj_id ) );
     363             : 
     364             :   /* Set up stake input */
     365           0 :   ctx->stake_in_idx = fd_topo_find_tile_in_link( topo, tile, "stake_out", 0 );
     366           0 :   FD_TEST( ctx->stake_in_idx!=ULONG_MAX );
     367           0 :   fd_topo_link_t * stake_in_link = &topo->links[ tile->in_link_id[ ctx->stake_in_idx ] ];
     368           0 :   ctx->stake_in_mem    = topo->workspaces[ topo->objs[ stake_in_link->dcache_obj_id ].wksp_id ].wksp;
     369           0 :   ctx->stake_in_chunk0 = fd_dcache_compact_chunk0( ctx->stake_in_mem, stake_in_link->dcache );
     370           0 :   ctx->stake_in_wmark  = fd_dcache_compact_wmark( ctx->stake_in_mem, stake_in_link->dcache, stake_in_link->mtu );
     371             : 
     372             :   /* Set up contact input */
     373           0 :   ctx->contact_in_idx = fd_topo_find_tile_in_link( topo, tile, "gossip_voter", 0 );
     374           0 :   FD_TEST( ctx->contact_in_idx!=ULONG_MAX );
     375           0 :   fd_topo_link_t * contact_in_link = &topo->links[ tile->in_link_id[ ctx->contact_in_idx ] ];
     376           0 :   ctx->contact_in_mem    = topo->workspaces[ topo->objs[ contact_in_link->dcache_obj_id ].wksp_id ].wksp;
     377           0 :   ctx->contact_in_chunk0 = fd_dcache_compact_chunk0( ctx->contact_in_mem, contact_in_link->dcache );
     378           0 :   ctx->contact_in_wmark  = fd_dcache_compact_wmark( ctx->contact_in_mem, contact_in_link->dcache, contact_in_link->mtu );
     379             : 
     380             :   /* Set up replay tile input */
     381           0 :   ctx->replay_in_idx = fd_topo_find_tile_in_link( topo, tile, "replay_voter", 0 );
     382           0 :   FD_TEST( ctx->replay_in_idx!=ULONG_MAX );
     383           0 :   fd_topo_link_t * replay_in_link = &topo->links[ tile->in_link_id[ ctx->replay_in_idx ] ];
     384           0 :   ctx->replay_in_mem    = topo->workspaces[ topo->objs[ replay_in_link->dcache_obj_id ].wksp_id ].wksp;
     385           0 :   ctx->replay_in_chunk0 = fd_dcache_compact_chunk0( ctx->replay_in_mem, replay_in_link->dcache );
     386           0 :   ctx->replay_in_wmark  = fd_dcache_compact_wmark( ctx->replay_in_mem, replay_in_link->dcache, replay_in_link->mtu );
     387             : 
     388             :   /* Set up repair request output */
     389           0 :   ctx->gossip_out_idx = fd_topo_find_tile_out_link( topo, tile, "voter_gossip", 0 );
     390           0 :   FD_TEST( ctx->gossip_out_idx!=ULONG_MAX );
     391           0 :   fd_topo_link_t * gossip_out_link = &topo->links[ tile->out_link_id[ ctx->gossip_out_idx ] ];
     392           0 :   ctx->gossip_out_mcache = gossip_out_link->mcache;
     393           0 :   ctx->gossip_out_sync   = fd_mcache_seq_laddr( ctx->gossip_out_mcache );
     394           0 :   ctx->gossip_out_depth  = fd_mcache_depth( ctx->gossip_out_mcache );
     395           0 :   ctx->gossip_out_seq    = fd_mcache_seq_query( ctx->gossip_out_sync );
     396           0 :   ctx->gossip_out_mem    = topo->workspaces[ topo->objs[ gossip_out_link->dcache_obj_id ].wksp_id ].wksp;
     397           0 :   ctx->gossip_out_chunk0 = fd_dcache_compact_chunk0( ctx->gossip_out_mem, gossip_out_link->dcache );
     398           0 :   ctx->gossip_out_wmark  = fd_dcache_compact_wmark ( ctx->gossip_out_mem, gossip_out_link->dcache, gossip_out_link->mtu );
     399           0 :   ctx->gossip_out_chunk  = ctx->gossip_out_chunk0;
     400             : 
     401             :   /* Set up dedup output */
     402           0 :   ctx->dedup_out_idx = fd_topo_find_tile_out_link( topo, tile, "voter_dedup", 0 );
     403           0 :   FD_TEST( ctx->dedup_out_idx!=ULONG_MAX );
     404           0 :   fd_topo_link_t * dedup_out_link = &topo->links[ tile->out_link_id[ ctx->dedup_out_idx ] ];
     405           0 :   ctx->dedup_out_mcache = dedup_out_link->mcache;
     406           0 :   ctx->dedup_out_sync   = fd_mcache_seq_laddr( ctx->dedup_out_mcache );
     407           0 :   ctx->dedup_out_depth  = fd_mcache_depth( ctx->dedup_out_mcache );
     408           0 :   ctx->dedup_out_seq    = fd_mcache_seq_query( ctx->dedup_out_sync );
     409           0 :   ctx->dedup_out_mem    = topo->workspaces[ topo->objs[ dedup_out_link->dcache_obj_id ].wksp_id ].wksp;
     410           0 :   ctx->dedup_out_chunk0 = fd_dcache_compact_chunk0( ctx->dedup_out_mem, dedup_out_link->dcache );
     411           0 :   ctx->dedup_out_wmark  = fd_dcache_compact_wmark ( ctx->dedup_out_mem, dedup_out_link->dcache, dedup_out_link->mtu );
     412           0 :   ctx->dedup_out_chunk  = ctx->dedup_out_chunk0;
     413             : 
     414             :   /* Set up net output */
     415           0 :   ctx->net_out_idx = fd_topo_find_tile_out_link( topo, tile, "voter_net", 0 );
     416           0 :   FD_TEST( ctx->net_out_idx!=ULONG_MAX );
     417           0 :   fd_topo_link_t * net_out_link = &topo->links[ tile->out_link_id[ ctx->net_out_idx ] ];
     418           0 :   ctx->net_out_mcache = net_out_link->mcache;
     419           0 :   ctx->net_out_sync   = fd_mcache_seq_laddr( ctx->net_out_mcache );
     420           0 :   ctx->net_out_depth  = fd_mcache_depth( ctx->net_out_mcache );
     421           0 :   ctx->net_out_seq    = fd_mcache_seq_query( ctx->net_out_sync );
     422           0 :   ctx->net_out_mem    = topo->workspaces[ topo->objs[ net_out_link->dcache_obj_id ].wksp_id ].wksp;
     423           0 :   ctx->net_out_chunk0 = fd_dcache_compact_chunk0( ctx->net_out_mem, net_out_link->dcache );
     424           0 :   ctx->net_out_wmark  = fd_dcache_compact_wmark ( ctx->net_out_mem, net_out_link->dcache, net_out_link->mtu );
     425           0 :   ctx->net_out_chunk  = ctx->net_out_chunk0;
     426             : 
     427             : 
     428             :   /* Set up keyguard(s) */
     429           0 :   ctx->sign_in_idx  = fd_topo_find_tile_in_link( topo, tile, "sign_voter", 0 );
     430           0 :   ctx->sign_out_idx = fd_topo_find_tile_out_link( topo, tile, "voter_sign", 0 );
     431           0 :   FD_TEST( ctx->sign_in_idx==( tile->in_cnt-1 ) );
     432             : 
     433           0 :   fd_topo_link_t * sign_in  = &topo->links[ tile->in_link_id[ ctx->sign_in_idx ] ];
     434           0 :   fd_topo_link_t * sign_out = &topo->links[ tile->out_link_id[ ctx->sign_out_idx ] ];
     435             : 
     436           0 :   if ( fd_keyguard_client_join( fd_keyguard_client_new( ctx->keyguard_client,
     437           0 :                                                             sign_out->mcache,
     438           0 :                                                             sign_out->dcache,
     439           0 :                                                             sign_in->mcache,
     440           0 :                                                             sign_in->dcache ) )==NULL ) {
     441           0 :     FD_LOG_ERR(( "Keyguard join failed" ));
     442           0 :   }
     443           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     444           0 :   if( FD_UNLIKELY( scratch_top != (ulong)scratch + scratch_footprint( tile ) ) ) {
     445           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     446           0 :   }
     447           0 : }
     448             : 
     449             : 
     450             : static ulong
     451             : populate_allowed_seccomp( fd_topo_t const *      topo,
     452             :                           fd_topo_tile_t const * tile,
     453             :                           ulong                  out_cnt,
     454           0 :                           struct sock_filter *   out ) {
     455           0 :   (void)topo;
     456           0 :   (void)tile;
     457             : 
     458           0 :   populate_sock_filter_policy_fd_sender_tile( out_cnt, out, (uint)fd_log_private_logfile_fd() );
     459           0 :   return sock_filter_policy_fd_sender_tile_instr_cnt;
     460           0 : }
     461             : 
     462             : static ulong
     463             : populate_allowed_fds( fd_topo_t const *      topo,
     464             :                       fd_topo_tile_t const * tile,
     465             :                       ulong                  out_fds_cnt,
     466           0 :                       int *                  out_fds ) {
     467           0 :   (void)topo;
     468           0 :   (void)tile;
     469             : 
     470           0 :   if( FD_UNLIKELY( out_fds_cnt<2UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     471             : 
     472           0 :   ulong out_cnt = 0;
     473           0 :   out_fds[ out_cnt++ ] = 2UL; /* stderr */
     474           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     475           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     476           0 :   return out_cnt;
     477           0 : }
     478             : 
     479           0 : #define STEM_BURST (1UL)
     480             : 
     481           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_sender_tile_ctx_t
     482           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_sender_tile_ctx_t)
     483             : 
     484           0 : #define STEM_CALLBACK_DURING_FRAG during_frag
     485           0 : #define STEM_CALLBACK_AFTER_FRAG  after_frag
     486             : 
     487             : #include "../../disco/stem/fd_stem.c"
     488             : 
     489             : fd_topo_run_tile_t fd_tile_sender = {
     490             :   .name                     = "sender",
     491             :   .loose_footprint          = loose_footprint,
     492             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     493             :   .populate_allowed_fds     = populate_allowed_fds,
     494             :   .scratch_align            = scratch_align,
     495             :   .scratch_footprint        = scratch_footprint,
     496             :   .privileged_init          = privileged_init,
     497             :   .unprivileged_init        = unprivileged_init,
     498             :   .run                      = stem_run,
     499             : };

Generated by: LCOV version 1.14