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