Skip to content

Commit a372a86

Browse files
committed
replay, sched: verify PoH
1 parent e63a71b commit a372a86

File tree

9 files changed

+699
-136
lines changed

9 files changed

+699
-136
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/capture/fd_capture_ctx.h"
78
#include "../../flamenco/runtime/fd_bank.h"
@@ -145,7 +146,7 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
145146
fd_exec_txn_exec_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
146147
ctx->bank = fd_banks_bank_query( ctx->banks, msg->bank_idx );
147148
FD_TEST( ctx->bank );
148-
ctx->txn_in.txn = &msg->txn;
149+
ctx->txn_in.txn = msg->txn;
149150
ctx->txn_in.exec_accounts = &ctx->exec_accounts;
150151

151152
/* Set the capture txn index from the message so account updates
@@ -181,7 +182,7 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
181182
}
182183
case FD_EXEC_TT_TXN_SIGVERIFY: {
183184
fd_exec_txn_sigverify_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
184-
int res = fd_executor_txn_verify( &msg->txn, ctx->sha_lj );
185+
int res = fd_executor_txn_verify( msg->txn, ctx->sha_lj );
185186
fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
186187
out_msg->bank_idx = msg->bank_idx;
187188
out_msg->txn_sigverify->txn_idx = msg->txn_idx;
@@ -190,6 +191,17 @@ returnable_frag( fd_exec_tile_ctx_t * ctx,
190191
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 );
191192
break;
192193
}
194+
case FD_EXEC_TT_POH_HASH: {
195+
fd_exec_poh_hash_msg_t * msg = fd_chunk_to_laddr( ctx->replay_in->mem, chunk );
196+
fd_exec_task_done_msg_t * out_msg = fd_chunk_to_laddr( ctx->exec_replay_out->mem, ctx->exec_replay_out->chunk );
197+
out_msg->bank_idx = msg->bank_idx;
198+
out_msg->poh_hash->mblk_idx = msg->mblk_idx;
199+
out_msg->poh_hash->hashcnt = msg->hashcnt;
200+
fd_sha256_hash_32_repeated( msg->hash, out_msg->poh_hash->hash, msg->hashcnt );
201+
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 );
202+
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 );
203+
break;
204+
}
193205
default: FD_LOG_CRIT(( "unexpected signature %lu", sig ));
194206
}
195207
} 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,7 +20,7 @@
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
/* Used currently by solcap to maintain ordering of messages
2626
this will change to using txn sigs eventually */
@@ -31,13 +31,22 @@ typedef struct fd_exec_txn_exec_msg fd_exec_txn_exec_msg_t;
3131
struct fd_exec_txn_sigverify_msg {
3232
ulong bank_idx;
3333
ulong txn_idx;
34-
fd_txn_p_t txn;
34+
fd_txn_p_t txn[ 1 ];
3535
};
3636
typedef struct fd_exec_txn_sigverify_msg fd_exec_txn_sigverify_msg_t;
3737

38+
struct fd_exec_poh_hash_msg {
39+
ulong bank_idx;
40+
ulong mblk_idx;
41+
ulong hashcnt;
42+
fd_hash_t hash[ 1 ];
43+
};
44+
typedef struct fd_exec_poh_hash_msg fd_exec_poh_hash_msg_t;
45+
3846
union fd_exec_task_msg {
3947
fd_exec_txn_exec_msg_t txn_exec;
4048
fd_exec_txn_sigverify_msg_t txn_sigverify;
49+
fd_exec_poh_hash_msg_t poh_hash;
4150
};
4251
typedef union fd_exec_task_msg fd_exec_task_msg_t;
4352

@@ -63,11 +72,19 @@ struct fd_exec_txn_sigverify_done_msg {
6372
};
6473
typedef struct fd_exec_txn_sigverify_done_msg fd_exec_txn_sigverify_done_msg_t;
6574

75+
struct fd_exec_poh_hash_done_msg {
76+
ulong mblk_idx;
77+
ulong hashcnt;
78+
fd_hash_t hash[ 1 ];
79+
};
80+
typedef struct fd_exec_poh_hash_done_msg fd_exec_poh_hash_done_msg_t;
81+
6682
struct fd_exec_task_done_msg {
6783
ulong bank_idx;
6884
union {
6985
fd_exec_txn_exec_done_msg_t txn_exec[ 1 ];
7086
fd_exec_txn_sigverify_done_msg_t txn_sigverify[ 1 ];
87+
fd_exec_poh_hash_done_msg_t poh_hash[ 1 ];
7188
};
7289
};
7390
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
@@ -606,22 +606,21 @@ replay_block_start( fd_replay_tile_t * ctx,
606606

607607
fd_bank_has_identity_vote_set( bank, 0 );
608608

609-
/* Set the tick height. */
610-
fd_bank_tick_height_set( bank, fd_bank_max_tick_height_get( bank ) );
611-
612609
/* Update block height. */
613610
fd_bank_block_height_set( bank, fd_bank_block_height_get( bank ) + 1UL );
614611

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

616+
ulong max_tick_height;
617+
if( FD_UNLIKELY( FD_RUNTIME_EXECUTE_SUCCESS!=fd_runtime_compute_max_tick_height( fd_bank_ticks_per_slot_get( parent_bank ), slot, &max_tick_height ) ) ) {
618+
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 ) ));
619+
}
620+
fd_bank_max_tick_height_set( bank, max_tick_height );
621+
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. */
622+
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 ) );
623+
625624
return bank;
626625
}
627626

@@ -1524,7 +1523,7 @@ dispatch_task( fd_replay_tile_t * ctx,
15241523

15251524
fd_replay_out_link_t * exec_out = ctx->exec_out;
15261525
fd_exec_txn_exec_msg_t * exec_msg = fd_chunk_to_laddr( exec_out->mem, exec_out->chunk );
1527-
memcpy( &exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
1526+
memcpy( exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
15281527
exec_msg->bank_idx = task->txn_exec->bank_idx;
15291528
exec_msg->txn_idx = task->txn_exec->txn_idx;
15301529
if( FD_UNLIKELY( ctx->capture_ctx ) ) {
@@ -1542,13 +1541,27 @@ dispatch_task( fd_replay_tile_t * ctx,
15421541

15431542
fd_replay_out_link_t * exec_out = ctx->exec_out;
15441543
fd_exec_txn_sigverify_msg_t * exec_msg = fd_chunk_to_laddr( exec_out->mem, exec_out->chunk );
1545-
memcpy( &exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
1544+
memcpy( exec_msg->txn, txn_p, sizeof(fd_txn_p_t) );
15461545
exec_msg->bank_idx = task->txn_sigverify->bank_idx;
15471546
exec_msg->txn_idx = task->txn_sigverify->txn_idx;
15481547
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 );
15491548
exec_out->chunk = fd_dcache_compact_next( exec_out->chunk, sizeof(*exec_msg), exec_out->chunk0, exec_out->wmark );
15501549
break;
15511550
};
1551+
case FD_SCHED_TT_POH_HASH: {
1552+
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, task->poh_hash->bank_idx );
1553+
bank->refcnt++;
1554+
1555+
fd_replay_out_link_t * exec_out = ctx->exec_out;
1556+
fd_exec_poh_hash_msg_t * exec_msg = fd_chunk_to_laddr( exec_out->mem, exec_out->chunk );
1557+
exec_msg->bank_idx = task->poh_hash->bank_idx;
1558+
exec_msg->mblk_idx = task->poh_hash->mblk_idx;
1559+
exec_msg->hashcnt = task->poh_hash->hashcnt;
1560+
memcpy( exec_msg->hash, task->poh_hash->hash, sizeof(fd_hash_t) );
1561+
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 );
1562+
exec_out->chunk = fd_dcache_compact_next( exec_out->chunk, sizeof(*exec_msg), exec_out->chunk0, exec_out->wmark );
1563+
break;
1564+
};
15521565
default: {
15531566
FD_LOG_CRIT(( "unexpected task type %lu", task->task_type ));
15541567
}
@@ -1573,22 +1586,29 @@ replay( fd_replay_tile_t * ctx,
15731586
switch( task->task_type ) {
15741587
case FD_SCHED_TT_BLOCK_START: {
15751588
replay_block_start( ctx, stem, task->block_start->bank_idx, task->block_start->parent_bank_idx, task->block_start->slot );
1576-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_START, ULONG_MAX, ULONG_MAX );
1589+
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_START, ULONG_MAX, ULONG_MAX, NULL );
15771590
break;
15781591
}
15791592
case FD_SCHED_TT_BLOCK_END: {
15801593
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, task->block_end->bank_idx );
15811594
if( FD_LIKELY( !(bank->flags&FD_BANK_FLAGS_DEAD) ) ) replay_block_finalize( ctx, stem, bank );
1582-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_END, ULONG_MAX, ULONG_MAX );
1595+
fd_sched_task_done( ctx->sched, FD_SCHED_TT_BLOCK_END, ULONG_MAX, ULONG_MAX, NULL );
15831596
break;
15841597
}
15851598
case FD_SCHED_TT_TXN_EXEC:
1586-
case FD_SCHED_TT_TXN_SIGVERIFY: {
1599+
case FD_SCHED_TT_TXN_SIGVERIFY:
1600+
case FD_SCHED_TT_POH_HASH: {
15871601
/* Likely/common case: we have a transaction we actually need to
15881602
execute. */
15891603
dispatch_task( ctx, stem, task );
15901604
break;
15911605
}
1606+
case FD_SCHED_TT_MARK_DEAD: {
1607+
fd_bank_t * bank = fd_banks_bank_query( ctx->banks, task->mark_dead->bank_idx );
1608+
publish_slot_dead( ctx, stem, bank );
1609+
fd_banks_mark_bank_dead( ctx->banks, bank );
1610+
break;
1611+
}
15921612
default: {
15931613
FD_LOG_CRIT(( "unexpected task type %lu", task->task_type ));
15941614
}
@@ -1957,7 +1977,8 @@ process_exec_task_done( fd_replay_tile_t * ctx,
19571977
if( FD_UNLIKELY( (bank->flags&FD_BANK_FLAGS_DEAD) && bank->refcnt==0UL ) ) {
19581978
fd_banks_mark_bank_frozen( ctx->banks, bank );
19591979
}
1960-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_EXEC, msg->txn_exec->txn_idx, exec_tile_idx );
1980+
int res = fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_EXEC, msg->txn_exec->txn_idx, exec_tile_idx, NULL );
1981+
FD_TEST( res==0 );
19611982
break;
19621983
}
19631984
case FD_EXEC_TT_TXN_SIGVERIFY: {
@@ -1972,7 +1993,17 @@ process_exec_task_done( fd_replay_tile_t * ctx,
19721993
if( FD_UNLIKELY( (bank->flags&FD_BANK_FLAGS_DEAD) && bank->refcnt==0UL ) ) {
19731994
fd_banks_mark_bank_frozen( ctx->banks, bank );
19741995
}
1975-
fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_SIGVERIFY, msg->txn_sigverify->txn_idx, exec_tile_idx );
1996+
int res = fd_sched_task_done( ctx->sched, FD_SCHED_TT_TXN_SIGVERIFY, msg->txn_sigverify->txn_idx, exec_tile_idx, NULL );
1997+
FD_TEST( res==0 );
1998+
break;
1999+
}
2000+
case FD_EXEC_TT_POH_HASH: {
2001+
int res = fd_sched_task_done( ctx->sched, FD_SCHED_TT_POH_HASH, ULONG_MAX, exec_tile_idx, msg->poh_hash );
2002+
if( FD_UNLIKELY( res<0 && !(bank->flags&FD_BANK_FLAGS_DEAD) ) ) {
2003+
publish_slot_dead( ctx, stem, bank );
2004+
fd_banks_mark_bank_dead( ctx->banks, bank );
2005+
}
2006+
if( FD_UNLIKELY( (bank->flags&FD_BANK_FLAGS_DEAD) && bank->refcnt==0UL ) ) fd_banks_mark_bank_frozen( ctx->banks, bank );
19762007
break;
19772008
}
19782009
default: FD_LOG_CRIT(( "unexpected sig 0x%lx", sig ));

0 commit comments

Comments
 (0)