[WIP] flamenco, runtime: implement replace_spl_token_with_p_token#8921
[WIP] flamenco, runtime: implement replace_spl_token_with_p_token#8921topointon-jump wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Implements the replace_spl_token_with_p_token feature transition in the Flamenco runtime by upgrading the SPL Token (loader v2) program to loader v3 using a new Core BPF migration helper, and wiring in the required buffer address + feature ID plumbing.
Changes:
- Adds
fd_upgrade_loader_v2_program_with_loader_v3_program()and supporting target checks/ELF validation in Core BPF migration code. - Introduces the ptoken program buffer address constant and ID bytes in system IDs.
- Registers the
replace_spl_token_with_p_tokenfeature and triggers the migration at feature activation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/flamenco/runtime/program/fd_builtin_programs.h | Declares the new loader v2 → loader v3 upgrade helper. |
| src/flamenco/runtime/fd_system_ids_pp.h | Adds PTOKEN_PROG_BUFFER_ID macro bytes. |
| src/flamenco/runtime/fd_system_ids.h | Exposes fd_solana_ptoken_program_buffer_address. |
| src/flamenco/runtime/fd_system_ids.c | Defines fd_solana_ptoken_program_buffer_address. |
| src/flamenco/runtime/fd_runtime.c | Triggers the migration when replace_spl_token_with_p_token activates. |
| src/flamenco/runtime/fd_core_bpf_migration.c | Implements the migration logic and ELF validation. |
| src/flamenco/features/feature_map.json | Adds the new feature name/pubkey mapping. |
| src/flamenco/features/fd_features_generated.h | Updates generated feature count/set ID and adds the feature field. |
| src/flamenco/features/fd_features_generated.c | Adds the feature ID entry and perfect-hash mapping entries. |
You can also share your feedback on Copilot code review. Take the survey.
2bf49a9 to
8d381b3
Compare
8d381b3 to
e11aa03
Compare
There was a problem hiding this comment.
Pull request overview
Implements the replace_spl_token_with_p_token feature activation path in the Flamenco runtime by adding a Loader-v2 → Loader-v3 program upgrade routine and wiring it into epoch-boundary feature activation, along with the required new IDs/constants.
Changes:
- Add
fd_upgrade_loader_v2_program_with_loader_v3_program()and supporting target checks in core BPF migration code. - Introduce the ptoken program buffer system ID and expose it via
fd_system_ids.{h,c}for use at runtime. - Add the
replace_spl_token_with_p_tokenfeature to the feature map and generated feature tables, and invoke the upgrade when the feature activates.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/flamenco/runtime/program/fd_builtin_programs.h | Exposes new upgrade helper prototype to runtime. |
| src/flamenco/runtime/fd_system_ids_pp.h | Adds PTOKEN program buffer ID bytes. |
| src/flamenco/runtime/fd_system_ids.h | Declares new ptoken program buffer address constant. |
| src/flamenco/runtime/fd_system_ids.c | Defines new ptoken program buffer address constant. |
| src/flamenco/runtime/fd_runtime.c | Triggers Loader v2→v3 upgrade on replace_spl_token_with_p_token activation. |
| src/flamenco/runtime/fd_core_bpf_migration.c | Implements target checks and upgrade flow; adds ELF validation step. |
| src/flamenco/features/feature_map.json | Adds new feature pubkey mapping. |
| src/flamenco/features/fd_features_generated.h | Updates feature count/set ID and adds the new feature bitfield entry. |
| src/flamenco/features/fd_features_generated.c | Adds new feature ID entry and perfect-hash lookup/static asserts. |
You can also share your feedback on Copilot code review. Take the survey.
Performance Measurements ⏳
|
e11aa03 to
8f5477f
Compare
Performance Measurements ⏳
|
| There is no direct equivalent in Agave to this function, because | ||
| we are not updating the program cache here. However, we do the same | ||
| checks that our program cache does upon deployment. | ||
|
|
There was a problem hiding this comment.
worth adding a comment why you dont need to explicitly update the progcache
| uchar rodata_mem [ FD_RUNTIME_ACC_SZ_MAX ] __attribute__((aligned(FD_SBPF_PROG_RODATA_ALIGN))); | ||
| uchar scratch_mem [ FD_RUNTIME_ACC_SZ_MAX ] __attribute__((aligned(FD_ACCOUNT_REC_ALIGN))); |
There was a problem hiding this comment.
fix these bounds to account for the header size of the structs + max acc size
| /* Staging memory for ELF validation during BPF program | ||
| migrations. */ | ||
| struct { | ||
| uchar calldests_mem[ FD_SBPF_PROGRAM_FOOTPRINT ] __attribute__((aligned(alignof(fd_sbpf_program_t)))); |
There was a problem hiding this comment.
double check the worst case mem
| return; | ||
|
|
||
| fd_rent_t const * rent = fd_bank_rent_query( bank ); | ||
| ulong const slot = fd_bank_slot_get ( bank ); |
There was a problem hiding this comment.
| ulong const slot = fd_bank_slot_get ( bank ); | |
| ulong slot = fd_bank_slot_get ( bank ); |
| ulong scratch_sz = sizeof( runtime_stack->bpf_migration.progcache_validate.scratch_mem ); | ||
|
|
||
| fd_features_t const * features = fd_bank_features_query( bank ); | ||
| ulong const load_slot = fd_bank_slot_get( bank ); |
| /* Setup calldests */ | ||
| int has_calldests = !fd_sbpf_enable_stricter_elf_headers_enabled( elf_info->sbpf_version ); | ||
| void * calldests_mem = NULL; | ||
| if( has_calldests && elf_info->text_cnt>0UL ) { | ||
| FD_SCRATCH_ALLOC_INIT( cd, calldests_base ); | ||
| calldests_mem = FD_SCRATCH_ALLOC_APPEND( cd, fd_sbpf_calldests_align(), fd_sbpf_calldests_footprint( elf_info->text_cnt ) ); | ||
| void * cd_end = (void *)FD_SCRATCH_ALLOC_FINI( cd, alignof(uchar) ); | ||
| if( FD_UNLIKELY( ((ulong)cd_end<(ulong)calldests_base) | ((ulong)cd_end>(ulong)calldests_base + calldests_sz) ) ) return 1; | ||
| } |
There was a problem hiding this comment.
possible to use fd_sbpf_program_new?
| FD_SCRATCH_ALLOC_INIT( sc, scratch_base ); | ||
| void * scratch = FD_SCRATCH_ALLOC_APPEND( sc, alignof(uchar), elf_sz ); | ||
| void * sc_end = (void *)FD_SCRATCH_ALLOC_FINI( sc, alignof(uchar) ); | ||
| if( FD_UNLIKELY( ((ulong)sc_end<(ulong)scratch_base) | ((ulong)sc_end>(ulong)scratch_base + scratch_sz) ) ) return 1; |
There was a problem hiding this comment.
| if( FD_UNLIKELY( ((ulong)sc_end<(ulong)scratch_base) | ((ulong)sc_end>(ulong)scratch_base + scratch_sz) ) ) return 1; | |
| if( FD_UNLIKELY( ((ulong)sc_end<(ulong)scratch_base) || ((ulong)sc_end>(ulong)scratch_base + scratch_sz) ) ) return 1; |
| if( FD_UNLIKELY( fd_vm_syscall_register_slot( syscalls, load_slot, features, /* is_deploy */ 1 )!=FD_VM_SUCCESS ) ) return 1; | ||
|
|
||
| /* fd_sbpf_program_load checks */ | ||
| if( FD_UNLIKELY( fd_sbpf_program_load( prog, elf, elf_sz, syscalls, &loader_config, scratch, elf_sz ) ) ) return 1; |
There was a problem hiding this comment.
scratch_sz for last argument
solana-foundation/solana-improvement-documents#266