Skip to content

Commit 70a7175

Browse files
riptlripatel-fd
authored andcommitted
Fix missing funk API error handling
1 parent ec1baa3 commit 70a7175

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

src/discof/restart/fd_restart_tile.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,18 @@ after_frag( fd_restart_tile_ctx_t * ctx,
298298
slot_bank->hard_forks.hard_forks_len = ctx->new_hard_forks_len;
299299

300300
/* Write the slot bank back to funk, referencing fd_runtime_save_slot_bank */
301-
int opt_err = 0;
301+
int funk_err = 0;
302302
fd_funk_rec_prepare_t prepare[1];
303-
fd_funk_rec_t * new_rec = fd_funk_rec_prepare( ctx->funk,
304-
funk_txn,
305-
&id,
306-
prepare,
307-
&opt_err );
303+
fd_funk_rec_t * new_rec = fd_funk_rec_prepare(
304+
ctx->funk, funk_txn, &id, prepare, &funk_err );
308305
if( FD_UNLIKELY( !new_rec ) ) {
309-
FD_LOG_ERR(( "Wen-restart fails at inserting a hard fork in slot bank and save it in funk" ));
306+
FD_LOG_ERR(( "fd_funk_rec_prepare() failed (%i-%s)", funk_err, fd_funk_strerror( funk_err ) ));
310307
}
311308

312-
ulong sz = sizeof(uint) + fd_slot_bank_size( slot_bank );
313-
uchar * buf = fd_funk_val_truncate( new_rec, sz, fd_funk_alloc( ctx->funk ), fd_funk_wksp( ctx->funk ), &opt_err );
314-
*(uint*)buf = FD_RUNTIME_ENC_BINCODE;
309+
ulong sz = sizeof(uint) + fd_slot_bank_size( slot_bank );
310+
uchar * buf = fd_funk_val_truncate( new_rec, sz, fd_funk_alloc( ctx->funk ), fd_funk_wksp( ctx->funk ), &funk_err );
311+
if( FD_UNLIKELY( !buf ) ) FD_LOG_ERR(( "fd_funk_val_truncate(sz=%lu) failed (%i-%s)", sz, funk_err, fd_funk_strerror( funk_err ) ));
312+
FD_STORE( uint, buf, FD_RUNTIME_ENC_BINCODE );
315313
fd_bincode_encode_ctx_t slot_bank_encode_ctx = {
316314
.data = buf + sizeof(uint),
317315
.dataend = buf + sz,

src/flamenco/runtime/fd_acc_mgr.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ fd_funk_get_acc_meta_mutable( fd_funk_t * funk,
9292

9393
ulong sz = sizeof(fd_account_meta_t)+min_data_sz;
9494
void * val;
95-
if( fd_funk_val_sz( rec ) < sz )
95+
if( fd_funk_val_sz( rec ) < sz ) {
9696
val = fd_funk_val_truncate( rec, sz, fd_funk_alloc( funk ), wksp, &funk_err );
97-
else
97+
if( FD_UNLIKELY( !val ) ) FD_LOG_ERR(( "fd_funk_val_truncate(sz=%lu) failed (%i-%s)", sz, funk_err, fd_funk_strerror( funk_err ) ));
98+
} else {
9899
val = fd_funk_val( rec, wksp );
99-
100+
}
100101

101102
if (NULL != opt_out_rec) {
102103
*opt_out_rec = rec;

src/flamenco/runtime/fd_runtime_init.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ fd_runtime_save_epoch_bank( fd_exec_slot_ctx_t * slot_ctx ) {
2424
return opt_err;
2525
}
2626

27-
uchar *buf = fd_funk_val_truncate(rec, sz, fd_funk_alloc( funk ), fd_funk_wksp(funk), NULL);
28-
*(uint*)buf = FD_RUNTIME_ENC_BINCODE;
27+
int funk_err = 0;
28+
uchar * buf = fd_funk_val_truncate( rec, sz, fd_funk_alloc( funk ), fd_funk_wksp( funk ), &funk_err );
29+
if( FD_UNLIKELY( !buf ) ) FD_LOG_ERR(( "fd_funk_val_truncate() failed (%i-%s)", funk_err, fd_funk_strerror( funk_err ) ));
30+
FD_STORE( uint, buf, FD_RUNTIME_ENC_BINCODE );
2931
fd_bincode_encode_ctx_t ctx = {
3032
.data = buf + sizeof(uint),
3133
.dataend = buf + sz,
@@ -63,8 +65,10 @@ int fd_runtime_save_slot_bank( fd_exec_slot_ctx_t * slot_ctx ) {
6365
return opt_err;
6466
}
6567

66-
uchar * buf = fd_funk_val_truncate(rec, sz, fd_funk_alloc( funk ), fd_funk_wksp( funk ), NULL);
67-
*(uint*)buf = FD_RUNTIME_ENC_BINCODE;
68+
int funk_err = 0;
69+
uchar * buf = fd_funk_val_truncate( rec, sz, fd_funk_alloc( funk ), fd_funk_wksp( funk ), &funk_err );
70+
if( FD_UNLIKELY( !buf ) ) FD_LOG_ERR(( "fd_funk_val_truncate() failed (%i-%s)", funk_err, fd_funk_strerror( funk_err ) ));
71+
FD_STORE( uint, buf, FD_RUNTIME_ENC_BINCODE );
6872
fd_bincode_encode_ctx_t ctx = {
6973
.data = buf + sizeof(uint),
7074
.dataend = buf + sz,

src/flamenco/runtime/fd_txn_account.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,12 @@ fd_txn_account_save( fd_txn_account_t * acct,
301301
ulong reclen = sizeof(fd_account_meta_t)+acct->private_state.const_meta->dlen;
302302
fd_wksp_t * wksp = fd_funk_wksp( funk );
303303
if( fd_funk_val_truncate( rec, reclen, fd_funk_alloc( funk ), wksp, &err ) == NULL ) {
304-
FD_LOG_ERR(( "unable to allocate account value, err %d", err ));
304+
FD_LOG_ERR(( "fd_funk_val_truncate(sz=%lu) for account failed (%i-%s)", reclen, err, fd_funk_strerror( err ) ));
305305
}
306306
err = fd_txn_account_save_internal( acct, funk );
307+
if( FD_UNLIKELY( err ) ) {
308+
FD_LOG_ERR(( "fd_txn_account_save_internal() failed (%i-%s)", err, fd_funk_strerror( err ) ));
309+
}
307310

308311
fd_funk_rec_publish( funk, prepare );
309312

src/flamenco/runtime/program/fd_bpf_program_util.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,17 @@ fd_bpf_create_bpf_program_cache_entry( fd_exec_slot_ctx_t * slot_ctx,
211211
return -1;
212212
}
213213

214-
fd_wksp_t * wksp = fd_funk_wksp( funk );
215-
void * val = fd_funk_val_truncate( rec, fd_sbpf_validated_program_footprint( &elf_info ), fd_funk_alloc( funk ), wksp, NULL );;
214+
ulong val_sz = fd_sbpf_validated_program_footprint( &elf_info );
215+
void * val = fd_funk_val_truncate(
216+
rec,
217+
val_sz,
218+
fd_funk_alloc( funk ),
219+
fd_funk_wksp( funk ),
220+
&funk_err );
221+
if( FD_UNLIKELY( funk_err ) ) {
222+
FD_LOG_ERR(( "fd_funk_val_truncate(sz=%lu) for account failed (%i-%s)", val_sz, funk_err, fd_funk_strerror( funk_err ) ));
223+
}
224+
216225
fd_sbpf_validated_program_t * validated_prog = fd_sbpf_validated_program_new( val, &elf_info );
217226

218227
ulong prog_align = fd_sbpf_program_align();

0 commit comments

Comments
 (0)