forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reject blocks for costs above the max block cost (solana-labs#18994)
- Loading branch information
1 parent
ab4bc22
commit e1af026
Showing
6 changed files
with
155 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! defines block cost related limits | ||
//! | ||
// see https://github.com/solana-labs/solana/issues/18944 | ||
// and https://github.com/solana-labs/solana/pull/18994#issuecomment-896128992 | ||
// | ||
pub const MAX_BLOCK_TIME_US: u64 = 400_000; // aiming at 400ms/block max time | ||
pub const AVG_INSTRUCTION_TIME_US: u64 = 1_000; // average instruction execution time | ||
pub const SYSTEM_PARALLELISM: u64 = 10; | ||
pub const MAX_INSTRUCTION_COST: u64 = 200_000; | ||
pub const MAX_NUMBER_BPF_INSTRUCTIONS_PER_ACCOUNT: u64 = 200; | ||
|
||
pub const fn max_instructions_per_block() -> u64 { | ||
(MAX_BLOCK_TIME_US / AVG_INSTRUCTION_TIME_US) * SYSTEM_PARALLELISM | ||
} | ||
|
||
pub const fn block_cost_max() -> u64 { | ||
MAX_INSTRUCTION_COST * max_instructions_per_block() | ||
} | ||
|
||
pub const fn account_cost_max() -> u64 { | ||
MAX_INSTRUCTION_COST * max_instructions_per_block() | ||
} | ||
|
||
pub const fn compute_unit_to_us_ratio() -> u64 { | ||
block_cost_max() / MAX_BLOCK_TIME_US | ||
} | ||
|
||
pub const fn signature_cost() -> u64 { | ||
// signature takes average 10us | ||
compute_unit_to_us_ratio() * 10 | ||
} | ||
|
||
pub const fn account_read_cost() -> u64 { | ||
// read account averages 5us | ||
compute_unit_to_us_ratio() * 5 | ||
} | ||
|
||
pub const fn account_write_cost() -> u64 { | ||
// write account averages 25us | ||
compute_unit_to_us_ratio() * 25 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.