Line data Source code
1 : #ifndef HEADER_fd_src_disco_fd_txn_m_h
2 : #define HEADER_fd_src_disco_fd_txn_m_h
3 :
4 : /* A fd_txn_m_t is a parsed meta transaction, containing not just the
5 : payload */
6 :
7 : #include "../ballet/txn/fd_txn.h"
8 :
9 0 : #define FD_TXN_M_TPU_SOURCE_QUIC (1UL)
10 0 : #define FD_TXN_M_TPU_SOURCE_UDP (2UL)
11 0 : #define FD_TXN_M_TPU_SOURCE_GOSSIP (3UL)
12 0 : #define FD_TXN_M_TPU_SOURCE_BUNDLE (4UL)
13 0 : #define FD_TXN_M_TPU_SOURCE_TXSEND (5UL)
14 :
15 : struct fd_txn_m {
16 : /* The block height of the computed slot that this transaction is
17 : referencing, aka. the block height of the reference_blockhash. If
18 : it could not be determined, this will be the block height of the
19 : current slot. */
20 : ulong reference_block_height;
21 :
22 : ushort payload_sz;
23 :
24 : /* Can be computed from the txn_t but it's expensive to parse again,
25 : so we just store this redundantly. */
26 : ushort txn_t_sz;
27 :
28 : /* Source tpu and IP address for this transaction. Note that
29 : source_ipv4 is in big endian. */
30 : uint source_ipv4;
31 : uchar source_tpu;
32 :
33 : /* 7 bytes of padding here */
34 :
35 : /* Wallclock nanoseconds at which this transaction entered the
36 : validator. */
37 : long first_seen_nanos;
38 :
39 : struct {
40 : /* If the transaction is part of a bundle, the bundle_id will be
41 : non-zero, and if this transaction is the first one in the
42 : bundle, bundle_txn_cnt will be non-zero.
43 :
44 : The pack tile can accumulate transactions from a bundle until
45 : it has all of them, at which point the bundle is schedulable.
46 :
47 : Bundles will not arrive to pack interleaved with other bundles
48 : (although might be interleaved with other non-bundle
49 : transactions), so if pack sees the bundle_id change before
50 : collecting all the bundle_txn_cnt transactions, it should
51 : abandon the bundle, as one or more of the transactions failed
52 : to signature verify or resolve.
53 :
54 : The commission and commission_pubkey fields are provided by
55 : the block engine, and the validator will crank the tip payment
56 : program with these values, if it is not using them already.
57 : These fields are only provided on the first transaction in a
58 : bundle. */
59 : ulong bundle_id;
60 : ulong bundle_txn_cnt;
61 : uchar commission;
62 : uchar commission_pubkey[ 32 ];
63 :
64 : /* alignof is 8, so 7 bytes of padding here */
65 :
66 : } block_engine;
67 :
68 : /* There are three additional fields at the end here, which are
69 : variable length and not included in the size of this struct. txn_t
70 : and alut are only found in frags after the verify step.
71 : uchar payload[ ]
72 : fd_txn_t txn_t[ ]
73 : fd_acct_addr_t alut[ ] */
74 : };
75 :
76 : typedef struct fd_txn_m fd_txn_m_t;
77 :
78 : static FD_FN_CONST inline ulong
79 0 : fd_txn_m_align( void ) {
80 0 : return alignof(fd_txn_m_t);
81 0 : }
82 :
83 : static inline ulong
84 : fd_txn_m_footprint( ulong payload_sz,
85 : ulong instr_cnt,
86 : ulong addr_table_lookup_cnt,
87 0 : ulong addr_table_adtl_cnt ) {
88 0 : ulong l = FD_LAYOUT_INIT;
89 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_txn_m_t), sizeof(fd_txn_m_t) );
90 0 : l = FD_LAYOUT_APPEND( l, 1UL, payload_sz );
91 0 : l = FD_LAYOUT_APPEND( l, fd_txn_align(), fd_txn_footprint( instr_cnt, addr_table_lookup_cnt ) );
92 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_acct_addr_t), addr_table_adtl_cnt*sizeof(fd_acct_addr_t) );
93 0 : return FD_LAYOUT_FINI( l, fd_txn_m_align() );
94 0 : }
95 :
96 : static inline uchar *
97 0 : fd_txn_m_payload( fd_txn_m_t * txnm ) {
98 0 : return (uchar *)(txnm+1UL);
99 0 : }
100 :
101 : static inline uchar const *
102 0 : fd_txn_m_payload_const( fd_txn_m_t const * txnm ) {
103 0 : return (uchar const *)(txnm+1UL);
104 0 : }
105 :
106 : static inline fd_txn_t *
107 0 : fd_txn_m_txn_t( fd_txn_m_t * txnm ) {
108 0 : return (fd_txn_t *)fd_ulong_align_up( (ulong)(txnm+1UL) + txnm->payload_sz, alignof( fd_txn_t ) );
109 0 : }
110 :
111 : static inline fd_txn_t const *
112 0 : fd_txn_m_txn_t_const( fd_txn_m_t const * txnm ) {
113 0 : return (fd_txn_t const *)fd_ulong_align_up( (ulong)(txnm+1UL) + txnm->payload_sz, alignof( fd_txn_t ) );
114 0 : }
115 :
116 : static inline fd_acct_addr_t *
117 0 : fd_txn_m_alut( fd_txn_m_t * txnm ) {
118 0 : return (fd_acct_addr_t *)fd_ulong_align_up( fd_ulong_align_up( (ulong)(txnm+1UL) + txnm->payload_sz, alignof( fd_txn_t ) )+txnm->txn_t_sz, alignof( fd_acct_addr_t ) );
119 0 : }
120 :
121 : static inline ulong
122 : fd_txn_m_realized_footprint( fd_txn_m_t const * txnm,
123 : int include_txn_t,
124 0 : int include_alut ) {
125 0 : if( FD_LIKELY( include_txn_t ) ) {
126 0 : ulong l = FD_LAYOUT_INIT;
127 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_txn_m_t), sizeof(fd_txn_m_t) );
128 0 : l = FD_LAYOUT_APPEND( l, 1UL, txnm->payload_sz );
129 0 : l = FD_LAYOUT_APPEND( l, fd_txn_align(), fd_txn_footprint( fd_txn_m_txn_t_const( txnm )->instr_cnt, fd_txn_m_txn_t_const( txnm )->addr_table_lookup_cnt ) );
130 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_acct_addr_t), fd_uchar_if(include_alut, fd_txn_m_txn_t_const( txnm )->addr_table_adtl_cnt, 0U)*sizeof(fd_acct_addr_t) );
131 :
132 : /* FD_LAYOUT_FINI is not included since the _realized_ footprint
133 : should not include the extra padding typically added after the
134 : last struct used to align the entire footprint. */
135 0 : return l;
136 0 : } else {
137 0 : ulong l = FD_LAYOUT_INIT;
138 0 : l = FD_LAYOUT_APPEND( l, alignof(fd_txn_m_t), sizeof(fd_txn_m_t) );
139 0 : l = FD_LAYOUT_APPEND( l, 1UL, txnm->payload_sz );
140 0 : return l;
141 0 : }
142 0 : }
143 :
144 : #define FD_TPU_RAW_MTU FD_ULONG_ALIGN_UP( \
145 : sizeof(fd_txn_m_t)+FD_TPU_MTU, \
146 : alignof(fd_txn_m_t) )
147 :
148 0 : #define FD_TPU_PARSED_MTU FD_ULONG_ALIGN_UP( \
149 0 : FD_ULONG_ALIGN_UP( \
150 0 : sizeof(fd_txn_m_t)+FD_TPU_MTU, \
151 0 : alignof(fd_txn_t) ) \
152 0 : +FD_TXN_MAX_SZ, \
153 0 : alignof(fd_txn_m_t) )
154 :
155 0 : #define FD_TPU_RESOLVED_MTU FD_ULONG_ALIGN_UP( \
156 0 : FD_ULONG_ALIGN_UP( \
157 0 : FD_ULONG_ALIGN_UP( \
158 0 : sizeof(fd_txn_m_t)+FD_TPU_MTU, \
159 0 : alignof(fd_txn_t) ) \
160 0 : +FD_TXN_MAX_SZ, \
161 0 : alignof(fd_acct_addr_t) ) \
162 0 : +FD_TXN_ACCT_ADDR_MAX*sizeof(fd_acct_addr_t), \
163 0 : alignof(fd_txn_m_t) )
164 :
165 : #endif /* HEADER_fd_src_disco_fd_txn_m_h */
|