Line data Source code
1 : #ifndef HEADER_fd_src_app_fdctl_run_tiles_fd_send_tile_h 2 : #define HEADER_fd_src_app_fdctl_run_tiles_fd_send_tile_h 3 : 4 : /* Sender tile signs and sends transactions to the current leader. 5 : Currently only supports transactions which require one signature. 6 : Designed with voting as primary use case. Signing those votes will 7 : eventually move to a separate consensus tile.*/ 8 : #define _GNU_SOURCE 9 : 10 : #include "../../util/net/fd_net_headers.h" 11 : #include "../../disco/stem/fd_stem.h" 12 : #include "../../disco/fd_disco.h" 13 : #include "../../disco/pack/fd_microblock.h" 14 : #include "../../disco/net/fd_net_tile.h" 15 : #include "../../disco/keyguard/fd_keyguard_client.h" 16 : #include "../../flamenco/leaders/fd_multi_epoch_leaders.h" 17 : #include "../../flamenco/gossip/fd_gossip.h" 18 : #include "../../waltz/quic/fd_quic.h" 19 : 20 : #define IN_KIND_SIGN (0UL) 21 0 : #define IN_KIND_GOSSIP (1UL) 22 0 : #define IN_KIND_STAKE (2UL) 23 0 : #define IN_KIND_TOWER (3UL) 24 0 : #define IN_KIND_NET (4UL) 25 : 26 : /* Send votes to leaders for next SEND_TO_LEADER_CNT slots */ 27 0 : #define SEND_TO_LEADER_CNT 4UL 28 : 29 0 : #define QUIC_IDLE_TIMEOUT_NS (2e9) /* 2 seconds */ 30 0 : #define QUIC_ACK_DELAY_NS (25e6) /* 25ms */ 31 : 32 : struct fd_send_link_in { 33 : fd_wksp_t * mem; 34 : ulong chunk0; 35 : ulong wmark; 36 : ulong kind; 37 : void * dcache; 38 : }; 39 : typedef struct fd_send_link_in fd_send_link_in_t; 40 : 41 : struct fd_send_link_out { 42 : ulong idx; 43 : fd_frag_meta_t * mcache; 44 : ulong * sync; 45 : ulong depth; 46 : 47 : fd_wksp_t * mem; 48 : ulong chunk0; 49 : ulong wmark; 50 : ulong chunk; 51 : }; 52 : typedef struct fd_send_link_out fd_send_link_out_t; 53 : struct fd_send_conn_entry { 54 : fd_pubkey_t pubkey; 55 : uint hash; 56 : fd_quic_conn_t * conn; 57 : long last_ci_ticks; 58 : uint ip4_addr; 59 : ushort udp_port; 60 : }; 61 : typedef struct fd_send_conn_entry fd_send_conn_entry_t; 62 : 63 : 64 : struct fd_send_tile_ctx { 65 : fd_pubkey_t identity_key[ 1 ]; /* also tls pubkey */ 66 : fd_pubkey_t vote_acct_addr[ 1 ]; 67 : 68 : fd_multi_epoch_leaders_t * mleaders; 69 : 70 : fd_shred_dest_wire_t contact_buf[ MAX_STAKED_LEADERS ]; 71 : ulong contact_cnt; 72 : 73 : uchar txn_buf[ sizeof(fd_txn_p_t) ] __attribute__((aligned(alignof(fd_txn_p_t)))); 74 : 75 : uint src_ip_addr; 76 : ushort src_port; 77 : fd_ip4_udp_hdrs_t packet_hdr[1]; 78 : 79 : #define fd_send_MAX_IN_LINK_CNT 32UL 80 : fd_send_link_in_t in_links[ fd_send_MAX_IN_LINK_CNT ]; 81 : 82 : fd_send_link_out_t gossip_verify_out[1]; 83 : fd_send_link_out_t net_out [1]; 84 : 85 : fd_keyguard_client_t keyguard_client[ 1 ]; 86 : 87 : fd_quic_t * quic; 88 : fd_aio_t quic_tx_aio[1]; 89 : 90 : uchar quic_buf[ FD_NET_MTU ]; 91 : 92 : fd_net_rx_bounds_t net_in_bounds; 93 : 94 : /* Connection map for outgoing QUIC connections and contact info */ 95 : fd_send_conn_entry_t * conn_map; 96 : 97 : fd_stem_context_t * stem; 98 : long now; 99 : 100 : struct { 101 : ulong leader_not_found; /* Number of times slot leader not found when voting. */ 102 : ulong contact_stale; /* Number of reconnects skipped due to stale contact info */ 103 : ulong quic_conn_create_failed; /* QUIC connection creation failed */ 104 : 105 : /* Handling of new contact info */ 106 : ulong new_contact_info[FD_METRICS_ENUM_NEW_CONTACT_OUTCOME_CNT]; 107 : 108 : /* Outcome of trying to send data over quic */ 109 : ulong quic_send_result_cnt[FD_METRICS_ENUM_TXN_QUIC_SEND_RESULT_CNT]; 110 : 111 : /* Time spent waiting for tls_cv signatures */ 112 : fd_histf_t sign_duration[ 1 ]; 113 : } metrics; 114 : 115 : uchar __attribute__((aligned(FD_MULTI_EPOCH_LEADERS_ALIGN))) mleaders_mem[ FD_MULTI_EPOCH_LEADERS_FOOTPRINT ]; 116 : 117 : }; 118 : typedef struct fd_send_tile_ctx fd_send_tile_ctx_t; 119 : 120 : 121 : /* A few larger functions to wrap QUIC interactions */ 122 : 123 : /* quic_connect initiates a quic connection. It uses the contact info 124 : stored in entry, and points the conn and entry to each other. Returns 125 : a handle to the new connection, and NULL if creating it failed */ 126 : fd_quic_conn_t * 127 : quic_connect( fd_send_tile_ctx_t * ctx, 128 : fd_send_conn_entry_t * entry ); 129 : 130 : /* quic_send sends a payload to 'pubkey' via quic. Requires an already 131 : established connection to 'pubkey'. */ 132 : void 133 : quic_send( fd_send_tile_ctx_t * ctx, 134 : fd_pubkey_t const * pubkey, 135 : uchar const * payload, 136 : ulong payload_sz ); 137 : 138 : #endif