Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_fd_hashes_h
2 : #define HEADER_fd_src_flamenco_runtime_fd_hashes_h
3 :
4 : #include "../fd_flamenco_base.h"
5 : #include "../types/fd_types.h"
6 : #include "../../funk/fd_funk.h"
7 : #include "../../ballet/lthash/fd_lthash.h"
8 : #include "fd_runtime_public.h"
9 :
10 0 : #define FD_PUBKEY_HASH_PAIR_ALIGN (16UL)
11 : struct __attribute__((aligned(FD_PUBKEY_HASH_PAIR_ALIGN))) fd_pubkey_hash_pair {
12 : fd_funk_rec_t const * rec;
13 : fd_hash_t const * hash;
14 : };
15 : typedef struct fd_pubkey_hash_pair fd_pubkey_hash_pair_t;
16 0 : #define FD_PUBKEY_HASH_PAIR_FOOTPRINT (sizeof(fd_pubkey_hash_pair_t))
17 :
18 : struct fd_pubkey_hash_pair_list {
19 : fd_pubkey_hash_pair_t * pairs;
20 : ulong pairs_len;
21 : };
22 : typedef struct fd_pubkey_hash_pair_list fd_pubkey_hash_pair_list_t;
23 :
24 : struct fd_subrange_task_info {
25 : fd_features_t const * features;
26 : fd_funk_t * funk;
27 : ulong num_lists;
28 : fd_pubkey_hash_pair_list_t * lists;
29 : fd_lthash_value_t * lthash_values;
30 : };
31 : typedef struct fd_subrange_task_info fd_subrange_task_info_t;
32 :
33 : struct fd_accounts_hash_task_info {
34 : fd_exec_slot_ctx_t * slot_ctx;
35 : fd_pubkey_t acc_pubkey[1];
36 : fd_hash_t acc_hash[1];
37 : uint should_erase;
38 : uint hash_changed;
39 : };
40 : typedef struct fd_accounts_hash_task_info fd_accounts_hash_task_info_t;
41 :
42 : struct fd_accounts_hash_task_data {
43 : fd_accounts_hash_task_info_t * info;
44 : ulong info_sz;
45 : fd_lthash_value_t * lthash_values;
46 : ulong num_recs;
47 : };
48 : typedef struct fd_accounts_hash_task_data fd_accounts_hash_task_data_t;
49 :
50 : union fd_features;
51 : typedef union fd_features fd_features_t;
52 :
53 : FD_PROTOTYPES_BEGIN
54 :
55 : /* These functions are used to size out and gather all of the accounts
56 : that are going to be hashed.
57 : TODO: This code can be removed when lthash is enabled. */
58 :
59 : ulong
60 : fd_accounts_sorted_subrange_count( fd_funk_t * funk,
61 : uint range_idx,
62 : uint range_cnt );
63 :
64 : void
65 : fd_accounts_sorted_subrange_gather( fd_funk_t * funk,
66 : uint range_idx,
67 : uint range_cnt,
68 : ulong * num_pairs_out,
69 : fd_lthash_value_t * lthash_values_out,
70 : fd_pubkey_hash_pair_t * pairs,
71 : fd_features_t const * features );
72 :
73 : void
74 : fd_accounts_hash_counter_and_gather_tpool_cb( void * para_arg_1,
75 : void * para_arg_2,
76 : void * fn_arg_1,
77 : void * fn_arg_2,
78 : void * fn_arg_3,
79 : void * fn_arg_4 );
80 :
81 : int
82 : fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx,
83 : fd_hash_t * hash,
84 : fd_capture_ctx_t * capture_ctx,
85 : fd_accounts_hash_task_data_t * task_datas,
86 : ulong task_datas_cnt,
87 : fd_lthash_value_t * lt_hashes,
88 : ulong lt_hashes_cnt,
89 : ulong signature_cnt,
90 : fd_spad_t * runtime_spad );
91 :
92 : void
93 : fd_collect_modified_accounts( fd_exec_slot_ctx_t * slot_ctx,
94 : fd_accounts_hash_task_data_t * task_data,
95 : fd_spad_t * runtime_spad );
96 :
97 : void
98 : fd_account_hash( fd_funk_t * funk,
99 : fd_funk_txn_t * funk_txn,
100 : fd_accounts_hash_task_info_t * task_info,
101 : fd_lthash_value_t * lt_hash,
102 : ulong slot,
103 : fd_features_t const * features );
104 :
105 : int
106 : fd_update_hash_bank_tpool( fd_exec_slot_ctx_t * slot_ctx,
107 : fd_capture_ctx_t * capture_ctx,
108 : fd_hash_t * hash,
109 : ulong signature_cnt,
110 : fd_tpool_t * tpool,
111 : fd_spad_t * runtime_spad );
112 :
113 :
114 : /* fd_hash_account is the method to compute the account
115 : hash. It includes the following content:
116 : - lamports
117 : - rent_epoch
118 : - data
119 : - executable
120 : - owner
121 : - pubkey
122 :
123 : Writes the resulting hash to hash, and returns hash. */
124 :
125 : void const *
126 : fd_hash_account( uchar hash [ static 32 ],
127 : fd_lthash_value_t * lthash,
128 : fd_account_meta_t const * account,
129 : fd_pubkey_t const * pubkey,
130 : uchar const * data,
131 : int hash_needed,
132 : fd_features_t const * features
133 : );
134 :
135 : /* fd_hash_account_current chooses the correct account hash function
136 : based on feature activation state. */
137 :
138 0 : #define FD_HASH_JUST_ACCOUNT_HASH (1)
139 0 : #define FD_HASH_JUST_LTHASH (2)
140 0 : #define FD_HASH_BOTH_HASHES (3)
141 :
142 : void const *
143 : fd_hash_account_current( uchar hash [ static 32 ],
144 : fd_lthash_value_t *lthash,
145 : fd_account_meta_t const *account,
146 : fd_pubkey_t const *pubkey,
147 : uchar const * data,
148 : int hash_needed,
149 : fd_features_t const * features );
150 :
151 : /* Generate a complete accounts_hash of the entire account database. */
152 :
153 : int
154 : fd_accounts_hash( fd_funk_t * funk,
155 : ulong slot,
156 : fd_hash_t * accounts_hash,
157 : fd_spad_t * runtime_spad,
158 : fd_features_t const * features,
159 : fd_exec_para_cb_ctx_t * exec_para_ctx,
160 : fd_lthash_value_t * lt_hash );
161 :
162 : /* Generate a non-incremental hash of the entire account database, including
163 : the epoch account hash. It differs from fd_snapshot_hash in that this version
164 : is used by the snapshot service which doesn't have access to a slot_ctx
165 : handle. However, it retains a copy of funk and epoch_bank.
166 : Do the same for the incremental hash. These functions are also
167 : responsible for conditionally including the epoch account hash into
168 : the account hash. These hashes are used by the snapshot service.
169 : TODO: These should be used to generate the hashes from snapshot loading. */
170 :
171 : int
172 : fd_snapshot_service_hash( fd_hash_t * accounts_hash,
173 : fd_hash_t * snapshot_hash,
174 : fd_funk_t * funk,
175 : fd_tpool_t * tpool,
176 : fd_spad_t * runtime_spad,
177 : fd_features_t * features );
178 :
179 : int
180 : fd_snapshot_service_inc_hash( fd_hash_t * accounts_hash,
181 : fd_hash_t * snapshot_hash,
182 : fd_funk_t * funk,
183 : fd_funk_rec_key_t const * * pubkeys,
184 : ulong pubkeys_len,
185 : fd_spad_t * spad,
186 : fd_features_t * features );
187 :
188 : void
189 : fd_accounts_check_lthash( fd_funk_t * funk,
190 : fd_funk_txn_t * funk_txn,
191 : fd_spad_t * runtime_spad,
192 : fd_features_t * features );
193 :
194 : void
195 : fd_calculate_epoch_accounts_hash_values(fd_exec_slot_ctx_t * slot_ctx);
196 :
197 : int
198 : fd_accounts_hash_inc_only( fd_exec_slot_ctx_t * slot_ctx,
199 : fd_hash_t * accounts_hash,
200 : fd_funk_txn_t * child_txn,
201 : ulong do_hash_verify,
202 : fd_spad_t * spad );
203 :
204 : void
205 : fd_account_hash_task( void * tpool,
206 : ulong t0, ulong t1,
207 : void *args,
208 : void *reduce, ulong stride,
209 : ulong l0 , ulong l1 ,
210 : ulong m0 , ulong m1 ,
211 : ulong n0 , ulong n1 );
212 :
213 : FD_PROTOTYPES_END
214 :
215 : #endif /* HEADER_fd_src_flamenco_runtime_fd_hashes_h */
|