From f608472f613b854171ff66edae723635116901fe Mon Sep 17 00:00:00 2001 From: Richard Patel Date: Tue, 8 Sep 2026 06:53:55 +0000 Subject: [PATCH] runtime: cost tracker polishing --- src/flamenco/runtime/fd_cost_tracker.h | 4 ++-- src/flamenco/runtime/fd_runtime_const.h | 14 +++++++------- src/flamenco/runtime/test_cost_tracker.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/flamenco/runtime/fd_cost_tracker.h b/src/flamenco/runtime/fd_cost_tracker.h index df41956547b..c40467d9356 100644 --- a/src/flamenco/runtime/fd_cost_tracker.h +++ b/src/flamenco/runtime/fd_cost_tracker.h @@ -23,10 +23,10 @@ #define FD_COST_TRACKER_ERROR_WOULD_EXCEED_ACCOUNT_DATA_TOTAL_LIMIT (5) FD_STATIC_ASSERT( FD_WRITE_LOCK_UNITS*FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT + - FD_PACK_COST_PER_SIGNATURE*((FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT+63UL)/64UL)<=87500000UL, + FD_PACK_COST_PER_SIGNATURE*((FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT+MAX_TX_ACCOUNT_LOCKS-1UL)/MAX_TX_ACCOUNT_LOCKS)<=FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND, max_writable_accounts_per_slot_fits ); FD_STATIC_ASSERT( FD_WRITE_LOCK_UNITS*(FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT+1UL) + - FD_PACK_COST_PER_SIGNATURE*((FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT+64UL)/64UL)>87500000UL, + FD_PACK_COST_PER_SIGNATURE*((FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT+MAX_TX_ACCOUNT_LOCKS)/MAX_TX_ACCOUNT_LOCKS)>FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND, max_writable_accounts_per_slot_is_tight ); /* TODO: Extremely gross. Used because these are in a pool which needs diff --git a/src/flamenco/runtime/fd_runtime_const.h b/src/flamenco/runtime/fd_runtime_const.h index 20bb5615387..df97cb24fa4 100644 --- a/src/flamenco/runtime/fd_runtime_const.h +++ b/src/flamenco/runtime/fd_runtime_const.h @@ -73,17 +73,17 @@ FD_PROTOTYPES_BEGIN #define FD_RUNTIME_ACC_SZ_MAX (10UL<<20) /* 10MiB */ /* Bound the number of distinct writable accounts that can enter the - cost tracker in an 87.5M CU block. A transaction with w writable + cost tracker in a 100M CU block. A transaction with w writable accounts costs at least 720+300*w CUs and carries at most 64 writable accounts. Thus W writables need at least ceil(W/64) transactions: - 300*W + 720*ceil(W/64) <= 87500000 + 300*W + 720*ceil(W/64) <= 100000000 - The largest solution is 281123: 4392 full 64-account transactions - plus one 35-account transaction cost 87499860 CUs. A 281124th - writable would cost 87500160 CUs. */ + The largest solution is 321282: 5020 full 64-account transactions + plus one 2-account transaction cost 99999720 CUs. A 321283rd + writable would cost 100000020 CUs. */ -#define FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT (281123UL) +#define FD_RUNTIME_MAX_TXN_ACC_WRITES_PER_SLOT (321282UL) /* With 100M stake accounts, ceil(100M/4096)=24415 partitions. Assuming uniform hashing, one partition has @@ -96,7 +96,7 @@ FD_PROTOTYPES_BEGIN on the number of unique accounts that can be written to in a single slot. The worst case can be defined by: 1. Worst case number of writable accounts in a slot from worst-case - transactions. This bound comes from the cost tracker: 281123. + transactions. This bound comes from the cost tracker: 321282. 2. During partitioned epoch rewards. A reasonable upper bound is 8192 accounts per stake partition since the odds of this happening are very very low. diff --git a/src/flamenco/runtime/test_cost_tracker.c b/src/flamenco/runtime/test_cost_tracker.c index 1a9496c74be..52324f1d6e7 100644 --- a/src/flamenco/runtime/test_cost_tracker.c +++ b/src/flamenco/runtime/test_cost_tracker.c @@ -16,16 +16,16 @@ test_cost_tracker_init_reconciliation( fd_cost_tracker_t * ct ) { fd_cost_tracker_init( ct, &f, &FD_SLOT_PARAMS_400MS, SLOT ); FD_TEST( ct->block_cost_limit ==60000000UL ); FD_TEST( ct->account_cost_limit==24000000UL ); - FD_TEST( ct->data_size_limit ==100000000UL ); + FD_TEST( ct->data_size_limit ==FD_PACK_MAX_ALLOCATED_DATA_PER_BLOCK ); /* 400ms + raise_block_limits_to_100m: table scaled by 100/60 -> 100M / 40M. */ memset( &f, 0xFF, sizeof(f) ); f.raise_block_limits_to_100m = 0UL; fd_cost_tracker_init( ct, &f, &FD_SLOT_PARAMS_400MS, SLOT ); - FD_TEST( ct->block_cost_limit ==100000000UL ); + FD_TEST( ct->block_cost_limit ==FD_PACK_MAX_COST_PER_BLOCK_UPPER_BOUND ); FD_TEST( ct->account_cost_limit==40000000UL ); - FD_TEST( ct->data_size_limit ==100000000UL ); + FD_TEST( ct->data_size_limit ==FD_PACK_MAX_ALLOCATED_DATA_PER_BLOCK ); /* 200ms + 100m: regime table scaled by 100/60 -> 50M / 20M / 50M. */ memset( &f, 0xFF, sizeof(f) );