Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h 2 : #define HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h 3 : 4 : #include "../../fd_flamenco_base.h" 5 : #include "../fd_bank.h" 6 : #include "../fd_system_ids_pp.h" 7 : 8 0 : #define FD_CORE_BPF_MIGRATION_TARGET_BUILTIN (0) 9 0 : #define FD_CORE_BPF_MIGRATION_TARGET_STATELESS (1) 10 : 11 : /* https://github.com/anza-xyz/agave/blob/v2.3.0/builtins/src/core_bpf_migration.rs#L17-L43 12 : Configuration for migrating a built-in program to Core BPF. 13 : - `migration_target` is one of 14 : FD_CORE_BPF_MIGRATION_TARGET_{BUILTIN,STATELESS}. */ 15 : struct fd_core_bpf_migration_config { 16 : fd_pubkey_t const * source_buffer_address; 17 : fd_pubkey_t * upgrade_authority_address; 18 : ulong enable_feature_offset; 19 : uchar migration_target; 20 : fd_pubkey_t const * builtin_program_id; 21 : fd_hash_t const * verified_build_hash; 22 : }; 23 : typedef struct fd_core_bpf_migration_config fd_core_bpf_migration_config_t; 24 : 25 : /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/prototypes.rs#L7-L13 26 : Transitions of built-in programs at epoch boundaries when features are activated */ 27 : struct fd_builtin_program { 28 : fd_pubkey_t const * pubkey; 29 : char const * data; 30 : ulong enable_feature_offset; 31 : fd_core_bpf_migration_config_t const * core_bpf_migration_config; 32 : }; 33 : typedef struct fd_builtin_program fd_builtin_program_t; 34 : 35 : /* https://github.com/anza-xyz/agave/blob/v2.1.0/runtime/src/bank/builtins/prototypes.rs#L31-L35 36 : Transitions of stateless built-in programs at epoch boundaries when features are activated */ 37 : struct fd_stateless_builtin_program { 38 : fd_pubkey_t const * pubkey; 39 : fd_core_bpf_migration_config_t const * core_bpf_migration_config; 40 : }; 41 : typedef struct fd_stateless_builtin_program fd_stateless_builtin_program_t; 42 : 43 : struct fd_tmp_account { 44 : fd_pubkey_t addr; 45 : fd_account_meta_t meta; 46 : uchar data[FD_RUNTIME_ACC_SZ_MAX]__attribute__((aligned(8UL))); 47 : ulong data_sz; 48 : }; 49 : typedef struct fd_tmp_account fd_tmp_account_t; 50 : 51 : FD_PROTOTYPES_BEGIN 52 : 53 : /* Initialize the builtin program accounts */ 54 : void 55 : fd_builtin_programs_init( fd_bank_t * bank, 56 : fd_accdb_user_t * accdb, 57 : fd_funk_txn_xid_t const * xid, 58 : fd_capture_ctx_t * capture_ctx ); 59 : 60 : void 61 : fd_write_builtin_account( fd_bank_t * bank, 62 : fd_accdb_user_t * accdb, 63 : fd_funk_txn_xid_t const * xid, 64 : fd_capture_ctx_t * capture_ctx, 65 : fd_pubkey_t const pubkey, 66 : void const * data, 67 : ulong sz ); 68 : 69 : fd_builtin_program_t const * 70 : fd_builtins( void ); 71 : 72 : ulong 73 : fd_num_builtins( void ); 74 : 75 : fd_stateless_builtin_program_t const * 76 : fd_stateless_builtins( void ); 77 : 78 : ulong 79 : fd_num_stateless_builtins( void ); 80 : 81 : /* `migrated_yet` is an output value thats set based on the rules below: 82 : 83 : | Return Value | *migrated_yet | Description | 84 : |--------------|-------------------|--------------------------------------------------------------------------| 85 : | 0 | 0 | Program is not a migrating builtin program | 86 : | 1 | 0 | Program is a migrating builtin program id, BUT has not been migrated yet | 87 : | 1 | 1 | Program is a migrating builtin program id, AND has been migrated to BPF | 88 : */ 89 : uchar 90 : fd_is_migrating_builtin_program( fd_bank_t const * bank, 91 : fd_pubkey_t const * pubkey, 92 : uchar * migrated_yet ); 93 : 94 : uchar 95 : fd_is_non_migrating_builtin_program( fd_pubkey_t const * pubkey ); 96 : 97 : void 98 : fd_migrate_builtin_to_core_bpf( fd_bank_t * bank, 99 : fd_accdb_user_t * accdb, 100 : fd_funk_txn_xid_t const * xid, 101 : fd_runtime_stack_t * runtime_stack, 102 : fd_core_bpf_migration_config_t const * config, 103 : fd_capture_ctx_t * capture_ctx ); 104 : 105 : void 106 : fd_upgrade_core_bpf_program( fd_bank_t * bank, 107 : fd_accdb_user_t * accdb, 108 : fd_funk_txn_xid_t const * xid, 109 : fd_runtime_stack_t * runtime_stack, 110 : fd_pubkey_t const * builtin_program_id, 111 : fd_pubkey_t const * source_buffer_address, 112 : fd_capture_ctx_t * capture_ctx ); 113 : 114 : FD_PROTOTYPES_END 115 : 116 : #endif /* HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h */