Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Refactor: Rename max_invoke_depth to max_invoke_stack_height (#28427
Browse files Browse the repository at this point in the history
)

Refactor: Rename max_invoke_depth to max_invoke_stack_height
  • Loading branch information
jstarry authored Oct 17, 2022
1 parent 108a02c commit 70445b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/src/developing/programming-model/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ max_units: 1,400,000,
log_u64_units: 100,
create_program address units: 1500,
invoke_units: 1000,
max_invoke_depth: 4,
max_invoke_stack_height: 5,
max_instruction_trace_length: 64,
max_call_depth: 64,
stack_frame_size: 4096,
Expand All @@ -97,7 +97,7 @@ Then any transaction:
- Could execute 1,400,000 BPF instructions, if it did nothing else.
- Cannot exceed 4k of stack usage.
- Cannot exceed a BPF call depth of 64.
- Cannot exceed 4 levels of cross-program invocations.
- Cannot exceed invoke stack height of 5 (4 levels of cross-program invocations).

> **NOTE:** Since the compute budget is consumed incrementally as the transaction executes,
> the total budget consumption will be a combination of the various costs of the
Expand Down
9 changes: 6 additions & 3 deletions program-runtime/src/compute_budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ pub struct ComputeBudget {
/// Number of compute units consumed by an invoke call (not including the cost incurred by
/// the called program)
pub invoke_units: u64,
/// Maximum cross-program invocation depth allowed
pub max_invoke_depth: usize,
/// Maximum program instruction invocation stack height. Invocation stack
/// height starts at 1 for transaction instructions and the stack height is
/// incremented each time a program invokes an instruction and decremented
/// when a program returns.
pub max_invoke_stack_height: usize,
/// Maximum cross-program invocation and instructions per transaction
pub max_instruction_trace_length: usize,
/// Base number of compute units consumed to call SHA256
Expand Down Expand Up @@ -113,7 +116,7 @@ impl ComputeBudget {
log_64_units: 100,
create_program_address_units: 1500,
invoke_units: 1000,
max_invoke_depth: 4,
max_invoke_stack_height: 5,
max_instruction_trace_length: 64,
sha256_base_cost: 85,
sha256_byte_cost: 1,
Expand Down
6 changes: 3 additions & 3 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ pub fn with_mock_invoke_context<R, F: FnMut(&mut InvokeContext) -> R>(
let mut transaction_context = TransactionContext::new(
preparation.transaction_accounts,
Some(Rent::default()),
compute_budget.max_invoke_depth.saturating_add(1),
compute_budget.max_invoke_stack_height,
compute_budget.max_instruction_trace_length,
);
transaction_context.enable_cap_accounts_data_allocations_per_transaction();
Expand Down Expand Up @@ -967,7 +967,7 @@ pub fn mock_process_instruction(
let mut transaction_context = TransactionContext::new(
preparation.transaction_accounts,
Some(Rent::default()),
compute_budget.max_invoke_depth.saturating_add(1),
compute_budget.max_invoke_stack_height,
compute_budget.max_instruction_trace_length,
);
transaction_context.enable_cap_accounts_data_allocations_per_transaction();
Expand Down Expand Up @@ -1190,7 +1190,7 @@ mod tests {
let mut transaction_context = TransactionContext::new(
accounts,
Some(Rent::default()),
ComputeBudget::default().max_invoke_depth,
ComputeBudget::default().max_invoke_stack_height,
MAX_DEPTH,
);
let mut invoke_context = InvokeContext::new_mock(&mut transaction_context, &[]);
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4086,7 +4086,7 @@ impl Bank {
} else {
None
},
compute_budget.max_invoke_depth.saturating_add(1),
compute_budget.max_invoke_stack_height,
if self
.feature_set
.is_active(&feature_set::limit_max_instruction_trace_length::id())
Expand Down Expand Up @@ -18267,7 +18267,7 @@ pub(crate) mod tests {
let transaction_context = TransactionContext::new(
loaded_txs[0].0.as_ref().unwrap().accounts.clone(),
Some(Rent::default()),
compute_budget.max_invoke_depth.saturating_add(1),
compute_budget.max_invoke_stack_height,
compute_budget.max_instruction_trace_length,
);

Expand Down

0 comments on commit 70445b7

Please sign in to comment.