Skip to content

Commit

Permalink
Clean/blockifier (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron authored May 8, 2024
1 parent a6d28fa commit 900718f
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 61 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

- refactor: remove blockifier dependencie
- perf: convert blocks in parallel
- feat(commitments): Joined hash computation in event and tx commitments
- feat(l2 sync): polling to get new blocks once sync has caught up with the chain
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion crates/pallets/starknet/runtime_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ version = "0.1.0"
mp-felt = { workspace = true, features = ["parity-scale-codec", "serde"] }

# Starknet
blockifier = { workspace = true }
starknet_api = { workspace = true }

# Substrate
Expand Down
5 changes: 0 additions & 5 deletions crates/pallets/starknet/runtime_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Specifically, the macro generates a trait (`StarknetRuntimeApi`) with unused type parameters.
#![allow(clippy::extra_unused_type_parameters)]

use blockifier::context::{BlockContext, FeeTokenAddresses};
use mp_felt::Felt252Wrapper;
pub extern crate alloc;
use alloc::vec::Vec;
Expand All @@ -31,15 +30,11 @@ sp_api::decl_runtime_apis! {
fn program_hash() -> Felt252Wrapper;
/// Returns the Starknet config hash.
fn config_hash() -> StarkHash;
/// Returns the fee token address.
fn fee_token_addresses() -> FeeTokenAddresses;

fn get_events_for_tx_by_hash(tx_hash: TransactionHash) -> Vec<StarknetEvent>;

/// Return the outcome of the tx execution
fn get_tx_execution_outcome(tx_hash: TransactionHash) -> Option<Vec<u8>>;
/// Return the block context
fn get_block_context() -> BlockContext;
/// Return is fee disabled in state
fn is_transaction_fee_disabled() -> bool;
/// Return messages sent to L1 during tx execution
Expand Down
40 changes: 2 additions & 38 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;

use blockifier::blockifier::block::{BlockInfo, GasPrices};
use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses};
use blockifier::context::FeeTokenAddresses;
use blockifier::execution::call_info::CallInfo;
use blockifier::versioned_constants::VersionedConstants;
use frame_support::pallet_prelude::*;
use frame_support::traits::Time;
use frame_system::pallet_prelude::*;
Expand All @@ -71,8 +69,7 @@ use mp_sequencer_address::{InherentError, InherentType, DEFAULT_SEQUENCER_ADDRES
use mp_storage::{StarknetStorageSchemaVersion, PALLET_STARKNET_SCHEMA};
use sp_runtime::traits::UniqueSaturatedInto;
use sp_runtime::DigestItem;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{ChainId, CompiledClassHash, ContractAddress};
use starknet_api::core::{CompiledClassHash, ContractAddress};
use starknet_api::hash::{StarkFelt, StarkHash};
use starknet_api::state::StorageKey;
use starknet_api::transaction::{Event as StarknetEvent, MessageToL1, TransactionHash};
Expand Down Expand Up @@ -117,9 +114,6 @@ pub mod pallet {
type SystemHash: HasherT;
/// The block time
type TimestampProvider: Time;
/// The gas price
#[pallet::constant]
type L1GasPrices: Get<GasPrices>;
/// 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 @@ -391,36 +385,6 @@ pub mod pallet {

/// The Starknet pallet internal functions.
impl<T: Config> Pallet<T> {
/// Creates a [BlockContext] object. The [BlockContext] is needed by the blockifier to execute
/// properly the transaction. Substrate caches data so it's fine to call multiple times this
/// function, only the first transaction/block will be "slow" to load these data.
pub fn get_block_context() -> BlockContext {
let block_number = UniqueSaturatedInto::<u64>::unique_saturated_into(frame_system::Pallet::<T>::block_number());
let block_timestamp = Self::block_timestamp();

let fee_token_addresses = Self::fee_token_addresses();
let sequencer_address = Self::sequencer_address();

let chain_id = ChainId(Self::chain_id_str());
let gas_prices = T::L1GasPrices::get();

BlockContext::new_unchecked(
&BlockInfo {
block_number: BlockNumber(block_number),
block_timestamp: BlockTimestamp(block_timestamp),
sequencer_address,
gas_prices,
// TODO
// I have no idea what this is, let's say we did not use any for now
use_kzg_da: false,
},
&ChainInfo { chain_id, fee_token_addresses },
// TODO
// I'm clueless on what those values should be
VersionedConstants::latest_constants(),
)
}

/// convert chain_id
#[inline(always)]
pub fn chain_id_str() -> String {
Expand Down
1 change: 0 additions & 1 deletion crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ mp-felt = { workspace = true }
mp-program-hash = { workspace = true }
mp-types = { workspace = true }
# Starknet dependencies
blockifier = { workspace = true }
starknet_api = { workspace = true }

[features]
Expand Down
9 changes: 0 additions & 9 deletions crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod opaque;
mod pallets;
mod runtime_tests;

use blockifier::context::FeeTokenAddresses;
pub use config::*;
pub use frame_support::traits::{ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo};
pub use frame_support::weights::constants::{
Expand Down Expand Up @@ -193,10 +192,6 @@ impl_runtime_apis! {
Starknet::config_hash()
}

fn fee_token_addresses() -> FeeTokenAddresses {
Starknet::fee_token_addresses()
}

fn is_transaction_fee_disabled() -> bool {
Starknet::is_transaction_fee_disabled()
}
Expand All @@ -212,10 +207,6 @@ impl_runtime_apis! {
fn get_tx_execution_outcome(tx_hash: TransactionHash) -> Option<Vec<u8>> {
Starknet::tx_revert_error(tx_hash).map(|s| s.into_bytes())
}

fn get_block_context() -> blockifier::context::BlockContext {
Starknet::get_block_context()
}
}

impl pallet_starknet_runtime_api::ConvertTransactionRuntimeApi<Block> for Runtime {
Expand Down
5 changes: 0 additions & 5 deletions crates/runtime/src/pallets.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! 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.
use std::num::NonZeroU128;

use blockifier::blockifier::block::GasPrices;
pub use frame_support::traits::{
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, OnTimestampSet, Randomness, StorageInfo,
};
Expand Down Expand Up @@ -52,7 +49,6 @@ impl pallet_starknet::Config for Runtime {
type ChainId = ChainId;
type MaxRecursionDepth = MaxRecursionDepth;
type ProgramHash = ProgramHash;
type L1GasPrices = L1GasPrices;
}

/// --------------------------------------
Expand Down Expand Up @@ -168,7 +164,6 @@ parameter_types! {
pub const ChainId: Felt252Wrapper = mp_chain_id::SN_MAIN_CHAIN_ID;
pub const MaxRecursionDepth: u32 = 50;
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) } };
}

/// Implement the OnTimestampSet trait to override the default Aura.
Expand Down

0 comments on commit 900718f

Please sign in to comment.