Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/flamenco/features/fd_features_generated.c
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,12 @@ fd_feature_id_t const ids[] = {
.name = "create_account_allow_prefund",
.cleaned_up = 0 },

{ .index = offsetof(fd_features_t, replace_spl_token_with_p_token)>>3,
.id = {"\x0c\x44\xe0\x0e\x03\x6f\xc8\xa4\xc4\x7e\xdb\x02\xb0\x8d\xff\x3b\xc2\x2f\x04\x5a\x7d\x01\xa1\x00\x07\x1f\x85\x5f\x21\x09\x7a\x6a"},
/* ptokFjwyJtrwCa9Kgo9xoDS59V4QccBGEaRFnRPnSdP */
.name = "replace_spl_token_with_p_token",
.cleaned_up = 0 },

{ .index = ULONG_MAX }
};

Expand Down Expand Up @@ -2088,6 +2094,7 @@ typedef struct fd_feature_id_lookup_entry fd_feature_id_lookup_entry_t;
#define MAP_PERFECT_262 0x8b0786cd93f63607UL, .val = &ids[262]
#define MAP_PERFECT_263 0x4908ae0360664f6dUL, .val = &ids[263]
#define MAP_PERFECT_264 0x632b9b7c9e9a3257UL, .val = &ids[264]
#define MAP_PERFECT_265 0xa4c86f030ee0440cUL, .val = &ids[265]

#include "../../util/tmpl/fd_map_perfect.c"

Expand Down Expand Up @@ -2363,4 +2370,5 @@ FD_STATIC_ASSERT( offsetof( fd_features_t, limit_instruction_accounts
FD_STATIC_ASSERT( offsetof( fd_features_t, validator_admission_ticket )>>3==262UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, discard_unexpected_data_complete_shreds )>>3==263UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, create_account_allow_prefund )>>3==264UL, layout );
FD_STATIC_ASSERT( offsetof( fd_features_t, replace_spl_token_with_p_token )>>3==265UL, layout );
FD_STATIC_ASSERT( sizeof( fd_features_t )>>3==FD_FEATURE_ID_CNT, layout );
5 changes: 3 additions & 2 deletions src/flamenco/features/fd_features_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#endif

/* FEATURE_ID_CNT is the number of features in ids */
#define FD_FEATURE_ID_CNT (265UL)
#define FD_FEATURE_ID_CNT (266UL)

/* Feature set ID calculated from all feature names */
#define FD_FEATURE_SET_ID (2642541842U)
#define FD_FEATURE_SET_ID (1894134510U)

union fd_features {
ulong f[ FD_FEATURE_ID_CNT ];
Expand Down Expand Up @@ -281,5 +281,6 @@ union fd_features {
/* 0x8b0786cd93f63607 */ ulong validator_admission_ticket;
/* 0x4908ae0360664f6d */ ulong discard_unexpected_data_complete_shreds;
/* 0x632b9b7c9e9a3257 */ ulong create_account_allow_prefund;
/* 0xa4c86f030ee0440c */ ulong replace_spl_token_with_p_token;
};
};
3 changes: 2 additions & 1 deletion src/flamenco/features/feature_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,6 @@
{"name":"limit_instruction_accounts","pubkey":"DqbnFPASg7tHmZ6qfpdrt2M6MWoSeiicWPXxPhxqFCQ"},
{"name":"validator_admission_ticket","pubkey":"VATtb1DepUwdPh5bFVasdtkbeDNsftZSRzr2aKpKWJA"},
{"name":"discard_unexpected_data_complete_shreds","pubkey":"8MhfKhoZEoiySpVe248bDkisyEcBA7JQLyUS94xoTSqN"},
{"name":"create_account_allow_prefund","pubkey":"6sPDzwyARRExKH52LECxcGoqziH8G7SZofwuxi8Ja331"}
{"name":"create_account_allow_prefund","pubkey":"6sPDzwyARRExKH52LECxcGoqziH8G7SZofwuxi8Ja331"},
{"name":"replace_spl_token_with_p_token","pubkey":"ptokFjwyJtrwCa9Kgo9xoDS59V4QccBGEaRFnRPnSdP"}
]
297 changes: 294 additions & 3 deletions src/flamenco/runtime/fd_core_bpf_migration.c

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/flamenco/runtime/fd_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,19 @@ fd_compute_and_apply_new_feature_activations( fd_bank_t * bank,
if( FD_UNLIKELY( FD_FEATURE_JUST_ACTIVATED_BANK( bank, vote_state_v4 ) ) ) {
fd_upgrade_core_bpf_program( bank, accdb, xid, runtime_stack, &fd_solana_stake_program_id, &fd_solana_stake_program_vote_state_v4_buffer_address, capture_ctx );
}

/* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.2/runtime/src/bank.rs#L5703-L5716 */
if( FD_UNLIKELY( FD_FEATURE_JUST_ACTIVATED_BANK( bank, replace_spl_token_with_p_token ) ) ) {
fd_upgrade_loader_v2_program_with_loader_v3_program(
bank,
accdb,
xid,
runtime_stack,
&fd_solana_spl_token_id,
&fd_solana_ptoken_program_buffer_address,
FD_FEATURE_ACTIVE_BANK( bank, relax_programdata_account_check_migration ),
capture_ctx );
}
}

/* Starting a new epoch.
Expand Down
9 changes: 9 additions & 0 deletions src/flamenco/runtime/fd_runtime_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "sysvar/fd_sysvar_clock.h"
#include "program/fd_builtin_programs.h"
#include "fd_runtime_const.h"
#include "../../ballet/sbpf/fd_sbpf_loader.h"

/* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/points.rs#L27 */
struct fd_calculated_stake_points {
Expand Down Expand Up @@ -79,6 +80,14 @@ struct fd_runtime_stack {
fd_tmp_account_t new_target_program;
fd_tmp_account_t new_target_program_data;
fd_tmp_account_t empty;

/* Staging memory for ELF validation during BPF program
migrations. */
struct {
uchar calldests_mem[ FD_SBPF_PROGRAM_FOOTPRINT ] __attribute__((aligned(alignof(fd_sbpf_program_t))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check the worst case mem

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)));
Comment on lines +88 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix these bounds to account for the header size of the structs + max acc size

} progcache_validate;
} bpf_migration;

struct {
Expand Down
1 change: 1 addition & 0 deletions src/flamenco/runtime/fd_system_ids.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const fd_pubkey_t fd_solana_feature_program_buffer_address = { .u
const fd_pubkey_t fd_solana_stake_program_buffer_address = { .uc = { STAKE_PROG_BUFFER_ID } };
const fd_pubkey_t fd_solana_stake_program_vote_state_v4_buffer_address = { .uc = { STAKE_PROG_VOTE_STATE_V4_BUFFER_ID } };
const fd_pubkey_t fd_solana_slashing_program_buffer_address = { .uc = { SLASHING_PROG_BUFFER_ID } };
const fd_pubkey_t fd_solana_ptoken_program_buffer_address = { .uc = { PTOKEN_PROG_BUFFER_ID } };

const fd_pubkey_t fd_solana_migration_authority = { .uc = { MIGRATION_AUTHORITY_ID } };

Expand Down
1 change: 1 addition & 0 deletions src/flamenco/runtime/fd_system_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern const fd_pubkey_t fd_solana_feature_program_buffer_address;
extern const fd_pubkey_t fd_solana_stake_program_buffer_address;
extern const fd_pubkey_t fd_solana_stake_program_vote_state_v4_buffer_address;
extern const fd_pubkey_t fd_solana_slashing_program_buffer_address;
extern const fd_pubkey_t fd_solana_ptoken_program_buffer_address;

/* BPF migration authority
https://github.com/anza-xyz/agave/blob/v2.2.6/programs/bpf_loader/src/lib.rs#L399-L401 */
Expand Down
2 changes: 2 additions & 0 deletions src/flamenco/runtime/fd_system_ids_pp.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@
0x0dU,0x79U,0xd4U,0x08U,0xa8U,0x96U,0xe6U,0x1aU,0xe2U,0x65U,0xf9U,0x8fU,0x23U,0xd4U,0x52U,0x64U
#define SLASHING_PROG_BUFFER_ID 0x06U,0x68U,0x2eU,0x32U,0xc0U,0x4cU,0xe7U,0x71U,0xa4U,0x71U,0xc5U,0x09U,0xd0U,0xf0U,0xc6U,0xa8U, \
0x30U,0x2bU,0x19U,0x20U,0x7bU,0xc3U,0x8aU,0x70U,0x77U,0x0aU,0xddU,0xc6U,0x16U,0x48U,0xb6U,0x3fU
#define PTOKEN_PROG_BUFFER_ID 0x0cU,0x44U,0xe0U,0x0aU,0xa3U,0xddU,0x2cU,0xf3U,0xb5U,0x43U,0x4dU,0x54U,0x3fU,0x9eU,0xa7U,0xafU, \
0x85U,0x76U,0x97U,0x50U,0xefU,0xc7U,0x5fU,0x16U,0xadU,0xe0U,0xadU,0x88U,0x59U,0xdfU,0xdcU,0x14U
#define MIGRATION_AUTHORITY_ID 0x24U,0x47U,0x35U,0xd0U,0x66U,0xd1U,0x46U,0x66U,0x76U,0x6dU,0xb4U,0x43U,0xd0U,0xf2U,0xcaU,0xe8U, \
0x0aU,0xcbU,0xb0U,0x23U,0x6fU,0x8cU,0x76U,0x21U,0xebU,0xeeU,0x3eU,0x0bU,0xa3U,0xceU,0x8dU,0xa3U
11 changes: 11 additions & 0 deletions src/flamenco/runtime/program/fd_builtin_programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ fd_upgrade_core_bpf_program( fd_bank_t * bank,
fd_pubkey_t const * source_buffer_address,
fd_capture_ctx_t * capture_ctx );

/* https://github.com/anza-xyz/agave/blob/v4.0.0-beta.2/runtime/src/bank/builtins/core_bpf_migration/mod.rs#L402-L408 */
void
fd_upgrade_loader_v2_program_with_loader_v3_program( fd_bank_t * bank,
fd_accdb_user_t * accdb,
fd_funk_txn_xid_t const * xid,
fd_runtime_stack_t * runtime_stack,
fd_pubkey_t const * loader_v2_program_address,
fd_pubkey_t const * source_buffer_address,
int allow_prefunded,
fd_capture_ctx_t * capture_ctx );

FD_PROTOTYPES_END

#endif /* HEADER_fd_src_flamenco_runtime_program_fd_builtin_programs_h */
Loading