solana_cost_model/
block_cost_limits.rs

1//! defines block cost related limits
2//!
3
4/// Static configurations:
5///
6/// Number of microseconds replaying a block should take, 400 millisecond block times
7/// is currently publicly communicated on solana.com
8pub const MAX_BLOCK_REPLAY_TIME_US: u64 = 400_000;
9/// number of concurrent processes,
10pub const MAX_CONCURRENCY: u64 = 4;
11
12// Cluster data, method of collecting at https://github.com/solana-labs/solana/issues/19627
13// Dashboard: https://metrics.solana.com/d/monitor-edge/cluster-telemetry?orgId=1
14
15/// Cluster averaged compute unit to micro-sec conversion rate
16pub const COMPUTE_UNIT_TO_US_RATIO: u64 = 30;
17/// Number of compute units for one signature verification.
18pub const SIGNATURE_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 24;
19/// Number of compute units for one secp256k1 signature verification.
20pub const SECP256K1_VERIFY_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 223;
21/// Number of compute units for one ed25519 signature verification.
22pub const ED25519_VERIFY_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 76;
23/// Number of compute units for one ed25519 strict signature verification.
24pub const ED25519_VERIFY_STRICT_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 80;
25/// Number of compute units for one write lock
26pub const WRITE_LOCK_UNITS: u64 = COMPUTE_UNIT_TO_US_RATIO * 10;
27/// Number of data bytes per compute units
28pub const INSTRUCTION_DATA_BYTES_COST: u64 = 140 /*bytes per us*/ / COMPUTE_UNIT_TO_US_RATIO;
29
30/// Statically computed data:
31///
32/// Number of compute units that a block is allowed. A block's compute units are
33/// accumulated by Transactions added to it; A transaction's compute units are
34/// calculated by cost_model, based on transaction's signatures, write locks,
35/// data size and built-in and SBF instructions.
36pub const MAX_BLOCK_UNITS: u64 =
37    MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO * MAX_CONCURRENCY;
38
39#[cfg(test)]
40static_assertions::const_assert_eq!(MAX_BLOCK_UNITS, 48_000_000);
41pub const MAX_BLOCK_UNITS_SIMD_0207: u64 = 50_000_000;
42
43/// Number of compute units that a writable account in a block is allowed. The
44/// limit is to prevent too many transactions write to same account, therefore
45/// reduce block's parallelism.
46pub const MAX_WRITABLE_ACCOUNT_UNITS: u64 = MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO;
47
48#[cfg(test)]
49static_assertions::const_assert_eq!(MAX_WRITABLE_ACCOUNT_UNITS, 12_000_000);
50
51/// Number of compute units that a block can have for vote transactions,
52/// sets at ~75% of MAX_BLOCK_UNITS to leave room for non-vote transactions
53pub const MAX_VOTE_UNITS: u64 = (MAX_BLOCK_UNITS as f64 * 0.75_f64) as u64;
54
55#[cfg(test)]
56static_assertions::const_assert_eq!(MAX_VOTE_UNITS, 36_000_000);
57
58/// The maximum allowed size, in bytes, that accounts data can grow, per block.
59/// This can also be thought of as the maximum size of new allocations per block.
60pub const MAX_BLOCK_ACCOUNTS_DATA_SIZE_DELTA: u64 = 100_000_000;
61
62/// Return the block limits that will be used upon activation of SIMD-0207.
63/// Returns as
64/// (account_limit, block_limit, vote_limit)
65// ^ Above order is used to be consistent with the order of
66//   `CostTracker::set_limits`.
67pub const fn simd_0207_block_limits() -> (u64, u64, u64) {
68    (
69        MAX_WRITABLE_ACCOUNT_UNITS,
70        MAX_BLOCK_UNITS_SIMD_0207,
71        MAX_VOTE_UNITS,
72    )
73}