Skip to content

Commit 82b2ad3

Browse files
ravyu-jumpjumpsiegel
authored andcommitted
fd_runtime_read_genesis: use new types decode conventions to decode genesis_block
1 parent 62f5412 commit 82b2ad3

File tree

3 files changed

+63
-53
lines changed

3 files changed

+63
-53
lines changed

src/discof/replay/fd_replay_tile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,11 +2165,6 @@ read_snapshot( void * _ctx,
21652165
ctx->runtime_spad,
21662166
&exec_para_ctx );
21672167
FD_LOG_NOTICE(( "finished fd_bpf_scan_and_create_bpf_program_cache_entry..." ));
2168-
2169-
fd_blockstore_init( ctx->slot_ctx->blockstore,
2170-
ctx->blockstore_fd,
2171-
FD_BLOCKSTORE_ARCHIVE_MIN_SIZE,
2172-
&ctx->slot_ctx->slot_bank );
21732168
}
21742169

21752170
static void
@@ -2321,6 +2316,11 @@ init_snapshot( fd_replay_tile_ctx_t * ctx,
23212316
ctx->capture_ctx,
23222317
NULL,
23232318
ctx->runtime_spad );
2319+
fd_blockstore_init( ctx->slot_ctx->blockstore,
2320+
ctx->blockstore_fd,
2321+
FD_BLOCKSTORE_ARCHIVE_MIN_SIZE,
2322+
&ctx->slot_ctx->slot_bank );
2323+
23242324
ctx->epoch_ctx->bank_hash_cmp = ctx->bank_hash_cmp;
23252325
ctx->epoch_ctx->runtime_public = ctx->runtime_public;
23262326
init_after_snapshot( ctx, stem );

src/flamenco/runtime/fd_runtime.c

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,85 +3685,91 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
36853685
FD_LOG_ERR(("cannot open %s : %s", genesis_filepath, strerror(errno)));
36863686
}
36873687

3688-
fd_genesis_solana_t genesis_block = {0};
3689-
fd_hash_t genesis_hash;
3690-
36913688
fd_epoch_bank_t * epoch_bank = fd_exec_epoch_ctx_epoch_bank( slot_ctx->epoch_ctx );
36923689

36933690
FD_SPAD_FRAME_BEGIN( runtime_spad ) {
3691+
fd_genesis_solana_t * genesis_block;
3692+
fd_hash_t genesis_hash;
36943693
uchar * buf = fd_spad_alloc( runtime_spad, alignof(ulong), (ulong)sbuf.st_size );
36953694
ssize_t n = read( fd, buf, (ulong)sbuf.st_size );
36963695
close( fd );
36973696

3698-
/* FIXME: This needs to be patched to support new decoder properly */
36993697
fd_bincode_decode_ctx_t decode_ctx = {
37003698
.data = buf,
37013699
.dataend = buf + n,
37023700
};
37033701

3704-
fd_genesis_solana_decode( &genesis_block, &decode_ctx );
3702+
ulong decoded_sz = 0UL;
3703+
int err = fd_genesis_solana_decode_footprint( &decode_ctx, &decoded_sz );
3704+
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) {
3705+
FD_LOG_ERR(( "fd_genesis_solana_decode_footprint failed (%d)", err ));
3706+
}
3707+
3708+
uchar * mem = fd_spad_alloc( runtime_spad, fd_genesis_solana_align(), decoded_sz );
3709+
genesis_block = fd_genesis_solana_decode( mem, &decode_ctx );
37053710

37063711
// The hash is generated from the raw data... don't mess with this..
37073712
fd_sha256_hash( buf, (ulong)n, genesis_hash.uc );
37083713

3709-
} FD_SPAD_FRAME_END;
3710-
3711-
fd_memcpy( epoch_bank->genesis_hash.uc, genesis_hash.uc, sizeof(fd_hash_t) );
3712-
epoch_bank->cluster_type = genesis_block.cluster_type;
3714+
fd_memcpy( epoch_bank->genesis_hash.uc, genesis_hash.uc, sizeof(fd_hash_t) );
3715+
epoch_bank->cluster_type = genesis_block->cluster_type;
37133716

3714-
if( !is_snapshot ) {
3715-
fd_runtime_init_bank_from_genesis( slot_ctx,
3716-
&genesis_block,
3717-
&genesis_hash,
3718-
runtime_spad );
3717+
if( !is_snapshot ) {
3718+
fd_runtime_init_bank_from_genesis( slot_ctx,
3719+
genesis_block,
3720+
&genesis_hash,
3721+
runtime_spad );
37193722

3720-
fd_runtime_init_program( slot_ctx, runtime_spad );
3723+
fd_runtime_init_program( slot_ctx, runtime_spad );
37213724

3722-
FD_LOG_DEBUG(( "start genesis accounts - count: %lu", genesis_block.accounts_len ));
3725+
FD_LOG_DEBUG(( "start genesis accounts - count: %lu", genesis_block->accounts_len ));
37233726

3724-
for( ulong i=0; i<genesis_block.accounts_len; i++ ) {
3725-
fd_pubkey_account_pair_t * a = &genesis_block.accounts[i];
3727+
for( ulong i=0; i<genesis_block->accounts_len; i++ ) {
3728+
fd_pubkey_account_pair_t * a = &genesis_block->accounts[i];
37263729

3727-
FD_TXN_ACCOUNT_DECL( rec );
3730+
FD_TXN_ACCOUNT_DECL( rec );
37283731

3729-
int err = fd_txn_account_init_from_funk_mutable( rec,
3730-
&a->key,
3731-
slot_ctx->funk,
3732-
slot_ctx->funk_txn,
3733-
1, /* do_create */
3734-
a->account.data_len );
3732+
int err = fd_txn_account_init_from_funk_mutable( rec,
3733+
&a->key,
3734+
slot_ctx->funk,
3735+
slot_ctx->funk_txn,
3736+
1, /* do_create */
3737+
a->account.data_len );
37353738

3736-
if( FD_UNLIKELY( err ) ) {
3737-
FD_LOG_ERR(( "fd_txn_account_init_from_funk_mutable failed (%d)", err ));
3738-
}
3739+
if( FD_UNLIKELY( err ) ) {
3740+
FD_LOG_ERR(( "fd_txn_account_init_from_funk_mutable failed (%d)", err ));
3741+
}
37393742

3740-
rec->vt->set_data( rec, a->account.data, a->account.data_len );
3741-
rec->vt->set_lamports( rec, a->account.lamports );
3742-
rec->vt->set_rent_epoch( rec, a->account.rent_epoch );
3743-
rec->vt->set_executable( rec, a->account.executable );
3744-
rec->vt->set_owner( rec, &a->account.owner );
3743+
rec->vt->set_data( rec, a->account.data, a->account.data_len );
3744+
rec->vt->set_lamports( rec, a->account.lamports );
3745+
rec->vt->set_rent_epoch( rec, a->account.rent_epoch );
3746+
rec->vt->set_executable( rec, a->account.executable );
3747+
rec->vt->set_owner( rec, &a->account.owner );
37453748

3746-
fd_txn_account_mutable_fini( rec, slot_ctx->funk, slot_ctx->funk_txn );
3747-
}
3749+
fd_txn_account_mutable_fini( rec, slot_ctx->funk, slot_ctx->funk_txn );
3750+
}
37483751

3749-
FD_LOG_DEBUG(( "end genesis accounts" ));
3752+
FD_LOG_DEBUG(( "end genesis accounts" ));
37503753

3751-
FD_LOG_DEBUG(( "native instruction processors - count: %lu", genesis_block.native_instruction_processors_len ));
3754+
FD_LOG_DEBUG(( "native instruction processors - count: %lu", genesis_block->native_instruction_processors_len ));
37523755

3753-
for( ulong i=0UL; i < genesis_block.native_instruction_processors_len; i++ ) {
3754-
fd_string_pubkey_pair_t * a = &genesis_block.native_instruction_processors[i];
3755-
fd_write_builtin_account( slot_ctx, a->pubkey, (const char *) a->string, a->string_len );
3756-
}
3756+
for( ulong i=0UL; i < genesis_block->native_instruction_processors_len; i++ ) {
3757+
fd_string_pubkey_pair_t * a = &genesis_block->native_instruction_processors[i];
3758+
fd_write_builtin_account( slot_ctx, a->pubkey, (const char *) a->string, a->string_len );
3759+
}
37573760

3758-
fd_features_restore( slot_ctx, runtime_spad );
3761+
fd_features_restore( slot_ctx, runtime_spad );
37593762

3760-
slot_ctx->slot_bank.slot = 0UL;
3763+
slot_ctx->slot_bank.slot = 0UL;
37613764

3762-
int err = fd_runtime_process_genesis_block( slot_ctx, capture_ctx, tpool, runtime_spad );
3763-
if( FD_UNLIKELY( err ) ) {
3764-
FD_LOG_ERR(( "Genesis slot 0 execute failed with error %d", err ));
3765+
int err = fd_runtime_process_genesis_block( slot_ctx, capture_ctx, tpool, runtime_spad );
3766+
if( FD_UNLIKELY( err ) ) {
3767+
FD_LOG_ERR(( "Genesis slot 0 execute failed with error %d", err ));
3768+
}
37653769
}
3766-
}
3770+
3771+
fd_genesis_solana_destroy( genesis_block );
3772+
} FD_SPAD_FRAME_END;
37673773

37683774
slot_ctx->slot_bank.stake_account_keys.account_keys_root = NULL;
37693775
uchar * pool_mem = fd_spad_alloc( runtime_spad, fd_account_keys_pair_t_map_align(), fd_account_keys_pair_t_map_footprint( 100000UL ) );
@@ -3773,7 +3779,6 @@ fd_runtime_read_genesis( fd_exec_slot_ctx_t * slot_ctx,
37733779
pool_mem = fd_spad_alloc( runtime_spad, fd_account_keys_pair_t_map_align(), fd_account_keys_pair_t_map_footprint( 100000UL ) );
37743780
slot_ctx->slot_bank.vote_account_keys.account_keys_pool = fd_account_keys_pair_t_map_join( fd_account_keys_pair_t_map_new( pool_mem, 100000UL ) );
37753781

3776-
fd_genesis_solana_destroy( &genesis_block );
37773782
}
37783783

37793784
/******************************************************************************/

src/flamenco/runtime/sysvar/fd_sysvar_slot_hashes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ void
3737
fd_sysvar_slot_hashes_update( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) {
3838
fd_slot_hashes_t * slot_hashes = fd_sysvar_slot_hashes_read( slot_ctx, runtime_spad );
3939
if( !slot_hashes ) {
40+
void * shashes_mem = fd_spad_alloc( runtime_spad,
41+
fd_slot_hashes_align(),
42+
fd_slot_hashes_footprint() );
43+
slot_hashes = (fd_slot_hashes_t *)shashes_mem;
44+
4045
uchar * deque_mem = fd_spad_alloc( runtime_spad,
4146
deq_fd_slot_hash_t_align(),
4247
deq_fd_slot_hash_t_footprint( FD_SYSVAR_SLOT_HASHES_CAP ) );

0 commit comments

Comments
 (0)