Skip to content

Commit 1224b07

Browse files
committed
flamenco: testing lthash and fixing some off-by-one errors
1 parent de2803c commit 1224b07

15 files changed

+101
-53
lines changed

src/flamenco/capture/fd_solcap.pb.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/capture/fd_solcap.pb.h

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/flamenco/capture/fd_solcap.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ message BankPreimage {
4848
// account_table_coff is offset from the first byte of the current
4949
// chunk to the first byte of the account table chunk.
5050
int64 account_table_coff = 8;
51+
52+
// accounts_lt_hash_checksum is the hash of all the accounts
53+
bytes accounts_lt_hash_checksum = 9
54+
[(nanopb).max_size = 32, (nanopb).fixed_length = true];
5155
}
5256

5357
message AccountTableMeta {

src/flamenco/capture/fd_solcap_diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,13 @@ fd_solcap_diff_bank( fd_solcap_differ_t * diff ) {
748748
diff->file_paths[0], FD_BASE58_ENC_32_ALLOCA( pre[0].account_delta_hash ),
749749
diff->file_paths[1], FD_BASE58_ENC_32_ALLOCA( pre[1].account_delta_hash ) );
750750
}
751+
if( 0!=memcmp( pre[0].accounts_lt_hash_checksum, pre[1].accounts_lt_hash_checksum, 32UL ) ) {
752+
only_account_mismatch = 1;
753+
printf( "(%s) accounts_lt_hash_checksum: %s\n"
754+
"(%s) accounts_lt_hash_checksum: %s\n",
755+
diff->file_paths[0], FD_BASE58_ENC_32_ALLOCA( pre[0].accounts_lt_hash_checksum ),
756+
diff->file_paths[1], FD_BASE58_ENC_32_ALLOCA( pre[1].accounts_lt_hash_checksum ) );
757+
}
751758
if( 0!=memcmp( pre[0].prev_bank_hash, pre[1].prev_bank_hash, 32UL ) ) {
752759
only_account_mismatch = 0;
753760
printf( "(%s) prev_bank_hash: %s\n"

src/flamenco/capture/fd_solcap_import.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ unmarshal_bank_preimage( cJSON const * json,
142142

143143
FD_TEST( unmarshal_hash( cJSON_GetObjectItem( head, "bank_hash" ), out->bank_hash ) );
144144
FD_TEST( unmarshal_hash( cJSON_GetObjectItem( head, "parent_bank_hash" ), out->prev_bank_hash ) );
145-
FD_TEST( unmarshal_hash( cJSON_GetObjectItem( head, "accounts_delta_hash" ), out->account_delta_hash ) );
145+
if ( !unmarshal_hash( cJSON_GetObjectItem( head, "accounts_delta_hash" ), out->account_delta_hash ) )
146+
fd_memset(out->account_delta_hash, 0, sizeof(out->account_delta_hash));
147+
if ( !unmarshal_hash( cJSON_GetObjectItem( head, "accounts_lt_hash_checksum" ), out->accounts_lt_hash_checksum ) )
148+
fd_memset(out->account_delta_hash, 0, sizeof(out->accounts_lt_hash_checksum));
146149
FD_TEST( unmarshal_hash( cJSON_GetObjectItem( head, "last_blockhash" ), out->poh_hash ) );
147150

148151
if ( cJSON_GetObjectItem( head, "signature_count" ) != NULL )

src/flamenco/capture/fd_solcap_writer.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ fd_solcap_write_bank_preimage( fd_solcap_writer_t * writer,
474474
void const * bank_hash,
475475
void const * prev_bank_hash,
476476
void const * account_delta_hash,
477+
void const * accounts_lt_hash_checksum,
477478
void const * poh_hash,
478479
ulong signature_cnt ) {
479480

@@ -482,10 +483,17 @@ fd_solcap_write_bank_preimage( fd_solcap_writer_t * writer,
482483
fd_solcap_BankPreimage preimage_pb[1] = {{0}};
483484
preimage_pb->signature_cnt = signature_cnt;
484485
preimage_pb->account_cnt = writer->account_idx;
485-
memcpy( preimage_pb->bank_hash, bank_hash, 32UL );
486-
memcpy( preimage_pb->prev_bank_hash, prev_bank_hash, 32UL );
487-
memcpy( preimage_pb->account_delta_hash, account_delta_hash, 32UL );
488-
memcpy( preimage_pb->poh_hash, poh_hash, 32UL );
486+
memcpy( preimage_pb->bank_hash, bank_hash, 32UL );
487+
memcpy( preimage_pb->prev_bank_hash, prev_bank_hash, 32UL );
488+
if (NULL != account_delta_hash )
489+
memcpy( preimage_pb->account_delta_hash, account_delta_hash, 32UL );
490+
else
491+
fd_memset( preimage_pb->account_delta_hash, 0, 32UL );
492+
if( NULL != accounts_lt_hash_checksum )
493+
memcpy( preimage_pb->accounts_lt_hash_checksum, accounts_lt_hash_checksum, 32UL );
494+
else
495+
fd_memset(preimage_pb->accounts_lt_hash_checksum, 0, 32UL );
496+
memcpy( preimage_pb->poh_hash, poh_hash, 32UL );
489497

490498
return fd_solcap_write_bank_preimage2( writer, preimage_pb );
491499
}

src/flamenco/capture/fd_solcap_writer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ fd_solcap_write_bank_preimage( fd_solcap_writer_t * writer,
118118
void const * bank_hash,
119119
void const * prev_bank_hash,
120120
void const * account_delta_hash,
121+
void const * accounts_lt_hash_checksum,
121122
void const * poh_hash,
122123
ulong signature_cnt );
123124

src/flamenco/capture/fd_solcap_writer_stub.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ fd_solcap_write_bank_preimage( fd_solcap_writer_t * writer FD_PARAM_
6666
void const * bank_hash FD_PARAM_UNUSED,
6767
void const * prev_bank_hash FD_PARAM_UNUSED,
6868
void const * account_delta_hash FD_PARAM_UNUSED,
69+
void const * accounts_lt_hash_checksum FD_PARAM_UNUSED,
6970
void const * poh_hash FD_PARAM_UNUSED,
7071
ulong signature_cnt FD_PARAM_UNUSED ) {
7172
return 0;

src/flamenco/capture/fd_solcap_yaml.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,19 @@ process_bank( fd_solcap_chunk_t const * chunk,
340340
printf( "- slot: %lu\n", meta.slot );
341341

342342
printf(
343-
" - bank_hash: '%s'\n",
343+
" - bank_hash: '%s'\n",
344344
FD_BASE58_ENC_32_ALLOCA( meta.bank_hash ) );
345345

346346
if( verbose>=1 ) {
347347
printf(
348-
" - prev_bank_hash: '%s'\n"
349-
" - account_delta_hash: '%s'\n"
350-
" - poh_hash: '%s'\n"
351-
" - signature_cnt: %lu\n",
348+
" - prev_bank_hash: '%s'\n"
349+
" - account_delta_hash: '%s'\n"
350+
" - accounts_lt_hash_checksum: '%s'\n"
351+
" - poh_hash: '%s'\n"
352+
" - signature_cnt: %lu\n",
352353
FD_BASE58_ENC_32_ALLOCA( meta.prev_bank_hash ),
353354
FD_BASE58_ENC_32_ALLOCA( meta.account_delta_hash ),
355+
FD_BASE58_ENC_32_ALLOCA( meta.accounts_lt_hash_checksum ),
354356
FD_BASE58_ENC_32_ALLOCA( meta.poh_hash ),
355357
meta.signature_cnt );
356358
}

src/flamenco/runtime/fd_hashes.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,19 @@ fd_hash_bank( fd_exec_slot_ctx_t * slot_ctx,
246246
}
247247

248248
if( capture_ctx != NULL && capture_ctx->capture != NULL && slot_ctx->slot_bank.slot>=capture_ctx->solcap_start_slot ) {
249+
uchar *lthash = NULL;
250+
251+
if( FD_FEATURE_ACTIVE( slot_ctx->slot_bank.slot, slot_ctx->epoch_ctx->features, accounts_lt_hash ) ) {
252+
lthash = (uchar *)fd_alloca_check( 1UL, 32UL );
253+
fd_lthash_hash((fd_lthash_value_t *) slot_ctx->slot_bank.lthash.lthash, lthash);
254+
}
255+
249256
fd_solcap_write_bank_preimage(
250257
capture_ctx->capture,
251258
hash->hash,
252259
slot_ctx->slot_bank.prev_banks_hash.hash,
253-
slot_ctx->account_delta_hash.hash,
260+
FD_FEATURE_ACTIVE( slot_ctx->slot_bank.slot, slot_ctx->epoch_ctx->features, remove_accounts_delta_hash) ? NULL : slot_ctx->account_delta_hash.hash,
261+
lthash,
254262
&slot_ctx->slot_bank.poh.hash,
255263
slot_ctx->signature_cnt );
256264
}
@@ -348,7 +356,10 @@ fd_account_hash( fd_funk_t * funk,
348356

349357
if( memcmp( task_info->acc_hash->hash, acc_meta->hash, sizeof(fd_hash_t) ) != 0 ) {
350358
task_info->hash_changed = 1;
359+
// char *prev_lthash = FD_LTHASH_ENC_32_ALLOCA( lt_hash );
351360
fd_lthash_add( lt_hash, &new_lthash_value);
361+
// FD_LOG_NOTICE(( "lthash %s + %s = %s (%s)", prev_lthash, FD_LTHASH_ENC_32_ALLOCA( &new_lthash_value ), FD_LTHASH_ENC_32_ALLOCA( lt_hash ),
362+
// FD_BASE58_ENC_32_ALLOCA( task_info->acc_pubkey )));
352363
}
353364
}
354365
if( FD_LIKELY(task_info->hash_changed && ((NULL != acc_meta_parent) && (acc_meta_parent->info.lamports != 0) ) ) ) {
@@ -364,15 +375,19 @@ fd_account_hash( fd_funk_t * funk,
364375
acc_data,
365376
FD_HASH_JUST_LTHASH,
366377
features );
378+
379+
// char *prev_lthash = FD_LTHASH_ENC_32_ALLOCA( lt_hash );
367380
fd_lthash_sub( lt_hash, &old_lthash_value );
381+
// FD_LOG_NOTICE(( "lthash %s - %s = %s (%s)", prev_lthash, FD_LTHASH_ENC_32_ALLOCA( &old_lthash_value ), FD_LTHASH_ENC_32_ALLOCA( lt_hash ),
382+
// FD_BASE58_ENC_32_ALLOCA( task_info->acc_pubkey )));
368383
}
369384

370385
if( acc_meta->slot == slot ) {
371386
task_info->hash_changed = 1;
372387
}
373388
}
374389

375-
static void
390+
void
376391
fd_account_hash_task( void * tpool,
377392
ulong t0, ulong t1,
378393
void *args,
@@ -387,6 +402,8 @@ fd_account_hash_task( void * tpool,
387402

388403
fd_lthash_value_t * lthash = (fd_lthash_value_t*)args;
389404

405+
FD_LOG_NOTICE(( "fd_account_hash_task: %lu %lu", start_idx, stop_idx));
406+
390407
for( ulong i=start_idx; i<=stop_idx; i++ ) {
391408
fd_accounts_hash_task_info_t * task_info = &task_data->info[i];
392409
fd_exec_slot_ctx_t * slot_ctx = task_info->slot_ctx;
@@ -395,7 +412,8 @@ fd_account_hash_task( void * tpool,
395412
task_info,
396413
lthash,
397414
slot_ctx->slot_bank.slot,
398-
&slot_ctx->epoch_ctx->features );
415+
&slot_ctx->epoch_ctx->features
416+
);
399417
}
400418
}
401419

0 commit comments

Comments
 (0)