Skip to content

Commit e35d048

Browse files
committed
flamenco, runtime: create program cache entry for invalid program data
1 parent 1898a05 commit e35d048

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
63bea0cd43a8ae2f653c9699340b7b13df5b8a04
1+
e4b2e1d169cb5ce1fe12175783804d95584ce592

src/flamenco/runtime/program/fd_program_cache.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ fd_get_executable_program_content_for_v4_loader( fd_txn_account_t const * progra
101101
return NULL;
102102
}
103103

104+
/* This subtraction is safe because get_state() implicitly checks the
105+
dlen. */
104106
*program_data_len = program_acc->vt->get_data_len( program_acc ) - LOADER_V4_PROGRAM_DATA_OFFSET;
105107
return program_acc->vt->get_data( program_acc ) + LOADER_V4_PROGRAM_DATA_OFFSET;
106108
}
@@ -361,9 +363,6 @@ fd_program_cache_create_cache_entry( fd_exec_slot_ctx_t * slot_ctx,
361363
program_acc,
362364
&program_data_len,
363365
runtime_spad );
364-
if( FD_UNLIKELY( program_data==NULL ) ) {
365-
return;
366-
}
367366

368367
/* This prepare should never fail. */
369368
int funk_err = FD_FUNK_SUCCESS;
@@ -373,6 +372,20 @@ fd_program_cache_create_cache_entry( fd_exec_slot_ctx_t * slot_ctx,
373372
FD_LOG_CRIT(( "fd_funk_rec_prepare() failed: %i-%s", funk_err, fd_funk_strerror( funk_err ) ));
374373
}
375374

375+
/* In Agave's load_program_with_pubkey(), if program data cannot be
376+
obtained, a tombstone cache entry of type Closed or
377+
FailedVerification is created. For correctness, we could just
378+
not insert a cache entry when there is no valid program data.
379+
Nonetheless, for purely conformance on instruction error log
380+
messages reasons, specifically "Program is not deployed" vs
381+
"Program is not cached", we would like to have a cache entry
382+
precisely when Agave does, such that we match Agave exactly on
383+
this error log. So, we insert a cache entry here. */
384+
if( FD_UNLIKELY( program_data==NULL ) ) {
385+
fd_program_cache_publish_failed_verification_rec( funk, prepare, rec, current_slot );
386+
return;
387+
}
388+
376389
fd_sbpf_elf_info_t elf_info = {0};
377390
if( FD_UNLIKELY( fd_program_cache_parse_elf_info( &elf_info, program_data, program_data_len, slot_ctx ) ) ) {
378391
fd_program_cache_publish_failed_verification_rec( funk, prepare, rec, current_slot );
@@ -516,6 +529,12 @@ FD_SPAD_FRAME_BEGIN( runtime_spad ) {
516529
&program_data_len,
517530
runtime_spad );
518531
if( FD_UNLIKELY( program_data==NULL ) ) {
532+
/* Unlike in fd_program_cache_create_cache_entry(), where we need to
533+
insert an entry into the cache when we cannot obtain valid
534+
program data, here we could simply return because we know, at
535+
this point, that the program is already in the cache. So we
536+
don't need to do anything extra for matching Agave on cache entry
537+
presence. */
519538
return;
520539
}
521540

src/flamenco/runtime/program/fd_program_cache.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ fd_program_cache_load_entry( fd_funk_t const * funk,
225225
NULL on failure or if the program account is not owned by a BPF
226226
loader program ID, and leaves `out_program_data_len` in an undefined
227227
state. Reasons for failure vary on the loader version. See the
228-
respective functions in this file for more details. */
228+
respective functions in this file for more details.
229+
230+
This is essentially load_program_with_pubkey(), sans the ELF parsing
231+
and whatnot which is done in load_program_from_bytes(). */
229232
uchar const *
230233
fd_program_cache_get_account_programdata( fd_funk_t const * funk,
231234
fd_funk_txn_t const * funk_txn,

0 commit comments

Comments
 (0)