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