diff --git a/CHANGELOG.md b/CHANGELOG.md index 9105da8485..616bf9dddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Next release - feat: types in `mp-transactions` impl a method to get their version +- feat: make L1 gas price a `const` of the `RuntimeConfig` - fix: broken class hashes and contracts in genesis - refactor: rename LAST_SYNCED_L1_BLOCK to be more clear - chore: add headers to da calldata, fix eth da in sovereign mode diff --git a/Cargo.lock b/Cargo.lock index 8f17f06687..8dceb33e69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6150,6 +6150,7 @@ dependencies = [ "frame-try-runtime", "mp-block", "mp-chain-id", + "mp-fee", "mp-felt", "mp-hashers", "mp-program-hash", diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index c9ea9c4354..9f94da2101 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -138,8 +138,11 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The hashing function to use. type SystemHash: HasherT; - /// The time idk what. + /// The block time type TimestampProvider: Time; + /// The gas price + #[pallet::constant] + type L1GasPrice: Get; /// A configuration for base priority of unsigned transactions. /// /// This is exposed so that it can be tuned for particular runtime, when @@ -814,8 +817,6 @@ impl Pallet { let chain_id = Self::chain_id_str(); let vm_resource_fee_cost = Default::default(); - // FIXME: https://github.com/keep-starknet-strange/madara/issues/329 - let gas_price = 10; BlockContext { block_number: BlockNumber(block_number), block_timestamp: BlockTimestamp(block_timestamp), @@ -825,7 +826,7 @@ impl Pallet { vm_resource_fee_cost, invoke_tx_max_n_steps: T::InvokeTxMaxNSteps::get(), validate_max_n_steps: T::ValidateMaxNSteps::get(), - gas_price, + gas_price: T::L1GasPrice::get().price_in_wei, max_recursion_depth: T::MaxRecursionDepth::get(), } } @@ -949,8 +950,7 @@ impl Pallet { let protocol_version = T::ProtocolVersion::get(); let extra_data = None; - // TODO: Compute l1_gas_price correctly - let l1_gas_price = ResourcePrice::default(); + let l1_gas_price = T::L1GasPrice::get(); let block = StarknetBlock::new( StarknetHeader::new( diff --git a/crates/pallets/starknet/src/tests/mock/setup_mock.rs b/crates/pallets/starknet/src/tests/mock/setup_mock.rs index fb64c7ac92..3113361b19 100644 --- a/crates/pallets/starknet/src/tests/mock/setup_mock.rs +++ b/crates/pallets/starknet/src/tests/mock/setup_mock.rs @@ -18,6 +18,7 @@ macro_rules! mock_runtime { use mp_felt::Felt252Wrapper; use starknet_api::api_core::{PatriciaKey, ContractAddress}; use starknet_api::hash::StarkFelt; + use mp_fee::ResourcePrice; type Block = frame_system::mocking::MockBlock; @@ -74,6 +75,7 @@ macro_rules! mock_runtime { pub const ChainId: Felt252Wrapper = mp_chain_id::SN_GOERLI_CHAIN_ID; pub const MaxRecursionDepth: u32 = 50; pub const ProgramHash: Felt252Wrapper = mp_program_hash::SN_OS_PROGRAM_HASH; + pub const L1GasPrice: ResourcePrice = ResourcePrice { price_in_strk: None, price_in_wei: 10 }; } impl pallet_starknet::Config for MockRuntime { @@ -90,6 +92,7 @@ macro_rules! mock_runtime { type ChainId = ChainId; type MaxRecursionDepth = MaxRecursionDepth; type ProgramHash = ProgramHash; + type L1GasPrice = L1GasPrice; } /// Run to block n. diff --git a/crates/primitives/fee/src/lib.rs b/crates/primitives/fee/src/lib.rs index 00c45148bc..c5ea5a5bfc 100644 --- a/crates/primitives/fee/src/lib.rs +++ b/crates/primitives/fee/src/lib.rs @@ -63,12 +63,14 @@ pub struct ResourcePrice { /// The price of one unit of the given resource, denominated in fri (10^-18 strk) pub price_in_strk: Option, /// The price of one unit of the given resource, denominated in wei - pub price_in_wei: u64, + pub price_in_wei: u128, } impl From for CoreResourcePrice { fn from(item: ResourcePrice) -> Self { - CoreResourcePrice { price_in_strk: item.price_in_strk, price_in_wei: item.price_in_wei } + // TODO: when we rebase starknet-rs those field type will be FieldElements + // Get rid of the type conversions + CoreResourcePrice { price_in_strk: item.price_in_strk, price_in_wei: item.price_in_wei as u64 } } } diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index 2428aa2a56..d1f02d968d 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -55,6 +55,7 @@ pallet-starknet-runtime-api = { workspace = true } # Madara Primitives mp-block = { workspace = true } mp-chain-id = { workspace = true } +mp-fee = { workspace = true } mp-felt = { workspace = true } mp-hashers = { workspace = true } mp-program-hash = { workspace = true } diff --git a/crates/runtime/src/pallets.rs b/crates/runtime/src/pallets.rs index 12a57d6ace..210a5188f1 100644 --- a/crates/runtime/src/pallets.rs +++ b/crates/runtime/src/pallets.rs @@ -11,6 +11,7 @@ pub use frame_support::weights::{IdentityFee, Weight}; pub use frame_support::{construct_runtime, parameter_types, StorageValue}; pub use frame_system::Call as SystemCall; pub use mp_chain_id::SN_GOERLI_CHAIN_ID; +use mp_fee::ResourcePrice; pub use mp_program_hash::SN_OS_PROGRAM_HASH; /// Import the StarkNet pallet. pub use pallet_starknet; @@ -48,6 +49,7 @@ impl pallet_starknet::Config for Runtime { type ChainId = ChainId; type MaxRecursionDepth = MaxRecursionDepth; type ProgramHash = ProgramHash; + type L1GasPrice = L1GasPrice; } /// -------------------------------------- @@ -162,6 +164,7 @@ parameter_types! { pub const ChainId: Felt252Wrapper = SN_GOERLI_CHAIN_ID; pub const MaxRecursionDepth: u32 = 50; pub const ProgramHash: Felt252Wrapper = SN_OS_PROGRAM_HASH; + pub const L1GasPrice: ResourcePrice = ResourcePrice { price_in_strk: None, price_in_wei: 10 }; } /// Implement the OnTimestampSet trait to override the default Aura.