Skip to content

Commit 7932bc9

Browse files
committed
replay, sched: verify PoH
1 parent 32ed6f9 commit 7932bc9

File tree

9 files changed

+690
-133
lines changed

9 files changed

+690
-133
lines changed

src/app/firedancer/config/default.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ user = ""
766766
# much parallelism is possible.
767767
#
768768
# More exec tiles can allow the validator to replay through blocks
769-
# faster, subject to Amdahl's law. Empirically, we've found 8 exec
769+
# faster, subject to Amdahl's law. Empirically, we've found 10 exec
770770
# tiles to achieve near optimal replay speed under current
771771
# `mainnet-beta` conditions.
772772
#
@@ -775,7 +775,7 @@ user = ""
775775
# to be highly concurrent, most of the time account writeback can be
776776
# done in parallel without blocking. Multiple exec tiles exploit this
777777
# parallelism supported by the accounts database.
778-
exec_tile_count = 8
778+
exec_tile_count = 10
779779

780780
# How many shred tiles to run. Should be set to 1. This is
781781
# configurable and designed to scale out for future network

src/discof/exec/fd_exec_tile.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "generated/fd_exec_tile_seccomp.h"
33

44
#include "../../util/pod/fd_pod_format.h"
5+
#include "../../ballet/sha256/fd_sha256.h" /* fd_sha256_hash_32_repeated */
56
#include "../../discof/replay/fd_exec.h"
67
#include "../../flamenco/runtime/context/fd_capture_ctx.h"
78
#include "../../flamenco/runtime/fd_bank.h"
@@ -128,7 +129,7 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
128129
fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
129130
ctx->bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
130131
FD_TEST( ctx->bank );
131-
ctx->txn_in.txn = &msg->txn;
132+
ctx->txn_in.txn = msg->txn;
132133
ctx->txn_in.exec_accounts = &ctx->exec_accounts;
133134

134135
fd_runtime_prepare_and_execute_txn( ctx->runtime, ctx->bank, &ctx->txn_in, &ctx->txn_out );
@@ -158,7 +159,7 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
158159
}
159160
case FD_EXEC_TT_TXN_SIGVERIFY: {
160161
fd_exec_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
161-
int res = fd_executor_txn_verify( &msg->txn, ctx->sha_lj );
162+
int res = fd_executor_txn_verify( msg->txn, ctx->sha_lj );
162163
fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
163164
out_msg->bank_idx = msg->bank_idx;
164165
out_msg->txn_sigverify->txn_idx = msg->txn_idx;
@@ -167,6 +168,17 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
167168
ctx->exec_replay_out->chunk = fd_dcache_compact_next( ctx->exec_replay_out->chunk, sizeof(*out_msg), ctx->exec_replay_out->chunk0, ctx->exec_replay_out->wmark );
168169
break;
169170
}
171+
case FD_EXEC_TT_POH_HASH: {
172+
fd_exec_poh_hash_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
173+
fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
174+
out_msg->bank_idx = msg->bank_idx;
175+
out_msg->poh_hash->mblk_idx = msg->mblk_idx;
176+
out_msg->poh_hash->hashcnt = msg->hashcnt;
177+
fd_sha256_hash_32_repeated( msg->hash, out_msg->poh_hash->hash, msg->hashcnt );
178+
fd_stem_publish( stem, ctx->exec_replay_out->idx, (FD_EXEC_TT_POH_HASH<<32)|ctx->tile_idx, ctx->exec_replay_out->chunk, sizeof(*out_msg), 0UL, 0UL, 0UL );
179+
ctx->exec_replay_out->chunk = fd_dcache_compact_next( ctx->exec_replay_out->chunk, sizeof(*out_msg), ctx->exec_replay_out->chunk0, ctx->exec_replay_out->wmark );
180+
break;
181+
}
170182
default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
171183
}
172184
} else FD_LOG_CRIT(( "invalid in_idx %lu", in_idx ));

src/discof/replay/fd_exec.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define FD_EXEC_TT_TXN_EXEC (1UL) /* Transaction execution. */
1111
#define FD_EXEC_TT_TXN_SIGVERIFY (2UL) /* Transaction sigverify. */
1212
#define FD_EXEC_TT_LTHASH (3UL) /* Account lthash. */
13-
#define FD_EXEC_TT_POH_VERIFY (4UL) /* PoH hash verification. */
13+
#define FD_EXEC_TT_POH_HASH (4UL) /* PoH hashing. */
1414

1515
/* Sent from the replay tile to the exec tiles. These describe one of
1616
several types of tasks for an exec tile. An idx to the bank in the
@@ -20,20 +20,29 @@
2020
struct fd_exec_txn_exec_msg {
2121
ulong bank_idx;
2222
ulong txn_idx;
23-
fd_txn_p_t txn;
23+
fd_txn_p_t txn[ 1 ];
2424
};
2525
typedef struct fd_exec_txn_exec_msg fd_exec_txn_exec_msg_t;
2626

2727
struct fd_exec_txn_sigverify_msg {
2828
ulong bank_idx;
2929
ulong txn_idx;
30-
fd_txn_p_t txn;
30+
fd_txn_p_t txn[ 1 ];
3131
};
3232
typedef struct fd_exec_txn_sigverify_msg fd_exec_txn_sigverify_msg_t;
3333

34+
struct fd_exec_poh_hash_msg {
35+
ulong bank_idx;
36+
ulong mblk_idx;
37+
ulong hashcnt;
38+
fd_hash_t hash[ 1 ];
39+
};
40+
typedef struct fd_exec_poh_hash_msg fd_exec_poh_hash_msg_t;
41+
3442
union fd_exec_task_msg {
3543
fd_exec_txn_exec_msg_t txn_exec;
3644
fd_exec_txn_sigverify_msg_t txn_sigverify;
45+
fd_exec_poh_hash_msg_t poh_hash;
3746
};
3847
typedef union fd_exec_task_msg fd_exec_task_msg_t;
3948

@@ -59,11 +68,19 @@ struct fd_exec_txn_sigverify_done_msg {
5968
};
6069
typedef struct fd_exec_txn_sigverify_done_msg fd_exec_txn_sigverify_done_msg_t;
6170

71+
struct fd_exec_poh_hash_done_msg {
72+
ulong mblk_idx;
73+
ulong hashcnt;
74+
fd_hash_t hash[ 1 ];
75+
};
76+
typedef struct fd_exec_poh_hash_done_msg fd_exec_poh_hash_done_msg_t;
77+
6278
struct fd_exec_task_done_msg {
6379
ulong bank_idx;
6480
union {
6581
fd_exec_txn_exec_done_msg_t txn_exec[ 1 ];
6682
fd_exec_txn_sigverify_done_msg_t txn_sigverify[ 1 ];
83+
fd_exec_poh_hash_done_msg_t poh_hash[ 1 ];
6784
};
6885
};
6986
typedef struct fd_exec_task_done_msg fd_exec_task_done_msg_t;

src/discof/replay/fd_replay_tile.c

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -603,22 +603,21 @@ replay_block_start( fd_replay_tile_t * ctx,
603603

604604
fd_bank_has_identity_vote_set( bank, 0 );
605605

606-
/* Set the tick height. */
607-
fd_bank_tick_height_set( bank, fd_bank_max_tick_height_get( bank ) );
608-
609606
/* Update block height. */
610607
fd_bank_block_height_set( bank, fd_bank_block_height_get( bank ) + 1UL );
611608

612-
ulong * max_tick_height = fd_bank_max_tick_height_modify( bank );
613-
ulong ticks_per_slot = fd_bank_ticks_per_slot_get( bank );
614-
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( ticks_per_slot, slot, max_tick_height ) ) ) {
615-
FD_LOG_CRIT(( "couldn't compute tick height/max tick height slot %lu ticks_per_slot %lu", slot, ticks_per_slot ));
616-
}
617-
618609
int is_epoch_boundary = 0;
619610
fd_runtime_block_execute_prepare( ctx->banks, bank, ctx->accdb, &ctx->runtime_stack, ctx->capture_ctx, &is_epoch_boundary );
620611
if( FD_UNLIKELY( is_epoch_boundary ) ) publish_stake_weights( ctx, stem, bank, 1 );
621612

613+
ulong max_tick_height;
614+
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS != fd_runtime_compute_max_tick_height( fd_bank_ticks_per_slot_get( bank ), slot, &max_tick_height ) ) ) {
615+
FD_LOG_CRIT(( "couldn't compute tick height/max tick height slot %lu ticks_per_slot %lu", slot, fd_bank_ticks_per_slot_get( bank ) ));
616+
}
617+
fd_bank_max_tick_height_set( bank, max_tick_height );
618+
fd_bank_tick_height_set( bank, fd_bank_max_tick_height_get( parent_bank ) ); /* The parent's max tick height is our starting tick height. */
619+
fd_sched_set_poh_params( ctx->sched, bank->idx, fd_bank_tick_height_get( bank ), fd_bank_max_tick_height_get( bank ), fd_bank_hashes_per_tick_get( bank ), fd_bank_poh_query( parent_bank ) );
620+
622621
return bank;
623622
}
624623

@@ -1525,7 +1524,7 @@ dispatch_task( fd_replay_tile_t * ctx,
15251524

15261525
fd_replay_out_link_t * exec_out = ctx->exec_out;
15271526
fd_exec_txn_exec_msg_t * exec_msg = fd_chunk_to_laddr( exec_out->mem, exec_out->chunk );
1528-
memcpy( &exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
1527+
memcpy( exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
15291528
exec_msg->bank_idx = task->txn_exec->bank_idx;
15301529
exec_msg->txn_idx = task->txn_exec->txn_idx;
15311530
fd_stem_publish( stem, exec_out->idx, (FD_EXEC_TT_TXN_EXEC<<32) | task->txn_exec->exec_idx, exec_out->chunk, sizeof(*exec_msg), 0UL, 0UL, fd_frag_meta_ts_comp( fd_tickcount() ) );
@@ -1540,13 +1539,27 @@ dispatch_task( fd_replay_tile_t * ctx,
15401539

15411540
fd_replay_out_link_t * exec_out = ctx->exec_out;
15421541
fd_exec_txn_sigverify_msg_t * exec_msg = fd_chunk_to_laddr( exec_out->mem, exec_out->chunk );
1543-
memcpy( &exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
1542+
memcpy( exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
15441543
exec_msg->bank_idx = task->txn_sigverify->bank_idx;
15451544
exec_msg->txn_idx = task->txn_sigverify->txn_idx;
15461545
fd_stem_publish( stem, exec_out->idx, (FD_EXEC_TT_TXN_SIGVERIFY<<32) | task->txn_sigverify->exec_idx, exec_out->chunk, sizeof(*exec_msg), 0UL, 0UL, 0UL );
15471546
exec_out->chunk = fd_dcache_compact_next( exec_out->chunk, sizeof(*exec_msg), exec_out->chunk0, exec_out->wmark );
15481547
break;
15491548
};
1549+
case FD_SCHED_TT_POH_HASH: {
1550+
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, task->poh_hash->bank_idx );
1551+
bank->refcnt++;
1552+
1553+
fd_replay_out_link_t * exec_out = ctx->exec_out;
1554+
fd_exec_poh_hash_msg_t * exec_msg = fd_chunk_to_laddr( exec_out->mem, exec_out->chunk );
1555+
exec_msg->bank_idx = task->poh_hash->bank_idx;
1556+
exec_msg->mblk_idx = task->poh_hash->mblk_idx;
1557+
exec_msg->hashcnt = task->poh_hash->hashcnt;
1558+
memcpy( exec_msg->hash, task->poh_hash->hash, sizeof(fd_hash_t) );
1559+
fd_stem_publish( stem, exec_out->idx, (FD_EXEC_TT_POH_HASH<<32) | task->poh_hash->exec_idx, exec_out->chunk, sizeof(*exec_msg), 0UL, 0UL, 0UL );
1560+
exec_out->chunk = fd_dcache_compact_next( exec_out->chunk, sizeof(*exec_msg), exec_out->chunk0, exec_out->wmark );
1561+
break;
1562+
};
15501563
default: {
15511564
FD_LOG_CRIT(( "unexpected task type %lu", task->task_type ));
15521565
}
@@ -1571,22 +1584,29 @@ replay( fd_replay_tile_t * ctx,
15711584
switch( task->task_type ) {
15721585
case FD_SCHED_TT_BLOCK_START: {
15731586
replay_block_start( ctx, stem, task->block_start->bank_idx, task->block_start->parent_bank_idx, task->block_start->slot );
1574-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_START, ULONG_MAX, ULONG_MAX );
1587+
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_START, ULONG_MAX, ULONG_MAX, NULL );
15751588
break;
15761589
}
15771590
case FD_SCHED_TT_BLOCK_END: {
15781591
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, task->block_end->bank_idx );
15791592
if( FD_LIKELY( !(bank->flags&FD_BANK_FLAGS_DEAD) ) ) replay_block_finalize( ctx, stem, bank );
1580-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_END, ULONG_MAX, ULONG_MAX );
1593+
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_END, ULONG_MAX, ULONG_MAX, NULL );
15811594
break;
15821595
}
15831596
case FD_SCHED_TT_TXN_EXEC:
1584-
case FD_SCHED_TT_TXN_SIGVERIFY: {
1597+
case FD_SCHED_TT_TXN_SIGVERIFY:
1598+
case FD_SCHED_TT_POH_HASH: {
15851599
/* Likely/common case: we have a transaction we actually need to
15861600
execute. */
15871601
dispatch_task( ctx, stem, task );
15881602
break;
15891603
}
1604+
case FD_SCHED_TT_MARK_DEAD: {
1605+
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, task->mark_dead->bank_idx );
1606+
publish_slot_dead( ctx, stem, bank );
1607+
fd_banks_mark_bank_dead( ctx->banks, bank );
1608+
break;
1609+
}
15901610
default: {
15911611
FD_LOG_CRIT(( "unexpected task type %lu", task->task_type ));
15921612
}
@@ -1976,7 +1996,8 @@ process_exec_task_done( fd_replay_tile_t * ctx,
19761996
if( FD_UNLIKELY( (bank->flags&FD_BANK_FLAGS_DEAD) && bank->refcnt==0UL ) ) {
19771997
fd_banks_mark_bank_frozen( ctx->banks, bank );
19781998
}
1979-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_EXEC, msg->txn_exec->txn_idx, exec_tile_idx );
1999+
int res = fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_EXEC, msg->txn_exec->txn_idx, exec_tile_idx, NULL );
2000+
FD_TEST( res==0 );
19802001
break;
19812002
}
19822003
case FD_EXEC_TT_TXN_SIGVERIFY: {
@@ -1991,7 +2012,17 @@ process_exec_task_done( fd_replay_tile_t * ctx,
19912012
if( FD_UNLIKELY( (bank->flags&FD_BANK_FLAGS_DEAD) && bank->refcnt==0UL ) ) {
19922013
fd_banks_mark_bank_frozen( ctx->banks, bank );
19932014
}
1994-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_SIGVERIFY, msg->txn_sigverify->txn_idx, exec_tile_idx );
2015+
int res = fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_SIGVERIFY, msg->txn_sigverify->txn_idx, exec_tile_idx, NULL );
2016+
FD_TEST( res==0 );
2017+
break;
2018+
}
2019+
case FD_EXEC_TT_POH_HASH: {
2020+
int res = fd_sched_task_done( ctx->sched, FD_SCHED_TT_POH_HASH, ULONG_MAX, exec_tile_idx, msg->poh_hash );
2021+
if( FD_UNLIKELY( res<0 && !(bank->flags&FD_BANK_FLAGS_DEAD) ) ) {
2022+
publish_slot_dead( ctx, stem, bank );
2023+
fd_banks_mark_bank_dead( ctx->banks, bank );
2024+
}
2025+
if( FD_UNLIKELY( (bank->flags&FD_BANK_FLAGS_DEAD) && bank->refcnt==0UL ) ) fd_banks_mark_bank_frozen( ctx->banks, bank );
19952026
break;
19962027
}
19972028
default: FD_LOG_CRIT(( "unexpected sig 0x%lx", sig ));

0 commit comments

Comments
 (0)