@@ -31,7 +31,11 @@ struct fd_snapin_tile {
3131
3232 fd_funk_t funk [1 ];
3333 fd_funk_txn_t * funk_txn ;
34- uchar * acc_data ;
34+ uchar * acc_data ;
35+ uchar * acc_data_start ;
36+ uchar * acc_data_end ;
37+ fd_account_meta_t const * acc_meta ;
38+ fd_pubkey_t acc_pubkey ;
3539
3640 fd_stem_context_t * stem ;
3741 fd_snapshot_parser_t * ssparse ;
@@ -105,34 +109,6 @@ metrics_write( fd_snapin_tile_t * ctx ) {
105109 FD_MGAUGE_SET ( SNAPIN , STATE , (ulong )ctx -> state );
106110}
107111
108- static void
109- calculate_lthash ( fd_snapin_tile_t * ctx ) {
110- fd_funk_all_iter_t iter [1 ];
111- for ( fd_funk_all_iter_new ( ctx -> funk , iter );
112- !fd_funk_all_iter_done ( iter );
113- fd_funk_all_iter_next ( iter ) ) {
114- fd_funk_rec_t const * rec = fd_funk_all_iter_ele_const ( iter );
115- if ( !fd_funk_key_is_acc ( rec -> pair .key ) || /* not a solana record */
116- (rec -> flags & FD_FUNK_REC_FLAG_ERASE ) || /* this is a tombstone */
117- (rec -> pair .xid -> ul [0 ] | rec -> pair .xid -> ul [1 ]) != 0 /* not root xid */ ) {
118- continue ;
119- }
120-
121- fd_account_meta_t const * meta = fd_funk_val ( rec , fd_funk_wksp (ctx -> funk ) );
122- fd_lthash_value_t new_account_lthash [1 ];
123- fd_hashes_account_lthash ( fd_type_pun_const (rec -> pair .key -> uc ),
124- meta ,
125- fd_account_meta_get_data_const ( meta ),
126- new_account_lthash );
127- fd_lthash_add ( & ctx -> lthash_info .full .lthash , new_account_lthash );
128- }
129- if ( FD_UNLIKELY ( memcmp ( ctx -> lthash_info .full .lthash .bytes , ctx -> lthash_info .full .manifest_lthash .bytes , sizeof (fd_lthash_value_t ) ) ) ) {
130- FD_LOG_ERR (( "calculated accounts lthash %s does not match accounts lthash %s in snapshot manifest" ,
131- FD_LTHASH_ENC_32_ALLOCA ( & ctx -> lthash_info .full .lthash ),
132- FD_LTHASH_ENC_32_ALLOCA ( & ctx -> lthash_info .full .manifest_lthash ) ));
133- }
134- }
135-
136112static void
137113manifest_cb ( void * _ctx ,
138114 ulong manifest_sz ) {
@@ -166,19 +142,13 @@ is_duplicate_account( fd_snapin_tile_t * ctx,
166142 /* TODO: Reaching here means the existing value is a duplicate
167143 account. We need to hash the existing account and subtract that
168144 hash from the running lthash. */
169- // fd_lthash_value_t old_account_lthash[1];
170- // fd_lthash_value_t * lthash = ctx->full ? &ctx->lthash_info.full.lthash : &ctx->lthash_info.incremental.lthash;
171- // fd_hashes_account_lthash( (fd_pubkey_t*)account_pubkey,
172- // rec_meta,
173- // fd_account_meta_get_data_const( rec_meta ),
174- // old_account_lthash );
175- // FD_LOG_WARNING(("subtracting old account hash %s for pubkey %s from lthash %s",
176- // FD_LTHASH_ENC_32_ALLOCA( old_account_lthash ),
177- // FD_BASE58_ENC_32_ALLOCA( (fd_pubkey_t*)account_pubkey ),
178- // FD_LTHASH_ENC_32_ALLOCA( lthash )));
179- // fd_lthash_sub( lthash, old_account_lthash );
180- // FD_LOG_WARNING(("resulting lthash %s",
181- // FD_LTHASH_ENC_32_ALLOCA( lthash )));
145+ fd_lthash_value_t old_account_lthash [1 ];
146+ fd_lthash_value_t * lthash = ctx -> full ? & ctx -> lthash_info .full .lthash : & ctx -> lthash_info .incremental .lthash ;
147+ fd_hashes_account_lthash ( (fd_pubkey_t * )account_pubkey ,
148+ rec_meta ,
149+ fd_account_meta_get_data_const ( rec_meta ),
150+ old_account_lthash );
151+ fd_lthash_sub ( lthash , old_account_lthash );
182152 }
183153
184154 return 0 ;
@@ -210,24 +180,14 @@ account_cb( void * _ctx,
210180 fd_txn_account_set_hash ( rec , & hdr -> hash );
211181 fd_txn_account_set_meta_info ( rec , & hdr -> info );
212182
213- ctx -> acc_data = fd_txn_account_get_data_mut ( rec );
183+
184+ ctx -> acc_data_start = fd_txn_account_get_data_mut ( rec );
185+ ctx -> acc_data = fd_txn_account_get_data_mut ( rec );
186+ ctx -> acc_data_end = fd_txn_account_get_data_mut ( rec ) + hdr -> meta .data_len ;
187+ ctx -> acc_meta = fd_txn_account_get_meta ( rec );
188+ fd_memcpy ( ctx -> acc_pubkey .uc , hdr -> meta .pubkey , sizeof (fd_pubkey_t ) );
214189 ctx -> metrics .accounts_inserted ++ ;
215190 fd_txn_account_mutable_fini ( rec , ctx -> funk , ctx -> funk_txn , & prepare );
216-
217- // fd_lthash_value_t new_account_lthash[1];
218- // fd_lthash_value_t * lthash = ctx->full ? &ctx->lthash_info.full.lthash : &ctx->lthash_info.incremental.lthash;
219- // fd_hashes_account_lthash( (fd_pubkey_t*)hdr->meta.pubkey,
220- // fd_txn_account_get_meta( rec ),
221- // fd_txn_account_get_data( rec ),
222- // new_account_lthash );
223- // FD_LOG_WARNING(("adding new account hash %s for pubkey %s from lthash %s",
224- // FD_LTHASH_ENC_32_ALLOCA( new_account_lthash ),
225- // FD_BASE58_ENC_32_ALLOCA( (fd_pubkey_t*)hdr->meta.pubkey ),
226- // FD_LTHASH_ENC_32_ALLOCA( lthash )));
227- // fd_lthash_add( lthash, new_account_lthash );
228- // FD_LOG_WARNING(("resulting lthash %s",
229- // FD_LTHASH_ENC_32_ALLOCA( lthash )));
230-
231191}
232192
233193static void
@@ -239,11 +199,21 @@ account_data_cb( void * _ctx,
239199
240200 fd_memcpy ( ctx -> acc_data , buf , data_sz );
241201 ctx -> acc_data += data_sz ;
202+
203+ if ( ctx -> acc_data == ctx -> acc_data_end ) {
204+ fd_lthash_value_t new_account_lthash [1 ];
205+ fd_lthash_value_t * lthash = ctx -> full ? & ctx -> lthash_info .full .lthash : & ctx -> lthash_info .incremental .lthash ;
206+ fd_hashes_account_lthash ( & ctx -> acc_pubkey ,
207+ ctx -> acc_meta ,
208+ ctx -> acc_data_start ,
209+ new_account_lthash );
210+ fd_lthash_add ( lthash , new_account_lthash );
211+ }
242212}
243213
244214static void
245215transition_malformed ( fd_snapin_tile_t * ctx ,
246- fd_stem_context_t * stem ) {
216+ fd_stem_context_t * stem ) {
247217 ctx -> state = FD_SNAPIN_STATE_MALFORMED ;
248218 fd_stem_publish ( stem , 1UL , FD_SNAPSHOT_MSG_CTRL_MALFORMED , 0UL , 0UL , 0UL , 0UL , 0UL );
249219}
@@ -320,14 +290,13 @@ handle_control_frag( fd_snapin_tile_t * ctx,
320290 break ;
321291 }
322292
323- // if( FD_UNLIKELY( memcmp( ctx->lthash_info.full.lthash.bytes, ctx->lthash_info.full.manifest_lthash.bytes, sizeof(fd_lthash_value_t) ) ) ) {
324- // FD_LOG_WARNING(( "calculated accounts lthash %s does not match accounts lthash %s in snapshot manifest",
325- // FD_LTHASH_ENC_32_ALLOCA( &ctx->lthash_info.full.lthash ),
326- // FD_LTHASH_ENC_32_ALLOCA( &ctx->lthash_info.full.manifest_lthash ) ));
327- // transition_malformed( ctx, stem );
328- // break;
329- // }
330- calculate_lthash ( ctx );
293+ if ( FD_UNLIKELY ( memcmp ( ctx -> lthash_info .full .lthash .bytes , ctx -> lthash_info .full .manifest_lthash .bytes , sizeof (fd_lthash_value_t ) ) ) ) {
294+ FD_LOG_WARNING (( "calculated accounts lthash %s does not match accounts lthash %s in snapshot manifest" ,
295+ FD_LTHASH_ENC_32_ALLOCA ( & ctx -> lthash_info .full .lthash ),
296+ FD_LTHASH_ENC_32_ALLOCA ( & ctx -> lthash_info .full .manifest_lthash ) ));
297+ transition_malformed ( ctx , stem );
298+ break ;
299+ }
331300
332301 fd_snapshot_parser_reset ( ctx -> ssparse , fd_chunk_to_laddr ( ctx -> manifest_out .wksp , ctx -> manifest_out .chunk ), ctx -> manifest_out .mtu );
333302
@@ -343,15 +312,14 @@ handle_control_frag( fd_snapin_tile_t * ctx,
343312 break ;
344313 }
345314
346- // if( FD_UNLIKELY( memcmp( ctx->lthash_info.full.lthash.bytes, ctx->lthash_info.full.manifest_lthash.bytes, sizeof(fd_lthash_value_t) ) ||
347- // memcmp( ctx->lthash_info.incremental.lthash.bytes, ctx->lthash_info.incremental.manifest_lthash.bytes, sizeof(fd_lthash_value_t) ) ) ) {
348- // FD_LOG_WARNING(( "calculated accounts lthash %s does not match accounts lthash %s in snapshot manifest",
349- // FD_LTHASH_ENC_32_ALLOCA( &ctx->lthash_info.full.lthash ),
350- // FD_LTHASH_ENC_32_ALLOCA( &ctx->lthash_info.full.manifest_lthash ) ));
351- // transition_malformed( ctx, stem );
352- // break;
353- // }
354- calculate_lthash ( ctx );
315+ if ( FD_UNLIKELY ( memcmp ( ctx -> lthash_info .full .lthash .bytes , ctx -> lthash_info .full .manifest_lthash .bytes , sizeof (fd_lthash_value_t ) ) ||
316+ memcmp ( ctx -> lthash_info .incremental .lthash .bytes , ctx -> lthash_info .incremental .manifest_lthash .bytes , sizeof (fd_lthash_value_t ) ) ) ) {
317+ FD_LOG_WARNING (( "calculated accounts lthash %s does not match accounts lthash %s in snapshot manifest" ,
318+ FD_LTHASH_ENC_32_ALLOCA ( & ctx -> lthash_info .full .lthash ),
319+ FD_LTHASH_ENC_32_ALLOCA ( & ctx -> lthash_info .full .manifest_lthash ) ));
320+ transition_malformed ( ctx , stem );
321+ break ;
322+ }
355323
356324 if ( FD_LIKELY ( ctx -> funk_txn ) ) fd_funk_txn_publish_into_parent ( ctx -> funk , ctx -> funk_txn , 0 );
357325 fd_stem_publish ( stem , 0UL , fd_ssmsg_sig ( FD_SSMSG_DONE , 0UL ), 0UL , 0UL , 0UL , 0UL , 0UL );
0 commit comments