Add adjustable stack size and call depth (bp #12728) (#12770)

* Add adjustable stack size and call depth (#12728)

(cherry picked from commit c3907be623)

# Conflicts:
#	programs/bpf/Cargo.toml
#	programs/bpf_loader/Cargo.toml

* resolve conflicts

Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
mergify[bot]
2020-10-09 22:08:01 +00:00
committed by GitHub
parent 9188153b7d
commit 7a1889aaf9
12 changed files with 147 additions and 13 deletions

View File

@@ -53,6 +53,10 @@ pub mod max_invoke_depth_4 {
solana_sdk::declare_id!("EdM9xggY5y7AhNMskRG8NgGMnaP4JFNsWi8ZZtyT1af5");
}
pub mod max_program_call_depth_64 {
solana_sdk::declare_id!("YCKSgA6XmjtkQrHBQjpyNrX6EMhJPcYcLWMVgWn36iv");
}
lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@@ -68,6 +72,7 @@ lazy_static! {
(no_overflow_rent_distribution::id(), "no overflow rent distribution"),
(ristretto_mul_syscall_enabled::id(), "ristretto multiply syscall"),
(max_invoke_depth_4::id(), "max invoke call depth 4"),
(max_program_call_depth_64::id(), "max program call depth 64")
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()

View File

@@ -1,4 +1,6 @@
use crate::feature_set::{compute_budget_balancing, max_invoke_depth_4, FeatureSet};
use crate::feature_set::{
compute_budget_balancing, max_invoke_depth_4, max_program_call_depth_64, FeatureSet,
};
use solana_sdk::{
account::{Account, KeyedAccount},
instruction::{CompiledInstruction, Instruction, InstructionError},
@@ -92,6 +94,10 @@ pub struct ComputeBudget {
pub sha256_base_cost: u64,
/// Incremental number of units consumed by sha256 (based on bytes)
pub sha256_byte_cost: u64,
/// Maximum BPF to BPF call depth
pub max_call_depth: usize,
/// Size of a stack frame in bytes, must match the size specified in the LLVM BPF backend
pub stack_frame_size: usize,
}
impl Default for ComputeBudget {
fn default() -> Self {
@@ -111,6 +117,8 @@ impl ComputeBudget {
max_invoke_depth: 1,
sha256_base_cost: 85,
sha256_byte_cost: 1,
max_call_depth: 20,
stack_frame_size: 4_096,
};
if feature_set.is_active(&compute_budget_balancing::id()) {
@@ -127,9 +135,15 @@ impl ComputeBudget {
compute_budget = ComputeBudget {
max_invoke_depth: 4,
..compute_budget
}
};
}
if feature_set.is_active(&max_program_call_depth_64::id()) {
compute_budget = ComputeBudget {
max_call_depth: 64,
..compute_budget
};
}
compute_budget
}
}