Skip to content

Commit 73f1f55

Browse files
bank manager wip
1 parent 9c0bbf1 commit 73f1f55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2605
-1474
lines changed

src/app/ledger/main.c

+46-26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../../flamenco/runtime/fd_runtime_public.h"
88
#include "../../flamenco/runtime/fd_rocksdb.h"
99
#include "../../flamenco/runtime/fd_txncache.h"
10+
#include "../../flamenco/runtime/fd_bank_mgr.h"
1011
#include "../../flamenco/rewards/fd_rewards.h"
1112
#include "../../ballet/base58/fd_base58.h"
1213
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
@@ -291,7 +292,7 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
291292

292293
fd_features_restore( ledger_args->slot_ctx, ledger_args->runtime_spad );
293294

294-
fd_runtime_update_leaders( ledger_args->slot_ctx, ledger_args->slot_ctx->slot_bank.slot, ledger_args->runtime_spad );
295+
fd_runtime_update_leaders( ledger_args->slot_ctx, ledger_args->slot_ctx->slot, ledger_args->runtime_spad );
295296

296297
fd_calculate_epoch_accounts_hash_values( ledger_args->slot_ctx );
297298

@@ -300,8 +301,8 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
300301
ulong slot_cnt = 0;
301302
fd_blockstore_t * blockstore = ledger_args->slot_ctx->blockstore;
302303

303-
ulong prev_slot = ledger_args->slot_ctx->slot_bank.slot;
304-
ulong start_slot = ledger_args->slot_ctx->slot_bank.slot + 1;
304+
ulong prev_slot = ledger_args->slot_ctx->slot;
305+
ulong start_slot = ledger_args->slot_ctx->slot + 1;
305306

306307
ledger_args->slot_ctx->root_slot = prev_slot;
307308

@@ -350,7 +351,6 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
350351
for( ulong slot = start_slot; slot<=ledger_args->end_slot && !aborted; ++slot ) {
351352

352353
ledger_args->slot_ctx->slot_bank.prev_slot = prev_slot;
353-
ledger_args->slot_ctx->slot_bank.slot = slot;
354354

355355
FD_LOG_DEBUG(( "reading slot %lu", slot ));
356356

@@ -405,10 +405,18 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
405405
continue;
406406
}
407407

408-
ledger_args->slot_ctx->slot_bank.tick_height = ledger_args->slot_ctx->slot_bank.max_tick_height;
409-
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( ledger_args->epoch_ctx->epoch_bank.ticks_per_slot, slot, &ledger_args->slot_ctx->slot_bank.max_tick_height ) ) ) {
410-
FD_LOG_ERR(( "couldn't compute max tick height slot %lu ticks_per_slot %lu", slot, ledger_args->epoch_ctx->epoch_bank.ticks_per_slot ));
408+
ulong * max_tick_height = fd_bank_mgr_max_tick_height_query( ledger_args->slot_ctx->bank_mgr );
409+
ulong * ticks_per_slot = fd_bank_mgr_ticks_per_slot_query( ledger_args->slot_ctx->bank_mgr );
410+
ulong * tick_height = fd_bank_mgr_tick_height_modify( ledger_args->slot_ctx->bank_mgr );
411+
*tick_height = *max_tick_height;
412+
fd_bank_mgr_tick_height_save( ledger_args->slot_ctx->bank_mgr );
413+
414+
max_tick_height = fd_bank_mgr_max_tick_height_modify( ledger_args->slot_ctx->bank_mgr );
415+
416+
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( *ticks_per_slot, slot, max_tick_height ) ) ) {
417+
FD_LOG_ERR(( "couldn't compute max tick height slot %lu ticks_per_slot %lu", slot, *ticks_per_slot ));
411418
}
419+
fd_bank_mgr_max_tick_height_save( ledger_args->slot_ctx->bank_mgr );
412420

413421
if( ledger_args->slot_ctx->root_slot%ledger_args->snapshot_freq==0UL && !ledger_args->is_snapshotting ) {
414422

@@ -455,8 +463,9 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
455463
}
456464

457465
ulong blk_txn_cnt = 0UL;
458-
FD_LOG_NOTICE(( "Used memory in spad before slot=%lu %lu", ledger_args->slot_ctx->slot_bank.slot, ledger_args->runtime_spad->mem_used ));
466+
FD_LOG_NOTICE(( "Used memory in spad before slot=%lu %lu", slot, ledger_args->runtime_spad->mem_used ));
459467
FD_TEST( fd_runtime_block_eval_tpool( ledger_args->slot_ctx,
468+
slot,
460469
blk,
461470
ledger_args->capture_ctx,
462471
ledger_args->tpool,
@@ -471,11 +480,11 @@ runtime_replay( fd_ledger_args_t * ledger_args ) {
471480
fd_hash_t expected;
472481
int err = fd_blockstore_block_hash_query( blockstore, slot, &expected );
473482
if( FD_UNLIKELY( err ) ) FD_LOG_ERR( ( "slot %lu is missing its hash", slot ) );
474-
else if( FD_UNLIKELY( 0 != memcmp( ledger_args->slot_ctx->slot_bank.poh.hash, expected.hash, 32UL ) ) ) {
483+
else if( FD_UNLIKELY( 0 != memcmp( fd_bank_mgr_poh_query( ledger_args->slot_ctx->bank_mgr )->hash, expected.hash, sizeof(fd_hash_t) ) ) ) {
475484
char expected_hash[ FD_BASE58_ENCODED_32_SZ ];
476485
fd_acct_addr_cstr( expected_hash, expected.hash );
477486
char poh_hash[ FD_BASE58_ENCODED_32_SZ ];
478-
fd_acct_addr_cstr( poh_hash, ledger_args->slot_ctx->slot_bank.poh.hash );
487+
fd_acct_addr_cstr( poh_hash, fd_bank_mgr_poh_query( ledger_args->slot_ctx->bank_mgr )->hash );
479488
FD_LOG_WARNING(( "PoH hash mismatch! slot=%lu expected=%s, got=%s",
480489
slot,
481490
expected_hash,
@@ -718,7 +727,7 @@ fd_ledger_main_setup( fd_ledger_args_t * args ) {
718727

719728
/* Finish other runtime setup steps */
720729
fd_features_restore( args->slot_ctx, args->runtime_spad );
721-
fd_runtime_update_leaders( args->slot_ctx, args->slot_ctx->slot_bank.slot, args->runtime_spad );
730+
fd_runtime_update_leaders( args->slot_ctx, args->slot_ctx->slot, args->runtime_spad );
722731
fd_calculate_epoch_accounts_hash_values( args->slot_ctx );
723732

724733
fd_exec_para_cb_ctx_t exec_para_ctx = {
@@ -1156,11 +1165,11 @@ ingest( fd_ledger_args_t * args ) {
11561165

11571166
/* At this point the account state has been ingested into funk. Intake rocksdb */
11581167
if( args->start_slot == 0 ) {
1159-
args->start_slot = slot_ctx->slot_bank.slot + 1;
1168+
args->start_slot = slot_ctx->slot + 1;
11601169
}
11611170
fd_blockstore_t * blockstore = args->blockstore;
11621171
if( blockstore ) {
1163-
blockstore->shmem->lps = blockstore->shmem->hcs = blockstore->shmem->wmk = slot_ctx->slot_bank.slot;
1172+
blockstore->shmem->lps = blockstore->shmem->hcs = blockstore->shmem->wmk = slot_ctx->slot;
11641173
}
11651174

11661175
if( args->funk_only ) {
@@ -1169,8 +1178,8 @@ ingest( fd_ledger_args_t * args ) {
11691178
FD_LOG_NOTICE(( "using shredcap" ));
11701179
fd_shredcap_populate_blockstore( args->shredcap, blockstore, args->start_slot, args->end_slot );
11711180
} else if( args->rocksdb_list[ 0UL ] ) {
1172-
if( args->end_slot >= slot_ctx->slot_bank.slot + args->slot_history_max ) {
1173-
args->end_slot = slot_ctx->slot_bank.slot + args->slot_history_max - 1;
1181+
if( args->end_slot >= slot_ctx->slot + args->slot_history_max ) {
1182+
args->end_slot = slot_ctx->slot + args->slot_history_max - 1;
11741183
}
11751184
ingest_rocksdb( args->rocksdb_list[ 0UL ], args->start_slot, args->end_slot,
11761185
blockstore, args->copy_txn_status, args->trash_hash, args->valloc );
@@ -1269,24 +1278,31 @@ replay( fd_ledger_args_t * args ) {
12691278
fd_exec_epoch_ctx_bank_mem_clear( args->epoch_ctx );
12701279

12711280
/* TODO: This is very hacky, needs to be cleaned up */
1272-
args->epoch_ctx->epoch_bank.cluster_version[0] = args->cluster_version[0];
1273-
args->epoch_ctx->epoch_bank.cluster_version[1] = args->cluster_version[1];
1274-
args->epoch_ctx->epoch_bank.cluster_version[2] = args->cluster_version[2];
1281+
1282+
void * slot_ctx_mem = fd_spad_alloc_check( spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT );
1283+
args->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_ctx_mem, spad ) );
1284+
args->slot_ctx->epoch_ctx = args->epoch_ctx;
1285+
args->slot_ctx->funk = funk;
1286+
args->slot_ctx->blockstore = args->blockstore;
1287+
1288+
FD_TEST( args->slot_ctx->bank_mgr_mem );
1289+
args->slot_ctx->bank_mgr = fd_bank_mgr_join( fd_bank_mgr_new( args->slot_ctx->bank_mgr_mem ), funk, NULL );
1290+
1291+
fd_cluster_version_t * cluster_version = fd_bank_mgr_cluster_version_modify( args->slot_ctx->bank_mgr );
1292+
1293+
cluster_version->major = args->cluster_version[0];
1294+
cluster_version->minor = args->cluster_version[1];
1295+
cluster_version->patch = args->cluster_version[2];
1296+
fd_bank_mgr_cluster_version_save( args->slot_ctx->bank_mgr );
12751297

12761298
args->epoch_ctx->runtime_public = runtime_public;
12771299

1278-
fd_features_enable_cleaned_up( &args->epoch_ctx->features, args->epoch_ctx->epoch_bank.cluster_version );
1300+
fd_features_enable_cleaned_up( &args->epoch_ctx->features, cluster_version );
12791301
fd_features_enable_one_offs( &args->epoch_ctx->features, args->one_off_features, args->one_off_features_cnt, 0UL );
12801302

12811303
// activate them
12821304
fd_memcpy( &args->epoch_ctx->runtime_public->features, &args->epoch_ctx->features, sizeof(fd_features_t) );
12831305

1284-
void * slot_ctx_mem = fd_spad_alloc_check( spad, FD_EXEC_SLOT_CTX_ALIGN, FD_EXEC_SLOT_CTX_FOOTPRINT );
1285-
args->slot_ctx = fd_exec_slot_ctx_join( fd_exec_slot_ctx_new( slot_ctx_mem, spad ) );
1286-
args->slot_ctx->epoch_ctx = args->epoch_ctx;
1287-
args->slot_ctx->funk = funk;
1288-
args->slot_ctx->blockstore = args->blockstore;
1289-
12901306
void * status_cache_mem = fd_spad_alloc_check( spad,
12911307
FD_TXNCACHE_ALIGN,
12921308
fd_txncache_footprint( FD_TXNCACHE_DEFAULT_MAX_ROOTED_SLOTS,
@@ -1347,7 +1363,11 @@ replay( fd_ledger_args_t * args ) {
13471363

13481364
fd_ledger_main_setup( args );
13491365

1350-
fd_blockstore_init( args->blockstore, -1, FD_BLOCKSTORE_ARCHIVE_MIN_SIZE, &args->slot_ctx->slot_bank );
1366+
fd_blockstore_init( args->blockstore,
1367+
-1,
1368+
FD_BLOCKSTORE_ARCHIVE_MIN_SIZE,
1369+
&args->slot_ctx->slot_bank,
1370+
args->slot_ctx->slot );
13511371
fd_buf_shred_pool_reset( args->blockstore->shred_pool, 0 );
13521372

13531373
FD_LOG_WARNING(( "setup done" ));

src/app/shared_dev/commands/configure/genesis.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,12 @@ create_genesis( config_t const * config,
194194

195195
fd_features_t features[1];
196196
fd_features_disable_all( features );
197-
uint version[] = {FD_DEFAULT_AGAVE_CLUSTER_VERSION_MAJOR, FD_DEFAULT_AGAVE_CLUSTER_VERSION_MINOR, FD_DEFAULT_AGAVE_CLUSTER_VERSION_PATCH};
198-
fd_features_enable_cleaned_up(features, version);
197+
fd_cluster_version_t cluster_version = {
198+
.major = FD_DEFAULT_AGAVE_CLUSTER_VERSION_MAJOR,
199+
.minor = FD_DEFAULT_AGAVE_CLUSTER_VERSION_MINOR,
200+
.patch = FD_DEFAULT_AGAVE_CLUSTER_VERSION_PATCH
201+
};
202+
fd_features_enable_cleaned_up( features, &cluster_version );
199203
default_enable_features( features );
200204

201205
options->features = features;

src/choreo/epoch/fd_epoch.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "fd_epoch.h"
2-
2+
#include "../../flamenco/runtime/fd_bank_mgr.h"
33
void *
44
fd_epoch_new( void * shmem, ulong voter_max ) {
55
if( FD_UNLIKELY( !shmem ) ) {
@@ -103,12 +103,15 @@ fd_epoch_delete( void * epoch ) {
103103
}
104104

105105
void
106-
fd_epoch_init( fd_epoch_t * epoch, fd_epoch_bank_t const * epoch_bank ) {
107-
epoch->first_slot = epoch_bank->eah_start_slot;
108-
epoch->last_slot = epoch_bank->eah_stop_slot;
106+
fd_epoch_init( fd_epoch_t * epoch,
107+
ulong eah_start_slot,
108+
ulong eah_stop_slot,
109+
fd_vote_accounts_t const * vote_accounts ) {
110+
111+
epoch->first_slot = eah_start_slot;
112+
epoch->last_slot = eah_stop_slot;
109113

110-
fd_voter_t * epoch_voters = fd_epoch_voters( epoch );
111-
fd_vote_accounts_t const * vote_accounts = &epoch_bank->stakes.vote_accounts;
114+
fd_voter_t * epoch_voters = fd_epoch_voters( epoch );
112115

113116
for( fd_vote_accounts_pair_t_mapnode_t * curr = fd_vote_accounts_pair_t_map_minimum(
114117
vote_accounts->vote_accounts_pool,

src/choreo/epoch/fd_epoch.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ fd_epoch_delete( void * epoch );
9797
epoch. */
9898

9999
void
100-
fd_epoch_init( fd_epoch_t * epoch, fd_epoch_bank_t const * epoch_bank );
100+
fd_epoch_init( fd_epoch_t * epoch,
101+
ulong eah_start_slot,
102+
ulong eah_stop_slot,
103+
fd_vote_accounts_t const * vote_accounts );
101104

102105
/* fd_epoch_fini finishes an epoch. Assumes epoch is a valid local join
103106
and epoch has already been initialized. This should only be called

src/choreo/forks/fd_forks.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "../../flamenco/runtime/fd_runtime.h"
77
#include "../../flamenco/runtime/program/fd_program_util.h"
88
#include "../../flamenco/runtime/program/fd_vote_program.h"
9-
9+
#include "../../flamenco/runtime/fd_bank_mgr.h"
1010
void *
1111
fd_forks_new( void * shmem, ulong max, ulong seed ) {
1212

@@ -115,7 +115,7 @@ fd_forks_init( fd_forks_t * forks, fd_exec_slot_ctx_t * slot_ctx ) {
115115
}
116116

117117
fd_fork_t * fork = fd_fork_pool_ele_acquire( forks->pool );
118-
fork->slot = slot_ctx->slot_bank.slot;
118+
fork->slot = slot_ctx->slot;
119119
fork->prev = fd_fork_pool_idx_null( forks->pool );
120120
fork->lock = 0;
121121
fork->end_idx = UINT_MAX;
@@ -167,8 +167,8 @@ fd_forks_query_const( fd_forks_t const * forks, ulong slot ) {
167167
// // fork is advancing
168168
// FD_LOG_DEBUG(( "new block execution - slot: %lu, parent_slot: %lu", curr_slot, parent_slot ));
169169

170-
// fork->slot_ctx->slot_bank.prev_slot = fork->slot_ctx->slot_bank.slot;
171-
// fork->slot_ctx->slot_bank.slot = curr_slot;
170+
// fork->slot_ctx->slot_bank.prev_slot = fork->slot_ctx->slot;
171+
// fork->slot_ctx->slot = curr_slot;
172172

173173
// fork->slot_ctx.status_cache = status_cache;
174174
// fd_funk_txn_xid_t xid;
@@ -245,6 +245,7 @@ slot_ctx_restore( ulong slot,
245245
continue;
246246
}
247247

248+
slot_ctx_out->slot = slot;
248249
slot_ctx_out->slot_bank = *slot_bank;
249250
FD_TEST( !fd_runtime_sysvar_cache_load( slot_ctx_out, runtime_spad ) );
250251

@@ -259,20 +260,16 @@ slot_ctx_restore( ulong slot,
259260
// signature_cnt, account_delta_hash, prev_banks_hash are used for the banks
260261
// hash calculation and not needed when restoring parent
261262

262-
FD_LOG_NOTICE( ( "recovered slot_bank for slot=%lu banks_hash=%s poh_hash %s",
263-
slot_ctx_out->slot_bank.slot,
264-
FD_BASE58_ENC_32_ALLOCA( slot_ctx_out->slot_bank.banks_hash.hash ),
265-
FD_BASE58_ENC_32_ALLOCA( slot_ctx_out->slot_bank.poh.hash ) ) );
263+
FD_LOG_NOTICE(( "recovered slot_bank for slot=%lu banks_hash=%s",
264+
slot_ctx_out->slot,
265+
FD_BASE58_ENC_32_ALLOCA( slot_ctx_out->slot_bank.banks_hash.hash ) ));
266266

267267
/* Prepare bank for next slot */
268-
slot_ctx_out->slot_bank.slot = slot;
269-
slot_ctx_out->slot_bank.collected_execution_fees = 0;
270-
slot_ctx_out->slot_bank.collected_priority_fees = 0;
271-
slot_ctx_out->slot_bank.collected_rent = 0;
268+
slot_ctx_out->slot = slot;
272269

273270
/* FIXME epoch boundary stuff when replaying */
274271
// fd_features_restore( slot_ctx );
275-
// fd_runtime_update_leaders( slot_ctx, slot_ctx->slot_bank.slot );
272+
// fd_runtime_update_leaders( slot_ctx, slot_ctx->slot );
276273
// fd_calculate_epoch_accounts_hash_values( slot_ctx );
277274
}
278275

src/discof/batch/fd_batch_tile.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,20 @@ produce_eah( fd_snapshot_tile_ctx_t * ctx, fd_stem_context_t * stem, ulong batch
381381
FD_LOG_ERR(( "Slot bank record has wrong magic" ));
382382
}
383383

384-
int err;
385-
fd_slot_bank_t * slot_bank = fd_bincode_decode_spad( slot_bank, ctx->spad, (uchar *)slot_val+sizeof(uint), fd_funk_val_sz( slot_rec )-sizeof(uint), &err );
386-
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) {
387-
FD_LOG_ERR(( "Failed to read slot bank record: invalid decode" ));
388-
continue;
389-
}
384+
/* FIXME: The slot bank is getting replaced with the bank manager. */
385+
// int err;
386+
// fd_slot_bank_t * slot_bank = fd_bincode_decode_spad( slot_bank, ctx->spad, (uchar *)slot_val+sizeof(uint), fd_funk_val_sz( slot_rec )-sizeof(uint), &err );
387+
// if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) {
388+
// FD_LOG_ERR(( "Failed to read slot bank record: invalid decode" ));
389+
// continue;
390+
// }
390391

391392
/* At this point, calculate the epoch account hash. */
392393

393394
fd_hash_t epoch_account_hash = {0};
394395

395-
fd_accounts_hash( funk, slot_bank, &epoch_account_hash, ctx->spad, &ctx->runtime_public->features, NULL, NULL );
396+
/* FIXME: this has an invalid slot number. */
397+
fd_accounts_hash( funk, 0UL, &epoch_account_hash, ctx->spad, &ctx->runtime_public->features, NULL, NULL );
396398

397399
FD_LOG_NOTICE(( "Done computing epoch account hash (%s)", FD_BASE58_ENC_32_ALLOCA( &epoch_account_hash ) ));
398400

src/discof/consensus/test_consensus.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,14 @@ main( void ) {
552552
// if( incremental_snapshot ) {
553553
// ulong i, j;
554554
// FD_TEST( sscanf( incremental_snapshot, "incremental-snapshot-%lu-%lu", &i, &j ) == 2 );
555-
// FD_TEST( i == snapshot_slot_ctx->slot_bank.slot );
555+
// FD_TEST( i == snapshot_slot_ctx->slot );
556556
// FD_TEST( epoch_bank );
557557
// FD_TEST( fd_slot_to_epoch( &epoch_bank->epoch_schedule, i, NULL ) ==
558558
// fd_slot_to_epoch( &epoch_bank->epoch_schedule, j, NULL ) );
559559
// fd_snapshot_load_all( incremental_snapshot, NULL, snapshot_slot_ctx, 1, 1, FD_SNAPSHOT_TYPE_INCREMENTAL );
560560
// }
561561

562-
// ulong snapshot_slot = snapshot_slot_ctx->slot_bank.slot;
562+
// ulong snapshot_slot = snapshot_slot_ctx->slot;
563563
// FD_LOG_NOTICE( ( "snapshot_slot: %lu", snapshot_slot ) );
564564

565565
// snapshot_fork->slot = snapshot_slot;
@@ -568,7 +568,7 @@ main( void ) {
568568
// FD_TEST( !fd_runtime_sysvar_cache_load( snapshot_slot_ctx ) );
569569

570570
// fd_features_restore( snapshot_slot_ctx );
571-
// fd_runtime_update_leaders( snapshot_slot_ctx, snapshot_slot_ctx->slot_bank.slot );
571+
// fd_runtime_update_leaders( snapshot_slot_ctx, snapshot_slot_ctx->slot );
572572
// fd_calculate_epoch_accounts_hash_values( snapshot_slot_ctx );
573573

574574
// fd_funk_start_write( funk );

0 commit comments

Comments
 (0)