Skip to content

Commit 0ac6e03

Browse files
committed
funk: stricter handholding checks
Crash if handholding checks fail instead of logging warning
1 parent 51d8f95 commit 0ac6e03

File tree

7 files changed

+27
-45
lines changed

7 files changed

+27
-45
lines changed

src/discof/replay/fd_replay_tile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,9 +1297,7 @@ handle_new_slot( fd_replay_tile_ctx_t * ctx,
12971297
fd_funk_txn_t * parent_txn = fd_funk_txn_query( &parent_xid, txn_map );
12981298

12991299
fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( ctx->funk, parent_txn, &xid, 1 );
1300-
if( FD_UNLIKELY( !funk_txn ) ) {
1301-
FD_LOG_CRIT(( "invariant violation: funk_txn is NULL for slot %lu", slot ));
1302-
}
1300+
if( FD_UNLIKELY( !funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
13031301

13041302
ctx->slot_ctx->funk_txn = funk_txn;
13051303

src/discof/restore/fd_snapin_tile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ handle_control_frag( fd_snapin_tile_t * ctx,
241241

242242
fd_funk_txn_xid_t incremental_xid = fd_funk_generate_xid();
243243
ctx->funk_txn = fd_funk_txn_prepare( ctx->funk, ctx->funk_txn, &incremental_xid, 0 );
244+
if( FD_UNLIKELY( !ctx->funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
244245
ctx->full = 0;
245246
ctx->state = FD_SNAPIN_STATE_LOADING;
246247
break;

src/flamenco/runtime/fd_runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,7 @@ fd_migrate_builtin_to_core_bpf( fd_exec_slot_ctx_t * slot_ctx,
19541954
fd_funk_txn_xid_t migration_xid = fd_funk_generate_xid();
19551955
fd_funk_txn_start_write( slot_ctx->funk );
19561956
slot_ctx->funk_txn = fd_funk_txn_prepare( slot_ctx->funk, slot_ctx->funk_txn, &migration_xid, 0UL );
1957+
if( FD_UNLIKELY( !slot_ctx->funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
19571958
fd_funk_txn_end_write( slot_ctx->funk );
19581959

19591960
/* Attempt serialization of program account. If the program is
@@ -2804,6 +2805,7 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
28042805
xid.ul[1] = 0UL;
28052806
xid.ul[0] = 0UL;
28062807
slot_ctx->funk_txn = fd_funk_txn_prepare( slot_ctx->funk, NULL, &xid, 1 );
2808+
if( FD_UNLIKELY( !slot_ctx->funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
28072809
fd_funk_txn_end_write( slot_ctx->funk );
28082810

28092811
fd_runtime_init_bank_from_genesis( slot_ctx,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
205205
/* Create temporary funk transaction and slot / epoch contexts */
206206
fd_funk_txn_start_write( funk );
207207
fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( funk, NULL, xid, 1 );
208+
if( FD_UNLIKELY( !funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
208209
fd_funk_txn_end_write( funk );
209210

210211
/* Allocate contexts */
@@ -400,6 +401,7 @@ fd_runtime_fuzz_block_ctx_create( fd_runtime_fuzz_runner_t * runner,
400401
fd_funk_txn_xid_t fork_xid = { .ul = { slot, slot } };
401402
fd_funk_txn_start_write( funk );
402403
slot_ctx->funk_txn = fd_funk_txn_prepare( funk, slot_ctx->funk_txn, &fork_xid, 1 );
404+
if( FD_UNLIKELY( !slot_ctx->funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
403405
fd_funk_txn_end_write( funk );
404406

405407
/* Reset the lthash to zero, because we are in a new Funk transaction now */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fd_runtime_fuzz_instr_ctx_create( fd_runtime_fuzz_runner_t * runner,
3030

3131
fd_funk_txn_start_write( funk );
3232
fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( funk, NULL, xid, 1 );
33+
if( FD_UNLIKELY( !funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
3334
fd_funk_txn_end_write( funk );
3435

3536
/* Allocate contexts */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fd_runtime_fuzz_txn_ctx_create( fd_runtime_fuzz_runner_t * runner,
2525
fd_funk_txn_xid_t xid = { .ul = { slot, slot } };
2626
fd_funk_txn_start_write( funk );
2727
fd_funk_txn_t * funk_txn = fd_funk_txn_prepare( funk, NULL, &xid, 1 );
28+
if( FD_UNLIKELY( !funk_txn ) ) FD_LOG_ERR(( "fd_funk_txn_prepare failed" ));
2829
fd_funk_txn_end_write( funk );
2930

3031
/* Set up slot context */

src/funk/fd_funk_txn.c

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,13 @@ fd_funk_txn_prepare( fd_funk_t * funk,
5252
int verbose ) {
5353

5454
#ifdef FD_FUNK_HANDHOLDING
55-
if( FD_UNLIKELY( !funk ) ) {
56-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL funk" ));
57-
return NULL;
58-
}
59-
if( FD_UNLIKELY( !xid ) ) {
60-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL xid" ));
61-
return NULL;
62-
}
55+
if( FD_UNLIKELY( !funk ) ) FD_LOG_CRIT(( "NULL funk" ));
56+
if( FD_UNLIKELY( !xid ) ) FD_LOG_CRIT(( "NULL xid" ));
6357
if( FD_UNLIKELY( parent && !fd_funk_txn_valid( funk, parent ) ) ) {
64-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "bad txn" ));
65-
return NULL;
58+
FD_LOG_CRIT(( "invalid parent txn" ));
6659
}
6760
if( FD_UNLIKELY( fd_funk_txn_xid_eq_root( xid ) ) ) {
68-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "xid is the root" ));
69-
return NULL;
61+
FD_LOG_CRIT(( "attempted txn_prepare at root" ));
7062
}
7163
if( FD_UNLIKELY( fd_funk_txn_xid_eq( xid, funk->shmem->last_publish ) ) ) {
7264
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "xid is the last published" ));
@@ -274,13 +266,10 @@ fd_funk_txn_cancel( fd_funk_t * funk,
274266
int verbose ) {
275267

276268
#ifdef FD_FUNK_HANDHOLDING
277-
if( FD_UNLIKELY( !funk ) ) {
278-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL funk" ));
279-
return 0UL;
280-
}
269+
if( FD_UNLIKELY( !funk ) ) FD_LOG_CRIT(( "NULL funk" ));
270+
if( FD_UNLIKELY( !txn ) ) FD_LOG_CRIT(( "NULL txn" ));
281271
if( FD_UNLIKELY( !fd_funk_txn_valid( funk, txn ) ) ) {
282-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "bad txn" ));
283-
return 0UL;
272+
FD_LOG_CRIT(( "invalid txn" ));
284273
}
285274
#else
286275
(void)verbose;
@@ -363,13 +352,10 @@ fd_funk_txn_cancel_siblings( fd_funk_t * funk,
363352
int verbose ) {
364353

365354
#ifdef FD_FUNK_HANDHOLDING
366-
if( FD_UNLIKELY( !funk ) ) {
367-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL funk" ));
368-
return 0UL;
369-
}
355+
if( FD_UNLIKELY( !funk ) ) FD_LOG_CRIT(( "NULL funk" ));
356+
if( FD_UNLIKELY( !txn ) ) FD_LOG_CRIT(( "NULL txn" ));
370357
if( FD_UNLIKELY( !fd_funk_txn_valid( funk, txn ) ) ) {
371-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "bad txn" ));
372-
return 0UL;
358+
FD_LOG_CRIT(( "invalid txn" ));
373359
}
374360
#else
375361
(void)verbose;
@@ -388,13 +374,10 @@ fd_funk_txn_cancel_children( fd_funk_t * funk,
388374
int verbose ) {
389375

390376
#ifdef FD_FUNK_HANDHOLDING
391-
if( FD_UNLIKELY( !funk ) ) {
392-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL funk" ));
393-
return 0UL;
394-
}
377+
if( FD_UNLIKELY( !funk ) ) FD_LOG_CRIT(( "NULL funk" ));
378+
if( FD_UNLIKELY( !txn ) ) FD_LOG_CRIT(( "NULL txn" ));
395379
if( FD_UNLIKELY( !fd_funk_txn_valid( funk, txn ) ) ) {
396-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "bad txn" ));
397-
return 0UL;
380+
FD_LOG_CRIT(( "invalid txn" ));
398381
}
399382
#else
400383
(void)verbose;
@@ -622,13 +605,10 @@ fd_funk_txn_publish( fd_funk_t * funk,
622605
int verbose ) {
623606

624607
#ifdef FD_FUNK_HANDHOLDING
625-
if( FD_UNLIKELY( !funk ) ) {
626-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL funk" ));
627-
return 0UL;
628-
}
608+
if( FD_UNLIKELY( !funk ) ) FD_LOG_CRIT(( "NULL funk" ));
609+
if( FD_UNLIKELY( !txn ) ) FD_LOG_CRIT(( "NULL txn" ));
629610
if( FD_UNLIKELY( !fd_funk_txn_valid( funk, txn ) ) ) {
630-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "bad txn" ));
631-
return 0UL;
611+
FD_LOG_CRIT(( "invalid txn" ));
632612
}
633613
#else
634614
(void)verbose;
@@ -686,13 +666,10 @@ fd_funk_txn_publish_into_parent( fd_funk_t * funk,
686666
fd_funk_txn_t * txn,
687667
int verbose ) {
688668
#ifdef FD_FUNK_HANDHOLDING
689-
if( FD_UNLIKELY( !funk ) ) {
690-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "NULL funk" ));
691-
return FD_FUNK_ERR_INVAL;
692-
}
669+
if( FD_UNLIKELY( !funk ) ) FD_LOG_CRIT(( "NULL funk" ));
670+
if( FD_UNLIKELY( !txn ) ) FD_LOG_CRIT(( "NULL txn" ));
693671
if( FD_UNLIKELY( !fd_funk_txn_valid( funk, txn ) ) ) {
694-
if( FD_UNLIKELY( verbose ) ) FD_LOG_WARNING(( "bad txn" ));
695-
return 0UL;
672+
FD_LOG_CRIT(( "invalid txn" ));
696673
}
697674
#else
698675
(void)verbose;

0 commit comments

Comments
 (0)