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