Skip to content

Commit 2fb646a

Browse files
authored
Merge pull request #7389 from rob-stacks/feat/costs_5_from_valgrind_bench_tool
updated costs_5
2 parents 8a3bd08 + a5e8da9 commit 2fb646a

11 files changed

Lines changed: 321 additions & 941 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Recalibrated all Clarity 6 (Epoch 4.0) runtime cost functions in `costs_5.rs` using Callgrind instruction-count measurements from `clarity-cost-bench`. Arithmetic, tuple, sequence, hash, crypto, and store operations now have bench-derived linear formulas instead of forwarding to the Clarity 4 values, with a calibration baseline of 1 cost unit = 80,000 CPU instructions (a clean round value chosen to place the base overhead of any Clarity call at ≈38 units).

clarity/src/vm/costs/costs_5.rs

Lines changed: 265 additions & 144 deletions
Large diffs are not rendered by default.

clarity/src/vm/costs/mod.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,18 @@ impl TrackerData {
988988
let cost_function_ref = cost_function_references.remove(f).unwrap_or_else(|| {
989989
ClarityCostFunctionReference::new(boot_costs_id.clone(), f.get_name())
990990
});
991-
if !cost_contracts.contains_key(&cost_function_ref.contract_id) {
991+
992+
let is_boot_default = cost_function_ref.contract_id == boot_costs_id;
993+
994+
// Beginning in epoch 4.0 the costs are implemented in Rust only,
995+
// and not deployed on-chain in a contract. This is possible with
996+
// the disabling of cost-voting.
997+
let requires_contract_load =
998+
!is_boot_default || epoch_id.supports_cost_voting_contract();
999+
1000+
if requires_contract_load
1001+
&& !cost_contracts.contains_key(&cost_function_ref.contract_id)
1002+
{
9921003
let contract = match clarity_db.get_contract(&cost_function_ref.contract_id) {
9931004
Ok(contract) => contract,
9941005
Err(e) => {
@@ -1004,7 +1015,7 @@ impl TrackerData {
10041015
cost_contracts.insert(cost_function_ref.contract_id.clone(), contract);
10051016
}
10061017

1007-
if cost_function_ref.contract_id == boot_costs_id {
1018+
if is_boot_default {
10081019
m.insert(
10091020
f,
10101021
ClarityCostFunctionEvaluator::Default(cost_function_ref, f.clone(), v),

contrib/clarity-cli/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ use stackslib::burnchains::{PoxConstants, Txid};
5252
use stackslib::chainstate::stacks::boot::{
5353
BOOT_CODE_BNS, BOOT_CODE_COST_VOTING_MAINNET, BOOT_CODE_COST_VOTING_TESTNET, BOOT_CODE_COSTS,
5454
BOOT_CODE_COSTS_2, BOOT_CODE_COSTS_2_TESTNET, BOOT_CODE_COSTS_3, BOOT_CODE_COSTS_4,
55-
BOOT_CODE_COSTS_5, BOOT_CODE_GENESIS, BOOT_CODE_LOCKUP, BOOT_CODE_POX_MAINNET,
56-
BOOT_CODE_POX_TESTNET, POX_2_MAINNET_CODE, POX_2_TESTNET_CODE,
55+
BOOT_CODE_GENESIS, BOOT_CODE_LOCKUP, BOOT_CODE_POX_MAINNET, BOOT_CODE_POX_TESTNET,
56+
POX_2_MAINNET_CODE, POX_2_TESTNET_CODE,
5757
};
5858
use stackslib::chainstate::stacks::index::ClarityMarfTrieId;
5959
use stackslib::clarity_vm::clarity::{ClarityMarfStore, ClarityMarfStoreTransaction};
@@ -64,7 +64,7 @@ use stackslib::util_lib::boot::{boot_code_addr, boot_code_id};
6464
use stackslib::util_lib::db::{FromColumn, sqlite_open};
6565

6666
lazy_static! {
67-
pub static ref STACKS_BOOT_CODE_MAINNET_2_1: [(&'static str, &'static str); 11] = [
67+
pub static ref STACKS_BOOT_CODE_MAINNET_2_1: [(&'static str, &'static str); 10] = [
6868
("pox", &BOOT_CODE_POX_MAINNET),
6969
("lockup", BOOT_CODE_LOCKUP),
7070
("costs", BOOT_CODE_COSTS),
@@ -75,9 +75,8 @@ lazy_static! {
7575
("pox-2", &POX_2_MAINNET_CODE),
7676
("costs-3", BOOT_CODE_COSTS_3),
7777
("costs-4", BOOT_CODE_COSTS_4),
78-
("costs-5", BOOT_CODE_COSTS_5),
7978
];
80-
pub static ref STACKS_BOOT_CODE_TESTNET_2_1: [(&'static str, &'static str); 11] = [
79+
pub static ref STACKS_BOOT_CODE_TESTNET_2_1: [(&'static str, &'static str); 10] = [
8180
("pox", &BOOT_CODE_POX_TESTNET),
8281
("lockup", BOOT_CODE_LOCKUP),
8382
("costs", BOOT_CODE_COSTS),
@@ -88,7 +87,6 @@ lazy_static! {
8887
("pox-2", &POX_2_TESTNET_CODE),
8988
("costs-3", BOOT_CODE_COSTS_3),
9089
("costs-4", BOOT_CODE_COSTS_4),
91-
("costs-5", BOOT_CODE_COSTS_5),
9290
];
9391
}
9492

0 commit comments

Comments
 (0)