Skip to content

Commit 20dec15

Browse files
committed
poh, pack: adjust cost limits dynamically
1 parent 6d00fb8 commit 20dec15

File tree

19 files changed

+221
-110
lines changed

19 files changed

+221
-110
lines changed

book/api/metrics-generated.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
| pack_​cus_​scheduled | `histogram` | The number of cost units scheduled for each block pack produced. This can be higher than the block limit because of returned CUs. |
252252
| pack_​cus_​rebated | `histogram` | The number of compute units rebated for each block pack produced. Compute units are rebated when a transaction fails prior to execution or requests more compute units than it uses. |
253253
| pack_​cus_​net | `histogram` | The net number of cost units (scheduled - rebated) in each block pack produced. |
254+
| pack_​cus_​pct | `histogram` | The percent of the total block cost limit used for each block pack produced. |
254255
| pack_​delete_​missed | `counter` | Count of attempts to delete a transaction that wasn't found |
255256
| pack_​delete_​hit | `counter` | Count of attempts to delete a transaction that was found and deleted |
256257

src/app/fdctl/config/default.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ dynamic_port_range = "8900-9000"
14871487
affinity = "auto"
14881488

14891489
# Solana has a hard-coded maximum CUs per block limit of
1490-
# 48,000,000 which works out to around 80,000 transfers a
1490+
# 50,000,000+ which works out to around 83,000 transfers a
14911491
# second, since each consumes about 1500 CUs. When
14921492
# benchmarking, this can be the limiting bottleneck of the
14931493
# system, so this option is provided to raise the limit. If set

src/disco/gui/fd_gui_tile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ after_frag( fd_gui_ctx_t * ctx,
218218
else if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_POH_PACK ) ) {
219219
FD_TEST( fd_disco_poh_sig_pkt_type( sig )==POH_PKT_TYPE_BECAME_LEADER );
220220
fd_became_leader_t * became_leader = (fd_became_leader_t *)ctx->buf;
221-
fd_gui_became_leader( ctx->gui, fd_disco_poh_sig_slot( sig ), became_leader->slot_start_ns, became_leader->slot_end_ns, FD_PACK_MAX_COST_PER_BLOCK, became_leader->max_microblocks_in_slot );
221+
fd_gui_became_leader( ctx->gui, fd_disco_poh_sig_slot( sig ), became_leader->slot_start_ns, became_leader->slot_end_ns, became_leader->limits.slot_max_cost, became_leader->max_microblocks_in_slot );
222222
} else if( FD_UNLIKELY( ctx->in_kind[ in_idx ]==IN_KIND_PACK_BANK ) ) {
223223
if( FD_LIKELY( fd_disco_poh_sig_pkt_type( sig )==POH_PKT_TYPE_MICROBLOCK ) ) {
224224
FD_TEST( sz<ULONG_MAX );

src/disco/metrics/generated/fd_metrics_all.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ extern const fd_metrics_meta_t FD_METRICS_ALL_LINK_IN[FD_METRICS_ALL_LINK_IN_TOT
153153
#define FD_METRICS_ALL_LINK_OUT_TOTAL (1UL)
154154
extern const fd_metrics_meta_t FD_METRICS_ALL_LINK_OUT[FD_METRICS_ALL_LINK_OUT_TOTAL];
155155

156-
#define FD_METRICS_TOTAL_SZ (8UL*229UL)
156+
#define FD_METRICS_TOTAL_SZ (8UL*246UL)
157157

158158
#define FD_METRICS_TILE_KIND_CNT 17
159159
extern const char * FD_METRICS_TILE_KIND_NAMES[FD_METRICS_TILE_KIND_CNT];

src/disco/metrics/generated/fd_metrics_pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const fd_metrics_meta_t FD_METRICS_PACK[FD_METRICS_PACK_TOTAL] = {
6969
DECLARE_METRIC_HISTOGRAM_NONE( PACK_CUS_SCHEDULED ),
7070
DECLARE_METRIC_HISTOGRAM_NONE( PACK_CUS_REBATED ),
7171
DECLARE_METRIC_HISTOGRAM_NONE( PACK_CUS_NET ),
72+
DECLARE_METRIC_HISTOGRAM_NONE( PACK_CUS_PCT ),
7273
DECLARE_METRIC( PACK_DELETE_MISSED, COUNTER ),
7374
DECLARE_METRIC( PACK_DELETE_HIT, COUNTER ),
7475
};

src/disco/metrics/generated/fd_metrics_pack.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,27 @@
226226
#define FD_METRICS_HISTOGRAM_PACK_CUS_NET_DESC "The net number of cost units (scheduled - rebated) in each block pack produced."
227227
#define FD_METRICS_HISTOGRAM_PACK_CUS_NET_CVT (FD_METRICS_CONVERTER_NONE)
228228
#define FD_METRICS_HISTOGRAM_PACK_CUS_NET_MIN (1000000UL)
229-
#define FD_METRICS_HISTOGRAM_PACK_CUS_NET_MAX (48000000UL)
229+
#define FD_METRICS_HISTOGRAM_PACK_CUS_NET_MAX (60000000UL)
230230

231-
#define FD_METRICS_COUNTER_PACK_DELETE_MISSED_OFF (227UL)
231+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_OFF (227UL)
232+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_NAME "pack_cus_pct"
233+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_TYPE (FD_METRICS_TYPE_HISTOGRAM)
234+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_DESC "The percent of the total block cost limit used for each block pack produced."
235+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_CVT (FD_METRICS_CONVERTER_NONE)
236+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_MIN (0UL)
237+
#define FD_METRICS_HISTOGRAM_PACK_CUS_PCT_MAX (100UL)
238+
239+
#define FD_METRICS_COUNTER_PACK_DELETE_MISSED_OFF (244UL)
232240
#define FD_METRICS_COUNTER_PACK_DELETE_MISSED_NAME "pack_delete_missed"
233241
#define FD_METRICS_COUNTER_PACK_DELETE_MISSED_TYPE (FD_METRICS_TYPE_COUNTER)
234242
#define FD_METRICS_COUNTER_PACK_DELETE_MISSED_DESC "Count of attempts to delete a transaction that wasn't found"
235243
#define FD_METRICS_COUNTER_PACK_DELETE_MISSED_CVT (FD_METRICS_CONVERTER_NONE)
236244

237-
#define FD_METRICS_COUNTER_PACK_DELETE_HIT_OFF (228UL)
245+
#define FD_METRICS_COUNTER_PACK_DELETE_HIT_OFF (245UL)
238246
#define FD_METRICS_COUNTER_PACK_DELETE_HIT_NAME "pack_delete_hit"
239247
#define FD_METRICS_COUNTER_PACK_DELETE_HIT_TYPE (FD_METRICS_TYPE_COUNTER)
240248
#define FD_METRICS_COUNTER_PACK_DELETE_HIT_DESC "Count of attempts to delete a transaction that was found and deleted"
241249
#define FD_METRICS_COUNTER_PACK_DELETE_HIT_CVT (FD_METRICS_CONVERTER_NONE)
242250

243-
#define FD_METRICS_PACK_TOTAL (69UL)
251+
#define FD_METRICS_PACK_TOTAL (70UL)
244252
extern const fd_metrics_meta_t FD_METRICS_PACK[FD_METRICS_PACK_TOTAL];

src/disco/metrics/metrics.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,12 @@ metric introduced.
362362
<!-- Note: The switch from cost units to compute units here is deliberate. Of the various types of cost units, only compute units can be rebated. -->
363363
<summary>The number of compute units rebated for each block pack produced. Compute units are rebated when a transaction fails prior to execution or requests more compute units than it uses.</summary>
364364
</histogram>
365-
<histogram name="CusNet" min="1000000" max="48000000">
365+
<histogram name="CusNet" min="1000000" max="60000000">
366366
<summary>The net number of cost units (scheduled - rebated) in each block pack produced.</summary>
367367
</histogram>
368+
<histogram name="CusPct" min="0" max="100">
369+
<summary>The percent of the total block cost limit used for each block pack produced.</summary>
370+
</histogram>
368371

369372
<counter name="DeleteMissed" summary="Count of attempts to delete a transaction that wasn't found" />
370373
<counter name="DeleteHit" summary="Count of attempts to delete a transaction that was found and deleted" />

src/disco/pack/fd_pack.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ struct fd_pack_private {
544544
fd_histf_t scheduled_cus_per_block[ 1 ];
545545
fd_histf_t rebated_cus_per_block [ 1 ];
546546
fd_histf_t net_cus_per_block [ 1 ];
547+
fd_histf_t pct_cus_per_block [ 1 ];
547548
ulong cumulative_rebated_cus;
548549

549550

@@ -633,7 +634,7 @@ fd_pack_new( void * mem,
633634
ulong bundle_meta_sz,
634635
ulong bank_tile_cnt,
635636
fd_pack_limits_t const * limits,
636-
fd_rng_t * rng ) {
637+
fd_rng_t * rng ) {
637638

638639
int enable_bundles = !!bundle_meta_sz;
639640
ulong extra_depth = fd_ulong_if( enable_bundles, 1UL+2UL*FD_PACK_MAX_TXN_PER_BUNDLE, 1UL );
@@ -749,6 +750,8 @@ fd_pack_new( void * mem,
749750
FD_MHIST_MAX( PACK, CUS_REBATED ) );
750751
fd_histf_new( pack->net_cus_per_block, FD_MHIST_MIN( PACK, CUS_NET ),
751752
FD_MHIST_MAX( PACK, CUS_NET ) );
753+
fd_histf_new( pack->pct_cus_per_block, FD_MHIST_MIN( PACK, CUS_PCT ),
754+
FD_MHIST_MAX( PACK, CUS_PCT ) );
752755

753756
pack->compressed_slot_number = (ushort)(FD_PACK_SKIP_CNT+1);
754757

@@ -2337,11 +2340,16 @@ ulong fd_pack_current_block_cost( fd_pack_t const * pack ) { return pack->cumula
23372340

23382341

23392342
void
2340-
fd_pack_set_block_limits( fd_pack_t * pack,
2341-
ulong max_microblocks_per_block,
2342-
ulong max_data_bytes_per_block ) {
2343-
pack->lim->max_microblocks_per_block = max_microblocks_per_block;
2344-
pack->lim->max_data_bytes_per_block = max_data_bytes_per_block;
2343+
fd_pack_set_block_limits( fd_pack_t * pack, fd_pack_limits_t const * limits ) {
2344+
FD_TEST( limits->max_cost_per_block >= FD_PACK_MAX_COST_PER_BLOCK_LOWER_BOUND );
2345+
FD_TEST( limits->max_vote_cost_per_block >= FD_PACK_MAX_VOTE_COST_PER_BLOCK_LOWER_BOUND );
2346+
FD_TEST( limits->max_write_cost_per_acct >= FD_PACK_MAX_WRITE_COST_PER_ACCT_LOWER_BOUND );
2347+
2348+
pack->lim->max_microblocks_per_block = limits->max_microblocks_per_block;
2349+
pack->lim->max_data_bytes_per_block = limits->max_data_bytes_per_block;
2350+
pack->lim->max_cost_per_block = limits->max_cost_per_block;
2351+
pack->lim->max_vote_cost_per_block = limits->max_vote_cost_per_block;
2352+
pack->lim->max_write_cost_per_acct = limits->max_write_cost_per_acct;
23452353
}
23462354

23472355
void
@@ -2391,6 +2399,9 @@ fd_pack_expire_before( fd_pack_t * pack,
23912399

23922400
void
23932401
fd_pack_end_block( fd_pack_t * pack ) {
2402+
/* rounded division */
2403+
ulong pct_cus_per_block = (pack->cumulative_block_cost*100UL + (pack->lim->max_cost_per_block>>1))/pack->lim->max_cost_per_block;
2404+
fd_histf_sample( pack->pct_cus_per_block, pct_cus_per_block );
23942405
fd_histf_sample( pack->net_cus_per_block, pack->cumulative_block_cost );
23952406
fd_histf_sample( pack->rebated_cus_per_block, pack->cumulative_rebated_cus );
23962407
fd_histf_sample( pack->scheduled_cus_per_block, pack->cumulative_rebated_cus + pack->cumulative_block_cost );
@@ -2455,6 +2466,7 @@ fd_pack_end_block( fd_pack_t * pack ) {
24552466
FD_MHIST_COPY( PACK, CUS_SCHEDULED, pack->scheduled_cus_per_block );
24562467
FD_MHIST_COPY( PACK, CUS_REBATED, pack->rebated_cus_per_block );
24572468
FD_MHIST_COPY( PACK, CUS_NET, pack->net_cus_per_block );
2469+
FD_MHIST_COPY( PACK, CUS_PCT, pack->pct_cus_per_block );
24582470
}
24592471

24602472
static void

src/disco/pack/fd_pack.h

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,28 @@
1717

1818
/* NOTE: THE FOLLOWING CONSTANTS ARE CONSENSUS CRITICAL AND CANNOT BE
1919
CHANGED WITHOUT COORDINATING WITH ANZA. */
20-
#define FD_PACK_MAX_COST_PER_BLOCK (48000000UL)
21-
#define FD_PACK_MAX_VOTE_COST_PER_BLOCK (36000000UL)
22-
#define FD_PACK_MAX_WRITE_COST_PER_ACCT (12000000UL)
20+
21+
/* These are bounds on known limits. Upper bound values are used to
22+
calculate memory footprints while lower bounds are used for
23+
initializing consensus-dependent logic and invariant checking. As a
24+
leader, it is OK to produce blocks using limits smaller than the
25+
active on-chain limits. Replay should always use the correct
26+
chain-derived limits.
27+
28+
The actual limits used by pack may be updated dynamically to some
29+
in-bounds value. If there is an anticipated feature activation that
30+
changes these limits, the upper bound should be the largest
31+
anticipated value while the lower bound should be the current active
32+
limit. For Frankendancer, the actual value used for consensus will be
33+
retreived from Agave. */
34+
#define FD_PACK_MAX_COST_PER_BLOCK_LOWER_BOUND (48000000UL)
35+
#define FD_PACK_MAX_VOTE_COST_PER_BLOCK_LOWER_BOUND (36000000UL)
36+
#define FD_PACK_MAX_WRITE_COST_PER_ACCT_LOWER_BOUND (12000000UL)
37+
38+
#define FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND (60000000UL) /* simd 0256 */
39+
#define FD_PACK_MAX_VOTE_COST_PER_BLOCK_UPPER_BOUND (36000000UL)
40+
#define FD_PACK_MAX_WRITE_COST_PER_ACCT_UPPER_BOUND (12000000UL)
41+
2342
#define FD_PACK_FEE_PER_SIGNATURE (5000UL) /* In lamports */
2443

2544
/* Each block is limited to 32k parity shreds. We don't want pack to
@@ -202,20 +221,26 @@ FD_FN_PURE ulong fd_pack_current_block_cost( fd_pack_t const * pack );
202221
FD_FN_PURE ulong fd_pack_bank_tile_cnt( fd_pack_t const * pack );
203222

204223
/* fd_pack_set_block_limits: Updates the limits provided fd_pack_new to
205-
the new values. Any future microblocks produced by this pack object
206-
will not cause a block to have more than max_microblocks_per_block
207-
non-empty microblocks or more than max_data_bytes_per_block data
208-
bytes (counting microblock headers as before). Limits are inclusive,
209-
as per usual (i.e. a block may have exactly
210-
max_microblocks_per_block microblocks, but not more). pack must be
211-
a valid local join.
224+
these new values. Any future microblocks produced by this pack
225+
object will not cause a block to have more than
226+
limits->max_microblocks_per_block non-empty microblocks or more than
227+
limits->max_data_bytes_per_block data bytes (counting microblock
228+
headers as before). future microblocks will also exclude those that
229+
cause the total block cost to exceed limits->max_cost_per_block.
230+
Similarly those that cause the total vote-only cost to exceed
231+
limits->max_vote_cost_per_block. Also, those that cause the total
232+
per-account, per block write cost to exceed
233+
limits->max_write_cost_per_acct. Note that
234+
limits->max_txn_per_microblock is ignored. Limits are inclusive, as
235+
per usual (i.e. a block may have exactly max_microblocks_per_block
236+
microblocks, but not more). pack must be a valid local join.
212237
213238
The typical place to call this is immediately after
214239
fd_pack_end_block; if this is called after some microblocks have been
215240
produced for the current block, and the current block already exceeds
216241
the limits, all the remaining microblocks in the block will be empty,
217242
but the call is valid. */
218-
void fd_pack_set_block_limits( fd_pack_t * pack, ulong max_microblocks_per_block, ulong max_data_bytes_per_block );
243+
void fd_pack_set_block_limits( fd_pack_t * pack, fd_pack_limits_t const * limits );
219244

220245
/* Return values for fd_pack_insert_txn_fini: Non-negative values
221246
indicate the transaction was accepted and may be returned in a future

0 commit comments

Comments
 (0)