Skip to content

Commit

Permalink
version constants to pallet constants (keep-starknet-strange#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvsadana authored May 15, 2024
1 parent 8a23076 commit b5f893f
Show file tree
Hide file tree
Showing 10 changed files with 613 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
12 changes: 12 additions & 0 deletions crates/node/build.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
5 changes: 4 additions & 1 deletion crates/node/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -154,6 +155,8 @@ pub mod pallet {
type ProtocolVersion: Get<u8>;
#[pallet::constant]
type ProgramHash: Get<Felt252Wrapper>;
#[pallet::constant]
type ExecutionConstants: Get<Arc<VersionedConstants>>;
}

/// The Starknet pallet hooks.
Expand Down Expand Up @@ -857,7 +860,7 @@ impl<T: Config> Pallet<T> {
use_kzg_da: true,
},
&ChainInfo { chain_id, fee_token_addresses },
VersionedConstants::latest_constants(),
T::ExecutionConstants::get().deref(),
)
}

Expand Down Expand Up @@ -925,7 +928,7 @@ impl<T: Config> Pallet<T> {
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();
Expand Down
4 changes: 4 additions & 0 deletions crates/pallets/starknet/src/tests/mock/setup_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MockRuntime>;
Expand Down Expand Up @@ -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<VersionedConstants> = Arc::new(VersionedConstants::latest_constants().clone());
}

impl pallet_starknet::Config for MockRuntime {
Expand All @@ -84,6 +87,7 @@ macro_rules! mock_runtime {
type ProtocolVersion = ProtocolVersion;
type ProgramHash = ProgramHash;
type L1GasPrices = L1GasPrices;
type ExecutionConstants = ExecutionConstants;
}

/// Run to block n.
Expand Down
3 changes: 3 additions & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -90,3 +92,4 @@ runtime-benchmarks = [
# Madara pallets
"pallet-starknet/runtime-benchmarks",
]
dev = []
Loading

0 comments on commit b5f893f

Please sign in to comment.