From a0f49c2e4f5de9a5b2bbc27992a336ceb77b2a28 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Mon, 26 Sep 2022 20:50:31 +0800 Subject: [PATCH] Add assertions for computed block cost limit constants (#28056) --- Cargo.lock | 1 + runtime/Cargo.toml | 1 + runtime/src/block_cost_limits.rs | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6b8627292..1c364753b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6131,6 +6131,7 @@ dependencies = [ "solana-vote-program", "solana-zk-token-proof-program", "solana-zk-token-sdk 1.15.0", + "static_assertions", "strum", "strum_macros", "symlink", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index cc0738864..609e57b23 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -73,6 +73,7 @@ ed25519-dalek = "=1.0.1" libsecp256k1 = "0.6.0" rand_chacha = "0.2.2" solana-logger = { path = "../logger", version = "=1.15.0" } +static_assertions = "1.1.0" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/runtime/src/block_cost_limits.rs b/runtime/src/block_cost_limits.rs index 337eb4968..4906fa9fd 100644 --- a/runtime/src/block_cost_limits.rs +++ b/runtime/src/block_cost_limits.rs @@ -56,14 +56,25 @@ lazy_static! { /// data size and built-in and BPF instructions. pub const MAX_BLOCK_UNITS: u64 = MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO * MAX_CONCURRENCY; + +#[cfg(test)] +static_assertions::const_assert_eq!(MAX_BLOCK_UNITS, 48_000_000); + /// Number of compute units that a writable account in a block is allowed. The /// limit is to prevent too many transactions write to same account, therefore /// reduce block's parallelism. pub const MAX_WRITABLE_ACCOUNT_UNITS: u64 = MAX_BLOCK_REPLAY_TIME_US * COMPUTE_UNIT_TO_US_RATIO; + +#[cfg(test)] +static_assertions::const_assert_eq!(MAX_WRITABLE_ACCOUNT_UNITS, 12_000_000); + /// 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; +#[cfg(test)] +static_assertions::const_assert_eq!(MAX_VOTE_UNITS, 36_000_000); + /// The maximum allowed size, in bytes, that accounts data can grow, per block. /// This can also be thought of as the maximum size of new allocations per block. pub const MAX_BLOCK_ACCOUNTS_DATA_SIZE_DELTA: u64 = 100_000_000;