Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

feat: L1 gas price is configurable in the RuntimeConfig #1392

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::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<ResourcePrice>;
/// A configuration for base priority of unsigned transactions.
///
/// This is exposed so that it can be tuned for particular runtime, when
Expand Down Expand Up @@ -814,8 +817,6 @@ impl<T: Config> Pallet<T> {
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),
Expand All @@ -825,7 +826,7 @@ impl<T: Config> Pallet<T> {
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(),
}
}
Expand Down Expand Up @@ -949,8 +950,7 @@ impl<T: Config> Pallet<T> {
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(
Expand Down
3 changes: 3 additions & 0 deletions crates/pallets/starknet/src/tests/mock/setup_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MockRuntime>;
Expand Down Expand Up @@ -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 {
Expand All @@ -90,6 +92,7 @@ macro_rules! mock_runtime {
type ChainId = ChainId;
type MaxRecursionDepth = MaxRecursionDepth;
type ProgramHash = ProgramHash;
type L1GasPrice = L1GasPrice;
}

/// Run to block n.
Expand Down
6 changes: 4 additions & 2 deletions crates/primitives/fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
/// The price of one unit of the given resource, denominated in wei
pub price_in_wei: u64,
pub price_in_wei: u128,
}

impl From<ResourcePrice> 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 }
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions crates/runtime/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,7 @@ impl pallet_starknet::Config for Runtime {
type ChainId = ChainId;
type MaxRecursionDepth = MaxRecursionDepth;
type ProgramHash = ProgramHash;
type L1GasPrice = L1GasPrice;
}

/// --------------------------------------
Expand Down Expand Up @@ -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.
Expand Down