Skip to content

Commit

Permalink
refactor(ghost,tower,voter): ghost & tower polish, zero copy voter API
Browse files Browse the repository at this point in the history
  • Loading branch information
lidatong committed Dec 25, 2024
1 parent d3bad82 commit e90e344
Show file tree
Hide file tree
Showing 18 changed files with 678 additions and 759 deletions.
2 changes: 1 addition & 1 deletion agave
Submodule agave updated 1113 files
25 changes: 13 additions & 12 deletions src/app/fdctl/run/tiles/fd_replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct fd_replay_tile_ctx {
fd_forks_t * forks;
fd_ghost_t * ghost;
fd_tower_t * tower;
fd_voter_t * voter;
fd_voter_t voter[1];
fd_bank_hash_cmp_t * bank_hash_cmp;

/* Tpool */
Expand Down Expand Up @@ -288,7 +288,6 @@ scratch_footprint( fd_topo_tile_t const * tile FD_PARAM_UNUSED ) {
l = FD_LAYOUT_APPEND( l, fd_forks_align(), fd_forks_footprint( FD_BLOCK_MAX ) );
l = FD_LAYOUT_APPEND( l, fd_ghost_align(), fd_ghost_footprint( FD_BLOCK_MAX, FD_VOTER_MAX ) );
l = FD_LAYOUT_APPEND( l, fd_tower_align(), fd_tower_footprint() );
l = FD_LAYOUT_APPEND( l, fd_voter_align(), fd_voter_footprint() );
l = FD_LAYOUT_APPEND( l, fd_bank_hash_cmp_align(), fd_bank_hash_cmp_footprint( ) );
for( ulong i = 0UL; i<FD_PACK_MAX_BANK_TILES; i++ ) {
l = FD_LAYOUT_APPEND( l, FD_BMTREE_COMMIT_ALIGN, FD_BMTREE_COMMIT_FOOTPRINT(0) );
Expand Down Expand Up @@ -1105,7 +1104,14 @@ after_frag( fd_replay_tile_ctx_t * ctx,
/* Consensus */

FD_PARAM_UNUSED long tic_ = fd_log_wallclock();
fd_tower_fork_update( ctx->tower, fork, ctx->acc_mgr, ctx->blockstore, ctx->ghost );
fd_ghost_node_t const * ghost_node = fd_ghost_insert( ctx->ghost, curr_slot, parent_slot );
#if FD_GHOST_USE_HANDHOLDING
if( FD_UNLIKELY( !ghost_node ) ) {
FD_LOG_ERR(( "failed to insert ghost node %lu", fork->slot ));
}
#endif
// fd_tower_fork_update( ctx->tower, fork, ctx->acc_mgr, ctx->blockstore, ctx->ghost );
fd_tower_fork_update( ctx->tower, ctx->blockstore, ctx->ghost, ctx->funk, fork->slot_ctx.funk_txn );

/* Check which fork to reset to for pack. */

Expand Down Expand Up @@ -1165,6 +1171,7 @@ after_frag( fd_replay_tile_ctx_t * ctx,
fd_forks_print( ctx->forks );
fd_ghost_print( ctx->ghost );
fd_tower_print( ctx->tower );

fd_fork_t const * vote_fork = fd_tower_vote_fork( ctx->tower,
ctx->forks,
ctx->acc_mgr,
Expand Down Expand Up @@ -1456,12 +1463,8 @@ init_after_snapshot( fd_replay_tile_ctx_t * ctx ) {

fd_fork_t * snapshot_fork = fd_forks_init( ctx->forks, ctx->slot_ctx );
FD_TEST( snapshot_fork );
fd_tower_init( ctx->tower,
&ctx->voter->vote_acc_addr,
ctx->acc_mgr,
ctx->epoch_ctx,
snapshot_fork,
ctx->smr );
fd_tower_init( ctx->tower, &ctx->voter->addr, ctx->funk, snapshot_fork->slot_ctx.funk_txn, ctx->smr );
fd_tower_epoch_update( ctx->tower, ctx->epoch_ctx );
fd_ghost_init( ctx->ghost, snapshot_slot, ctx->tower->total_stake );
fd_tower_print( ctx->tower );

Expand Down Expand Up @@ -1718,7 +1721,6 @@ unprivileged_init( fd_topo_t * topo,
void * forks_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_forks_align(), fd_forks_footprint( FD_BLOCK_MAX ) );
void * ghost_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_ghost_align(), fd_ghost_footprint( FD_BLOCK_MAX, FD_VOTER_MAX ) );
void * tower_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_tower_align(), fd_tower_footprint() );
void * voter_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_voter_align(), fd_voter_footprint() );
void * bank_hash_cmp_mem = FD_SCRATCH_ALLOC_APPEND( l, fd_bank_hash_cmp_align(), fd_bank_hash_cmp_footprint( ) );
for( ulong i = 0UL; i<FD_PACK_MAX_BANK_TILES; i++ ) {
ctx->bmtree[i] = FD_SCRATCH_ALLOC_APPEND( l, FD_BMTREE_COMMIT_ALIGN, FD_BMTREE_COMMIT_FOOTPRINT(0) );
Expand Down Expand Up @@ -1908,8 +1910,7 @@ unprivileged_init( fd_topo_t * topo,
/* voter */
/**********************************************************************/

ctx->voter = fd_voter_join( fd_voter_new( voter_mem ) );
memcpy( &ctx->voter->vote_acc_addr.uc,
memcpy( &ctx->voter->addr.uc,
fd_keyload_load( tile->replay.vote_account_path, 1 ),
sizeof( fd_pubkey_t ) );
memcpy( &ctx->voter->validator_identity.uc,
Expand Down
2 changes: 1 addition & 1 deletion src/ballet/shred/fd_shred.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ struct __attribute__((packed)) fd_shred {
} code;
};
};
typedef struct fd_shred fd_shred_t;
typedef struct fd_shred_data fd_shred_data_t;
typedef struct fd_shred_code fd_shred_code_t;
typedef struct fd_shred fd_shred_t;

FD_PROTOTYPES_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion src/choreo/fd_choreo_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define FD_VOTER_MAX (1UL << 12UL) /* the maximum # of unique voters ie. node pubkeys. */
#define FD_EQVOCSAFE_PCT (0.52)
#define FD_CONFIRMED_PCT (2.0 / 3.0)
#define FD_FINALIZED_PCT FD_CONFIRMED_PCT
#define FD_FINALIZED_PCT FD_CONFIRMED_PCT
#define FD_SLOT_HASH_CMP(k0,k1) (fd_int_if(((k0)->slot)<((k1)->slot),-1,fd_int_if(((k0)->slot)>((k1)->slot),1),memcmp((k0),(k1),sizeof(fd_slot_hash_t))))
#define FD_SLOT_HASH_EQ(k0,k1) ((((k0)->slot)==((k1)->slot)) & !(memcmp(((k0)->hash.uc),((k1)->hash.uc),sizeof(fd_hash_t))))
#define FD_SLOT_HASH_HASH(key,seed) fd_ulong_hash( ((key)->slot) ^ ((key)->hash.ul[0]) ^ (seed) )
Expand Down
2 changes: 1 addition & 1 deletion src/choreo/forks/fd_forks.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fd_forks_publish( fd_forks_t * forks, ulong slot, fd_ghost_t const * ghost ) {
Optimize for unlikely because there is usually just one fork. */

int stale = fork->slot < slot || !fd_ghost_is_descendant( ghost, fork->slot, slot );
int stale = fork->slot < slot || !fd_ghost_is_ancestor( ghost, fork->slot, slot );
if( FD_UNLIKELY( !fork->lock && stale ) ) {
FD_LOG_NOTICE(( "adding %lu to prune. root %lu", fork->slot, slot ));
if( FD_LIKELY( !curr ) ) {
Expand Down
Loading

0 comments on commit e90e344

Please sign in to comment.