Cleanup feature: sycall base costs (#26304)
This commit is contained in:
parent
e8ed7c1c46
commit
265f36c044
|
@ -26,7 +26,7 @@ use {
|
|||
curve25519_syscall_enabled, disable_fees_sysvar, executables_incur_cpi_data_cost,
|
||||
libsecp256k1_0_5_upgrade_enabled, limit_secp256k1_recovery_id,
|
||||
prevent_calling_precompiles_as_programs, quick_bail_on_panic, syscall_saturated_math,
|
||||
update_syscall_base_costs, zk_token_sdk_enabled,
|
||||
zk_token_sdk_enabled,
|
||||
},
|
||||
hash::{Hasher, HASH_BYTES},
|
||||
instruction::{
|
||||
|
@ -577,12 +577,9 @@ declare_syscall!(
|
|||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
if !invoke_context
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
|| invoke_context
|
||||
.feature_set
|
||||
.is_active(&quick_bail_on_panic::id())
|
||||
.is_active(&quick_bail_on_panic::id())
|
||||
{
|
||||
question_mark!(invoke_context.get_compute_meter().consume(len), result);
|
||||
}
|
||||
|
@ -617,17 +614,10 @@ declare_syscall!(
|
|||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
let cost = if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
{
|
||||
invoke_context
|
||||
.get_compute_budget()
|
||||
.syscall_base_cost
|
||||
.max(len)
|
||||
} else {
|
||||
len
|
||||
};
|
||||
let cost = invoke_context
|
||||
.get_compute_budget()
|
||||
.syscall_base_cost
|
||||
.max(len);
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
|
||||
question_mark!(
|
||||
|
@ -700,14 +690,7 @@ declare_syscall!(
|
|||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
let cost = if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
{
|
||||
invoke_context.get_compute_budget().syscall_base_cost
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let cost = invoke_context.get_compute_budget().syscall_base_cost;
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
|
||||
ic_logger_msg!(
|
||||
|
@ -1006,11 +989,7 @@ declare_syscall!(
|
|||
result
|
||||
);
|
||||
let compute_budget = invoke_context.get_compute_budget();
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
&& compute_budget.sha256_max_slices < vals_len
|
||||
{
|
||||
if compute_budget.sha256_max_slices < vals_len {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Sha256 hashing {} sequences in one syscall is over the limit {}",
|
||||
|
@ -1060,20 +1039,11 @@ declare_syscall!(
|
|||
),
|
||||
result
|
||||
);
|
||||
let cost = if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
{
|
||||
compute_budget.mem_op_base_cost.max(
|
||||
compute_budget
|
||||
.sha256_byte_cost
|
||||
.saturating_mul((val.len() as u64).saturating_div(2)),
|
||||
)
|
||||
} else {
|
||||
let cost = compute_budget.mem_op_base_cost.max(
|
||||
compute_budget
|
||||
.sha256_byte_cost
|
||||
.saturating_mul((val.len() as u64).saturating_div(2))
|
||||
};
|
||||
.saturating_mul((val.len() as u64).saturating_div(2)),
|
||||
);
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
hasher.hash(bytes);
|
||||
}
|
||||
|
@ -1243,11 +1213,7 @@ declare_syscall!(
|
|||
result
|
||||
);
|
||||
let compute_budget = invoke_context.get_compute_budget();
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
&& compute_budget.sha256_max_slices < vals_len
|
||||
{
|
||||
if compute_budget.sha256_max_slices < vals_len {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Keccak256 hashing {} sequences in one syscall is over the limit {}",
|
||||
|
@ -1297,20 +1263,11 @@ declare_syscall!(
|
|||
),
|
||||
result
|
||||
);
|
||||
let cost = if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
{
|
||||
compute_budget.mem_op_base_cost.max(
|
||||
compute_budget
|
||||
.sha256_byte_cost
|
||||
.saturating_mul((val.len() as u64).saturating_div(2)),
|
||||
)
|
||||
} else {
|
||||
let cost = compute_budget.mem_op_base_cost.max(
|
||||
compute_budget
|
||||
.sha256_byte_cost
|
||||
.saturating_mul((val.len() as u64).saturating_div(2))
|
||||
};
|
||||
.saturating_mul((val.len() as u64).saturating_div(2)),
|
||||
);
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
hasher.hash(bytes);
|
||||
}
|
||||
|
@ -1325,16 +1282,9 @@ fn mem_op_consume<'a, 'b>(
|
|||
n: u64,
|
||||
) -> Result<(), EbpfError<BpfError>> {
|
||||
let compute_budget = invoke_context.get_compute_budget();
|
||||
let cost = if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
{
|
||||
compute_budget
|
||||
.mem_op_base_cost
|
||||
.max(n.saturating_div(compute_budget.cpi_bytes_per_unit))
|
||||
} else {
|
||||
n.saturating_div(compute_budget.cpi_bytes_per_unit)
|
||||
};
|
||||
let cost = compute_budget
|
||||
.mem_op_base_cost
|
||||
.max(n.saturating_div(compute_budget.cpi_bytes_per_unit));
|
||||
invoke_context.get_compute_meter().consume(cost)
|
||||
}
|
||||
|
||||
|
@ -1357,17 +1307,7 @@ declare_syscall!(
|
|||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
// When deprecating `update_syscall_base_costs` switch to `mem_op_consume`
|
||||
let compute_budget = invoke_context.get_compute_budget();
|
||||
let update_syscall_base_costs = invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id());
|
||||
if update_syscall_base_costs {
|
||||
let cost = compute_budget
|
||||
.mem_op_base_cost
|
||||
.max(n.saturating_div(compute_budget.cpi_bytes_per_unit));
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
}
|
||||
question_mark!(mem_op_consume(&invoke_context, n), result);
|
||||
|
||||
let do_check_physical_overlapping = invoke_context
|
||||
.feature_set
|
||||
|
@ -1378,11 +1318,6 @@ declare_syscall!(
|
|||
return;
|
||||
}
|
||||
|
||||
if !update_syscall_base_costs {
|
||||
let cost = n.saturating_div(compute_budget.cpi_bytes_per_unit);
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
};
|
||||
|
||||
let dst_ptr = question_mark!(
|
||||
translate_slice_mut::<u8>(
|
||||
memory_mapping,
|
||||
|
@ -2224,11 +2159,7 @@ declare_syscall!(
|
|||
result
|
||||
);
|
||||
let compute_budget = invoke_context.get_compute_budget();
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
&& compute_budget.sha256_max_slices < vals_len
|
||||
{
|
||||
if compute_budget.sha256_max_slices < vals_len {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Blake3 hashing {} sequences in one syscall is over the limit {}",
|
||||
|
@ -2278,28 +2209,11 @@ declare_syscall!(
|
|||
),
|
||||
result
|
||||
);
|
||||
let cost = if invoke_context
|
||||
.feature_set
|
||||
.is_active(&update_syscall_base_costs::id())
|
||||
{
|
||||
compute_budget.mem_op_base_cost.max(
|
||||
compute_budget
|
||||
.sha256_byte_cost
|
||||
.saturating_mul((val.len() as u64).saturating_div(2)),
|
||||
)
|
||||
} else if invoke_context
|
||||
.feature_set
|
||||
.is_active(&syscall_saturated_math::id())
|
||||
{
|
||||
let cost = compute_budget.mem_op_base_cost.max(
|
||||
compute_budget
|
||||
.sha256_byte_cost
|
||||
.saturating_mul((val.len() as u64).saturating_div(2))
|
||||
} else {
|
||||
#[allow(clippy::integer_arithmetic)]
|
||||
{
|
||||
compute_budget.sha256_byte_cost * (val.len() as u64 / 2)
|
||||
}
|
||||
};
|
||||
.saturating_mul((val.len() as u64).saturating_div(2)),
|
||||
);
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
hasher.hash(bytes);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue