Skip to content

Commit fd74c6d

Browse files
authored
txncache: fix generation check
1 parent 024ac06 commit fd74c6d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/flamenco/runtime/fd_txncache.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ fd_txncache_finalize_fork( fd_txncache_t * tc,
293293

294294
blockcache_t * fork = &tc->blockcache_pool[ fork_id.val ];
295295
FD_TEST( fork->shmem->frozen<=1 );
296+
FD_TEST( fork->shmem->frozen>=0 );
296297
fork->shmem->txnhash_offset = txnhash_offset;
297298

298299
memcpy( fork->shmem->blockhash.uc, blockhash, 32UL );
@@ -313,6 +314,7 @@ remove_blockcache( fd_txncache_t * tc,
313314
for( ulong i=0UL; i<tc->shmem->active_slots_max; i++ ) descends_set_remove( tc->blockcache_pool[ i ].descends, idx );
314315

315316
if( FD_LIKELY( blockcache->shmem->frozen ) ) blockhash_map_ele_remove_fast( tc->blockhash_map, blockcache->shmem, tc->blockcache_shmem_pool );
317+
blockcache->shmem->frozen = -1;
316318
blockcache_pool_ele_release( tc->blockcache_shmem_pool, blockcache->shmem );
317319
}
318320

@@ -408,6 +410,7 @@ fd_txncache_insert( fd_txncache_t * tc,
408410

409411
blockcache_t const * fork = &tc->blockcache_pool[ fork_id.val ];
410412
FD_TEST( fork->shmem->frozen<=1 );
413+
FD_TEST( fork->shmem->frozen>=0 );
411414
blockcache_t * blockcache = blockhash_on_fork( tc, fork, blockhash );
412415

413416
/* TODO: We can't print the full txnhash here typically because we
@@ -444,6 +447,8 @@ fd_txncache_query( fd_txncache_t * tc,
444447

445448
blockcache_t const * fork = &tc->blockcache_pool[ fork_id.val ];
446449
blockcache_t const * blockcache = blockhash_on_fork( tc, fork, blockhash );
450+
FD_TEST( fork->shmem->frozen>=0 );
451+
FD_TEST( blockcache->shmem->frozen==2 );
447452

448453
/* TODO: We can't print the full txnhash here typically because we
449454
might only be able to see 20 bytes, but we need to print it for
@@ -457,7 +462,8 @@ fd_txncache_query( fd_txncache_t * tc,
457462
for( uint head=blockcache->heads[ head_hash ]; head!=UINT_MAX; head=tc->txnpages[ head/FD_TXNCACHE_TXNS_PER_PAGE ].txns[ head%FD_TXNCACHE_TXNS_PER_PAGE ]->blockcache_next ) {
458463
fd_txncache_single_txn_t * txn = tc->txnpages[ head/FD_TXNCACHE_TXNS_PER_PAGE ].txns[ head%FD_TXNCACHE_TXNS_PER_PAGE ];
459464

460-
int descends = (txn->fork_id.val==fork_id.val || descends_set_test( fork->descends, txn->fork_id.val )) && fork->shmem->generation==txn->generation;
465+
blockcache_t const * txn_fork = &tc->blockcache_pool[ txn->fork_id.val ];
466+
int descends = (txn->fork_id.val==fork_id.val || descends_set_test( fork->descends, txn->fork_id.val )) && txn_fork->shmem->frozen>=0 && txn_fork->shmem->generation==txn->generation;
461467
if( FD_LIKELY( descends && !memcmp( txnhash+txnhash_offset, txn->txnhash, 20UL ) ) ) {
462468
found = 1;
463469
break;

src/flamenco/runtime/fd_txncache_private.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ struct fd_txncache_blockcache_shmem {
4545
fd_txncache_fork_id_t child_id;
4646
fd_txncache_fork_id_t sibling_id;
4747

48-
int frozen; /* If non-zero, the blockcache is frozen and should not be modified. This is used to enforce
49-
invariants on the caller of the txncache. */
48+
int frozen; /* This is used to enforce invariants on the caller of the txncache.
49+
-1: invalid
50+
0: active
51+
1: semi frozen, only happens during snapshot load
52+
2: frozen, should not be modified */
5053

5154
uint generation;
5255

src/flamenco/runtime/fd_txncache_shmem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fd_txncache_shmem_new( void * shmem,
145145

146146
fd_txncache_blockcache_shmem_t * blockcache_pool = blockcache_pool_join( blockcache_pool_new( _blockcache_pool, max_active_slots ) );
147147
FD_TEST( blockcache_pool );
148+
for( ulong i=0UL; i<max_active_slots; i++ ) blockcache_pool[ i ].frozen = -1;
148149

149150
blockhash_map_t * blockhash_map = blockhash_map_join( blockhash_map_new( _blockhash_map, blockhash_map_chains, 0UL /* seed not used */ ) );
150151
FD_TEST( blockhash_map );

0 commit comments

Comments
 (0)