From b5f893fa9fc61fb5d87f0f37c5dceff3d7206752 Mon Sep 17 00:00:00 2001 From: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Date: Wed, 15 May 2024 11:14:06 +0530 Subject: [PATCH] version constants to pallet constants (#1589) --- CHANGELOG.md | 1 + Cargo.lock | 2 + crates/node/Cargo.toml | 2 + crates/node/build.rs | 12 + crates/node/src/commands/run.rs | 5 +- crates/pallets/starknet/src/lib.rs | 7 +- .../starknet/src/tests/mock/setup_mock.rs | 4 + crates/runtime/Cargo.toml | 3 + .../resources/versioned_constants.json | 543 ++++++++++++++++++ crates/runtime/src/pallets.rs | 37 ++ 10 files changed, 613 insertions(+), 3 deletions(-) create mode 100644 crates/runtime/resources/versioned_constants.json diff --git a/CHANGELOG.md b/CHANGELOG.md index b2d6e415b0..277ae1c30b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- feat: add versioned constants to pallet constants - bug: fix contract serialisation - fix: starknet_call errs if contract nonexistent - fix: txn hash calculation and refactor diff --git a/Cargo.lock b/Cargo.lock index 0652aefc1a..6511ea1ff6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5601,6 +5601,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", + "lazy_static", "mp-chain-id", "mp-felt", "mp-hashers", @@ -5614,6 +5615,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 9079b7a113..c575676022 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -128,3 +128,5 @@ sharingan = [] sn-block-import = ["dep:mc-starknet-block-import"] # Enables Sierra class verification for both own and foreign blocks only + enabled for manual sealing mode sn-block-import-testing = ["sn-block-import"] +# Enables dev features to improve DevX +dev = ["madara-runtime/dev"] diff --git a/crates/node/build.rs b/crates/node/build.rs index f9d839f9be..c08eb234d7 100644 --- a/crates/node/build.rs +++ b/crates/node/build.rs @@ -1,6 +1,18 @@ +use std::env; + use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; fn main() { + // Check if the feature flag is enabled + let feature_enabled = env::var("CARGO_FEATURE_DEV").is_ok(); + // Check if we are in release mode + let debug_mode = env::var("PROFILE").map(|p| p == "debug").unwrap_or(false); + + if feature_enabled && !debug_mode { + // Emit a compile error if the feature is enabled in release mode + panic!("The feature 'dev' can only be enabled in debug mode."); + } + generate_cargo_keys(); rerun_if_git_head_changed(); diff --git a/crates/node/src/commands/run.rs b/crates/node/src/commands/run.rs index be75be4146..3de375a100 100644 --- a/crates/node/src/commands/run.rs +++ b/crates/node/src/commands/run.rs @@ -72,7 +72,10 @@ fn override_dev_environment(cmd: &mut ExtendedRunCmd) { cmd.base.force_authoring = true; cmd.base.alice = true; - cmd.base.tmp = true; + + if cmd.base.shared_params.base_path.is_none() { + cmd.base.tmp = true; + } // we can't set `--rpc-cors=all`, so it needs to be set manually if we want to connect with external // hosts diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index cc156e0b55..e30c381720 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -55,6 +55,7 @@ pub mod types; mod tests; use std::collections::BTreeSet; +use std::ops::Deref; use std::str::from_utf8_unchecked; use blockifier::blockifier::block::{BlockInfo, GasPrices}; @@ -154,6 +155,8 @@ pub mod pallet { type ProtocolVersion: Get; #[pallet::constant] type ProgramHash: Get; + #[pallet::constant] + type ExecutionConstants: Get>; } /// The Starknet pallet hooks. @@ -857,7 +860,7 @@ impl Pallet { use_kzg_da: true, }, &ChainInfo { chain_id, fee_token_addresses }, - VersionedConstants::latest_constants(), + T::ExecutionConstants::get().deref(), ) } @@ -925,7 +928,7 @@ impl Pallet { storage_address: address, caller_address: ContractAddress::default(), call_type: CallType::Call, - initial_gas: VersionedConstants::latest_constants().tx_initial_gas(), + initial_gas: T::ExecutionConstants::get().tx_initial_gas(), }; let mut resources = cairo_vm::vm::runners::cairo_runner::ExecutionResources::default(); diff --git a/crates/pallets/starknet/src/tests/mock/setup_mock.rs b/crates/pallets/starknet/src/tests/mock/setup_mock.rs index fcc2098249..67d06fed50 100644 --- a/crates/pallets/starknet/src/tests/mock/setup_mock.rs +++ b/crates/pallets/starknet/src/tests/mock/setup_mock.rs @@ -19,7 +19,9 @@ macro_rules! mock_runtime { use starknet_api::core::{PatriciaKey, ContractAddress}; use starknet_api::hash::StarkFelt; use blockifier::blockifier::block::GasPrices; + use blockifier::versioned_constants::VersionedConstants; use core::num::NonZeroU128; + use std::sync::Arc; type Block = frame_system::mocking::MockBlock; @@ -73,6 +75,7 @@ macro_rules! mock_runtime { pub const ProtocolVersion: u8 = 0; pub const ProgramHash: Felt252Wrapper = mp_program_hash::SN_OS_PROGRAM_HASH; pub const L1GasPrices: GasPrices = GasPrices { eth_l1_gas_price: unsafe { NonZeroU128::new_unchecked(10) }, strk_l1_gas_price: unsafe { NonZeroU128::new_unchecked(10) }, eth_l1_data_gas_price: unsafe { NonZeroU128::new_unchecked(10) }, strk_l1_data_gas_price: unsafe { NonZeroU128::new_unchecked(10) } }; + pub ExecutionConstants: Arc = Arc::new(VersionedConstants::latest_constants().clone()); } impl pallet_starknet::Config for MockRuntime { @@ -84,6 +87,7 @@ macro_rules! mock_runtime { type ProtocolVersion = ProtocolVersion; type ProgramHash = ProgramHash; type L1GasPrices = L1GasPrices; + type ExecutionConstants = ExecutionConstants; } /// Run to block n. diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index 225f636a4f..873445ed52 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -19,9 +19,11 @@ targets = ["x86_64-unknown-linux-gnu"] ignored = ["scale-info"] # Used in the macros [dependencies] +lazy_static = { workspace = true } parity-scale-codec = { workspace = true } scale-info = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } @@ -90,3 +92,4 @@ runtime-benchmarks = [ # Madara pallets "pallet-starknet/runtime-benchmarks", ] +dev = [] diff --git a/crates/runtime/resources/versioned_constants.json b/crates/runtime/resources/versioned_constants.json new file mode 100644 index 0000000000..0d01e17e66 --- /dev/null +++ b/crates/runtime/resources/versioned_constants.json @@ -0,0 +1,543 @@ +{ + "tx_event_limits": { + "max_data_length": 300, + "max_keys_length": 50, + "max_n_emitted_events": 1000 + }, + "gateway": { + "max_calldata_length": 4000, + "max_contract_bytecode_size": 81920 + }, + "invoke_tx_max_n_steps": 4000000, + "l2_resource_gas_costs": { + "gas_per_data_felt": [128, 1000], + "event_key_factor": [2, 1], + "gas_per_code_byte": [875, 1000] + }, + "max_recursion_depth": 50, + "os_constants": { + "block_hash_contract_address": 1, + "call_contract_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 10, + "syscall_base_gas_cost": 1 + }, + "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "default_entry_point_selector": 0, + "deploy_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 200, + "syscall_base_gas_cost": 1 + }, + "emit_event_gas_cost": { + "step_gas_cost": 10, + "syscall_base_gas_cost": 1 + }, + "entry_point_gas_cost": { + "entry_point_initial_budget": 1, + "step_gas_cost": 500 + }, + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "entry_point_type_constructor": 2, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "error_block_number_out_of_range": "Block number out of range", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "error_out_of_gas": "Out of gas", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "fee_transfer_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 100 + }, + "get_block_hash_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "get_execution_info_gas_cost": { + "step_gas_cost": 10, + "syscall_base_gas_cost": 1 + }, + "initial_gas_cost": { + "step_gas_cost": 100000000 + }, + "keccak_gas_cost": { + "syscall_base_gas_cost": 1 + }, + "keccak_round_cost_gas_cost": 180000, + "l1_gas": "L1_GAS", + "l1_gas_index": 0, + "l1_handler_version": 0, + "l2_gas": "L2_GAS", + "l2_gas_index": 1, + "library_call_gas_cost": { + "call_contract_gas_cost": 1 + }, + "memory_hole_gas_cost": 10, + "nop_entry_point_offset": -1, + "range_check_gas_cost": 70, + "replace_class_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "secp256k1_add_gas_cost": { + "range_check_gas_cost": 29, + "step_gas_cost": 406 + }, + "secp256k1_get_point_from_x_gas_cost": { + "memory_hole_gas_cost": 20, + "range_check_gas_cost": 30, + "step_gas_cost": 391 + }, + "secp256k1_get_xy_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 11, + "step_gas_cost": 239 + }, + "secp256k1_mul_gas_cost": { + "memory_hole_gas_cost": 2, + "range_check_gas_cost": 7045, + "step_gas_cost": 76501 + }, + "secp256k1_new_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 35, + "step_gas_cost": 475 + }, + "secp256r1_add_gas_cost": { + "range_check_gas_cost": 57, + "step_gas_cost": 589 + }, + "secp256r1_get_point_from_x_gas_cost": { + "memory_hole_gas_cost": 20, + "range_check_gas_cost": 44, + "step_gas_cost": 510 + }, + "secp256r1_get_xy_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 11, + "step_gas_cost": 241 + }, + "secp256r1_mul_gas_cost": { + "memory_hole_gas_cost": 2, + "range_check_gas_cost": 13961, + "step_gas_cost": 125340 + }, + "secp256r1_new_gas_cost": { + "memory_hole_gas_cost": 40, + "range_check_gas_cost": 49, + "step_gas_cost": 594 + }, + "send_message_to_l1_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "sierra_array_len_bound": 4294967296, + "step_gas_cost": 100, + "storage_read_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "storage_write_gas_cost": { + "step_gas_cost": 50, + "syscall_base_gas_cost": 1 + }, + "stored_block_hash_buffer": 10, + "syscall_base_gas_cost": { + "step_gas_cost": 100 + }, + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 + }, + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_rounding_consts": { + "validate_block_number_rounding": 100, + "validate_timestamp_rounding": 3600 + }, + "validated": "VALID" + }, + "os_resources": { + "execute_syscalls": { + "CallContract": { + "n_steps": 760, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "DelegateCall": { + "n_steps": 713, + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "DelegateL1Handler": { + "n_steps": 692, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "Deploy": { + "n_steps": 1010, + "builtin_instance_counter": { + "pedersen_builtin": 7, + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "EmitEvent": { + "n_steps": 61, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetBlockHash": { + "n_steps": 104, + "builtin_instance_counter": { + "range_check_builtin": 2 + }, + "n_memory_holes": 0 + }, + "GetBlockNumber": { + "n_steps": 40, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetBlockTimestamp": { + "n_steps": 38, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetCallerAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetContractAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetExecutionInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetSequencerAddress": { + "n_steps": 34, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetTxInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetTxSignature": { + "n_steps": 44, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "Keccak": { + "n_steps": 381, + "builtin_instance_counter": { + "bitwise_builtin": 6, + "keccak_builtin": 1, + "range_check_builtin": 56 + }, + "n_memory_holes": 0 + }, + "LibraryCall": { + "n_steps": 751, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "LibraryCallL1Handler": { + "n_steps": 659, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "ReplaceClass": { + "n_steps": 98, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Secp256k1Add": { + "n_steps": 408, + "builtin_instance_counter": { + "range_check_builtin": 29 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetPointFromX": { + "n_steps": 393, + "builtin_instance_counter": { + "range_check_builtin": 30 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetXy": { + "n_steps": 205, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256k1Mul": { + "n_steps": 76503, + "builtin_instance_counter": { + "range_check_builtin": 7045 + }, + "n_memory_holes": 0 + }, + "Secp256k1New": { + "n_steps": 459, + "builtin_instance_counter": { + "range_check_builtin": 35 + }, + "n_memory_holes": 0 + }, + "Secp256r1Add": { + "n_steps": 591, + "builtin_instance_counter": { + "range_check_builtin": 57 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetPointFromX": { + "n_steps": 512, + "builtin_instance_counter": { + "range_check_builtin": 44 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetXy": { + "n_steps": 207, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256r1Mul": { + "n_steps": 125342, + "builtin_instance_counter": { + "range_check_builtin": 13961 + }, + "n_memory_holes": 0 + }, + "Secp256r1New": { + "n_steps": 578, + "builtin_instance_counter": { + "range_check_builtin": 49 + }, + "n_memory_holes": 0 + }, + "SendMessageToL1": { + "n_steps": 139, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "StorageRead": { + "n_steps": 87, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "StorageWrite": { + "n_steps": 89, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "execute_txs_inner": { + "Declare": { + "deprecated_resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 2957, + "builtin_instance_counter": { + "pedersen_builtin": 4, + "range_check_builtin": 68, + "poseidon_builtin": 10 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "DeployAccount": { + "deprecated_resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 3930, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 88, + "poseidon_builtin": 10 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + } + }, + "InvokeFunction": { + "deprecated_resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 3699, + "builtin_instance_counter": { + "pedersen_builtin": 4, + "range_check_builtin": 85, + "poseidon_builtin": 11 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + }, + "L1Handler": { + "deprecated_resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "resources": { + "constant": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 113, + "builtin_instance_counter": { + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + } + }, + "validate_max_n_steps": 1000000, + "vm_resource_fee_cost": { + "bitwise_builtin": [16, 100], + "ec_op_builtin": [256, 100], + "ecdsa_builtin": [512, 100], + "keccak_builtin": [512, 100], + "n_steps": [25, 10000], + "output_builtin": [0, 1], + "pedersen_builtin": [8, 100], + "poseidon_builtin": [8, 100], + "range_check_builtin": [4, 100] + } +} diff --git a/crates/runtime/src/pallets.rs b/crates/runtime/src/pallets.rs index d9b7ad6bd9..f0a5bf8e36 100644 --- a/crates/runtime/src/pallets.rs +++ b/crates/runtime/src/pallets.rs @@ -1,9 +1,16 @@ //! Configuration of the pallets used in the runtime. //! The pallets used in the runtime are configured here. //! This file is used to generate the `construct_runtime!` macro. +#[cfg(all(debug_assertions, feature = "dev"))] +use std::env::VarError; use std::num::NonZeroU128; +use std::ops::Deref; +#[cfg(all(debug_assertions, feature = "dev"))] +use std::path::Path; +use std::sync::Arc; use blockifier::blockifier::block::GasPrices; +use blockifier::versioned_constants::VersionedConstants; pub use frame_support::traits::{ ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, OnTimestampSet, Randomness, StorageInfo, }; @@ -13,6 +20,7 @@ pub use frame_support::weights::constants::{ pub use frame_support::weights::{IdentityFee, Weight}; pub use frame_support::{construct_runtime, parameter_types, StorageValue}; pub use frame_system::Call as SystemCall; +use lazy_static::lazy_static; pub use mp_chain_id::SN_GOERLI_CHAIN_ID; pub use mp_program_hash::SN_OS_PROGRAM_HASH; /// Import the StarkNet pallet. @@ -32,6 +40,29 @@ use crate::*; // -------------------------------------- // CUSTOM PALLETS // -------------------------------------- +const EXECUTION_CONSTANTS_STR: &str = include_str!("../resources/versioned_constants.json"); + +#[cfg(not(all(debug_assertions, feature = "dev")))] +lazy_static! { + static ref EXECUTION_CONSTANTS: Arc = serde_json::from_str(EXECUTION_CONSTANTS_STR).unwrap(); +} + +#[cfg(all(debug_assertions, feature = "dev"))] +lazy_static! { + static ref EXECUTION_CONSTANTS: Arc = Arc::new( + std::env::var("EXECUTION_CONSTANTS_PATH") + .map(|path| { + VersionedConstants::try_from(Path::new(path.as_str())) + .expect("Failed to load execution constants from path") + }) + .unwrap_or_else(|e| { + match e { + VarError::NotPresent => serde_json::from_str(EXECUTION_CONSTANTS_STR).unwrap(), + VarError::NotUnicode(_) => panic!("Failed to load execution constants variable"), + } + }) + ); +} /// Configure the Starknet pallet in pallets/starknet. impl pallet_starknet::Config for Runtime { @@ -46,6 +77,7 @@ impl pallet_starknet::Config for Runtime { type ProtocolVersion = ProtocolVersion; type ProgramHash = ProgramHash; type L1GasPrices = L1GasPrices; + type ExecutionConstants = ExecutionConstants; } /// -------------------------------------- @@ -151,12 +183,17 @@ impl pallet_timestamp::Config for Runtime { type WeightInfo = (); } +fn get_execution_constants() -> Arc { + EXECUTION_CONSTANTS.deref().clone() +} + parameter_types! { pub const UnsignedPriority: u64 = 1 << 20; pub const TransactionLongevity: u64 = u64::MAX; pub const ProtocolVersion: u8 = 0; pub const ProgramHash: Felt252Wrapper = SN_OS_PROGRAM_HASH; pub const L1GasPrices: GasPrices = GasPrices { eth_l1_gas_price: unsafe { NonZeroU128::new_unchecked(10) }, strk_l1_gas_price: unsafe { NonZeroU128::new_unchecked(10) }, eth_l1_data_gas_price: unsafe { NonZeroU128::new_unchecked(10) }, strk_l1_data_gas_price: unsafe { NonZeroU128::new_unchecked(10) } }; + pub ExecutionConstants: Arc = get_execution_constants(); } /// Implement the OnTimestampSet trait to override the default Aura.