solana_runtime/
block_cost_limits.rs

1//! defines block cost related limits
2//!
3use {
4    lazy_static::lazy_static,
5    solana_sdk::{
6        feature, incinerator, native_loader, pubkey::Pubkey, secp256k1_program, system_program,
7    },
8    std::collections::HashMap,
9};
10
11/// Static configurations:
12///
13/// Number of microseconds replaying a block should take, 400 millisecond block times
14/// is currently publicly communicated on solana.com
15pub const MAX_BLOCK_REPLAY_TIME_US: u64 = 400_000;
16/// number of concurrent processes,
17pub const MAX_CONCURRENCY: u64 = 4;
18
19// Cluster data, method of collecting at https://github.com/fair-exchange/safecoin/issues/19627
20// Dashboard: https://metrics.safecoin.org:8889/sources/0/dashboards/10?refresh=Paused&lower=now%28%29%20-%2012h
21
22/// Cluster averaged compute unit to micro-sec conversion rate
23pub const COMPUTE_UNIT_TO_US_RATIO: u64 = 30;
24/// Number of compute units for one signature verification.
25pub const SIGNATURE_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 24;
26/// Number of compute units for one write lock
27pub const WRITE_LOCK_UNITS: u64 = COMPUTE_UNIT_TO_US_RATIO * 10;
28/// Number of data bytes per compute units
29pub const DATA_BYTES_UNITS: u64 = 550 /*bytes per us*/ / COMPUTE_UNIT_TO_US_RATIO;
30// Number of compute units for each built-in programs
31lazy_static! {
32    /// Number of compute units for each built-in programs
33    pub static ref BUILT_IN_INSTRUCTION_COSTS: HashMap<Pubkey, u64> = [
34        (feature::id(), COMPUTE_UNIT_TO_US_RATIO * 2),
35        (incinerator::id(), COMPUTE_UNIT_TO_US_RATIO * 2),
36        (native_loader::id(), COMPUTE_UNIT_TO_US_RATIO * 2),
37        (solana_sdk::stake::config::id(), COMPUTE_UNIT_TO_US_RATIO * 2),
38        (solana_sdk::stake::program::id(), COMPUTE_UNIT_TO_US_RATIO * 25),
39        (solana_config_program::id(), COMPUTE_UNIT_TO_US_RATIO * 15),
40        (solana_vote_program::id(), COMPUTE_UNIT_TO_US_RATIO * 70),
41        // secp256k1 is executed in banking stage, it should cost similar to sigverify
42        (secp256k1_program::id(), COMPUTE_UNIT_TO_US_RATIO * 24),
43        (system_program::id(), COMPUTE_UNIT_TO_US_RATIO * 5),
44    ]
45    .iter()
46    .cloned()
47    .collect();
48}
49
50/// Statically computed data:
51///
52/// Number of compute units that a block is allowed. A block's compute units are
53/// accumulated by Transactions added to it; A transaction's compute units are
54/// calculated by cost_model, based on transaction's signatures, write locks,
55/// data size and built-in and BPF instructions.
56pub const MAX_BLOCK_UNITS: u64 =
57    MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO * MAX_CONCURRENCY;
58/// Number of compute units that a writable account in a block is allowed. The
59/// limit is to prevent too many transactions write to same account, therefore
60/// reduce block's parallelism.
61pub const MAX_WRITABLE_ACCOUNT_UNITS: u64 = MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO;
62/// Number of compute units that a block can have for vote transactions,
63/// sets at ~75% of MAX_BLOCK_UNITS to leave room for non-vote transactions
64pub const MAX_VOTE_UNITS: u64 = (MAX_BLOCK_UNITS as f64 * 0.75_f64) as u64;
65
66/// max length of account data in a block (bytes)
67pub const MAX_ACCOUNT_DATA_BLOCK_LEN: u64 = 100_000_000;