Skip to content

Commit 25f68a9

Browse files
lthash
1 parent 8213314 commit 25f68a9

File tree

11 files changed

+58
-44
lines changed

11 files changed

+58
-44
lines changed

src/flamenco/runtime/context/fd_exec_slot_ctx.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
390390
fd_bank_mgr_epoch_account_hash_save( slot_ctx->bank_mgr );
391391

392392
/* Prev Slot */
393+
393394
ulong * prev_slot = fd_bank_mgr_prev_slot_modify( slot_ctx->bank_mgr );
394395
*prev_slot = oldbank->parent_slot;
395396
fd_bank_mgr_prev_slot_save( slot_ctx->bank_mgr );
@@ -414,6 +415,15 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
414415
fd_bank_mgr_poh_save( slot_ctx->bank_mgr );
415416
}
416417

418+
/* Slot LTHash */
419+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_modify( slot_ctx->bank_mgr );
420+
if( NULL != manifest->lthash ) {
421+
*slot_lthash = *manifest->lthash;
422+
} else {
423+
fd_lthash_zero( (fd_lthash_value_t *)slot_lthash );
424+
}
425+
fd_bank_mgr_slot_lthash_save( slot_ctx->bank_mgr );
426+
417427
/* Last Restart Slot */
418428

419429
/* Update last restart slot
@@ -592,11 +602,6 @@ fd_exec_slot_ctx_recover( fd_exec_slot_ctx_t * slot_ctx,
592602

593603
FD_LOG_WARNING(("Recovered EpochStakes of size %lu", fd_vote_accounts_size( &epoch_bank->next_epoch_stakes )));
594604

595-
if ( NULL != manifest->lthash )
596-
slot_ctx->slot_bank.lthash = *manifest->lthash;
597-
else
598-
fd_lthash_zero( (fd_lthash_value_t *) slot_ctx->slot_bank.lthash.lthash );
599-
600605

601606
fd_rent_fresh_accounts_global_t * rent_fresh_accounts = fd_bank_mgr_rent_fresh_accounts_modify( slot_ctx->bank_mgr );
602607

src/flamenco/runtime/fd_bank_mgr.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ if( FD_UNLIKELY( !bank_mgr ) ) {
149149
X(fd_rent_fresh_accounts_global_t, rent_fresh_accounts, 31UL, 50000UL, 8UL ) \
150150
X(fd_cluster_version_t, cluster_version, 32UL, 12UL, 4UL ) \
151151
X(ulong, prev_slot, 33UL, 8UL, 8UL ) \
152-
X(fd_hash_t, bank_hash, 34UL, 32UL, 8UL )
152+
X(fd_hash_t, bank_hash, 34UL, 32UL, 8UL ) \
153+
X(fd_slot_lthash_t, slot_lthash, 35UL, 2048UL, 128UL )
153154
FD_BANK_MGR_ITER(BANK_MGR_FUNCTIONS)
154155

155156
FD_PROTOTYPES_END

src/flamenco/runtime/fd_hashes.c

+15-8
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
279279

280280
// https://github.com/anza-xyz/agave/blob/766cd682423b8049ddeac3c0ec6cebe0a1356e9e/runtime/src/bank.rs#L5250
281281
if( FD_FEATURE_ACTIVE( slot_ctx->slot, slot_ctx->epoch_ctx->features, accounts_lt_hash ) ) {
282+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( slot_ctx->bank_mgr );
282283
fd_sha256_init( &sha );
283284
fd_sha256_append( &sha, (uchar const *) &hash->hash, sizeof( fd_hash_t ) );
284-
fd_sha256_append( &sha, (uchar const *) &slot_ctx->slot_bank.lthash.lthash, sizeof( slot_ctx->slot_bank.lthash.lthash ) );
285+
fd_sha256_append( &sha, (uchar const *) slot_lthash, sizeof( fd_slot_lthash_t ) );
285286
fd_sha256_fini( &sha, hash->hash );
286287
} else {
287288
if (fd_should_include_epoch_accounts_hash(slot_ctx)) {
@@ -297,7 +298,9 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
297298

298299
if( FD_FEATURE_ACTIVE( slot_ctx->slot, slot_ctx->epoch_ctx->features, accounts_lt_hash ) ) {
299300
lthash = (uchar *)fd_alloca_check( 1UL, 32UL );
300-
fd_lthash_hash((fd_lthash_value_t *) slot_ctx->slot_bank.lthash.lthash, lthash);
301+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_modify( slot_ctx->bank_mgr );
302+
fd_lthash_hash((fd_lthash_value_t *) slot_lthash, lthash);
303+
fd_bank_mgr_slot_lthash_save( slot_ctx->bank_mgr );
301304
}
302305

303306
fd_solcap_write_bank_preimage(
@@ -310,6 +313,7 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
310313
signature_cnt );
311314
}
312315

316+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( slot_ctx->bank_mgr );
313317
if( FD_FEATURE_ACTIVE( slot_ctx->slot, slot_ctx->epoch_ctx->features, remove_accounts_delta_hash) ) {
314318
FD_LOG_NOTICE(( "\n\n[Replay]\n"
315319
"slot: %lu\n"
@@ -321,7 +325,7 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
321325
slot_ctx->slot,
322326
FD_BASE58_ENC_32_ALLOCA( hash->hash ),
323327
FD_BASE58_ENC_32_ALLOCA( slot_ctx->slot_bank.prev_banks_hash.hash ),
324-
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) slot_ctx->slot_bank.lthash.lthash ),
328+
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) slot_lthash ),
325329
signature_cnt,
326330
FD_BASE58_ENC_32_ALLOCA( poh->hash ) ));
327331
} else {
@@ -337,7 +341,7 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
337341
FD_BASE58_ENC_32_ALLOCA( hash->hash ),
338342
FD_BASE58_ENC_32_ALLOCA( slot_ctx->slot_bank.prev_banks_hash.hash ),
339343
FD_BASE58_ENC_32_ALLOCA( slot_ctx->account_delta_hash.hash ),
340-
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) slot_ctx->slot_bank.lthash.lthash ),
344+
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *) slot_lthash ),
341345
signature_cnt,
342346
FD_BASE58_ENC_32_ALLOCA( poh->hash ) ));
343347
}
@@ -521,7 +525,8 @@ fd_update_hash_bank_exec_hash( fd_exec_slot_ctx_t * slot_ctx,
521525
fd_funk_txn_t * txn = slot_ctx->funk_txn;
522526

523527
// Apply the lthash changes to the bank lthash
524-
fd_lthash_value_t * lt_hash = (fd_lthash_value_t *)fd_type_pun( slot_ctx->slot_bank.lthash.lthash );
528+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( slot_ctx->bank_mgr );
529+
fd_lthash_value_t * lt_hash = (fd_lthash_value_t *)fd_type_pun( slot_lthash );
525530
for( ulong i = 0; i < lt_hashes_cnt; i++ ) {
526531
fd_lthash_add( lt_hash, &lt_hashes[i] );
527532
}
@@ -1314,7 +1319,6 @@ fd_snapshot_service_inc_hash( fd_hash_t * accounts_hash,
13141319
void
13151320
fd_accounts_check_lthash( fd_funk_t * funk,
13161321
fd_funk_txn_t * funk_txn,
1317-
fd_slot_bank_t * slot_bank,
13181322
fd_spad_t * runtime_spad,
13191323
fd_features_t * features ) {
13201324

@@ -1400,8 +1404,11 @@ fd_accounts_check_lthash( fd_funk_t * funk,
14001404
}
14011405
}
14021406

1403-
// Compare the accumulator to the slot
1404-
fd_lthash_value_t * acc = (fd_lthash_value_t *)fd_type_pun_const( slot_bank->lthash.lthash );
1407+
// Compare the accumulator to the slot lthash
1408+
1409+
FD_BANK_MGR_DECL( bank_mgr, funk, funk_txn );
1410+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( bank_mgr );
1411+
fd_lthash_value_t * acc = (fd_lthash_value_t *)fd_type_pun_const( slot_lthash );
14051412
if ( memcmp( acc, &acc_lthash, sizeof( fd_lthash_value_t ) ) == 0 ) {
14061413
FD_LOG_NOTICE(("accounts_lthash %s == %s", FD_LTHASH_ENC_32_ALLOCA (acc), FD_LTHASH_ENC_32_ALLOCA (&acc_lthash)));
14071414
} else {

src/flamenco/runtime/fd_hashes.h

-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ fd_snapshot_service_inc_hash( fd_hash_t * accounts_hash,
192192
void
193193
fd_accounts_check_lthash( fd_funk_t * funk,
194194
fd_funk_txn_t * funk_txn,
195-
fd_slot_bank_t * slot_bank,
196195
fd_spad_t * runtime_spad,
197196
fd_features_t * features );
198197

src/flamenco/runtime/tests/fd_dump_pb.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ create_block_context_protobuf_from_block( fd_exec_test_block_context_t * block_c
483483
// fd_memcpy( block_context->slot_ctx.poh, &slot_ctx->slot_bank.poh, sizeof(fd_pubkey_t) ); // TODO: dump here when process epoch happens after poh verification
484484
fd_hash_t * bank_hash = fd_bank_mgr_bank_hash_query( bank_mgr );
485485
fd_memcpy( block_context->slot_ctx.parent_bank_hash, bank_hash, sizeof(fd_pubkey_t) );
486-
fd_memcpy( block_context->slot_ctx.parent_lt_hash, &slot_ctx->slot_bank.lthash.lthash, FD_LTHASH_LEN_BYTES );
486+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( bank_mgr );
487+
fd_memcpy( block_context->slot_ctx.parent_lt_hash, slot_lthash, sizeof(fd_slot_lthash_t) );
487488
block_context->slot_ctx.prev_slot = *(fd_bank_mgr_prev_slot_query( bank_mgr ));
488489
block_context->slot_ctx.prev_lps = *(fd_bank_mgr_prev_lamports_per_signature_query( bank_mgr ));
489490
block_context->slot_ctx.prev_epoch_capitalization = *(fd_bank_mgr_capitalization_query( bank_mgr ));

src/flamenco/runtime/tests/harness/fd_block_harness.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
8787
/* Set up slot bank */
8888
fd_slot_bank_t * slot_bank = &slot_ctx->slot_bank;
8989

90-
fd_memcpy( slot_bank->lthash.lthash, test_ctx->slot_ctx.parent_lt_hash, FD_LTHASH_LEN_BYTES );
90+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_modify( slot_ctx->bank_mgr );
91+
fd_memcpy( slot_lthash, test_ctx->slot_ctx.parent_lt_hash, sizeof(fd_slot_lthash_t) );
92+
fd_bank_mgr_slot_lthash_save( slot_ctx->bank_mgr );
9193

9294
/* Set up epoch context and epoch bank */
9395
/* TODO: Do we need any more of these? */
@@ -513,7 +515,8 @@ fd_runtime_fuzz_block_run( fd_runtime_fuzz_runner_t * runner,
513515

514516
/* Capture hashes */
515517
uchar out_lt_hash[32];
516-
fd_lthash_hash( (fd_lthash_value_t const *)slot_ctx->slot_bank.lthash.lthash, out_lt_hash );
518+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( slot_ctx->bank_mgr );
519+
fd_lthash_hash( (fd_lthash_value_t const *)slot_lthash, out_lt_hash );
517520
fd_hash_t * bank_hash = fd_bank_mgr_bank_hash_query( slot_ctx->bank_mgr );
518521
fd_memcpy( effects->bank_hash, bank_hash, sizeof(fd_hash_t) );
519522
fd_memcpy( effects->lt_hash, out_lt_hash, sizeof(fd_hash_t) );

src/flamenco/snapshot/fd_snapshot.c

+24-15
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) {
259259
#endif
260260
// https://github.com/anza-xyz/agave/blob/766cd682423b8049ddeac3c0ec6cebe0a1356e9e/runtime/src/bank.rs#L1831
261261
if( accounts_lt_hash ) {
262-
ulong *p = (ulong *) ctx->slot_ctx->slot_bank.lthash.lthash;
263-
ulong *e = (ulong *) &ctx->slot_ctx->slot_bank.lthash.lthash[sizeof(ctx->slot_ctx->slot_bank.lthash.lthash)];
262+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( ctx->slot_ctx->bank_mgr );
263+
ulong *p = (ulong *) slot_lthash;
264+
ulong *e = (ulong *) &slot_lthash[sizeof(fd_slot_lthash_t)];
264265
while (p < e) {
265266
if ( 0 != *(p++) )
266267
break;
@@ -274,7 +275,7 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) {
274275
FD_LOG_ERR(( "snapshot must have an accounts lt hash if the feature is enabled.. " ));
275276
#endif
276277
} else {
277-
FD_LOG_NOTICE(( "accounts_lthash found %s", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash) ) ));
278+
FD_LOG_NOTICE(( "accounts_lthash found %s", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)slot_lthash ) ));
278279
}
279280
}
280281

@@ -292,16 +293,20 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) {
292293
fd_snapshot_hash( ctx->slot_ctx, &accounts_hash, ctx->check_hash, ctx->runtime_spad, ctx->exec_para_ctx, lthash );
293294
} FD_SPAD_FRAME_END;
294295

295-
if ( snapshots_lt_hash ) {
296+
if( snapshots_lt_hash ) {
296297
#ifdef FD_LTHASH_SNAPSHOT_HACK
297-
if ( zero_lthash )
298-
fd_memcpy( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash), lthash, sizeof(lthash_buf) );
298+
if( zero_lthash ) {
299+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_modify( ctx->slot_ctx->bank_mgr );
300+
fd_memcpy( (fd_lthash_value_t *)slot_lthash, lthash, sizeof(lthash_buf) );
301+
fd_bank_mgr_slot_lthash_save( ctx->slot_ctx->bank_mgr );
302+
}
299303
#endif
300-
if( memcmp( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash), lthash, sizeof(lthash_buf) ) ) {
304+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( ctx->slot_ctx->bank_mgr );
305+
if( memcmp( (fd_lthash_value_t *)slot_lthash, lthash, sizeof(lthash_buf) ) ) {
301306
FD_LOG_ERR(( "snapshot accounts_hash (calculated) %s != (expected) %s",
302-
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash) ), FD_LTHASH_ENC_32_ALLOCA( lthash ) ));
307+
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)slot_lthash ), FD_LTHASH_ENC_32_ALLOCA( lthash ) ));
303308
} else {
304-
FD_LOG_NOTICE(( "accounts_lthash found %s verified successfully", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash) ) ));
309+
FD_LOG_NOTICE(( "accounts_lthash found %s verified successfully", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)slot_lthash ) ));
305310
}
306311
} else {
307312
if( memcmp( fhash->uc, accounts_hash.uc, sizeof(fd_hash_t) ) ) {
@@ -321,16 +326,20 @@ fd_snapshot_load_fini( fd_snapshot_load_ctx_t * ctx ) {
321326
fd_snapshot_hash( ctx->slot_ctx, &accounts_hash, ctx->check_hash, ctx->runtime_spad, ctx->exec_para_ctx, lthash );
322327
}
323328

324-
if ( snapshots_lt_hash ) {
329+
if( snapshots_lt_hash ) {
330+
fd_slot_lthash_t * slot_lthash = fd_bank_mgr_slot_lthash_query( ctx->slot_ctx->bank_mgr );
325331
#ifdef FD_LTHASH_SNAPSHOT_HACK
326-
if ( zero_lthash )
327-
fd_memcpy( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash), lthash, sizeof(lthash_buf) );
332+
if( zero_lthash ) {
333+
slot_lthash = fd_bank_mgr_slot_lthash_modify( ctx->slot_ctx->bank_mgr );
334+
fd_memcpy( (fd_lthash_value_t *)slot_lthash, lthash, sizeof(lthash_buf) );
335+
fd_bank_mgr_slot_lthash_save( ctx->slot_ctx->bank_mgr );
336+
}
328337
#endif
329-
if( memcmp( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash), lthash, sizeof(lthash_buf) ) ) {
338+
if( memcmp( (fd_lthash_value_t *)slot_lthash, lthash, sizeof(lthash_buf) ) ) {
330339
FD_LOG_ERR(( "snapshot accounts_hash (calculated) %s != (expected) %s",
331-
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash) ), FD_LTHASH_ENC_32_ALLOCA( lthash ) ));
340+
FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)slot_lthash ), FD_LTHASH_ENC_32_ALLOCA( lthash ) ));
332341
} else {
333-
FD_LOG_NOTICE(( "accounts_lthash found %s verified successfully", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)fd_type_pun(ctx->slot_ctx->slot_bank.lthash.lthash) ) ));
342+
FD_LOG_NOTICE(( "accounts_lthash found %s verified successfully", FD_LTHASH_ENC_32_ALLOCA( (fd_lthash_value_t *)slot_lthash ) ));
334343
}
335344
} else {
336345
if( memcmp( fhash->uc, accounts_hash.uc, sizeof(fd_hash_t) ) ) {

src/flamenco/types/fd_fuzz_types.h

-1
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,6 @@ void *fd_slot_bank_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
18261826
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_slot_bank_t);
18271827
fd_slot_bank_new(mem);
18281828
fd_vote_accounts_generate( &self->epoch_stakes, alloc_mem, rng );
1829-
fd_slot_lthash_generate( &self->lthash, alloc_mem, rng );
18301829
fd_hash_generate( &self->prev_banks_hash, alloc_mem, rng );
18311830
fd_epoch_reward_status_generate( &self->epoch_reward_status, alloc_mem, rng );
18321831
return mem;

src/flamenco/types/fd_types.c

-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/types/fd_types.h

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/types/fd_types.json

-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@
12331233
"type": "struct",
12341234
"fields": [
12351235
{ "name": "epoch_stakes", "type": "vote_accounts" },
1236-
{ "name": "lthash", "type": "slot_lthash" },
12371236
{ "name": "prev_banks_hash", "type": "hash" },
12381237
{ "name": "epoch_reward_status", "type": "epoch_reward_status" }
12391238
]

0 commit comments

Comments
 (0)