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)
* added realtime cost checking logic to reject block that would exceed max limit: - defines max limits at block_cost_limits.rs - right after each bath's execution, accumulate its cost and check again limit, return error if limit is exceeded * update abi that changed due to adding additional TransactionError * To avoid counting stats mltiple times, only accumulate execute-timing when a bank is completed * gate it by a feature * move cost const def into block_cost_limits.rs * redefine the cost for signature and account access, removed signer part as it is not well defined for now * check if per_program_timings of execute_timings before sending
- Loading branch information
1 parent
9d8594a
commit 414d904
Showing
10 changed files
with
159 additions
and
47 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
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.