From aa643b04870cdece0056ba45269749921169286d Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 22 Jan 2024 15:17:48 +0100 Subject: [PATCH 01/21] feat: CachedBlockifierStateAdapter --- crates/client/rpc/src/trace_api.rs | 14 ++-- .../pallets/starknet/runtime_api/src/lib.rs | 3 +- .../starknet/src/blockifier_state_adapter.rs | 71 ++++++++++++++++++- crates/pallets/starknet/src/lib.rs | 10 +-- crates/pallets/starknet/src/utils.rs | 26 +++++-- crates/runtime/src/lib.rs | 3 +- 6 files changed, 108 insertions(+), 19 deletions(-) diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index 92c636dff3..33c3bcc8c0 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -1,4 +1,5 @@ use blockifier::execution::entry_point::CallInfo; +use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::transaction::errors::TransactionExecutionError; use blockifier::transaction::objects::TransactionExecutionInfo; use jsonrpsee::core::{async_trait, RpcResult}; @@ -213,12 +214,13 @@ fn tx_execution_infos_to_simulated_transactions( storage_override: &dyn StorageOverride, substrate_block_hash: B::Hash, tx_types: Vec, - transaction_execution_results: Vec< + transaction_execution_results: Vec<( Result, - >, + CommitmentStateDiff, + )>, ) -> Result, ConvertCallInfoToExecuteInvocationError> { let mut results = vec![]; - for (tx_type, res) in tx_types.iter().zip(transaction_execution_results.iter()) { + for (tx_type, (res, state_diff)) in tx_types.iter().zip(transaction_execution_results.iter()) { match res { Ok(tx_exec_info) => { // If simulated with `SimulationFlag::SkipValidate` this will be `None` @@ -255,13 +257,13 @@ fn tx_execution_infos_to_simulated_transactions( }, fee_transfer_invocation, // TODO(#1291): Compute state diff correctly - state_diff: None, + state_diff, }), TxType::Declare => TransactionTrace::Declare(DeclareTransactionTrace { validate_invocation, fee_transfer_invocation, // TODO(#1291): Compute state diff correctly - state_diff: None, + state_diff, }), TxType::DeployAccount => { TransactionTrace::DeployAccount(DeployAccountTransactionTrace { @@ -274,7 +276,7 @@ fn tx_execution_infos_to_simulated_transactions( )?, fee_transfer_invocation, // TODO(#1291): Compute state diff correctly - state_diff: None, + state_diff, }) } TxType::L1Handler => unreachable!("L1Handler transactions cannot be simulated"), diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index 42fead4730..5db63994b8 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -9,6 +9,7 @@ use alloc::sync::Arc; use blockifier::execution::contract_class::ContractClass; +use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::transaction::objects::TransactionExecutionInfo; use mp_felt::Felt252Wrapper; use mp_transactions::{HandleL1MessageTransaction, Transaction, UserTransaction}; @@ -57,7 +58,7 @@ sp_api::decl_runtime_apis! { /// Returns fee estimate fn estimate_fee(transactions: Vec) -> Result, DispatchError>; /// Simulates transactions and returns their trace - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result>, DispatchError>; + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, CommitmentStateDiff)>, DispatchError>; /// Filters extrinsic transactions to return only Starknet transactions /// /// To support runtime upgrades, the client must be unaware of the specific extrinsic diff --git a/crates/pallets/starknet/src/blockifier_state_adapter.rs b/crates/pallets/starknet/src/blockifier_state_adapter.rs index 83f247202e..72f2c6e7fc 100644 --- a/crates/pallets/starknet/src/blockifier_state_adapter.rs +++ b/crates/pallets/starknet/src/blockifier_state_adapter.rs @@ -2,7 +2,7 @@ use alloc::collections::{BTreeMap, BTreeSet}; use core::marker::PhantomData; use blockifier::execution::contract_class::ContractClass; -use blockifier::state::cached_state::{CommitmentStateDiff, ContractStorageKey, StateChangesCount}; +use blockifier::state::cached_state::{CachedState, CommitmentStateDiff, ContractStorageKey, StateChangesCount}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{State, StateReader, StateResult}; use indexmap::IndexMap; @@ -133,3 +133,72 @@ impl State for BlockifierStateAdapter { } } } + +pub struct CachedBlockifierStateAdapter(pub CachedState>); + +impl StateChanges for CachedBlockifierStateAdapter +where + T: Config, +{ + fn count_state_changes(&self) -> StateChangesCount { + self.0.state.count_state_changes() + } +} + +impl State for CachedBlockifierStateAdapter +where + T: Config, +{ + fn set_storage_at(&mut self, contract_address: ContractAddress, key: StorageKey, value: StarkFelt) { + self.0.set_storage_at(contract_address, key, value); + } + + fn increment_nonce(&mut self, contract_address: ContractAddress) -> StateResult<()> { + self.0.increment_nonce(contract_address) + } + + fn set_class_hash_at(&mut self, contract_address: ContractAddress, class_hash: ClassHash) -> StateResult<()> { + self.0.set_class_hash_at(contract_address, class_hash) + } + + fn set_contract_class(&mut self, class_hash: &ClassHash, contract_class: ContractClass) -> StateResult<()> { + self.0.set_contract_class(class_hash, contract_class) + } + + fn set_compiled_class_hash( + &mut self, + class_hash: ClassHash, + compiled_class_hash: CompiledClassHash, + ) -> StateResult<()> { + self.0.set_compiled_class_hash(class_hash, compiled_class_hash) + } + + fn to_state_diff(&self) -> CommitmentStateDiff { + self.0.to_state_diff() + } +} + +impl StateReader for CachedBlockifierStateAdapter +where + T: Config, +{ + fn get_storage_at(&mut self, contract_address: ContractAddress, key: StorageKey) -> StateResult { + self.0.get_storage_at(contract_address, key) + } + + fn get_nonce_at(&mut self, contract_address: ContractAddress) -> StateResult { + self.0.get_nonce_at(contract_address) + } + + fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { + self.0.get_class_hash_at(contract_address) + } + + fn get_compiled_contract_class(&mut self, class_hash: &ClassHash) -> StateResult { + self.0.get_compiled_contract_class(class_hash) + } + + fn get_compiled_class_hash(&mut self, class_hash: ClassHash) -> StateResult { + self.0.get_compiled_class_hash(class_hash) + } +} diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index 8c8eee27d8..a271a42145 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -69,7 +69,7 @@ use blockifier::execution::entry_point::{ CallEntryPoint, CallInfo, CallType, EntryPointExecutionContext, ExecutionResources, }; use blockifier::execution::errors::{EntryPointExecutionError, PreExecutionError}; -use blockifier::state::cached_state::ContractStorageKey; +use blockifier::state::cached_state::{CommitmentStateDiff, ContractStorageKey}; use blockifier::transaction::objects::TransactionExecutionInfo; use blockifier_state_adapter::BlockifierStateAdapter; use frame_support::pallet_prelude::*; @@ -1087,7 +1087,7 @@ impl Pallet { )?; let mut results = vec![]; - for res in execution_results { + for (res, _) in execution_results { match res { Ok(tx_exec_info) => { log!(info, "Successfully estimated fee: {:?}", tx_exec_info); @@ -1109,8 +1109,10 @@ impl Pallet { pub fn simulate_transactions( transactions: Vec, simulation_flags: SimulationFlags, - ) -> Result>, DispatchError> - { + ) -> Result< + Vec<(Result, CommitmentStateDiff)>, + DispatchError, + > { let chain_id = Self::chain_id(); let tx_execution_results = execute_txs_and_rollback::( diff --git a/crates/pallets/starknet/src/utils.rs b/crates/pallets/starknet/src/utils.rs index fba4a0a4aa..0bae8668cb 100644 --- a/crates/pallets/starknet/src/utils.rs +++ b/crates/pallets/starknet/src/utils.rs @@ -1,6 +1,8 @@ use alloc::vec::Vec; use blockifier::block_context::BlockContext; +use blockifier::state::cached_state::{CachedState, CommitmentStateDiff}; +use blockifier::state::state_api::State; use blockifier::transaction::objects::TransactionExecutionInfo; use frame_support::storage; use mp_felt::Felt252Wrapper; @@ -9,7 +11,7 @@ use mp_transactions::execution::{Execute, ExecutionConfig}; use mp_transactions::UserTransaction; use sp_runtime::DispatchError; -use crate::blockifier_state_adapter::BlockifierStateAdapter; +use crate::blockifier_state_adapter::{BlockifierStateAdapter, CachedBlockifierStateAdapter}; use crate::{pallet, Error}; pub fn execute_txs_and_rollback( @@ -17,30 +19,42 @@ pub fn execute_txs_and_rollback( block_context: &BlockContext, chain_id: Felt252Wrapper, execution_config: &mut ExecutionConfig, -) -> Result>, Error> { +) -> Result< + Vec<(Result, CommitmentStateDiff)>, + Error, +> { let mut execution_results = vec![]; storage::transactional::with_transaction(|| { for tx in txs { execution_config.set_offset_version(tx.offset_version()); + let mut cached_state = + CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); let result = match tx { UserTransaction::Declare(tx, contract_class) => tx .try_into_executable::(chain_id, contract_class.clone(), tx.offset_version()) .and_then(|exec| { - exec.execute(&mut BlockifierStateAdapter::::default(), block_context, execution_config) + let execution_result = exec.execute(&mut cached_state, block_context, execution_config); + execution_result }), UserTransaction::DeployAccount(tx) => { let executable = tx.into_executable::(chain_id, tx.offset_version()); - executable.execute(&mut BlockifierStateAdapter::::default(), block_context, execution_config) + let mut cached_state = + CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); + let execution_result = executable.execute(&mut cached_state, block_context, execution_config); + execution_result } UserTransaction::Invoke(tx) => { let executable = tx.into_executable::(chain_id, tx.offset_version()); - executable.execute(&mut BlockifierStateAdapter::::default(), block_context, execution_config) + let mut cached_state = + CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); + let execution_result = executable.execute(&mut cached_state, block_context, execution_config); + execution_result } } .map_err(|_| PlaceHolderErrorTypeForFailedStarknetExecution); - execution_results.push(result); + execution_results.push((result, cached_state.to_state_diff())); } storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(())) }) diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 4b0afd2216..90d39d2309 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -18,6 +18,7 @@ mod runtime_tests; mod types; use blockifier::execution::contract_class::ContractClass; +use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::transaction::objects::TransactionExecutionInfo; pub use config::*; pub use frame_support::traits::{ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo}; @@ -280,7 +281,7 @@ impl_runtime_apis! { Starknet::estimate_fee(transactions) } - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result>, DispatchError> { + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, CommitmentStateDiff)>, DispatchError> { Starknet::simulate_transactions(transactions, simulation_flags) } From ad77ea6547703f2c95114ac97c6506a430dcfd7b Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 22 Jan 2024 16:04:23 +0100 Subject: [PATCH 02/21] feat: to_rpc_state_diff --- crates/client/rpc-core/src/utils.rs | 54 +++++++++++++++++++++++++++-- crates/client/rpc/src/trace_api.rs | 3 ++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/crates/client/rpc-core/src/utils.rs b/crates/client/rpc-core/src/utils.rs index 9e27dea176..356821c2e1 100644 --- a/crates/client/rpc-core/src/utils.rs +++ b/crates/client/rpc-core/src/utils.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use anyhow::{anyhow, Result}; use blockifier::execution::contract_class::ContractClass as BlockifierContractClass; +use blockifier::state::cached_state::CommitmentStateDiff; use cairo_lang_casm_contract_class::{CasmContractClass, CasmContractEntryPoint, CasmContractEntryPoints}; use cairo_lang_starknet::contract_class::{ ContractClass as SierraContractClass, ContractEntryPoint, ContractEntryPoints, @@ -18,8 +19,9 @@ use sp_blockchain::HeaderBackend; use starknet_api::deprecated_contract_class::{EntryPoint, EntryPointType}; use starknet_core::types::contract::{CompiledClass, CompiledClassEntrypoint, CompiledClassEntrypointList}; use starknet_core::types::{ - CompressedLegacyContractClass, ContractClass, EntryPointsByType, FieldElement, FlattenedSierraClass, - FromByteArrayError, LegacyContractEntryPoint, LegacyEntryPointsByType, SierraEntryPoint, + CompressedLegacyContractClass, ContractClass, ContractStorageDiffItem, DeclaredClassItem, DeployedContractItem, + EntryPointsByType, FieldElement, FlattenedSierraClass, FromByteArrayError, LegacyContractEntryPoint, + LegacyEntryPointsByType, NonceUpdate, SierraEntryPoint, StateDiff, StorageEntry, }; /// Returns a [`ContractClass`] from a [`BlockifierContractClass`] @@ -44,6 +46,54 @@ pub fn to_rpc_contract_class(contract_class: BlockifierContractClass) -> Result< } } +/// Returns a [`StateDiff`] from a [`CommitmentStateDiff`] +pub fn to_rpc_state_diff(commitment_state_diff: CommitmentStateDiff) -> Result { + let storage_diffs: Vec = commitment_state_diff + .storage_updates + .into_iter() + .map(|(address, storage_map)| { + let storage_entries = storage_map + .into_iter() + .map(|(key, value)| StorageEntry { key: key.0.0.into(), value: value.into() }) + .collect(); + ContractStorageDiffItem { address: address.0.0.into(), storage_entries } + }) + .collect(); + + let declared_classes = commitment_state_diff + .class_hash_to_compiled_class_hash + .into_iter() + .map(|(class_hash, compiled_class_hash)| DeclaredClassItem { + class_hash: class_hash.0.into(), + compiled_class_hash: compiled_class_hash.0.into(), + }) + .collect(); + + let deployed_contracts = commitment_state_diff + .address_to_class_hash + .into_iter() + .map(|(address, class_hash)| DeployedContractItem { + address: address.0.0.into(), + class_hash: class_hash.0.into(), + }) + .collect(); + + let nonces = commitment_state_diff + .address_to_nonce + .into_iter() + .map(|(address, nonce)| NonceUpdate { contract_address: address.0.0.into(), nonce: nonce.0.into() }) + .collect(); + + Ok(StateDiff { + storage_diffs, + deprecated_declared_classes: vec![], + declared_classes, + deployed_contracts, + replaced_classes: vec![], + nonces, + }) +} + /// Returns a compressed vector of bytes pub(crate) fn compress(data: &[u8]) -> Result> { let mut gzip_encoder = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::fast()); diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index 33c3bcc8c0..f8473ea8c1 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -5,6 +5,7 @@ use blockifier::transaction::objects::TransactionExecutionInfo; use jsonrpsee::core::{async_trait, RpcResult}; use log::error; use mc_genesis_data_provider::GenesisProvider; +use mc_rpc_core::utils::to_rpc_state_diff; use mc_rpc_core::{StarknetReadRpcApiServer, StarknetTraceRpcApiServer}; use mc_storage::StorageOverride; use mp_felt::Felt252Wrapper; @@ -242,6 +243,8 @@ fn tx_execution_infos_to_simulated_transactions( }) .transpose()?; + let state_diff = to_rpc_state_diff(state_diff)?; + let transaction_trace = match tx_type { TxType::Invoke => TransactionTrace::Invoke(InvokeTransactionTrace { validate_invocation, From 37643d51e1b589dabc1033ae1200db31620b175e Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 22 Jan 2024 16:08:25 +0100 Subject: [PATCH 03/21] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22b5656668..143baf02ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Next release +- feat(rpc): added state diff real value in trace api - refactor: rename LAST_SYNCED_L1_BLOCK to be more clear - chore: add headers to da calldata, fix eth da in sovereign mode - refacto(simulate_tx): move logic to the client From 8d107aae6c5dd192da26131bbfd0fe1e34bc245c Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Tue, 23 Jan 2024 00:12:04 +0100 Subject: [PATCH 04/21] fix: address review comments --- crates/client/rpc-core/src/utils.rs | 4 +-- crates/client/rpc/src/lib.rs | 4 +-- crates/client/rpc/src/trace_api.rs | 8 +++--- .../pallets/starknet/runtime_api/src/lib.rs | 2 +- crates/pallets/starknet/src/lib.rs | 7 ++++- crates/pallets/starknet/src/utils.rs | 26 ++++++++++++++----- crates/runtime/src/lib.rs | 2 +- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/crates/client/rpc-core/src/utils.rs b/crates/client/rpc-core/src/utils.rs index 356821c2e1..a023846e56 100644 --- a/crates/client/rpc-core/src/utils.rs +++ b/crates/client/rpc-core/src/utils.rs @@ -25,7 +25,7 @@ use starknet_core::types::{ }; /// Returns a [`ContractClass`] from a [`BlockifierContractClass`] -pub fn to_rpc_contract_class(contract_class: BlockifierContractClass) -> Result { +pub fn blockifier_to_rpc_contract_class_types(contract_class: BlockifierContractClass) -> Result { match contract_class { BlockifierContractClass::V0(contract_class) => { let entry_points_by_type = to_legacy_entry_points_by_type(&contract_class.entry_points_by_type)?; @@ -47,7 +47,7 @@ pub fn to_rpc_contract_class(contract_class: BlockifierContractClass) -> Result< } /// Returns a [`StateDiff`] from a [`CommitmentStateDiff`] -pub fn to_rpc_state_diff(commitment_state_diff: CommitmentStateDiff) -> Result { +pub fn blockifier_to_rpc_state_diff_types(commitment_state_diff: CommitmentStateDiff) -> Result { let storage_diffs: Vec = commitment_state_diff .storage_updates .into_iter() diff --git a/crates/client/rpc/src/lib.rs b/crates/client/rpc/src/lib.rs index b791105fb3..69cb654643 100644 --- a/crates/client/rpc/src/lib.rs +++ b/crates/client/rpc/src/lib.rs @@ -666,7 +666,7 @@ where StarknetRpcApiError::ContractNotFound })?; - Ok(to_rpc_contract_class(contract_class).map_err(|e| { + Ok(blockifier_to_rpc_contract_class_types(contract_class).map_err(|e| { error!("Failed to convert contract class at '{contract_address}' to RPC contract class: {e}"); StarknetRpcApiError::InvalidContractClass })?) @@ -804,7 +804,7 @@ where StarknetRpcApiError::ClassHashNotFound })?; - Ok(to_rpc_contract_class(contract_class).map_err(|e| { + Ok(blockifier_to_rpc_contract_class_types(contract_class).map_err(|e| { error!("Failed to convert contract class from hash '{class_hash}' to RPC contract class: {e}"); StarknetRpcApiError::InternalServerError })?) diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index f8473ea8c1..281f91909b 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -5,7 +5,7 @@ use blockifier::transaction::objects::TransactionExecutionInfo; use jsonrpsee::core::{async_trait, RpcResult}; use log::error; use mc_genesis_data_provider::GenesisProvider; -use mc_rpc_core::utils::to_rpc_state_diff; +use mc_rpc_core::utils::blockifier_to_rpc_state_diff_types; use mc_rpc_core::{StarknetReadRpcApiServer, StarknetTraceRpcApiServer}; use mc_storage::StorageOverride; use mp_felt::Felt252Wrapper; @@ -217,7 +217,7 @@ fn tx_execution_infos_to_simulated_transactions( tx_types: Vec, transaction_execution_results: Vec<( Result, - CommitmentStateDiff, + Option, )>, ) -> Result, ConvertCallInfoToExecuteInvocationError> { let mut results = vec![]; @@ -243,7 +243,7 @@ fn tx_execution_infos_to_simulated_transactions( }) .transpose()?; - let state_diff = to_rpc_state_diff(state_diff)?; + let state_diff = state_diff.map(blockifier_to_rpc_state_diff_types).transpose()?; let transaction_trace = match tx_type { TxType::Invoke => TransactionTrace::Invoke(InvokeTransactionTrace { @@ -259,13 +259,11 @@ fn tx_execution_infos_to_simulated_transactions( )?) }, fee_transfer_invocation, - // TODO(#1291): Compute state diff correctly state_diff, }), TxType::Declare => TransactionTrace::Declare(DeclareTransactionTrace { validate_invocation, fee_transfer_invocation, - // TODO(#1291): Compute state diff correctly state_diff, }), TxType::DeployAccount => { diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index 5db63994b8..eebade5ca4 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -58,7 +58,7 @@ sp_api::decl_runtime_apis! { /// Returns fee estimate fn estimate_fee(transactions: Vec) -> Result, DispatchError>; /// Simulates transactions and returns their trace - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, CommitmentStateDiff)>, DispatchError>; + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, Option)>, DispatchError>; /// Filters extrinsic transactions to return only Starknet transactions /// /// To support runtime upgrades, the client must be unaware of the specific extrinsic diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index a271a42145..7ceb3edea4 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -1084,6 +1084,7 @@ impl Pallet { &Self::get_block_context(), chain_id, &mut RuntimeExecutionConfigBuilder::new::().with_query_mode().build(), + false, )?; let mut results = vec![]; @@ -1110,7 +1111,10 @@ impl Pallet { transactions: Vec, simulation_flags: SimulationFlags, ) -> Result< - Vec<(Result, CommitmentStateDiff)>, + Vec<( + Result, + Option, + )>, DispatchError, > { let chain_id = Self::chain_id(); @@ -1120,6 +1124,7 @@ impl Pallet { &Self::get_block_context(), chain_id, &mut RuntimeExecutionConfigBuilder::new::().with_simulation_mode(&simulation_flags).build(), + true, )?; Ok(tx_execution_results) diff --git a/crates/pallets/starknet/src/utils.rs b/crates/pallets/starknet/src/utils.rs index 0bae8668cb..030ae63c0a 100644 --- a/crates/pallets/starknet/src/utils.rs +++ b/crates/pallets/starknet/src/utils.rs @@ -14,13 +14,30 @@ use sp_runtime::DispatchError; use crate::blockifier_state_adapter::{BlockifierStateAdapter, CachedBlockifierStateAdapter}; use crate::{pallet, Error}; +/// Executes the given transactions and rolls back the state. +/// +/// # Arguments +/// +/// * `txs` - The transactions to execute. +/// * `block_context` - The block context. +/// * `chain_id` - The chain id. +/// * `execution_config` - The execution config. +/// * `with_state_diff` - Whether to return the state diff. +/// +/// # Returns +/// +/// A vector of execution results and state diffs if `with_state_diff` is true else None. pub fn execute_txs_and_rollback( txs: &Vec, block_context: &BlockContext, chain_id: Felt252Wrapper, execution_config: &mut ExecutionConfig, + with_state_diff: bool, ) -> Result< - Vec<(Result, CommitmentStateDiff)>, + Vec<( + Result, + Option, + )>, Error, > { let mut execution_results = vec![]; @@ -39,22 +56,19 @@ pub fn execute_txs_and_rollback( }), UserTransaction::DeployAccount(tx) => { let executable = tx.into_executable::(chain_id, tx.offset_version()); - let mut cached_state = - CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); let execution_result = executable.execute(&mut cached_state, block_context, execution_config); execution_result } UserTransaction::Invoke(tx) => { let executable = tx.into_executable::(chain_id, tx.offset_version()); - let mut cached_state = - CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); let execution_result = executable.execute(&mut cached_state, block_context, execution_config); execution_result } } .map_err(|_| PlaceHolderErrorTypeForFailedStarknetExecution); - execution_results.push((result, cached_state.to_state_diff())); + let state_diff = if with_state_diff { Some(cached_state.to_state_diff()) } else { None }; + execution_results.push((result, state_diff)); } storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(())) }) diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 90d39d2309..60ad565270 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -281,7 +281,7 @@ impl_runtime_apis! { Starknet::estimate_fee(transactions) } - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, CommitmentStateDiff)>, DispatchError> { + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, Option)>, DispatchError> { Starknet::simulate_transactions(transactions, simulation_flags) } From 1e6d3fec89f00981b9355502893f5e404d7f40fb Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 24 Jan 2024 01:45:58 +0100 Subject: [PATCH 05/21] fix: refactor with new function --- crates/client/rpc/src/trace_api.rs | 11 +-- .../pallets/starknet/runtime_api/src/lib.rs | 2 +- crates/pallets/starknet/src/lib.rs | 20 ++--- crates/pallets/starknet/src/types.rs | 4 + crates/pallets/starknet/src/utils.rs | 80 ++++++++++++++----- crates/runtime/src/lib.rs | 2 +- 6 files changed, 75 insertions(+), 44 deletions(-) diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index 281f91909b..c615e6ad8c 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -217,7 +217,7 @@ fn tx_execution_infos_to_simulated_transactions( tx_types: Vec, transaction_execution_results: Vec<( Result, - Option, + CommitmentStateDiff, )>, ) -> Result, ConvertCallInfoToExecuteInvocationError> { let mut results = vec![]; @@ -243,8 +243,6 @@ fn tx_execution_infos_to_simulated_transactions( }) .transpose()?; - let state_diff = state_diff.map(blockifier_to_rpc_state_diff_types).transpose()?; - let transaction_trace = match tx_type { TxType::Invoke => TransactionTrace::Invoke(InvokeTransactionTrace { validate_invocation, @@ -259,12 +257,12 @@ fn tx_execution_infos_to_simulated_transactions( )?) }, fee_transfer_invocation, - state_diff, + state_diff: Some(state_diff), }), TxType::Declare => TransactionTrace::Declare(DeclareTransactionTrace { validate_invocation, fee_transfer_invocation, - state_diff, + state_diff: Some(state_diff), }), TxType::DeployAccount => { TransactionTrace::DeployAccount(DeployAccountTransactionTrace { @@ -276,8 +274,7 @@ fn tx_execution_infos_to_simulated_transactions( tx_exec_info.execute_call_info.as_ref().unwrap(), )?, fee_transfer_invocation, - // TODO(#1291): Compute state diff correctly - state_diff, + state_diff: Some(state_diff), }) } TxType::L1Handler => unreachable!("L1Handler transactions cannot be simulated"), diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index eebade5ca4..5db63994b8 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -58,7 +58,7 @@ sp_api::decl_runtime_apis! { /// Returns fee estimate fn estimate_fee(transactions: Vec) -> Result, DispatchError>; /// Simulates transactions and returns their trace - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, Option)>, DispatchError>; + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, CommitmentStateDiff)>, DispatchError>; /// Filters extrinsic transactions to return only Starknet transactions /// /// To support runtime upgrades, the client must be unaware of the specific extrinsic diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index ad2fcc8d93..2b9cf7abd1 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -70,7 +70,6 @@ use blockifier::execution::entry_point::{ }; use blockifier::execution::errors::{EntryPointExecutionError, PreExecutionError}; use blockifier::state::cached_state::{CommitmentStateDiff, ContractStorageKey}; -use blockifier::transaction::objects::TransactionExecutionInfo; use blockifier_state_adapter::BlockifierStateAdapter; use frame_support::pallet_prelude::*; use frame_support::traits::Time; @@ -81,7 +80,7 @@ use mp_fee::{ResourcePrice, INITIAL_GAS}; use mp_felt::Felt252Wrapper; use mp_hashers::HasherT; use mp_sequencer_address::{InherentError, InherentType, DEFAULT_SEQUENCER_ADDRESS, INHERENT_IDENTIFIER}; -use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; +use mp_simulations::SimulationFlags; use mp_storage::{StarknetStorageSchemaVersion, PALLET_STARKNET_SCHEMA}; use mp_transactions::execution::Execute; use mp_transactions::{ @@ -98,10 +97,11 @@ use starknet_api::state::StorageKey; use starknet_api::transaction::{Calldata, Event as StarknetEvent, Fee, MessageToL1, TransactionHash}; use starknet_crypto::FieldElement; use transaction_validation::TxPriorityInfo; +use utils::execute_txs_and_rollback_with_state_diff; use crate::alloc::string::ToString; use crate::execution_config::RuntimeExecutionConfigBuilder; -use crate::types::{CasmClassHash, SierraClassHash, StorageSlot}; +use crate::types::{CasmClassHash, SierraClassHash, StorageSlot, TransactionSimulationResult}; use crate::utils::execute_txs_and_rollback; pub(crate) const LOG_TARGET: &str = "runtime::starknet"; @@ -1084,11 +1084,10 @@ impl Pallet { &Self::get_block_context(), chain_id, &mut RuntimeExecutionConfigBuilder::new::().with_query_mode().build(), - false, )?; let mut results = vec![]; - for (res, _) in execution_results { + for res in execution_results { match res { Ok(tx_exec_info) => { log!(info, "Successfully estimated fee: {:?}", tx_exec_info); @@ -1110,21 +1109,14 @@ impl Pallet { pub fn simulate_transactions( transactions: Vec, simulation_flags: SimulationFlags, - ) -> Result< - Vec<( - Result, - Option, - )>, - DispatchError, - > { + ) -> Result, DispatchError> { let chain_id = Self::chain_id(); - let tx_execution_results = execute_txs_and_rollback::( + let tx_execution_results = execute_txs_and_rollback_with_state_diff::( &transactions, &Self::get_block_context(), chain_id, &mut RuntimeExecutionConfigBuilder::new::().with_simulation_mode(&simulation_flags).build(), - true, )?; Ok(tx_execution_results) diff --git a/crates/pallets/starknet/src/types.rs b/crates/pallets/starknet/src/types.rs index 719aa3de19..41c59ae5de 100644 --- a/crates/pallets/starknet/src/types.rs +++ b/crates/pallets/starknet/src/types.rs @@ -1,6 +1,8 @@ //! Starknet pallet custom types. use blockifier::execution::contract_class::ContractClass; +use blockifier::transaction::objects::TransactionExecutionInfo; use mp_felt::Felt252Wrapper; +use mp_simulations::PlaceHolderErrorTypeForFailedStarknetExecution; use sp_core::ConstU32; use sp_std::vec::Vec; use starknet_api::api_core::{ClassHash, ContractAddress}; @@ -22,6 +24,8 @@ pub type StorageSlot = (StorageKey, Felt252Wrapper); pub type CasmClassHash = ClassHash; pub type SierraClassHash = ClassHash; +pub type TransactionSimulationResult = Result; + /// Declare Transaction Output #[derive(Clone, Debug, PartialEq, Eq, parity_scale_codec::Encode, parity_scale_codec::Decode, scale_info::TypeInfo)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/pallets/starknet/src/utils.rs b/crates/pallets/starknet/src/utils.rs index 26808bde8d..dbc3078e11 100644 --- a/crates/pallets/starknet/src/utils.rs +++ b/crates/pallets/starknet/src/utils.rs @@ -3,7 +3,6 @@ use alloc::vec::Vec; use blockifier::block_context::BlockContext; use blockifier::state::cached_state::{CachedState, CommitmentStateDiff}; use blockifier::state::state_api::State; -use blockifier::transaction::objects::TransactionExecutionInfo; use frame_support::storage; use mp_felt::Felt252Wrapper; use mp_simulations::PlaceHolderErrorTypeForFailedStarknetExecution; @@ -12,6 +11,7 @@ use mp_transactions::UserTransaction; use sp_runtime::DispatchError; use crate::blockifier_state_adapter::{BlockifierStateAdapter, CachedBlockifierStateAdapter}; +use crate::types::TransactionSimulationResult; use crate::{pallet, Error}; /// Executes the given transactions and rolls back the state. @@ -22,24 +22,16 @@ use crate::{pallet, Error}; /// * `block_context` - The block context. /// * `chain_id` - The chain id. /// * `execution_config` - The execution config. -/// * `with_state_diff` - Whether to return the state diff. /// /// # Returns /// -/// A vector of execution results and state diffs if `with_state_diff` is true else None. -pub fn execute_txs_and_rollback( +/// A vector of execution results and the generated state diff. +pub fn execute_txs_and_rollback_with_state_diff( txs: &Vec, block_context: &BlockContext, chain_id: Felt252Wrapper, execution_config: &mut ExecutionConfig, - with_state_diff: bool, -) -> Result< - Vec<( - Result, - Option, - )>, - Error, -> { +) -> Result, Error> { let mut execution_results = vec![]; storage::transactional::with_transaction(|| { @@ -50,19 +42,14 @@ pub fn execute_txs_and_rollback( let result = match tx { UserTransaction::Declare(tx, contract_class) => tx .try_into_executable::(chain_id, contract_class.clone(), tx.offset_version()) - .and_then(|exec| { - let execution_result = exec.execute(&mut cached_state, block_context, execution_config); - execution_result - }), + .and_then(|exec| exec.execute(&mut cached_state, block_context, execution_config)), UserTransaction::DeployAccount(tx) => { let executable = tx.into_executable::(chain_id, tx.offset_version()); - let execution_result = executable.execute(&mut cached_state, block_context, execution_config); - execution_result + executable.execute(&mut cached_state, block_context, execution_config) } UserTransaction::Invoke(tx) => { let executable = tx.into_executable::(chain_id, tx.offset_version()); - let execution_result = executable.execute(&mut cached_state, block_context, execution_config); - execution_result + executable.execute(&mut cached_state, block_context, execution_config) } } .map_err(|e| { @@ -70,7 +57,7 @@ pub fn execute_txs_and_rollback( PlaceHolderErrorTypeForFailedStarknetExecution }); - let state_diff = if with_state_diff { Some(cached_state.to_state_diff()) } else { None }; + let state_diff = cached_state.to_state_diff(); execution_results.push((result, state_diff)); } storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(())) @@ -79,3 +66,54 @@ pub fn execute_txs_and_rollback( Ok(execution_results) } + +/// Executes the given transactions and rolls back the state. +/// +/// # Arguments +/// +/// * `txs` - The transactions to execute. +/// * `block_context` - The block context. +/// * `chain_id` - The chain id. +/// * `execution_config` - The execution config. +/// +/// # Returns +/// +/// A vector of execution results. +pub fn execute_txs_and_rollback( + txs: &Vec, + block_context: &BlockContext, + chain_id: Felt252Wrapper, + execution_config: &mut ExecutionConfig, +) -> Result, Error> { + let mut execution_results = vec![]; + + storage::transactional::with_transaction(|| { + for tx in txs { + execution_config.set_offset_version(tx.offset_version()); + let mut state = BlockifierStateAdapter::::default(); + let result = match tx { + UserTransaction::Declare(tx, contract_class) => tx + .try_into_executable::(chain_id, contract_class.clone(), tx.offset_version()) + .and_then(|exec| exec.execute(&mut state, block_context, execution_config)), + UserTransaction::DeployAccount(tx) => { + let executable = tx.into_executable::(chain_id, tx.offset_version()); + executable.execute(&mut state, block_context, execution_config) + } + UserTransaction::Invoke(tx) => { + let executable = tx.into_executable::(chain_id, tx.offset_version()); + executable.execute(&mut state, block_context, execution_config) + } + } + .map_err(|e| { + log::info!("Failed to execute transaction: {:?}", e); + PlaceHolderErrorTypeForFailedStarknetExecution + }); + + execution_results.push(result); + } + storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(())) + }) + .map_err(|_| Error::::FailedToCreateATransactionalStorageExecution)?; + + Ok(execution_results) +} diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 60ad565270..1c7ceb7f32 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -281,7 +281,7 @@ impl_runtime_apis! { Starknet::estimate_fee(transactions) } - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, Option)>, DispatchError> { + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result)>, DispatchError> { Starknet::simulate_transactions(transactions, simulation_flags) } From d6907b85217f3bafa21331ce30df25f1ee728ce1 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 24 Jan 2024 18:02:52 +0100 Subject: [PATCH 06/21] fix: cargo update --- Cargo.lock | 443 +++++++++++++++-------------- crates/client/rpc/src/trace_api.rs | 8 +- crates/runtime/src/lib.rs | 6 +- 3 files changed, 231 insertions(+), 226 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8dceb33e69..771f16880c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", "once_cell", "version_check", ] @@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", - "getrandom 0.2.11", + "getrandom 0.2.12", "once_cell", "version_check", "zerocopy", @@ -146,9 +146,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.5" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -581,18 +581,18 @@ dependencies = [ [[package]] name = "async-io" -version = "2.2.2" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6afaa937395a620e33dc6a742c593c01aced20aa376ffb0f628121198578ccc7" +checksum = "fb41eb19024a91746eba0773aa5e16036045bbf45733766661099e182ea6a744" dependencies = [ - "async-lock 3.2.0", + "async-lock 3.3.0", "cfg-if", "concurrent-queue", "futures-io", "futures-lite", "parking", "polling", - "rustix 0.38.28", + "rustix 0.38.30", "slab", "tracing", "windows-sys 0.52.0", @@ -609,11 +609,11 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c" +checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" dependencies = [ - "event-listener 4.0.2", + "event-listener 4.0.3", "event-listener-strategy", "pin-project-lite 0.2.13", ] @@ -767,9 +767,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" @@ -865,9 +865,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "bitvec" @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.1.0-rc2" -source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#48638f2bf136af194be9e645559032b6627c77bc" +source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#85b4d15788eac61aa8af8ba21ac302657c78d014" dependencies = [ "ark-ff 0.4.2", "ark-secp256k1", @@ -1726,7 +1726,7 @@ name = "celestia-types" version = "0.1.0" source = "git+https://github.com/eigerco/lumina?rev=ccc5b9bfeac632cccd32d35ecb7b7d51d71fbb87#ccc5b9bfeac632cccd32d35ecb7b7d51d71fbb87" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bech32", "blockstore", "bytes", @@ -1762,7 +1762,7 @@ version = "0.15.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6100bc57b6209840798d95cb2775684849d332f7bd788db2a8c8caf7ef82a41a" dependencies = [ - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -1813,9 +1813,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "41daef31d7a747c5c847246f36de49ced6f7403b4cdabc807a97b5cc184cda7a" dependencies = [ "android-tzdata", "iana-time-zone", @@ -1823,7 +1823,7 @@ dependencies = [ "num-traits 0.2.17", "serde", "wasm-bindgen", - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] @@ -1899,9 +1899,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.13" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52bdc885e4cacc7f7c9eedc1ef6da641603180c783c41a15c264944deeaab642" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", @@ -1909,9 +1909,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.12" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", @@ -1985,7 +1985,7 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bech32", "bs58 0.5.0", "digest 0.10.7", @@ -2058,15 +2058,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", "lazy_static", "libc", "unicode-width", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -2109,7 +2109,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", "once_cell", "tiny-keccak", ] @@ -2235,7 +2235,7 @@ dependencies = [ "hashbrown 0.13.2", "log", "regalloc2", - "smallvec 1.11.2", + "smallvec 1.13.1", "target-lexicon", ] @@ -2271,7 +2271,7 @@ checksum = "64a25d9d0a0ae3079c463c34115ec59507b4707175454f0eee0891e83e30e82d" dependencies = [ "cranelift-codegen", "log", - "smallvec 1.11.2", + "smallvec 1.13.1", "target-lexicon", ] @@ -2303,7 +2303,7 @@ dependencies = [ "cranelift-frontend", "itertools 0.10.5", "log", - "smallvec 1.11.2", + "smallvec 1.13.1", "wasmparser", "wasmtime-types", ] @@ -2319,34 +2319,28 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.17" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crunchy" @@ -2485,9 +2479,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed3a27153f220bb42b96005947ca3b87266cfdae5b4b4d703642c3a565e9708" +checksum = "8de00f15a6fa069c99b88c5c78c4541d0e7899a33b86f7480e23df2431fce0bc" dependencies = [ "cc", "cxxbridge-flags", @@ -2497,9 +2491,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "005721caedeb9869792e656d567695281c7e2bf2ac022d4ed95e5240b215f44d" +checksum = "0a71e1e631fa2f2f5f92e8b0d860a00c198c6771623a6cefcc863e3554f0d8d6" dependencies = [ "cc", "codespan-reporting", @@ -2512,15 +2506,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6981d27196cca89f82c8a89fd495cca25066d2933c974e907f7c3699801e112" +checksum = "6f3fed61d56ba497c4efef9144dfdbaa25aa58f2f6b3a7cf441d4591c583745c" [[package]] name = "cxxbridge-macro" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca7e7d41b675af76ee4844e8e4c1cec70b65555dbc4852eae7b11c9cd5525d60" +checksum = "8908e380a8efd42150c017b0cfa31509fc49b6d47f7cb6b33e93ffb8f4e3661e" dependencies = [ "proc-macro2", "quote", @@ -2533,8 +2527,8 @@ version = "0.1.0" dependencies = [ "anyhow", "assert_matches", - "async-lock 3.2.0", - "clap 4.4.13", + "async-lock 3.3.0", + "clap 4.4.18", "ethers", "flate2", "lazy_static", @@ -3074,7 +3068,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe81b5c06ecfdbc71dd845216f225f53b62a10cb8a16c946836a3467f701d05b" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bytes", "hex", "k256", @@ -3112,9 +3106,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ "humantime", "is-terminal", @@ -3311,7 +3305,7 @@ dependencies = [ "ethabi", "generic-array 0.14.7", "k256", - "num_enum 0.7.1", + "num_enum 0.7.2", "once_cell", "open-fastrlp", "rand 0.8.5", @@ -3374,7 +3368,7 @@ source = "git+https://github.com/gakonst/ethers-rs?rev=f0e5b194f09c533feb10d1a68 dependencies = [ "async-trait", "auto_impl", - "base64 0.21.5", + "base64 0.21.7", "bytes", "const-hex", "enr", @@ -3460,9 +3454,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "4.0.2" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "218a870470cce1469024e9fb66b901aa983929d81304a1cdb299f28118e550d5" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" dependencies = [ "concurrent-queue", "parking", @@ -3475,7 +3469,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ - "event-listener 4.0.2", + "event-listener 4.0.3", "pin-project-lite 0.2.13", ] @@ -3741,7 +3735,7 @@ dependencies = [ "Inflector", "array-bytes 6.2.2", "chrono", - "clap 4.4.13", + "clap 4.4.18", "comfy-table", "frame-benchmarking", "frame-support", @@ -3864,7 +3858,7 @@ dependencies = [ "scale-info", "serde", "serde_json", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-api", "sp-arithmetic 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-core 21.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", @@ -4056,9 +4050,9 @@ checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-lite" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeee267a1883f7ebef3700f262d2d54de95dfaf38189015a74fdc4e0c7ad8143" +checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" dependencies = [ "futures-core", "pin-project-lite 0.2.13", @@ -4153,7 +4147,7 @@ checksum = "98d7af598790738fee616426e669360fa361273b1b9c9b7f30c92fa627605cad" dependencies = [ "genco-macros", "relative-path", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -4210,9 +4204,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "js-sys", @@ -4263,7 +4257,7 @@ dependencies = [ "aho-corasick", "bstr", "log", - "regex-automata 0.4.3", + "regex-automata 0.4.4", "regex-syntax 0.8.2", ] @@ -4335,9 +4329,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.22" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" dependencies = [ "bytes", "fnv", @@ -4454,9 +4448,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" [[package]] name = "hex" @@ -4875,7 +4869,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi 0.3.4", "libc", "windows-sys 0.48.0", ] @@ -4910,8 +4904,8 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ - "hermit-abi 0.3.3", - "rustix 0.38.28", + "hermit-abi 0.3.4", + "rustix 0.38.30", "windows-sys 0.52.0", ] @@ -4959,9 +4953,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -5250,7 +5244,7 @@ version = "8.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "pem", "ring 0.16.20", "serde", @@ -5260,9 +5254,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.2" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f01b677d82ef7a676aa37e099defd83a28e15687112cafdd112d60236b6115b" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ "cfg-if", "ecdsa", @@ -5274,9 +5268,9 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" dependencies = [ "cpufeatures", ] @@ -5293,7 +5287,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d770dcb02bf6835887c3a979b5107a04ff4bbde97a5f0928d27404a155add9" dependencies = [ - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -5317,7 +5311,7 @@ dependencies = [ "parking_lot 0.12.1", "regex", "rocksdb", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -5369,9 +5363,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libloading" @@ -5398,7 +5392,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.11", + "getrandom 0.2.12", "instant", "libp2p-allow-block-list", "libp2p-connection-limits", @@ -5468,7 +5462,7 @@ dependencies = [ "quick-protobuf", "rand 0.8.5", "rw-stream-sink", - "smallvec 1.11.2", + "smallvec 1.13.1", "thiserror", "unsigned-varint 0.7.2", "void", @@ -5484,7 +5478,7 @@ dependencies = [ "libp2p-core", "log", "parking_lot 0.12.1", - "smallvec 1.11.2", + "smallvec 1.13.1", "trust-dns-resolver", ] @@ -5505,7 +5499,7 @@ dependencies = [ "lru 0.10.1", "quick-protobuf", "quick-protobuf-codec", - "smallvec 1.11.2", + "smallvec 1.13.1", "thiserror", "void", ] @@ -5564,7 +5558,7 @@ dependencies = [ "quick-protobuf", "rand 0.8.5", "sha2 0.10.8", - "smallvec 1.11.2", + "smallvec 1.13.1", "thiserror", "uint", "unsigned-varint 0.7.2", @@ -5585,7 +5579,7 @@ dependencies = [ "libp2p-swarm", "log", "rand 0.8.5", - "smallvec 1.11.2", + "smallvec 1.13.1", "socket2 0.4.10", "tokio", "trust-dns-proto", @@ -5681,7 +5675,7 @@ dependencies = [ "libp2p-identity 0.1.3", "libp2p-swarm", "rand 0.8.5", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -5700,7 +5694,7 @@ dependencies = [ "libp2p-swarm-derive", "log", "rand 0.8.5", - "smallvec 1.11.2", + "smallvec 1.13.1", "tokio", "void", ] @@ -5803,7 +5797,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "libc", "redox_syscall 0.4.1", ] @@ -5873,9 +5867,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.12" +version = "1.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" dependencies = [ "cc", "pkg-config", @@ -5923,9 +5917,9 @@ checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "linux-raw-sys" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lioness" @@ -6065,7 +6059,7 @@ version = "0.6.0" dependencies = [ "async-trait", "blockifier", - "clap 4.4.13", + "clap 4.4.18", "ethers", "frame-benchmarking", "frame-benchmarking-cli", @@ -6187,7 +6181,7 @@ version = "0.1.0" dependencies = [ "anyhow", "assert_matches", - "async-lock 3.2.0", + "async-lock 3.3.0", "async-trait", "derive_more", "flate2", @@ -6294,7 +6288,7 @@ dependencies = [ "blockifier", "celestia-rpc", "celestia-types", - "clap 4.4.13", + "clap 4.4.18", "ethers", "futures", "indexmap 2.0.0-pre", @@ -6322,7 +6316,7 @@ dependencies = [ "thiserror", "tokio", "url", - "uuid 1.6.1", + "uuid 1.7.0", ] [[package]] @@ -6340,7 +6334,7 @@ dependencies = [ "sp-runtime 24.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "starknet_api", "thiserror", - "uuid 1.6.1", + "uuid 1.7.0", ] [[package]] @@ -6486,7 +6480,7 @@ name = "mc-settlement" version = "0.1.0" dependencies = [ "async-trait", - "clap 4.4.13", + "clap 4.4.18", "ethers", "futures", "futures-timer", @@ -6562,7 +6556,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.28", + "rustix 0.38.30", ] [[package]] @@ -7020,7 +7014,7 @@ dependencies = [ "futures", "log", "pin-project", - "smallvec 1.11.2", + "smallvec 1.13.1", "unsigned-varint 0.7.2", ] @@ -7339,7 +7333,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.3", + "hermit-abi 0.3.4", "libc", ] @@ -7354,11 +7348,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683751d591e6d81200c39fb0d1032608b77724f34114db54f571ff1317b337c0" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" dependencies = [ - "num_enum_derive 0.7.1", + "num_enum_derive 0.7.2", ] [[package]] @@ -7375,11 +7369,11 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c11e44798ad209ccdd91fc192f0526a369a01234f7373e1b141c96d7cee4f0e" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ - "proc-macro-crate 2.0.0", + "proc-macro-crate 3.1.0", "proc-macro2", "quote", "syn 2.0.48", @@ -7472,11 +7466,11 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.62" +version = "0.10.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cde4d2d9200ad5909f8dac647e29482e07c3a35de8a13fce7c9c7747ad9f671" +checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "cfg-if", "foreign-types", "libc", @@ -7504,9 +7498,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.98" +version = "0.9.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" dependencies = [ "cc", "libc", @@ -7787,7 +7781,7 @@ dependencies = [ "instant", "libc", "redox_syscall 0.2.16", - "smallvec 1.11.2", + "smallvec 1.13.1", "winapi", ] @@ -7800,7 +7794,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall 0.4.1", - "smallvec 1.11.2", + "smallvec 1.13.1", "windows-targets 0.48.5", ] @@ -8063,9 +8057,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" +checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" [[package]] name = "platforms" @@ -8075,14 +8069,14 @@ checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" [[package]] name = "polling" -version = "3.3.1" +version = "3.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf63fa624ab313c11656b4cda960bfc46c410187ad493c41f6ba2d8c1e991c9e" +checksum = "545c980a3880efd47b2e262f6a4bb6daad6555cf3367aa9c4e52895f69537a41" dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite 0.2.13", - "rustix 0.38.28", + "rustix 0.38.30", "tracing", "windows-sys 0.52.0", ] @@ -8227,6 +8221,15 @@ dependencies = [ "toml_edit 0.20.7", ] +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit 0.21.0", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -8264,9 +8267,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -8320,7 +8323,7 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "lazy_static", "num-traits 0.2.17", "rand 0.8.5", @@ -8578,7 +8581,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", ] [[package]] @@ -8626,9 +8629,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" dependencies = [ "either", "rayon-core", @@ -8636,9 +8639,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -8680,7 +8683,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", "libredox", "thiserror", ] @@ -8714,18 +8717,18 @@ dependencies = [ "fxhash", "log", "slice-group-by", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.3", + "regex-automata 0.4.4", "regex-syntax 0.8.2", ] @@ -8740,9 +8743,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" dependencies = [ "aho-corasick", "memchr", @@ -8779,7 +8782,7 @@ version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -8874,7 +8877,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", - "getrandom 0.2.11", + "getrandom 0.2.12", "libc", "spin 0.9.8", "untrusted 0.9.0", @@ -9078,14 +9081,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "errno", "libc", - "linux-raw-sys 0.4.12", + "linux-raw-sys 0.4.13", "windows-sys 0.52.0", ] @@ -9131,7 +9134,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", ] [[package]] @@ -9190,7 +9193,7 @@ dependencies = [ "parking_lot 0.11.2", "rustc-hash", "salsa-macros", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -9309,7 +9312,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot dependencies = [ "array-bytes 6.2.2", "chrono", - "clap 4.4.13", + "clap 4.4.18", "fdlimit", "futures", "libp2p-identity 0.1.3", @@ -9735,7 +9738,7 @@ dependencies = [ "sc-utils", "serde", "serde_json", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-arithmetic 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-blockchain", "sp-core 21.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", @@ -9846,7 +9849,7 @@ dependencies = [ "sc-network-common", "sc-utils", "schnellru", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-arithmetic 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-blockchain", "sp-consensus", @@ -10246,7 +10249,7 @@ dependencies = [ "scale-bits", "scale-decode-derive", "scale-info", - "smallvec 1.11.2", + "smallvec 1.13.1", "thiserror", ] @@ -10274,7 +10277,7 @@ dependencies = [ "scale-bits", "scale-encode-derive", "scale-info", - "smallvec 1.11.2", + "smallvec 1.13.1", "thiserror", ] @@ -10529,9 +10532,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b114498256798c94a0689e1a15fec6005dee8ac1f41de56404b67afc2a4b773" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] @@ -10558,9 +10561,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.194" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", @@ -10730,9 +10733,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" @@ -10816,15 +10819,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "smol_str" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c" +checksum = "e6845563ada680337a52d43bb0b29f396f2d911616f6573012645b9e3d048a49" dependencies = [ "serde", ] @@ -10837,9 +10840,9 @@ checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" [[package]] name = "snow" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58021967fd0a5eeeb23b08df6cc244a4d4a5b4aec1d27c9e02fad1a58b4cd74e" +checksum = "2e87c18a6608909007e75a60e04d03eda77b601c94de1c74d9a9dc2c04ab789a" dependencies = [ "aes-gcm", "blake2 0.10.6", @@ -11620,7 +11623,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "rand 0.8.5", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-externalities 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-panic-handler 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -11640,7 +11643,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "rand 0.8.5", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-core 21.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-externalities 0.19.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-panic-handler 8.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", @@ -11887,7 +11890,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-arithmetic 16.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-debug-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -11902,7 +11905,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "smallvec 1.11.2", + "smallvec 1.13.1", "sp-arithmetic 16.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-core 21.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", "sp-debug-derive 8.0.0 (git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0)", @@ -11955,9 +11958,9 @@ dependencies = [ [[package]] name = "ss58-registry" -version = "1.44.0" +version = "1.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35935738370302d5e33963665b77541e4b990a3e919ec904c837a56cfc891de1" +checksum = "b1114ee5900b8569bbc8b1a014a942f937b752af4b44f4607430b5f86cedaac0" dependencies = [ "Inflector", "num-format", @@ -12006,7 +12009,7 @@ name = "starknet-core" version = "0.7.2" source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=64ebc36#64ebc364c0c346e81b715c5b4a3b32ef37b055c8" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "flate2", "hex", "serde", @@ -12136,7 +12139,7 @@ dependencies = [ "ark-ff 0.4.2", "bigdecimal", "crypto-bigint", - "getrandom 0.2.11", + "getrandom 0.2.12", "hex", "serde", ] @@ -12148,7 +12151,7 @@ source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=a35ce22#a35ce2 dependencies = [ "ark-ff 0.4.2", "crypto-bigint", - "getrandom 0.2.11", + "getrandom 0.2.12", "hex", ] @@ -12177,7 +12180,7 @@ version = "0.1.0" dependencies = [ "anyhow", "assert_matches", - "async-lock 3.2.0", + "async-lock 3.3.0", "async-trait", "flate2", "reqwest", @@ -12477,7 +12480,7 @@ dependencies = [ "either", "frame-metadata 15.1.0", "futures", - "getrandom 0.2.11", + "getrandom 0.2.12", "hex", "impl-serde", "jsonrpsee 0.16.3", @@ -12546,9 +12549,9 @@ dependencies = [ [[package]] name = "svm-rs" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20689c7d03b6461b502d0b95d6c24874c7d24dea2688af80486a130a06af3b07" +checksum = "7ce290b5536ab2a42a61c9c6f22d6bfa8f26339c602aa62db4c978c95d1afc47" dependencies = [ "dirs", "fs2", @@ -12640,7 +12643,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.4.1", - "rustix 0.38.28", + "rustix 0.38.30", "windows-sys 0.52.0", ] @@ -12702,9 +12705,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] @@ -13130,7 +13133,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "bytes", "futures-core", "futures-util", @@ -13233,7 +13236,7 @@ dependencies = [ "serde", "serde_json", "sharded-slab", - "smallvec 1.11.2", + "smallvec 1.13.1", "thread_local", "tracing", "tracing-core", @@ -13251,7 +13254,7 @@ dependencies = [ "hashbrown 0.13.2", "log", "rustc-hex", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -13264,7 +13267,7 @@ dependencies = [ "hashbrown 0.13.2", "log", "rustc-hex", - "smallvec 1.11.2", + "smallvec 1.13.1", ] [[package]] @@ -13293,7 +13296,7 @@ dependencies = [ "ipnet", "lazy_static", "rand 0.8.5", - "smallvec 1.11.2", + "smallvec 1.13.1", "socket2 0.4.10", "thiserror", "tinyvec", @@ -13315,7 +13318,7 @@ dependencies = [ "lru-cache", "parking_lot 0.12.1", "resolv-conf", - "smallvec 1.11.2", + "smallvec 1.13.1", "thiserror", "tokio", "tracing", @@ -13334,7 +13337,7 @@ version = "0.10.0-dev" source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.3.0#401f8a3e9448db854f5605b679fa085b8f445039" dependencies = [ "async-trait", - "clap 4.4.13", + "clap 4.4.18", "frame-remote-externalities", "frame-try-runtime", "hex", @@ -13435,18 +13438,18 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unescaper" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f0f68e58d297ba8b22b8b5a96a87b863ba6bb46aaf51e19a4b02c5a6dd5b7f" +checksum = "0adf6ad32eb5b3cadff915f7b770faaac8f7ff0476633aa29eb0d9584d889d34" dependencies = [ "thiserror", ] [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -13550,17 +13553,17 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", "serde", ] [[package]] name = "uuid" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.12", "serde", ] @@ -13651,9 +13654,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -13661,9 +13664,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -13676,9 +13679,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -13688,9 +13691,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -13698,9 +13701,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -13711,9 +13714,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasm-instrument" @@ -13833,7 +13836,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c86437fa68626fe896e5afc69234bb2b5894949083586535f200385adfd71213" dependencies = [ "anyhow", - "base64 0.21.5", + "base64 0.21.7", "bincode 1.3.3", "directories-next", "file-per-thread-logger", @@ -13986,9 +13989,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", @@ -14028,14 +14031,14 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.28", + "rustix 0.38.30", ] [[package]] name = "wide" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68938b57b33da363195412cfc5fc37c9ed49aa9cfe2156fde64b8d2c9498242" +checksum = "b31891d644eba1789fb6715f27fbc322e4bdf2ecdc412ede1993246159271613" dependencies = [ "bytemuck", "safe_arch", @@ -14306,9 +14309,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.32" +version = "0.5.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8434aeec7b290e8da5c3f0d628cb0eac6cabcb31d14bb74f779a08109a5914d6" +checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" dependencies = [ "memchr", ] diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index c615e6ad8c..2995cffeda 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -243,6 +243,8 @@ fn tx_execution_infos_to_simulated_transactions( }) .transpose()?; + let state_diff = blockifier_to_rpc_state_diff_types(state_diff.clone()).ok(); + let transaction_trace = match tx_type { TxType::Invoke => TransactionTrace::Invoke(InvokeTransactionTrace { validate_invocation, @@ -257,12 +259,12 @@ fn tx_execution_infos_to_simulated_transactions( )?) }, fee_transfer_invocation, - state_diff: Some(state_diff), + state_diff, }), TxType::Declare => TransactionTrace::Declare(DeclareTransactionTrace { validate_invocation, fee_transfer_invocation, - state_diff: Some(state_diff), + state_diff, }), TxType::DeployAccount => { TransactionTrace::DeployAccount(DeployAccountTransactionTrace { @@ -274,7 +276,7 @@ fn tx_execution_infos_to_simulated_transactions( tx_exec_info.execute_call_info.as_ref().unwrap(), )?, fee_transfer_invocation, - state_diff: Some(state_diff), + state_diff, }) } TxType::L1Handler => unreachable!("L1Handler transactions cannot be simulated"), diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 1c7ceb7f32..b5a0e23282 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -19,7 +19,6 @@ mod types; use blockifier::execution::contract_class::ContractClass; use blockifier::state::cached_state::CommitmentStateDiff; -use blockifier::transaction::objects::TransactionExecutionInfo; pub use config::*; pub use frame_support::traits::{ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo}; pub use frame_support::weights::constants::{ @@ -30,13 +29,14 @@ pub use frame_support::{construct_runtime, parameter_types, StorageValue}; pub use frame_system::Call as SystemCall; use frame_system::{EventRecord, Phase}; use mp_felt::Felt252Wrapper; -use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; +use mp_simulations::SimulationFlags; use mp_transactions::compute_hash::ComputeTransactionHash; use mp_transactions::{HandleL1MessageTransaction, Transaction, UserTransaction}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; /// Import the Starknet pallet. pub use pallet_starknet; use pallet_starknet::pallet::Error as PalletError; +use pallet_starknet::types::TransactionSimulationResult; use pallet_starknet::Call::{consume_l1_message, declare, deploy_account, invoke}; use pallet_starknet::{Config, Event}; use pallet_starknet_runtime_api::StarknetTransactionExecutionError; @@ -281,7 +281,7 @@ impl_runtime_apis! { Starknet::estimate_fee(transactions) } - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result)>, DispatchError> { + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError> { Starknet::simulate_transactions(transactions, simulation_flags) } From 56aa57cb5db47707c068df005e161d360a1b5c71 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 24 Jan 2024 18:05:08 +0100 Subject: [PATCH 07/21] fix: prettier --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d71371c6bc..7f0dbf9ba0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Next release -- feat(rpc): added state diff real value in trace api +- feat(rpc): added state diff real value in trace api - 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 From adfa63421950a4af9f1f6b4f943627298221fabb Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 24 Jan 2024 18:06:57 +0100 Subject: [PATCH 08/21] fix: prettier --- CHANGELOG.md | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a38531dba..e18403ebc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Next release -- feat(rpc): added state diff real value in trace api +- feat(rpc): added state diff real value in trace api - fix: remove waiting loop from `getTxReceipt` - feat: types in `mp-transactions` impl a method to get their version - feat: make L1 gas price a `const` of the `RuntimeConfig` diff --git a/README.md b/README.md index a5928afa37..5d0b130f8c 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ [![Exploration_Team](https://img.shields.io/badge/Exploration_Team-29296E.svg?&style=for-the-badge&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJhIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxODEgMTgxIj48ZGVmcz48c3R5bGU+LmJ7ZmlsbDojZmZmO308L3N0eWxlPjwvZGVmcz48cGF0aCBjbGFzcz0iYiIgZD0iTTE3Ni43Niw4OC4xOGwtMzYtMzcuNDNjLTEuMzMtMS40OC0zLjQxLTIuMDQtNS4zMS0xLjQybC0xMC42MiwyLjk4LTEyLjk1LDMuNjNoLjc4YzUuMTQtNC41Nyw5LjktOS41NSwxNC4yNS0xNC44OSwxLjY4LTEuNjgsMS44MS0yLjcyLDAtNC4yN0w5Mi40NSwuNzZxLTEuOTQtMS4wNC00LjAxLC4xM2MtMTIuMDQsMTIuNDMtMjMuODMsMjQuNzQtMzYsMzcuNjktMS4yLDEuNDUtMS41LDMuNDQtLjc4LDUuMThsNC4yNywxNi41OGMwLDIuNzIsMS40Miw1LjU3LDIuMDcsOC4yOS00LjczLTUuNjEtOS43NC0xMC45Ny0xNS4wMi0xNi4wNi0xLjY4LTEuODEtMi41OS0xLjgxLTQuNCwwTDQuMzksODguMDVjLTEuNjgsMi4zMy0xLjgxLDIuMzMsMCw0LjUzbDM1Ljg3LDM3LjNjMS4zNiwxLjUzLDMuNSwyLjEsNS40NCwxLjQybDExLjQtMy4xMSwxMi45NS0zLjYzdi45MWMtNS4yOSw0LjE3LTEwLjIyLDguNzYtMTQuNzYsMTMuNzNxLTMuNjMsMi45OC0uNzgsNS4zMWwzMy40MSwzNC44NGMyLjIsMi4yLDIuOTgsMi4yLDUuMTgsMGwzNS40OC0zNy4xN2MxLjU5LTEuMzgsMi4xNi0zLjYsMS40Mi01LjU3LTEuNjgtNi4wOS0zLjI0LTEyLjMtNC43OS0xOC4zOS0uNzQtMi4yNy0xLjIyLTQuNjItMS40Mi02Ljk5LDQuMyw1LjkzLDkuMDcsMTEuNTIsMTQuMjUsMTYuNzEsMS42OCwxLjY4LDIuNzIsMS42OCw0LjQsMGwzNC4zMi0zNS43NHExLjU1LTEuODEsMC00LjAxWm0tNzIuMjYsMTUuMTVjLTMuMTEtLjc4LTYuMDktMS41NS05LjE5LTIuNTktMS43OC0uMzQtMy42MSwuMy00Ljc5LDEuNjhsLTEyLjk1LDEzLjg2Yy0uNzYsLjg1LTEuNDUsMS43Ni0yLjA3LDIuNzJoLS42NWMxLjMtNS4zMSwyLjcyLTEwLjYyLDQuMDEtMTUuOGwxLjY4LTYuNzNjLjg0LTIuMTgsLjE1LTQuNjUtMS42OC02LjA5bC0xMi45NS0xNC4xMmMtLjY0LS40NS0xLjE0LTEuMDgtMS40Mi0xLjgxbDE5LjA0LDUuMTgsMi41OSwuNzhjMi4wNCwuNzYsNC4zMywuMTQsNS43LTEuNTVsMTIuOTUtMTQuMzhzLjc4LTEuMDQsMS42OC0xLjE3Yy0xLjgxLDYuNi0yLjk4LDE0LjEyLTUuNDQsMjAuNDYtMS4wOCwyLjk2LS4wOCw2LjI4LDIuNDYsOC4xNiw0LjI3LDQuMTQsOC4yOSw4LjU1LDEyLjk1LDEyLjk1LDAsMCwxLjMsLjkxLDEuNDIsMi4wN2wtMTMuMzQtMy42M1oiLz48L3N2Zz4=)](https://github.com/keep-starknet-strange) + # âš¡ Madara App Chain Stack From 7a348ed8c78977820583add43a801eeb6f3da453 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Thu, 25 Jan 2024 20:12:23 +0100 Subject: [PATCH 09/21] fix: da layer cli bug --- crates/node/src/commands/run.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/node/src/commands/run.rs b/crates/node/src/commands/run.rs index a47f9c3009..37aa2cc760 100644 --- a/crates/node/src/commands/run.rs +++ b/crates/node/src/commands/run.rs @@ -186,13 +186,21 @@ pub fn run_node(mut cli: Cli) -> Result<()> { let da_client = match cli.run.da_layer { Some(da_layer) => { - let da_conf = cli.run.clone().da_conf.unwrap_or({ - let path_da_conf_json = chain_config_dir.join(format!("{da_layer}.json")); - if !path_da_conf_json.exists() { - return Err(sc_cli::Error::Input(format!("no file {da_layer}.json in base_path"))); + let da_conf = match cli.run.clone().da_conf { + Some(da_conf) => da_conf, + None => { + let path_da_conf_json = chain_config_dir.join(format!("{}.json", da_layer)); + if !path_da_conf_json.exists() { + return Err(sc_cli::Error::Input(format!( + "no file {} in base_path", + path_da_conf_json.to_string_lossy() + ))); + } + path_da_conf_json } - path_da_conf_json - }); + }; + + log::info!("Initializing DA client with layer: {:?}", da_layer); Some(init_da_client(da_layer, da_conf)?) } From 9fc2115a667cb25e0bf96a47dee91d1ade1be110 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Thu, 25 Jan 2024 20:32:43 +0100 Subject: [PATCH 10/21] temp: debug --- Cargo.lock | 1 + crates/client/rpc/src/trace_api.rs | 3 +++ crates/runtime/Cargo.toml | 2 ++ crates/runtime/src/lib.rs | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 406ec572db..2df5612105 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6142,6 +6142,7 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", + "log", "mp-block", "mp-chain-id", "mp-fee", diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index 2995cffeda..d8d618ff37 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -84,6 +84,8 @@ where StarknetRpcApiError::ContractError })?; + log::info!("is_ok: {:#?}", res[1].0.is_ok()); + let storage_override = self.overrides.for_block_hash(self.client.as_ref(), substrate_block_hash); let simulated_transactions = tx_execution_infos_to_simulated_transactions(&**storage_override, substrate_block_hash, tx_types, res) @@ -224,6 +226,7 @@ fn tx_execution_infos_to_simulated_transactions( for (tx_type, (res, state_diff)) in tx_types.iter().zip(transaction_execution_results.iter()) { match res { Ok(tx_exec_info) => { + // println!("tx_exec_info: {:#?}", tx_exec_info); // If simulated with `SimulationFlag::SkipValidate` this will be `None` // therefore we cannot unwrap it let validate_invocation = tx_exec_info diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index d1f02d968d..1e3e26dcb2 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -67,6 +67,8 @@ starknet-core = { workspace = true } starknet-ff = { workspace = true } starknet_api = { workspace = true } +log = { workspace = true } + [build-dependencies] substrate-wasm-builder = { workspace = true } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index bdc3897c26..fed5e9a506 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -286,7 +286,9 @@ impl_runtime_apis! { } fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError> { - Starknet::simulate_transactions(transactions, simulation_flags) + let txs = Starknet::simulate_transactions(transactions, simulation_flags); + log::info!("is_ok: {:#?}", txs.as_ref().unwrap()[1].0.is_ok()); + txs } fn get_starknet_events_and_their_associated_tx_hash(block_extrinsics: Vec<::Extrinsic>, chain_id: Felt252Wrapper) -> Vec<(Felt252Wrapper, StarknetEvent)> { From fd13e87df76f81b124d990ea0c0cc30bbf7f6157 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Thu, 25 Jan 2024 20:38:04 +0100 Subject: [PATCH 11/21] fix: settlement conf bug --- crates/node/src/commands/run.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/node/src/commands/run.rs b/crates/node/src/commands/run.rs index 37aa2cc760..f949719103 100644 --- a/crates/node/src/commands/run.rs +++ b/crates/node/src/commands/run.rs @@ -215,13 +215,21 @@ pub fn run_node(mut cli: Cli) -> Result<()> { let settlement_config: Option<(SettlementLayer, PathBuf)> = match cli.run.settlement { Some(SettlementLayer::Ethereum) => { - let settlement_conf = cli.run.clone().settlement_conf.unwrap_or({ - let path_sett_conf_json = chain_config_dir.join("settlement_conf.json"); - if !path_sett_conf_json.exists() { - return Err(sc_cli::Error::Input("no file settlement_conf in base_path".to_string())); + let settlement_conf = match cli.run.clone().settlement_conf { + Some(settlement_conf) => settlement_conf, + None => { + let path_settlement_conf_json = chain_config_dir.join("settlement_conf.json"); + if !path_settlement_conf_json.exists() { + return Err(sc_cli::Error::Input(format!( + "no file {} in base_path", + path_settlement_conf_json.to_string_lossy() + ))); + } + path_settlement_conf_json } - path_sett_conf_json - }); + }; + + log::info!("Initializing settlement client with layer: {:?}", SettlementLayer::Ethereum); Some((SettlementLayer::Ethereum, settlement_conf)) } From 3a9f2d58379e4f4db13f200313b416fa2ce7c7d1 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Fri, 26 Jan 2024 11:49:22 +0100 Subject: [PATCH 12/21] fix: rebase --- .../pallets/starknet/runtime_api/src/lib.rs | 4 +- crates/pallets/starknet/src/simulations.rs | 41 +++++++++++++++---- crates/runtime/src/lib.rs | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index bccb5f281a..8b864bf6c0 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -35,6 +35,8 @@ pub enum StarknetTransactionExecutionError { ContractError, } +type TransactionSimulationResult = Result; + sp_api::decl_runtime_apis! { pub trait StarknetRuntimeApi { /// Returns the nonce associated with the given address in the given block @@ -60,7 +62,7 @@ sp_api::decl_runtime_apis! { /// Returns message fee estimate fn estimate_message_fee(message: HandleL1MessageTransaction) -> Result<(u128, u64, u64), DispatchError>; /// Simulates transactions and returns their trace - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, CommitmentStateDiff)>, DispatchError>; + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError>; /// Filters extrinsic transactions to return only Starknet transactions /// /// To support runtime upgrades, the client must be unaware of the specific extrinsic diff --git a/crates/pallets/starknet/src/simulations.rs b/crates/pallets/starknet/src/simulations.rs index 231f106e7a..78ef7a2fd0 100644 --- a/crates/pallets/starknet/src/simulations.rs +++ b/crates/pallets/starknet/src/simulations.rs @@ -1,6 +1,8 @@ use alloc::vec::Vec; use blockifier::block_context::BlockContext; +use blockifier::state::cached_state::{CachedState, CommitmentStateDiff}; +use blockifier::state::state_api::State; use blockifier::transaction::errors::TransactionExecutionError; use blockifier::transaction::objects::TransactionExecutionInfo; use frame_support::storage; @@ -12,8 +14,9 @@ use sp_core::Get; use sp_runtime::DispatchError; use starknet_api::transaction::Fee; -use crate::blockifier_state_adapter::BlockifierStateAdapter; +use crate::blockifier_state_adapter::{BlockifierStateAdapter, CachedBlockifierStateAdapter}; use crate::execution_config::RuntimeExecutionConfigBuilder; +use crate::types::TransactionSimulationResult; use crate::{Config, Error, Pallet}; impl Pallet { @@ -74,8 +77,7 @@ impl Pallet { pub fn simulate_transactions( transactions: Vec, simulation_flags: &SimulationFlags, - ) -> Result>, DispatchError> - { + ) -> Result, DispatchError> { storage::transactional::with_transaction(|| { storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(Self::simulate_transactions_inner( transactions, @@ -88,8 +90,7 @@ impl Pallet { fn simulate_transactions_inner( transactions: Vec, simulation_flags: &SimulationFlags, - ) -> Result>, DispatchError> - { + ) -> Result, DispatchError> { let chain_id = Self::chain_id(); let block_context = Self::get_block_context(); let mut execution_config = @@ -100,10 +101,12 @@ impl Pallet { .map(|tx| { execution_config.set_offset_version(tx.offset_version()); - Self::execute_transaction(tx, chain_id, &block_context, &execution_config).map_err(|e| { + let res = Self::execute_transaction_with_state_diff(tx, chain_id, &block_context, &execution_config); + let result = res.0.map_err(|e| { log::error!("Transaction execution failed during simulation: {e}"); PlaceHolderErrorTypeForFailedStarknetExecution - }) + }); + (result, res.1) }) .collect(); @@ -163,4 +166,28 @@ impl Pallet { } } } + + fn execute_transaction_with_state_diff( + transaction: UserTransaction, + chain_id: Felt252Wrapper, + block_context: &BlockContext, + execution_config: &ExecutionConfig, + ) -> (Result, CommitmentStateDiff) { + let mut cached_state = CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); + let result = match transaction { + UserTransaction::Declare(tx, contract_class) => tx + .try_into_executable::(chain_id, contract_class.clone(), tx.offset_version()) + .and_then(|exec| exec.execute(&mut cached_state, block_context, execution_config)), + UserTransaction::DeployAccount(tx) => { + let executable = tx.into_executable::(chain_id, tx.offset_version()); + executable.execute(&mut cached_state, block_context, execution_config) + } + UserTransaction::Invoke(tx) => { + let executable = tx.into_executable::(chain_id, tx.offset_version()); + executable.execute(&mut cached_state, block_context, execution_config) + } + }; + + (result, cached_state.to_state_diff()) + } } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 3b8bde4c5a..44cd18a68e 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -286,7 +286,7 @@ impl_runtime_apis! { } fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError> { - let txs = Starknet::simulate_transactions(transactions, simulation_flags); + let txs = Starknet::simulate_transactions(transactions, &simulation_flags); log::info!("is_ok: {:#?}", txs.as_ref().unwrap()[1].0.is_ok()); txs } From 26c8bf97cf81742dfa3cc5901aa4e6f29f823be4 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Fri, 26 Jan 2024 16:51:21 +0100 Subject: [PATCH 13/21] Update Cargo.lock --- Cargo.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2df5612105..0b267e7f52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.1.0-rc2" -source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#85b4d15788eac61aa8af8ba21ac302657c78d014" +source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#b6f0c19e12ddda1985a2b6e0a2f41401e61fe0b9" dependencies = [ "ark-ff 0.4.2", "ark-secp256k1", @@ -1094,9 +1094,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytemuck" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +checksum = "ed2490600f404f2b94c167e31d3ed1d5f3c225a0f3b80230053b3e0b7b962bd9" [[package]] name = "byteorder" @@ -1813,9 +1813,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41daef31d7a747c5c847246f36de49ced6f7403b4cdabc807a97b5cc184cda7a" +checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb" dependencies = [ "android-tzdata", "iana-time-zone", @@ -4257,7 +4257,7 @@ dependencies = [ "aho-corasick", "bstr", "log", - "regex-automata 0.4.4", + "regex-automata 0.4.5", "regex-syntax 0.8.2", ] @@ -5867,9 +5867,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.14" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" +checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" dependencies = [ "cc", "pkg-config", @@ -8012,18 +8012,18 @@ checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", @@ -8731,7 +8731,7 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.4", + "regex-automata 0.4.5", "regex-syntax 0.8.2", ] @@ -8746,9 +8746,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -10843,9 +10843,9 @@ checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" [[package]] name = "snow" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e87c18a6608909007e75a60e04d03eda77b601c94de1c74d9a9dc2c04ab789a" +checksum = "850948bee068e713b8ab860fe1adc4d109676ab4c3b621fd8147f06b261f2f85" dependencies = [ "aes-gcm", "blake2 0.10.6", @@ -12220,7 +12220,7 @@ dependencies = [ [[package]] name = "starknet_api" version = "0.4.1" -source = "git+https://github.com/keep-starknet-strange/starknet-api?branch=no_std-support-dc83f05#3415c832bb0cd72d1764dcd9ce803ddf932895ef" +source = "git+https://github.com/keep-starknet-strange/starknet-api?branch=no_std-support-dc83f05#c76154572057fb53b31f3a29a24e2469ca721d51" dependencies = [ "cairo-lang-casm-contract-class", "derive_more", From c08dd074535242e0e254b502430dee6600d8c887 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Fri, 26 Jan 2024 17:01:36 +0100 Subject: [PATCH 14/21] fix: cleanup --- Cargo.lock | 1 - crates/client/rpc/src/trace_api.rs | 7 ++----- crates/runtime/Cargo.toml | 2 -- crates/runtime/src/lib.rs | 4 +--- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b267e7f52..e988237807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6142,7 +6142,6 @@ dependencies = [ "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", - "log", "mp-block", "mp-chain-id", "mp-fee", diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index d8d618ff37..c6593fd53a 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -84,8 +84,6 @@ where StarknetRpcApiError::ContractError })?; - log::info!("is_ok: {:#?}", res[1].0.is_ok()); - let storage_override = self.overrides.for_block_hash(self.client.as_ref(), substrate_block_hash); let simulated_transactions = tx_execution_infos_to_simulated_transactions(&**storage_override, substrate_block_hash, tx_types, res) @@ -223,10 +221,9 @@ fn tx_execution_infos_to_simulated_transactions( )>, ) -> Result, ConvertCallInfoToExecuteInvocationError> { let mut results = vec![]; - for (tx_type, (res, state_diff)) in tx_types.iter().zip(transaction_execution_results.iter()) { + for (tx_type, (res, state_diff)) in tx_types.iter().zip(transaction_execution_results.into_iter()) { match res { Ok(tx_exec_info) => { - // println!("tx_exec_info: {:#?}", tx_exec_info); // If simulated with `SimulationFlag::SkipValidate` this will be `None` // therefore we cannot unwrap it let validate_invocation = tx_exec_info @@ -246,7 +243,7 @@ fn tx_execution_infos_to_simulated_transactions( }) .transpose()?; - let state_diff = blockifier_to_rpc_state_diff_types(state_diff.clone()).ok(); + let state_diff = blockifier_to_rpc_state_diff_types(state_diff).ok(); let transaction_trace = match tx_type { TxType::Invoke => TransactionTrace::Invoke(InvokeTransactionTrace { diff --git a/crates/runtime/Cargo.toml b/crates/runtime/Cargo.toml index 1e3e26dcb2..d1f02d968d 100644 --- a/crates/runtime/Cargo.toml +++ b/crates/runtime/Cargo.toml @@ -67,8 +67,6 @@ starknet-core = { workspace = true } starknet-ff = { workspace = true } starknet_api = { workspace = true } -log = { workspace = true } - [build-dependencies] substrate-wasm-builder = { workspace = true } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 44cd18a68e..9f5e91777f 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -286,9 +286,7 @@ impl_runtime_apis! { } fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError> { - let txs = Starknet::simulate_transactions(transactions, &simulation_flags); - log::info!("is_ok: {:#?}", txs.as_ref().unwrap()[1].0.is_ok()); - txs + Starknet::simulate_transactions(transactions, &simulation_flags) } fn get_starknet_events_and_their_associated_tx_hash(block_extrinsics: Vec<::Extrinsic>, chain_id: Felt252Wrapper) -> Vec<(Felt252Wrapper, StarknetEvent)> { From 34ae64a4a03da8bf1243b3f7c4994a5a19720dcf Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 12 Feb 2024 14:42:04 +0100 Subject: [PATCH 15/21] fix: types --- crates/client/rpc/src/trace_api.rs | 25 +++--- .../pallets/starknet/runtime_api/src/lib.rs | 2 +- crates/pallets/starknet/src/simulations.rs | 79 ++++++++++--------- crates/runtime/src/lib.rs | 5 +- 4 files changed, 63 insertions(+), 48 deletions(-) diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index e7e4a88353..58924c1b9c 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -27,7 +27,7 @@ use starknet_api::api_core::{ClassHash, ContractAddress}; use starknet_core::types::{ BlockId, BroadcastedTransaction, DeclareTransactionTrace, DeployAccountTransactionTrace, ExecuteInvocation, FeeEstimate, InvokeTransactionTrace, L1HandlerTransactionTrace, RevertedInvocation, SimulatedTransaction, - SimulationFlag, TransactionTrace, TransactionTraceWithHash, + SimulationFlag, StateDiff, TransactionTrace, TransactionTraceWithHash, }; use starknet_ff::FieldElement; use thiserror::Error; @@ -227,13 +227,16 @@ where let traces = execution_infos .into_iter() .enumerate() - .map(|(tx_idx, tx_exec_info)| { + .map(|(tx_idx, (tx_exec_info, commitment_state_diff))| { + let state_diff = blockifier_to_rpc_state_diff_types(commitment_state_diff) + .map_err(|_| ConvertCallInfoToExecuteInvocationError::ConvertStateDiffFailed)?; tx_execution_infos_to_tx_trace( &**storage_override, substrate_block_hash, // Safe to unwrap coz re_execute returns exactly one ExecutionInfo for each tx TxType::from(block_transactions.get(tx_idx).unwrap()), &tx_exec_info, + Some(state_diff), ) .map(|trace_root| TransactionTraceWithHash { transaction_hash: block_transactions[tx_idx].compute_hash::(chain_id, false).into(), @@ -253,6 +256,8 @@ pub enum ConvertCallInfoToExecuteInvocationError { TransactionExecutionFailed, #[error(transparent)] GetFunctionInvocation(#[from] TryFuntionInvocationFromCallInfoError), + #[error("Failed to convert state diff")] + ConvertStateDiffFailed, } impl From for StarknetRpcApiError { @@ -262,6 +267,7 @@ impl From for StarknetRpcApiError { ConvertCallInfoToExecuteInvocationError::GetFunctionInvocation(_) => { StarknetRpcApiError::InternalServerError } + ConvertCallInfoToExecuteInvocationError::ConvertStateDiffFailed => StarknetRpcApiError::InternalServerError, } } } @@ -383,6 +389,7 @@ fn tx_execution_infos_to_tx_trace( substrate_block_hash: B::Hash, tx_type: TxType, tx_exec_info: &TransactionExecutionInfo, + state_diff: Option, ) -> Result { let mut class_hash_cache: HashMap = HashMap::new(); @@ -430,14 +437,12 @@ fn tx_execution_infos_to_tx_trace( )?) }, fee_transfer_invocation, - // TODO(#1291): Compute state diff correctly - state_diff: None, + state_diff, }), TxType::Declare => TransactionTrace::Declare(DeclareTransactionTrace { validate_invocation, fee_transfer_invocation, - // TODO(#1291): Compute state diff correctly - state_diff: None, + state_diff, }), TxType::DeployAccount => { TransactionTrace::DeployAccount(DeployAccountTransactionTrace { @@ -450,8 +455,7 @@ fn tx_execution_infos_to_tx_trace( &mut class_hash_cache, )?, fee_transfer_invocation, - // TODO(#1291): Compute state diff correctly - state_diff: None, + state_diff, }) } TxType::L1Handler => TransactionTrace::L1Handler(L1HandlerTransactionTrace { @@ -482,12 +486,15 @@ fn tx_execution_infos_to_simulated_transactions( for (tx_type, (res, state_diff)) in tx_types.into_iter().zip(transaction_execution_results.into_iter()) { match res { Ok(tx_exec_info) => { + let state_diff = blockifier_to_rpc_state_diff_types(state_diff) + .map_err(|_| ConvertCallInfoToExecuteInvocationError::ConvertStateDiffFailed)?; + let transaction_trace = tx_execution_infos_to_tx_trace( storage_override, substrate_block_hash, tx_type, &tx_exec_info, - state_diff, + Some(state_diff), )?; let gas_consumed = tx_exec_info.execute_call_info.as_ref().map(|x| x.execution.gas_consumed).unwrap_or_default(); diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index 18cbf0fe28..063e84994d 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -72,7 +72,7 @@ sp_api::decl_runtime_apis! { /// client to operate seamlessly while abstracting the extrinsic complexity. fn extrinsic_filter(xts: Vec<::Extrinsic>) -> Vec; /// Re-execute a block and return the TransactionExecutionInfos of every transaction in it, in the same order - fn re_execute_transactions(transactions: Vec) -> Result, PlaceHolderErrorTypeForFailedStarknetExecution>, DispatchError>; + fn re_execute_transactions(transactions: Vec) -> Result, PlaceHolderErrorTypeForFailedStarknetExecution>, DispatchError>; fn get_index_and_tx_for_tx_hash(xts: Vec<::Extrinsic>, chain_id: Felt252Wrapper, tx_hash: Felt252Wrapper) -> Option<(u32, Transaction)>; /// Returns events, call with index from get_index_and_tx_for_tx_hash method diff --git a/crates/pallets/starknet/src/simulations.rs b/crates/pallets/starknet/src/simulations.rs index 2aea5c7b51..531c1b83c8 100644 --- a/crates/pallets/starknet/src/simulations.rs +++ b/crates/pallets/starknet/src/simulations.rs @@ -146,8 +146,10 @@ impl Pallet { pub fn re_execute_transactions( transactions: Vec, - ) -> Result, PlaceHolderErrorTypeForFailedStarknetExecution>, DispatchError> - { + ) -> Result< + Result, PlaceHolderErrorTypeForFailedStarknetExecution>, + DispatchError, + > { storage::transactional::with_transaction(|| { storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(Self::re_execute_transactions_inner( transactions, @@ -158,54 +160,59 @@ impl Pallet { fn re_execute_transactions_inner( transactions: Vec, - ) -> Result, PlaceHolderErrorTypeForFailedStarknetExecution>, DispatchError> - { + ) -> Result< + Result, PlaceHolderErrorTypeForFailedStarknetExecution>, + DispatchError, + > { let chain_id = Self::chain_id(); let block_context = Self::get_block_context(); let execution_config = RuntimeExecutionConfigBuilder::new::().build(); let execution_infos = transactions .iter() - .map(|user_or_l1_tx| match user_or_l1_tx { - UserOrL1HandlerTransaction::User(tx) => match tx { - UserTransaction::Declare(tx, contract_class) => tx - .try_into_executable::(chain_id, contract_class.clone(), false) - .map_err(|e| { - log::error!("Failed to reexecute a tx: {}", e); - PlaceHolderErrorTypeForFailedStarknetExecution - }) - .and_then(|executable| { - executable - .execute(&mut BlockifierStateAdapter::::default(), &block_context, &execution_config) - .map_err(|e| { + .map(|user_or_l1_tx| { + let mut cached_state = + CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); + let res = match user_or_l1_tx { + UserOrL1HandlerTransaction::User(tx) => match tx { + UserTransaction::Declare(tx, contract_class) => tx + .try_into_executable::(chain_id, contract_class.clone(), false) + .map_err(|e| { + log::error!("Failed to reexecute a tx: {}", e); + PlaceHolderErrorTypeForFailedStarknetExecution + }) + .and_then(|executable| { + executable.execute(&mut cached_state, &block_context, &execution_config).map_err(|e| { log::error!("Failed to reexecute a tx: {}", e); PlaceHolderErrorTypeForFailedStarknetExecution }) - }), - UserTransaction::DeployAccount(tx) => tx - .into_executable::(chain_id, false) - .execute(&mut BlockifierStateAdapter::::default(), &block_context, &execution_config) + }), + UserTransaction::DeployAccount(tx) => tx + .into_executable::(chain_id, false) + .execute(&mut cached_state, &block_context, &execution_config) + .map_err(|e| { + log::error!("Failed to reexecute a tx: {}", e); + PlaceHolderErrorTypeForFailedStarknetExecution + }), + UserTransaction::Invoke(tx) => tx + .into_executable::(chain_id, false) + .execute(&mut cached_state, &block_context, &execution_config) + .map_err(|e| { + log::error!("Failed to reexecute a tx: {}", e); + PlaceHolderErrorTypeForFailedStarknetExecution + }), + }, + UserOrL1HandlerTransaction::L1Handler(tx, fee) => tx + .into_executable::(chain_id, *fee, false) + .execute(&mut cached_state, &block_context, &execution_config) .map_err(|e| { log::error!("Failed to reexecute a tx: {}", e); PlaceHolderErrorTypeForFailedStarknetExecution }), - UserTransaction::Invoke(tx) => tx - .into_executable::(chain_id, false) - .execute(&mut BlockifierStateAdapter::::default(), &block_context, &execution_config) - .map_err(|e| { - log::error!("Failed to reexecute a tx: {}", e); - PlaceHolderErrorTypeForFailedStarknetExecution - }), - }, - UserOrL1HandlerTransaction::L1Handler(tx, fee) => tx - .into_executable::(chain_id, *fee, false) - .execute(&mut BlockifierStateAdapter::::default(), &block_context, &execution_config) - .map_err(|e| { - log::error!("Failed to reexecute a tx: {}", e); - PlaceHolderErrorTypeForFailedStarknetExecution - }), + }; + res.map(|r| (r, cached_state.to_state_diff())) }) - .collect::, _>>(); + .collect(); Ok(execution_infos) } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 5941a732b6..14c4c98b07 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -19,6 +19,7 @@ mod types; use blockifier::execution::contract_class::ContractClass; use blockifier::state::cached_state::CommitmentStateDiff; +use blockifier::transaction::objects::TransactionExecutionInfo; pub use config::*; pub use frame_support::traits::{ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo}; pub use frame_support::weights::constants::{ @@ -29,7 +30,7 @@ pub use frame_support::{construct_runtime, parameter_types, StorageValue}; pub use frame_system::Call as SystemCall; use frame_system::{EventRecord, Phase}; use mp_felt::Felt252Wrapper; -use mp_simulations::SimulationFlags; +use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; use mp_transactions::compute_hash::ComputeTransactionHash; use mp_transactions::{HandleL1MessageTransaction, Transaction, UserOrL1HandlerTransaction, UserTransaction}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; @@ -281,7 +282,7 @@ impl_runtime_apis! { Starknet::estimate_fee(transactions) } - fn re_execute_transactions(transactions: Vec) -> Result, PlaceHolderErrorTypeForFailedStarknetExecution>, DispatchError> { + fn re_execute_transactions(transactions: Vec) -> Result, PlaceHolderErrorTypeForFailedStarknetExecution>, DispatchError> { Starknet::re_execute_transactions(transactions) } From 7ca3e76954f86ee102b9b167d451e737ec12f976 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 12 Feb 2024 15:05:53 +0100 Subject: [PATCH 16/21] chore: simulation type --- crates/pallets/starknet/runtime_api/src/lib.rs | 4 +--- crates/pallets/starknet/src/simulations.rs | 3 +-- crates/pallets/starknet/src/types.rs | 4 ---- crates/primitives/simulations/src/lib.rs | 3 +++ crates/runtime/src/lib.rs | 3 +-- starknet-rpc-test/get_state_update.rs | 6 ++++++ starknet-rpc-test/simulate_transaction.rs | 8 ++++++-- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index 063e84994d..6e9bc24ccb 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -17,7 +17,7 @@ pub extern crate alloc; use alloc::string::String; use alloc::vec::Vec; -use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; +use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags, TransactionSimulationResult}; use sp_runtime::DispatchError; use starknet_api::api_core::{ChainId, ClassHash, ContractAddress, EntryPointSelector, Nonce}; use starknet_api::block::{BlockNumber, BlockTimestamp}; @@ -34,8 +34,6 @@ pub enum StarknetTransactionExecutionError { ContractError, } -type TransactionSimulationResult = Result; - sp_api::decl_runtime_apis! { pub trait StarknetRuntimeApi { /// Returns the nonce associated with the given address in the given block diff --git a/crates/pallets/starknet/src/simulations.rs b/crates/pallets/starknet/src/simulations.rs index 531c1b83c8..f2ff4dd9aa 100644 --- a/crates/pallets/starknet/src/simulations.rs +++ b/crates/pallets/starknet/src/simulations.rs @@ -7,7 +7,7 @@ use blockifier::transaction::errors::TransactionExecutionError; use blockifier::transaction::objects::TransactionExecutionInfo; use frame_support::storage; use mp_felt::Felt252Wrapper; -use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; +use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags, TransactionSimulationResult}; use mp_transactions::execution::{Execute, ExecutionConfig}; use mp_transactions::{HandleL1MessageTransaction, UserOrL1HandlerTransaction, UserTransaction}; use sp_core::Get; @@ -16,7 +16,6 @@ use starknet_api::transaction::Fee; use crate::blockifier_state_adapter::{BlockifierStateAdapter, CachedBlockifierStateAdapter}; use crate::execution_config::RuntimeExecutionConfigBuilder; -use crate::types::TransactionSimulationResult; use crate::{Config, Error, Pallet}; impl Pallet { diff --git a/crates/pallets/starknet/src/types.rs b/crates/pallets/starknet/src/types.rs index 50ed93c62a..22031c555d 100644 --- a/crates/pallets/starknet/src/types.rs +++ b/crates/pallets/starknet/src/types.rs @@ -1,8 +1,6 @@ //! Starknet pallet custom types. use blockifier::execution::contract_class::ContractClass; -use blockifier::transaction::objects::TransactionExecutionInfo; use mp_felt::Felt252Wrapper; -use mp_simulations::PlaceHolderErrorTypeForFailedStarknetExecution; use sp_core::ConstU32; use sp_std::vec::Vec; use starknet_api::api_core::{ClassHash, ContractAddress}; @@ -25,8 +23,6 @@ pub type CasmClassHash = ClassHash; pub type SierraClassHash = ClassHash; pub type SierraOrCasmClassHash = ClassHash; -pub type TransactionSimulationResult = Result; - /// Declare Transaction Output #[derive(Clone, Debug, PartialEq, Eq, parity_scale_codec::Encode, parity_scale_codec::Decode, scale_info::TypeInfo)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/primitives/simulations/src/lib.rs b/crates/primitives/simulations/src/lib.rs index b574cb05ef..2c8221fa05 100644 --- a/crates/primitives/simulations/src/lib.rs +++ b/crates/primitives/simulations/src/lib.rs @@ -5,6 +5,7 @@ pub extern crate alloc; use alloc::vec::Vec; +use blockifier::transaction::objects::TransactionExecutionInfo; use starknet_core::types::SimulationFlag; // TODO: This is a placeholder @@ -16,6 +17,8 @@ use starknet_core::types::SimulationFlag; #[cfg_attr(feature = "parity-scale-codec", derive(parity_scale_codec::Encode, parity_scale_codec::Decode))] pub struct PlaceHolderErrorTypeForFailedStarknetExecution; +pub type TransactionSimulationResult = Result; + #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "parity-scale-codec", derive(parity_scale_codec::Encode, parity_scale_codec::Decode))] #[cfg_attr(feature = "scale-info", derive(scale_info::TypeInfo))] diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 14c4c98b07..de09555db3 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -30,14 +30,13 @@ pub use frame_support::{construct_runtime, parameter_types, StorageValue}; pub use frame_system::Call as SystemCall; use frame_system::{EventRecord, Phase}; use mp_felt::Felt252Wrapper; -use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; +use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags, TransactionSimulationResult}; use mp_transactions::compute_hash::ComputeTransactionHash; use mp_transactions::{HandleL1MessageTransaction, Transaction, UserOrL1HandlerTransaction, UserTransaction}; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; /// Import the Starknet pallet. pub use pallet_starknet; use pallet_starknet::pallet::Error as PalletError; -use pallet_starknet::types::TransactionSimulationResult; use pallet_starknet::Call::{consume_l1_message, declare, deploy_account, invoke}; use pallet_starknet::Event; use pallet_starknet_runtime_api::StarknetTransactionExecutionError; diff --git a/starknet-rpc-test/get_state_update.rs b/starknet-rpc-test/get_state_update.rs index 283cc789e1..11f3c54a2f 100644 --- a/starknet-rpc-test/get_state_update.rs +++ b/starknet-rpc-test/get_state_update.rs @@ -49,6 +49,9 @@ async fn returns_correct_state_diff_transfer(madara: &ThreadSafeMadaraClient) -> ))]) .await?; + // sleep 1s (make sure state diff is received before) + tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; + let state_update = match rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() { MaybePendingStateUpdate::Update(update) => update, MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending update")), @@ -88,6 +91,9 @@ async fn returns_correct_state_diff_declare(madara: &ThreadSafeMadaraClient) -> madara_write_lock.create_block_with_txs(vec![Transaction::Declaration(declare_tx)]).await?; + // sleep 1s (make sure state diff is received before) + tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; + let state_update = match rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() { MaybePendingStateUpdate::Update(update) => update, MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending update")), diff --git a/starknet-rpc-test/simulate_transaction.rs b/starknet-rpc-test/simulate_transaction.rs index d8b3590343..4e023a0a08 100644 --- a/starknet-rpc-test/simulate_transaction.rs +++ b/starknet-rpc-test/simulate_transaction.rs @@ -112,8 +112,10 @@ async fn fail_if_one_txn_cannot_be_executed(madara: &ThreadSafeMadaraClient) -> async fn works_ok_on_no_validate(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> { let rpc = madara.get_starknet_client().await; + let sender_address = FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(); + let tx = BroadcastedInvokeTransaction { - sender_address: FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(), + sender_address, calldata: vec![ FieldElement::from_hex_be(TEST_CONTRACT_ADDRESS).unwrap(), get_selector_from_name("sqrt").unwrap(), @@ -206,11 +208,13 @@ async fn works_ok_on_validate_without_signature_with_skip_validate( async fn works_ok_without_max_fee_with_skip_fee_charge(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> { let rpc = madara.get_starknet_client().await; + let sender_address = FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(); + let tx = BroadcastedInvokeTransaction { max_fee: FieldElement::from(0u8), signature: vec![], nonce: FieldElement::ZERO, - sender_address: FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(), + sender_address, calldata: vec![ FieldElement::from_hex_be(TEST_CONTRACT_ADDRESS).unwrap(), get_selector_from_name("sqrt").unwrap(), From 6d999f3df828ae04c78567fcb6504ad3c1843d12 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 12 Feb 2024 15:10:18 +0100 Subject: [PATCH 17/21] fix: test --- .../starknet/src/tests/re_execute_transactions.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/pallets/starknet/src/tests/re_execute_transactions.rs b/crates/pallets/starknet/src/tests/re_execute_transactions.rs index db7b0c109c..132478f680 100644 --- a/crates/pallets/starknet/src/tests/re_execute_transactions.rs +++ b/crates/pallets/starknet/src/tests/re_execute_transactions.rs @@ -104,7 +104,7 @@ fn re_execute_tx_ok() { .unwrap(), _ => unreachable!(), }; - assert_eq!(res[0], first_invoke_tx_info); + assert_eq!(res[0].0, first_invoke_tx_info); let second_invoke_tx_info = match txs.get(1).unwrap() { UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Invoke(invoke_tx)) => invoke_tx .into_executable::<::SystemHash>(chain_id, false) @@ -116,7 +116,7 @@ fn re_execute_tx_ok() { .unwrap(), _ => unreachable!(), }; - assert_eq!(res[1], second_invoke_tx_info); + assert_eq!(res[1].0, second_invoke_tx_info); let declare_tx_info = match txs.get(2).unwrap() { UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Declare(declare_tx, cc)) => declare_tx .try_into_executable::<::SystemHash>(chain_id, cc.clone(), false) @@ -129,7 +129,7 @@ fn re_execute_tx_ok() { .unwrap(), _ => unreachable!(), }; - assert_eq!(res[2], declare_tx_info); + assert_eq!(res[2].0, declare_tx_info); let deploy_account_tx_info = match txs.get(3).unwrap() { UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::DeployAccount(deploy_account_tx)) => { deploy_account_tx @@ -143,7 +143,7 @@ fn re_execute_tx_ok() { } _ => unreachable!(), }; - assert_eq!(res[3], deploy_account_tx_info); + assert_eq!(res[3].0, deploy_account_tx_info); let handle_l1_message_tx_info = match txs.get(4).unwrap() { UserOrL1HandlerTransaction::L1Handler(l1_tx, fee) => l1_tx .into_executable::<::SystemHash>(chain_id, *fee, false) @@ -155,6 +155,6 @@ fn re_execute_tx_ok() { .unwrap(), _ => unreachable!(), }; - assert_eq!(res[4], handle_l1_message_tx_info); + assert_eq!(res[4].0, handle_l1_message_tx_info); }); } From 77964ef3cf46fd5bc1c33bfa6ff0b6690de4d0ce Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Mon, 12 Feb 2024 17:04:34 +0100 Subject: [PATCH 18/21] feat: add state diff to test --- .../starknet/src/blockifier_state_adapter.rs | 154 +++++++++++++++++- crates/pallets/starknet/src/simulations.rs | 7 +- .../src/tests/re_execute_transactions.rs | 103 +++++++----- 3 files changed, 210 insertions(+), 54 deletions(-) diff --git a/crates/pallets/starknet/src/blockifier_state_adapter.rs b/crates/pallets/starknet/src/blockifier_state_adapter.rs index 72f2c6e7fc..84eb6e39f7 100644 --- a/crates/pallets/starknet/src/blockifier_state_adapter.rs +++ b/crates/pallets/starknet/src/blockifier_state_adapter.rs @@ -1,8 +1,9 @@ use alloc::collections::{BTreeMap, BTreeSet}; use core::marker::PhantomData; +use std::collections::HashMap; use blockifier::execution::contract_class::ContractClass; -use blockifier::state::cached_state::{CachedState, CommitmentStateDiff, ContractStorageKey, StateChangesCount}; +use blockifier::state::cached_state::{CommitmentStateDiff, ContractStorageKey, StateChangesCount, StorageView}; use blockifier::state::errors::StateError; use blockifier::state::state_api::{State, StateReader, StateResult}; use indexmap::IndexMap; @@ -24,6 +25,7 @@ pub struct BlockifierStateAdapter { storage_update: BTreeMap, class_hash_update: usize, compiled_class_hash_update: usize, + state_cache: StateCache, _phantom: PhantomData, } @@ -49,6 +51,7 @@ impl Default for BlockifierStateAdapter { storage_update: BTreeMap::default(), class_hash_update: usize::default(), compiled_class_hash_update: usize::default(), + state_cache: StateCache::default(), _phantom: PhantomData, } } @@ -134,14 +137,102 @@ impl State for BlockifierStateAdapter { } } -pub struct CachedBlockifierStateAdapter(pub CachedState>); +#[derive(Debug, Default, PartialEq)] +struct StateCache { + // Reader's cached information; initial values, read before any write operation (per cell). + nonce_initial_values: IndexMap, + class_hash_initial_values: IndexMap, + storage_initial_values: IndexMap, + compiled_class_hash_initial_values: IndexMap, + + // Writer's cached information. + nonce_writes: IndexMap, + class_hash_writes: IndexMap, + storage_writes: IndexMap, + compiled_class_hash_writes: IndexMap, +} + +impl StateCache { + fn get_storage_at(&self, contract_address: ContractAddress, key: StorageKey) -> Option<&StarkFelt> { + let contract_storage_key = (contract_address, key); + self.storage_writes + .get(&contract_storage_key) + .or_else(|| self.storage_initial_values.get(&contract_storage_key)) + } + + fn get_nonce_at(&self, contract_address: ContractAddress) -> Option<&Nonce> { + self.nonce_writes.get(&contract_address).or_else(|| self.nonce_initial_values.get(&contract_address)) + } + + pub fn set_storage_initial_value(&mut self, contract_address: ContractAddress, key: StorageKey, value: StarkFelt) { + let contract_storage_key = (contract_address, key); + self.storage_initial_values.insert(contract_storage_key, value); + } + + fn set_storage_value(&mut self, contract_address: ContractAddress, key: StorageKey, value: StarkFelt) { + let contract_storage_key = (contract_address, key); + self.storage_writes.insert(contract_storage_key, value); + } + + fn set_nonce_initial_value(&mut self, contract_address: ContractAddress, nonce: Nonce) { + self.nonce_initial_values.insert(contract_address, nonce); + } + + fn set_nonce_value(&mut self, contract_address: ContractAddress, nonce: Nonce) { + self.nonce_writes.insert(contract_address, nonce); + } + + fn get_class_hash_at(&self, contract_address: ContractAddress) -> Option<&ClassHash> { + self.class_hash_writes.get(&contract_address).or_else(|| self.class_hash_initial_values.get(&contract_address)) + } + + fn set_class_hash_initial_value(&mut self, contract_address: ContractAddress, class_hash: ClassHash) { + self.class_hash_initial_values.insert(contract_address, class_hash); + } + + fn set_class_hash_write(&mut self, contract_address: ContractAddress, class_hash: ClassHash) { + self.class_hash_writes.insert(contract_address, class_hash); + } + + fn get_compiled_class_hash(&self, class_hash: ClassHash) -> Option<&CompiledClassHash> { + self.compiled_class_hash_writes + .get(&class_hash) + .or_else(|| self.compiled_class_hash_initial_values.get(&class_hash)) + } + + fn set_compiled_class_hash_initial_value(&mut self, class_hash: ClassHash, compiled_class_hash: CompiledClassHash) { + self.compiled_class_hash_initial_values.insert(class_hash, compiled_class_hash); + } + + fn set_compiled_class_hash_write(&mut self, class_hash: ClassHash, compiled_class_hash: CompiledClassHash) { + self.compiled_class_hash_writes.insert(class_hash, compiled_class_hash); + } + + fn get_storage_updates(&self) -> HashMap { + HashMap::from_iter(subtract_mappings(&self.storage_writes, &self.storage_initial_values)) + } + + fn get_class_hash_updates(&self) -> IndexMap { + subtract_mappings(&self.class_hash_writes, &self.class_hash_initial_values) + } + + fn get_nonce_updates(&self) -> IndexMap { + subtract_mappings(&self.nonce_writes, &self.nonce_initial_values) + } + + fn get_compiled_class_hash_updates(&self) -> IndexMap { + subtract_mappings(&self.compiled_class_hash_writes, &self.compiled_class_hash_initial_values) + } +} + +pub struct CachedBlockifierStateAdapter(pub BlockifierStateAdapter); impl StateChanges for CachedBlockifierStateAdapter where T: Config, { fn count_state_changes(&self) -> StateChangesCount { - self.0.state.count_state_changes() + self.0.count_state_changes() } } @@ -150,14 +241,20 @@ where T: Config, { fn set_storage_at(&mut self, contract_address: ContractAddress, key: StorageKey, value: StarkFelt) { + self.0.state_cache.set_storage_value(contract_address, key, value); self.0.set_storage_at(contract_address, key, value); } fn increment_nonce(&mut self, contract_address: ContractAddress) -> StateResult<()> { + let current_nonce = Pallet::::nonce(contract_address); + let current_nonce: FieldElement = Felt252Wrapper::from(current_nonce.0).into(); + let new_nonce: Nonce = Felt252Wrapper(current_nonce + FieldElement::ONE).into(); + self.0.state_cache.set_nonce_value(contract_address, new_nonce); self.0.increment_nonce(contract_address) } fn set_class_hash_at(&mut self, contract_address: ContractAddress, class_hash: ClassHash) -> StateResult<()> { + self.0.state_cache.set_class_hash_write(contract_address, class_hash); self.0.set_class_hash_at(contract_address, class_hash) } @@ -170,11 +267,25 @@ where class_hash: ClassHash, compiled_class_hash: CompiledClassHash, ) -> StateResult<()> { + self.0.state_cache.set_compiled_class_hash_write(class_hash, compiled_class_hash); self.0.set_compiled_class_hash(class_hash, compiled_class_hash) } fn to_state_diff(&self) -> CommitmentStateDiff { - self.0.to_state_diff() + type StorageDiff = IndexMap>; + + let state_cache = &self.0.state_cache; + let class_hash_updates = state_cache.get_class_hash_updates(); + let storage_diffs = state_cache.get_storage_updates(); + let nonces = state_cache.get_nonce_updates(); + let declared_classes = state_cache.get_compiled_class_hash_updates(); + + CommitmentStateDiff { + address_to_class_hash: class_hash_updates, + storage_updates: StorageDiff::from(StorageView(storage_diffs)), + class_hash_to_compiled_class_hash: declared_classes, + address_to_nonce: nonces, + } } } @@ -183,15 +294,27 @@ where T: Config, { fn get_storage_at(&mut self, contract_address: ContractAddress, key: StorageKey) -> StateResult { - self.0.get_storage_at(contract_address, key) + let storage_value = self.0.get_storage_at(contract_address, key)?; + if self.0.state_cache.get_storage_at(contract_address, key).is_none() { + self.0.state_cache.set_storage_initial_value(contract_address, key, storage_value); + } + Ok(storage_value) } fn get_nonce_at(&mut self, contract_address: ContractAddress) -> StateResult { - self.0.get_nonce_at(contract_address) + let nonce = self.0.get_nonce_at(contract_address)?; + if self.0.state_cache.get_nonce_at(contract_address).is_none() { + self.0.state_cache.set_nonce_initial_value(contract_address, nonce); + } + Ok(nonce) } fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { - self.0.get_class_hash_at(contract_address) + let class_hash = self.0.get_class_hash_at(contract_address)?; + if self.0.state_cache.get_class_hash_at(contract_address).is_none() { + self.0.state_cache.set_class_hash_initial_value(contract_address, class_hash); + } + Ok(class_hash) } fn get_compiled_contract_class(&mut self, class_hash: &ClassHash) -> StateResult { @@ -199,6 +322,21 @@ where } fn get_compiled_class_hash(&mut self, class_hash: ClassHash) -> StateResult { - self.0.get_compiled_class_hash(class_hash) + let compiled_class_hash = self.0.get_compiled_class_hash(class_hash)?; + if self.0.state_cache.get_compiled_class_hash(class_hash).is_none() { + self.0.state_cache.set_compiled_class_hash_initial_value(class_hash, compiled_class_hash); + } + Ok(compiled_class_hash) } } + +/// Returns a `IndexMap` containing key-value pairs from `a` that are not included in `b` (if +/// a key appears in `b` with a different value, it will be part of the output). +/// Usage: Get updated items from a mapping. +pub fn subtract_mappings(lhs: &IndexMap, rhs: &IndexMap) -> IndexMap +where + K: Clone + Eq + core::hash::Hash, + V: Clone + PartialEq, +{ + lhs.iter().filter(|(k, v)| rhs.get(*k) != Some(v)).map(|(k, v)| (k.clone(), v.clone())).collect() +} diff --git a/crates/pallets/starknet/src/simulations.rs b/crates/pallets/starknet/src/simulations.rs index f2ff4dd9aa..2553a233a3 100644 --- a/crates/pallets/starknet/src/simulations.rs +++ b/crates/pallets/starknet/src/simulations.rs @@ -1,7 +1,7 @@ use alloc::vec::Vec; use blockifier::block_context::BlockContext; -use blockifier::state::cached_state::{CachedState, CommitmentStateDiff}; +use blockifier::state::cached_state::CommitmentStateDiff; use blockifier::state::state_api::State; use blockifier::transaction::errors::TransactionExecutionError; use blockifier::transaction::objects::TransactionExecutionInfo; @@ -170,8 +170,7 @@ impl Pallet { let execution_infos = transactions .iter() .map(|user_or_l1_tx| { - let mut cached_state = - CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); + let mut cached_state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); let res = match user_or_l1_tx { UserOrL1HandlerTransaction::User(tx) => match tx { UserTransaction::Declare(tx, contract_class) => tx @@ -245,7 +244,7 @@ impl Pallet { block_context: &BlockContext, execution_config: &ExecutionConfig, ) -> (Result, CommitmentStateDiff) { - let mut cached_state = CachedBlockifierStateAdapter(CachedState::from(BlockifierStateAdapter::::default())); + let mut cached_state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); let result = match transaction { UserTransaction::Declare(tx, contract_class) => tx .try_into_executable::(chain_id, contract_class.clone(), tx.offset_version()) diff --git a/crates/pallets/starknet/src/tests/re_execute_transactions.rs b/crates/pallets/starknet/src/tests/re_execute_transactions.rs index 132478f680..364b91c5ae 100644 --- a/crates/pallets/starknet/src/tests/re_execute_transactions.rs +++ b/crates/pallets/starknet/src/tests/re_execute_transactions.rs @@ -1,3 +1,4 @@ +use blockifier::state::state_api::State; use mp_felt::Felt252Wrapper; use mp_transactions::execution::Execute; use mp_transactions::{DeployAccountTransaction, HandleL1MessageTransaction, UserOrL1HandlerTransaction}; @@ -6,7 +7,7 @@ use starknet_api::transaction::Fee; use super::mock::default_mock::*; use super::mock::*; -use crate::blockifier_state_adapter::BlockifierStateAdapter; +use crate::blockifier_state_adapter::{BlockifierStateAdapter, CachedBlockifierStateAdapter}; use crate::execution_config::RuntimeExecutionConfigBuilder; use crate::tests::utils::get_contract_class; use crate::tests::{constants, get_declare_dummy, get_invoke_dummy, set_infinite_tokens}; @@ -94,67 +95,85 @@ fn re_execute_tx_ok() { // Now let's check the TransactionInfos returned let first_invoke_tx_info = match txs.get(0).unwrap() { - UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Invoke(invoke_tx)) => invoke_tx - .into_executable::<::SystemHash>(chain_id, false) - .execute( - &mut BlockifierStateAdapter::::default(), - &Starknet::get_block_context(), - &RuntimeExecutionConfigBuilder::new::().build(), - ) - .unwrap(), + UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Invoke(invoke_tx)) => { + let mut state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); + let tx_info = invoke_tx + .into_executable::<::SystemHash>(chain_id, false) + .execute( + &mut state, + &Starknet::get_block_context(), + &RuntimeExecutionConfigBuilder::new::().build(), + ) + .unwrap(); + (tx_info, state.to_state_diff()) + } _ => unreachable!(), }; - assert_eq!(res[0].0, first_invoke_tx_info); + assert_eq!(res[0], first_invoke_tx_info); let second_invoke_tx_info = match txs.get(1).unwrap() { - UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Invoke(invoke_tx)) => invoke_tx - .into_executable::<::SystemHash>(chain_id, false) - .execute( - &mut BlockifierStateAdapter::::default(), - &Starknet::get_block_context(), - &RuntimeExecutionConfigBuilder::new::().build(), - ) - .unwrap(), + UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Invoke(invoke_tx)) => { + let mut state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); + let tx_info = invoke_tx + .into_executable::<::SystemHash>(chain_id, false) + .execute( + &mut state, + &Starknet::get_block_context(), + &RuntimeExecutionConfigBuilder::new::().build(), + ) + .unwrap(); + (tx_info, state.to_state_diff()) + } _ => unreachable!(), }; - assert_eq!(res[1].0, second_invoke_tx_info); + assert_eq!(res[1], second_invoke_tx_info); let declare_tx_info = match txs.get(2).unwrap() { - UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Declare(declare_tx, cc)) => declare_tx - .try_into_executable::<::SystemHash>(chain_id, cc.clone(), false) - .unwrap() - .execute( - &mut BlockifierStateAdapter::::default(), - &Starknet::get_block_context(), - &RuntimeExecutionConfigBuilder::new::().build(), - ) - .unwrap(), + UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::Declare(declare_tx, cc)) => { + let mut state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); + let tx_info = declare_tx + .try_into_executable::<::SystemHash>(chain_id, cc.clone(), false) + .unwrap() + .execute( + &mut state, + &Starknet::get_block_context(), + &RuntimeExecutionConfigBuilder::new::().build(), + ) + .unwrap(); + (tx_info, state.to_state_diff()) + } _ => unreachable!(), }; - assert_eq!(res[2].0, declare_tx_info); + assert_eq!(res[2], declare_tx_info); let deploy_account_tx_info = match txs.get(3).unwrap() { UserOrL1HandlerTransaction::User(mp_transactions::UserTransaction::DeployAccount(deploy_account_tx)) => { - deploy_account_tx + let mut state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); + let tx_info = deploy_account_tx .into_executable::<::SystemHash>(chain_id, false) .execute( - &mut BlockifierStateAdapter::::default(), + &mut state, &Starknet::get_block_context(), &RuntimeExecutionConfigBuilder::new::().build(), ) - .unwrap() + .unwrap(); + (tx_info, state.to_state_diff()) } _ => unreachable!(), }; - assert_eq!(res[3].0, deploy_account_tx_info); + assert_eq!(res[3], deploy_account_tx_info); let handle_l1_message_tx_info = match txs.get(4).unwrap() { - UserOrL1HandlerTransaction::L1Handler(l1_tx, fee) => l1_tx - .into_executable::<::SystemHash>(chain_id, *fee, false) - .execute( - &mut BlockifierStateAdapter::::default(), - &Starknet::get_block_context(), - &RuntimeExecutionConfigBuilder::new::().build(), - ) - .unwrap(), + UserOrL1HandlerTransaction::L1Handler(l1_tx, fee) => { + let mut state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); + let tx_info = l1_tx + .into_executable::<::SystemHash>(chain_id, *fee, false) + .execute( + &mut state, + &Starknet::get_block_context(), + &RuntimeExecutionConfigBuilder::new::().build(), + ) + .unwrap(); + (tx_info, state.to_state_diff()) + } _ => unreachable!(), }; - assert_eq!(res[4].0, handle_l1_message_tx_info); + assert_eq!(res[4], handle_l1_message_tx_info); }); } From 941121f5893b320400562e9a0253bfefaf2314a2 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Tue, 27 Feb 2024 17:59:59 +0000 Subject: [PATCH 19/21] fix: rebase & unskip tests --- crates/client/rpc/src/runtime_api.rs | 1 + crates/client/rpc/src/trace_api.rs | 11 +- .../pallets/starknet/runtime_api/src/lib.rs | 4 +- crates/pallets/starknet/src/simulations.rs | 28 ++- crates/runtime/src/lib.rs | 2 +- starknet-rpc-test/get_state_update.rs | 188 ++++++++++-------- starknet-rpc-test/simulate_transaction.rs | 3 + 7 files changed, 136 insertions(+), 101 deletions(-) diff --git a/crates/client/rpc/src/runtime_api.rs b/crates/client/rpc/src/runtime_api.rs index a0d57fc362..b0133e25b5 100644 --- a/crates/client/rpc/src/runtime_api.rs +++ b/crates/client/rpc/src/runtime_api.rs @@ -220,6 +220,7 @@ where StarknetRpcApiError::ContractError })? .swap_remove(0) + .1 .map_err(|e| { error!("Failed to simulate User Transaction: {:?}", e); StarknetRpcApiError::InternalServerError diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index 18a49a832a..f1eee92910 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -13,7 +13,7 @@ use mc_rpc_core::{StarknetReadRpcApiServer, StarknetTraceRpcApiServer}; use mc_storage::StorageOverride; use mp_felt::Felt252Wrapper; use mp_hashers::HasherT; -use mp_simulations::{PlaceHolderErrorTypeForFailedStarknetExecution, SimulationFlags}; +use mp_simulations::{SimulationFlags, TransactionSimulationResult}; use mp_transactions::compute_hash::ComputeTransactionHash; use mp_transactions::{DeclareTransaction, Transaction, TxType, UserOrL1HandlerTransaction, UserTransaction}; use pallet_starknet_runtime_api::{ConvertTransactionRuntimeApi, StarknetRuntimeApi}; @@ -90,6 +90,8 @@ where StarknetRpcApiError::ContractError })?; + println!("res: {:?}", res); + let storage_override = self.overrides.for_block_hash(self.client.as_ref(), substrate_block_hash); let simulated_transactions = tx_execution_infos_to_simulated_transactions(&**storage_override, substrate_block_hash, tx_types, res) @@ -477,13 +479,10 @@ fn tx_execution_infos_to_simulated_transactions( storage_override: &dyn StorageOverride, substrate_block_hash: B::Hash, tx_types: Vec, - transaction_execution_results: Vec<( - Result, - CommitmentStateDiff, - )>, + transaction_execution_results: Vec<(CommitmentStateDiff, TransactionSimulationResult)>, ) -> Result, ConvertCallInfoToExecuteInvocationError> { let mut results = vec![]; - for (tx_type, (res, state_diff)) in tx_types.into_iter().zip(transaction_execution_results.into_iter()) { + for (tx_type, (state_diff, res)) in tx_types.into_iter().zip(transaction_execution_results.into_iter()) { match res { Ok(tx_exec_info) => { let state_diff = blockifier_to_rpc_state_diff_types(state_diff) diff --git a/crates/pallets/starknet/runtime_api/src/lib.rs b/crates/pallets/starknet/runtime_api/src/lib.rs index 6fddebcf78..218a0e0c33 100644 --- a/crates/pallets/starknet/runtime_api/src/lib.rs +++ b/crates/pallets/starknet/runtime_api/src/lib.rs @@ -58,10 +58,10 @@ sp_api::decl_runtime_apis! { fn estimate_fee(transactions: Vec) -> Result, DispatchError>; /// Returns message fee estimate fn estimate_message_fee(message: HandleL1MessageTransaction) -> Result<(u128, u64, u64), DispatchError>; - /// Simulates transactions and returns their trace - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError>; /// Simulates single L1 Message and returns its trace fn simulate_message(message: HandleL1MessageTransaction, simulation_flags: SimulationFlags) -> Result, DispatchError>; + /// Simulates transactions and returns their trace + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError>; /// Filters extrinsic transactions to return only Starknet transactions /// /// To support runtime upgrades, the client must be unaware of the specific extrinsic diff --git a/crates/pallets/starknet/src/simulations.rs b/crates/pallets/starknet/src/simulations.rs index 4258769a52..0df46c574a 100644 --- a/crates/pallets/starknet/src/simulations.rs +++ b/crates/pallets/starknet/src/simulations.rs @@ -76,7 +76,7 @@ impl Pallet { pub fn simulate_transactions( transactions: Vec, simulation_flags: &SimulationFlags, - ) -> Result, DispatchError> { + ) -> Result, DispatchError> { storage::transactional::with_transaction(|| { storage::TransactionOutcome::Rollback(Result::<_, DispatchError>::Ok(Self::simulate_transactions_inner( transactions, @@ -89,13 +89,13 @@ impl Pallet { fn simulate_transactions_inner( transactions: Vec, simulation_flags: &SimulationFlags, - ) -> Result, DispatchError> { + ) -> Result, DispatchError> { let chain_id = Self::chain_id(); let block_context = Self::get_block_context(); let mut execution_config = RuntimeExecutionConfigBuilder::new::().with_simulation_mode(simulation_flags).build(); - let tx_execution_results = transactions + let tx_execution_results: Vec<(CommitmentStateDiff, TransactionSimulationResult)> = transactions .into_iter() .map(|tx| { execution_config.set_offset_version(tx.offset_version()); @@ -105,9 +105,25 @@ impl Pallet { log::error!("Transaction execution failed during simulation: {e}"); PlaceHolderErrorTypeForFailedStarknetExecution }); - (result, res.1) + (res.1, result) }) .collect(); + println!("tx_execution_results: {:?}", tx_execution_results); + use parity_scale_codec::{Decode, Encode}; + // let encoded = tx_execution_results[0].encode(); + // let decoded = <(CommitmentStateDiff, TransactionSimulationResult)>::decode(&mut + // &encoded[..]).unwrap(); println!("decoded: {:?}", decoded); + // let to_encode = (tx_execution_results[0].0.clone(), tx_execution_results[0].0.clone()); + // println!("to_encode: {:?}", to_encode.clone()); + // let test = to_encode.encode(); + // let decoded = <(CommitmentStateDiff, CommitmentStateDiff)>::decode(&mut &test[..]).unwrap(); + // println!("decoded: {:?}", decoded); + + let to_encode_simple = tx_execution_results[0].0.clone(); + println!("to_encode_simple: {:?}", to_encode_simple.clone()); + let test_simple = to_encode_simple.encode(); + let decoded_simple = CommitmentStateDiff::decode(&mut &test_simple[..]).unwrap(); + println!("decoded_simple: {:?}", decoded_simple); Ok(tx_execution_results) } @@ -290,6 +306,7 @@ impl Pallet { block_context: &BlockContext, execution_config: &ExecutionConfig, ) -> (Result, CommitmentStateDiff) { + println!("block_context: {:?}", block_context); let mut cached_state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); let result = match transaction { UserTransaction::Declare(tx, contract_class) => tx @@ -306,7 +323,8 @@ impl Pallet { }; (result, cached_state.to_state_diff()) - + } + fn execute_message( message: HandleL1MessageTransaction, chain_id: Felt252Wrapper, diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 43b1ffaeb8..8d827560f6 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -287,7 +287,7 @@ impl_runtime_apis! { Starknet::estimate_message_fee(message) } - fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError> { + fn simulate_transactions(transactions: Vec, simulation_flags: SimulationFlags) -> Result, DispatchError> { Starknet::simulate_transactions(transactions, &simulation_flags) } diff --git a/starknet-rpc-test/get_state_update.rs b/starknet-rpc-test/get_state_update.rs index 648ade61a3..ed5f15fa14 100644 --- a/starknet-rpc-test/get_state_update.rs +++ b/starknet-rpc-test/get_state_update.rs @@ -1,12 +1,16 @@ extern crate starknet_rpc_test; +use anyhow::anyhow; use assert_matches::assert_matches; use rstest::rstest; -use starknet_core::types::{BlockId, StarknetError}; +use starknet_core::types::{BlockId, BlockTag, DeclaredClassItem, MaybePendingStateUpdate, NonceUpdate, StarknetError}; use starknet_ff::FieldElement; use starknet_providers::ProviderError::StarknetError as StarknetProviderError; use starknet_providers::{MaybeUnknownErrorCode, Provider, StarknetErrorWithMessage}; +use starknet_rpc_test::constants::{ARGENT_CONTRACT_ADDRESS, SIGNER_PRIVATE}; use starknet_rpc_test::fixtures::{madara, ThreadSafeMadaraClient}; +use starknet_rpc_test::utils::{build_single_owner_account, AccountActions}; +use starknet_rpc_test::Transaction; #[rstest] #[tokio::test] @@ -25,89 +29,99 @@ async fn fail_non_existing_block(madara: &ThreadSafeMadaraClient) -> Result<(), Ok(()) } -// #[rstest] -// #[tokio::test] -// async fn returns_correct_state_diff_transfer(madara: &ThreadSafeMadaraClient) -> Result<(), -// anyhow::Error> { let rpc = madara.get_starknet_client().await; - -// let recipient = FieldElement::from_hex_be("0x1234").unwrap(); -// let sender_account_address = -// FieldElement::from_hex_be(ARGENT_CONTRACT_ADDRESS).expect("Invalid Contract Address"); - -// let (state_update, block_hash, new_nonce) = { -// let mut madara_write_lock = madara.write().await; -// let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, -// true); - -// madara_write_lock -// .create_block_with_txs(vec![Transaction::Execution(account.transfer_tokens( -// recipient, -// FieldElement::ONE, -// None, -// ))]) -// .await?; - -// let state_update = match -// rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() { -// MaybePendingStateUpdate::Update(update) => update, -// MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending -// update")), }; -// let block_hash_and_number = rpc.block_hash_and_number().await?; -// let new_nonce = rpc.get_nonce(BlockId::Tag(BlockTag::Latest), -// sender_account_address).await?; - -// (state_update, block_hash_and_number.block_hash, new_nonce) -// }; - -// assert_eq!(state_update.block_hash, block_hash); -// assert_eq!(state_update.old_root, FieldElement::ZERO); -// assert_eq!(state_update.new_root, FieldElement::ZERO); - -// assert_eq!(state_update.state_diff.nonces.len(), 1); -// assert_eq!( -// state_update.state_diff.nonces[0], -// NonceUpdate { contract_address: sender_account_address, nonce: new_nonce } -// ); - -// Ok(()) -// } - -// #[rstest] -// #[tokio::test] -// async fn returns_correct_state_diff_declare(madara: &ThreadSafeMadaraClient) -> Result<(), -// anyhow::Error> { let rpc = madara.get_starknet_client().await; - -// let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, -// true); let (declare_tx, expected_class_hash, expected_compiled_class_hash) = -// account.declare_contract( "./contracts/counter6/counter6.contract_class.json", -// "./contracts/counter6/counter6.compiled_contract_class.json", -// ); - -// let (state_update, block_hash) = { -// let mut madara_write_lock = madara.write().await; - -// madara_write_lock.create_block_with_txs(vec![Transaction::Declaration(declare_tx)]). -// await?; - -// let state_update = match -// rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() { -// MaybePendingStateUpdate::Update(update) => update, -// MaybePendingStateUpdate::PendingUpdate(_) => return Err(anyhow!("Expected update, got pending -// update")), }; -// let block_hash_and_number = rpc.block_hash_and_number().await?; - -// (state_update, block_hash_and_number.block_hash) -// }; - -// assert_eq!(state_update.block_hash, block_hash); -// assert_eq!(state_update.old_root, FieldElement::ZERO); -// assert_eq!(state_update.new_root, FieldElement::ZERO); - -// assert_eq!(state_update.state_diff.declared_classes.len(), 1); -// assert_eq!( -// state_update.state_diff.declared_classes[0], -// DeclaredClassItem { class_hash: expected_class_hash, compiled_class_hash: -// expected_compiled_class_hash } ); - -// Ok(()) -// } +#[rstest] +#[tokio::test] +async fn returns_correct_state_diff_transfer(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> { + let rpc = madara.get_starknet_client().await; + + let recipient = FieldElement::from_hex_be("0x1234").unwrap(); + let sender_account_address = FieldElement::from_hex_be(ARGENT_CONTRACT_ADDRESS).expect("Invalid Contract Address"); + + let (state_update, block_hash, new_nonce) = { + let mut madara_write_lock = madara.write().await; + let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true); + + madara_write_lock + .create_block_with_txs(vec![Transaction::Execution(account.transfer_tokens( + recipient, + FieldElement::ONE, + None, + ))]) + .await?; + + // sleep for a bit to make sure state diff is published + tokio::time::sleep(std::time::Duration::from_secs(2)).await; + + let state_update = match rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() { + MaybePendingStateUpdate::Update(update) => update, + MaybePendingStateUpdate::PendingUpdate(_) => { + return Err(anyhow!( + "Expected update, got pending +update" + )); + } + }; + let block_hash_and_number = rpc.block_hash_and_number().await?; + let new_nonce = rpc.get_nonce(BlockId::Tag(BlockTag::Latest), sender_account_address).await?; + + (state_update, block_hash_and_number.block_hash, new_nonce) + }; + + assert_eq!(state_update.block_hash, block_hash); + assert_eq!(state_update.old_root, FieldElement::ZERO); + assert_eq!(state_update.new_root, FieldElement::ZERO); + + assert_eq!(state_update.state_diff.nonces.len(), 1); + assert_eq!( + state_update.state_diff.nonces[0], + NonceUpdate { contract_address: sender_account_address, nonce: new_nonce } + ); + + Ok(()) +} + +#[rstest] +#[tokio::test] +async fn returns_correct_state_diff_declare(madara: &ThreadSafeMadaraClient) -> Result<(), anyhow::Error> { + let rpc = madara.get_starknet_client().await; + + let account = build_single_owner_account(&rpc, SIGNER_PRIVATE, ARGENT_CONTRACT_ADDRESS, true); + let (declare_tx, expected_class_hash, expected_compiled_class_hash) = account.declare_contract( + "./contracts/counter6/counter6.contract_class.json", + "./contracts/counter6/counter6.compiled_contract_class.json", + ); + + let (state_update, block_hash) = { + let mut madara_write_lock = madara.write().await; + + madara_write_lock.create_block_with_txs(vec![Transaction::Declaration(declare_tx)]).await?; + + // sleep for a bit to make sure state diff is published + tokio::time::sleep(std::time::Duration::from_secs(2)).await; + + let state_update = match rpc.get_state_update(BlockId::Tag(BlockTag::Latest)).await.unwrap() { + MaybePendingStateUpdate::Update(update) => update, + MaybePendingStateUpdate::PendingUpdate(_) => { + return Err(anyhow!( + "Expected update, got pending +update" + )); + } + }; + let block_hash_and_number = rpc.block_hash_and_number().await?; + + (state_update, block_hash_and_number.block_hash) + }; + + assert_eq!(state_update.block_hash, block_hash); + assert_eq!(state_update.old_root, FieldElement::ZERO); + assert_eq!(state_update.new_root, FieldElement::ZERO); + + assert_eq!(state_update.state_diff.declared_classes.len(), 1); + assert_eq!( + state_update.state_diff.declared_classes[0], + DeclaredClassItem { class_hash: expected_class_hash, compiled_class_hash: expected_compiled_class_hash } + ); + + Ok(()) +} diff --git a/starknet-rpc-test/simulate_transaction.rs b/starknet-rpc-test/simulate_transaction.rs index 9239fb6284..d9669b290d 100644 --- a/starknet-rpc-test/simulate_transaction.rs +++ b/starknet-rpc-test/simulate_transaction.rs @@ -114,6 +114,9 @@ async fn works_ok_on_no_validate(madara: &ThreadSafeMadaraClient) -> Result<(), let sender_address = FieldElement::from_hex_be(ACCOUNT_CONTRACT).unwrap(); + let mut madara_write_lock = madara.write().await; + let _ = madara_write_lock.create_empty_block().await; + let tx = BroadcastedInvokeTransaction { sender_address, calldata: vec![ From 98d8f9c32d7d94621f4990bd6b7fa14bc5ddfa8e Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 28 Feb 2024 20:01:29 +0100 Subject: [PATCH 20/21] chore: blockifier --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a144637ef3..1145eda51f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "blockifier" version = "0.1.0-rc2" -source = "git+https://github.com/massalabs/blockifier?branch=no_std-support-7578442-std#acd23a1fcc2ccdb73093350c6a139c2bd29ca276" +source = "git+https://github.com/keep-starknet-strange/blockifier?branch=no_std-support-7578442#dc3863a8cddc844b2a5ce7f368d13f603286a440" dependencies = [ "ark-ff 0.4.2", "ark-secp256k1", diff --git a/Cargo.toml b/Cargo.toml index 03e8a721aa..1fe85e2b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -276,7 +276,7 @@ starknet-signers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", re starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false } starknet-contract = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false } -blockifier = { git = "https://github.com/massalabs/blockifier", branch = "no_std-support-7578442-std", default-features = false, features = [ +blockifier = { git = "https://github.com/keep-starknet-strange/blockifier", branch = "no_std-support-7578442", default-features = false, features = [ "std", "parity-scale-codec", ] } From 324c56997fe2125b4747b1dc70a70a77b0e9ea13 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 28 Feb 2024 20:02:31 +0100 Subject: [PATCH 21/21] cleanup --- crates/client/rpc/src/trace_api.rs | 2 -- crates/pallets/starknet/src/simulations.rs | 17 ----------------- 2 files changed, 19 deletions(-) diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index f1eee92910..9756a8140e 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -90,8 +90,6 @@ where StarknetRpcApiError::ContractError })?; - println!("res: {:?}", res); - let storage_override = self.overrides.for_block_hash(self.client.as_ref(), substrate_block_hash); let simulated_transactions = tx_execution_infos_to_simulated_transactions(&**storage_override, substrate_block_hash, tx_types, res) diff --git a/crates/pallets/starknet/src/simulations.rs b/crates/pallets/starknet/src/simulations.rs index 0df46c574a..4b22e7202d 100644 --- a/crates/pallets/starknet/src/simulations.rs +++ b/crates/pallets/starknet/src/simulations.rs @@ -108,22 +108,6 @@ impl Pallet { (res.1, result) }) .collect(); - println!("tx_execution_results: {:?}", tx_execution_results); - use parity_scale_codec::{Decode, Encode}; - // let encoded = tx_execution_results[0].encode(); - // let decoded = <(CommitmentStateDiff, TransactionSimulationResult)>::decode(&mut - // &encoded[..]).unwrap(); println!("decoded: {:?}", decoded); - // let to_encode = (tx_execution_results[0].0.clone(), tx_execution_results[0].0.clone()); - // println!("to_encode: {:?}", to_encode.clone()); - // let test = to_encode.encode(); - // let decoded = <(CommitmentStateDiff, CommitmentStateDiff)>::decode(&mut &test[..]).unwrap(); - // println!("decoded: {:?}", decoded); - - let to_encode_simple = tx_execution_results[0].0.clone(); - println!("to_encode_simple: {:?}", to_encode_simple.clone()); - let test_simple = to_encode_simple.encode(); - let decoded_simple = CommitmentStateDiff::decode(&mut &test_simple[..]).unwrap(); - println!("decoded_simple: {:?}", decoded_simple); Ok(tx_execution_results) } @@ -306,7 +290,6 @@ impl Pallet { block_context: &BlockContext, execution_config: &ExecutionConfig, ) -> (Result, CommitmentStateDiff) { - println!("block_context: {:?}", block_context); let mut cached_state = CachedBlockifierStateAdapter(BlockifierStateAdapter::::default()); let result = match transaction { UserTransaction::Declare(tx, contract_class) => tx