Skip to content

Commit

Permalink
genesis: use flamenco features API
Browse files Browse the repository at this point in the history
  • Loading branch information
riptl committed Apr 21, 2024
1 parent fc4f4db commit 4245f68
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 220 deletions.
187 changes: 0 additions & 187 deletions src/app/fddev/configure/dump_genesis_features.py

This file was deleted.

84 changes: 74 additions & 10 deletions src/app/fddev/configure/genesis.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,80 @@

#include "../../../ballet/poh/fd_poh.h"
#include "../../../disco/keyguard/fd_keyload.h"
#include "../../../flamenco/features/fd_features.h"
#include "../../../flamenco/genesis/fd_genesis_create.h"
#include "../../../flamenco/types/fd_types_custom.h"
#include "../../../flamenco/runtime/sysvar/fd_sysvar_clock.h"

#define NAME "genesis"

FD_IMPORT( feature_gate, "src/app/fddev/configure/genesis_features.bin", fd_pubkey_t, 5, "" );
/* default_enable_features is a table of features enabled by default */

static void
default_enable_features( fd_features_t * features ) {
features->index_erasure_conflict_duplicate_proofs = 0UL;
features->curve25519_restrict_msm_length = 0UL;
features->commission_updates_only_allowed_in_first_half_of_epoch = 0UL;
features->validate_fee_collector_account = 0UL;
features->zk_token_sdk_enabled = 0UL;
features->enable_zk_transfer_with_fee = 0UL;
features->incremental_snapshot_only_incremental_hash_calculation = 0UL;
features->stake_redelegate_instruction = 0UL;
features->timely_vote_credits = 0UL;
features->apply_cost_tracker_during_replay = 0UL;
features->reject_callx_r10 = 0UL;
features->update_hashes_per_tick = 0UL;
features->enable_partitioned_epoch_reward = 0UL;
features->pico_inflation = 0UL;
features->libsecp256k1_fail_on_bad_count2 = 0UL;
features->remaining_compute_units_syscall_enabled = 0UL;
features->simplify_writable_program_account_check = 0UL;
features->set_exempt_rent_epoch_max = 0UL;
features->enable_bpf_loader_set_authority_checked_ix = 0UL;
features->consume_blockstore_duplicate_proofs = 0UL;
features->disable_deploy_of_alloc_free_syscall = 0UL;
features->disable_bpf_loader_instructions = 0UL;
features->full_inflation_enable = 0UL;
features->vote_state_add_vote_latency = 0UL;
features->curve25519_syscall_enabled = 0UL;
features->error_on_syscall_bpf_function_hash_collisions = 0UL;
features->update_hashes_per_tick3 = 0UL;
features->update_hashes_per_tick4 = 0UL;
features->enable_bpf_loader_extend_program_ix = 0UL;
features->libsecp256k1_fail_on_bad_count = 0UL;
features->enable_program_runtime_v2_and_loader_v4 = 0UL;
features->increase_tx_account_lock_limit = 0UL;
features->stake_raise_minimum_delegation_to_1_sol = 0UL;
features->enable_alt_bn128_syscall = 0UL;
features->revise_turbine_epoch_stakes = 0UL;
features->clean_up_delegation_errors = 0UL;
features->update_hashes_per_tick5 = 0UL;
features->full_inflation_vote = 0UL;
features->skip_rent_rewrites = 0UL;
features->switch_to_new_elf_parser = 0UL;
features->require_rent_exempt_split_destination = 0UL;
features->enable_turbine_fanout_experiments = 0UL;
features->devnet_and_testnet = 0UL;
features->enable_big_mod_exp_syscall = 0UL;
features->enable_alt_bn128_compression_syscall = 0UL;
features->update_hashes_per_tick2 = 0UL;
features->include_loaded_accounts_data_size_in_fee_calculation = 0UL;
features->bpf_account_data_direct_mapping = 0UL;
features->relax_authority_signer_check_for_lookup_table_creation = 0UL;
features->update_hashes_per_tick6 = 0UL;
features->enable_poseidon_syscall = 0UL;
features->better_error_codes_for_tx_lamport_check = 0UL;
features->stake_minimum_delegation_for_rewards = 0UL;
features->loosen_cpi_size_restriction = 0UL;
features->drop_legacy_shreds = 0UL;
features->deprecate_rewards_sysvar = 0UL;
features->warp_timestamp_again = 0UL;
features->reduce_stake_warmup_cooldown = 0UL;
features->disable_turbine_fanout_experiments = 0UL;
features->blake3_syscall_enabled = 0UL;
features->last_restart_slot_sysvar = 0UL;
features->disable_fees_sysvar = 0UL;
}

/* estimate_hashes_per_tick approximates the PoH hashrate of the current
tile. Spins PoH hashing for estimate_dur_ns nanoseconds. Returns
Expand Down Expand Up @@ -120,15 +187,12 @@ create_genesis( config_t * const config,
options->fund_initial_accounts = config->development.genesis.fund_initial_accounts;
options->fund_initial_amount_lamports = config->development.genesis.fund_initial_amount_lamports;

/* Enable features gates */
ulong feature_gate_cnt = feature_gate_sz/32UL;
FD_LOG_INFO(( "Enabling %lu feature gates", feature_gate_cnt ));
for( ulong i=0UL; i<feature_gate_cnt; i++ ) {
char base58[ FD_BASE58_ENCODED_32_SZ ];
fd_base58_encode_32( feature_gate[i].uc, NULL, base58 );
FD_LOG_INFO(( "Enabling %s", base58 ));
}
fd_features_t features[1];
fd_features_disable_all( features );
fd_features_enable_hardcoded( features );
default_enable_features( features );

options->features = features;

/* Serialize blob */

Expand All @@ -137,7 +201,7 @@ create_genesis( config_t * const config,
fd_scratch_attach( scratch_smem, scratch_fmem,
sizeof(scratch_smem), sizeof(scratch_fmem)/sizeof(ulong) );

ulong blob_len = fd_genesis_create( blob, blob_sz, options, feature_gate, feature_gate_sz/32UL );
ulong blob_len = fd_genesis_create( blob, blob_sz, options );
if( FD_UNLIKELY( !blob_sz ) ) FD_LOG_ERR(( "Failed to create genesis blob" ));

FD_LOG_DEBUG(( "Created genesis blob (sz=%lu)", blob_len ));
Expand Down
Binary file removed src/app/fddev/configure/genesis_features.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions src/flamenco/features/fd_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ fd_features_enable_hardcoded( fd_features_t * );
for( fd_feature_id_t const * id = fd_feature_iter_init();
!fd_feature_iter_done( id );
id = fd_feature_iter_next( id ) ) {{
id = fd_feature_iter_next( id ) ) {
...
}} */
} */

static inline fd_feature_id_t const *
fd_feature_iter_init( void ) {
Expand Down
31 changes: 21 additions & 10 deletions src/flamenco/genesis/fd_genesis_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
static ulong
genesis_create( void * buf,
ulong bufsz,
fd_genesis_options_t const * options,
fd_pubkey_t const * feature_gates,
ulong feature_gate_cnt ) {
fd_genesis_options_t const * options ) {

# define REQUIRE(c) \
do { \
Expand Down Expand Up @@ -183,12 +181,27 @@ genesis_create( void * buf,
REQUIRE( fd_stake_state_v2_encode( state, &encode ) == FD_BINCODE_SUCCESS );
} while(0);

/* Read enabled features */

ulong feature_cnt = 0UL;
fd_pubkey_t * features =
fd_scratch_alloc( alignof(fd_pubkey_t), FD_FEATURE_ID_CNT * sizeof(fd_pubkey_t) );

if( options->features ) {
for( fd_feature_id_t const * id = fd_feature_iter_init();
!fd_feature_iter_done( id );
id = fd_feature_iter_next( id ) ) {
if( fd_features_get( options->features, id ) == 0UL )
features[ feature_cnt++ ] = id->id;
}
}

/* Allocate the account table */

ulong default_funded_cnt = options->fund_initial_accounts;

ulong default_funded_idx = genesis->accounts_len; genesis->accounts_len += default_funded_cnt;
ulong feature_gate_idx = genesis->accounts_len; genesis->accounts_len += feature_gate_cnt;
ulong feature_gate_idx = genesis->accounts_len; genesis->accounts_len += feature_cnt;

genesis->accounts = fd_scratch_alloc( alignof(fd_pubkey_account_pair_t),
genesis->accounts_len * sizeof(fd_pubkey_account_pair_t) );
Expand Down Expand Up @@ -241,10 +254,10 @@ genesis_create( void * buf,
ulong default_feature_enabled_balance = fd_rent_exempt_minimum_balance2( &genesis->rent, FEATURE_ENABLED_SZ );

/* Set up feature gate accounts */
for( ulong j=0UL; j<feature_gate_cnt; j++ ) {
for( ulong j=0UL; j<feature_cnt; j++ ) {
fd_pubkey_account_pair_t * pair = &genesis->accounts[ feature_gate_idx+j ];

pair->key = feature_gates[ j ];
pair->key = features[ j ];
pair->account = (fd_solana_account_t) {
.lamports = default_feature_enabled_balance,
.data_len = FEATURE_ENABLED_SZ,
Expand Down Expand Up @@ -286,11 +299,9 @@ genesis_create( void * buf,
ulong
fd_genesis_create( void * buf,
ulong bufsz,
fd_genesis_options_t const * options,
fd_pubkey_t const * feature_gates,
ulong feature_gate_cnt ) {
fd_genesis_options_t const * options ) {
fd_scratch_push();
ulong ret = genesis_create( buf, bufsz, options, feature_gates, feature_gate_cnt );
ulong ret = genesis_create( buf, bufsz, options );
fd_scratch_pop();
return ret;
}
Loading

0 comments on commit 4245f68

Please sign in to comment.