Skip to content

Commit

Permalink
feat: 🎨 fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbelleng committed Feb 17, 2024
1 parent c3a8ac6 commit 8960a6e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 49 deletions.
3 changes: 2 additions & 1 deletion crates/client/rpc/src/trace_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ fn tx_execution_infos_to_tx_trace<B: BlockT>(
// TODO(#1291): Compute state diff correctly
state_diff: None,
}),
TxType::Deploy => todo!(), //TODO: Implement this using Starknet-rs old commits (becareful, Receipt version exist but here we need a trace)
TxType::Deploy => todo!(), /* TODO: Implement this using Starknet-rs old commits (becareful, Receipt version
* exist but here we need a trace) */
TxType::DeployAccount => {
TransactionTrace::DeployAccount(DeployAccountTransactionTrace {
validate_invocation,
Expand Down
52 changes: 25 additions & 27 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ use mp_sequencer_address::{InherentError, InherentType, DEFAULT_SEQUENCER_ADDRES
use mp_storage::{StarknetStorageSchemaVersion, PALLET_STARKNET_SCHEMA};
use mp_transactions::execution::Execute;
use mp_transactions::{
DeclareTransaction, DeployAccountTransaction, HandleL1MessageTransaction, InvokeTransaction, Transaction,
UserOrL1HandlerTransaction, UserTransaction, DeployTransaction,
DeclareTransaction, DeployAccountTransaction, DeployTransaction, HandleL1MessageTransaction, InvokeTransaction,
Transaction, UserOrL1HandlerTransaction, UserTransaction,
};
use sp_runtime::traits::UniqueSaturatedInto;
use sp_runtime::DigestItem;
Expand Down Expand Up @@ -727,8 +727,6 @@ pub mod pallet {
Ok(())
}



/// Consume a message from L1.
///
/// # Arguments
Expand All @@ -751,33 +749,33 @@ pub mod pallet {
) -> DispatchResult {
// This ensures that the function can only be called via unsigned transaction.
ensure_none(origin)?;

let input_transaction = transaction;
let chain_id = Self::chain_id();
let transaction = input_transaction.into_executable::<T::SystemHash>(chain_id, paid_fee_on_l1, false);

let nonce: Nonce = transaction.tx.nonce;

// Ensure that L1 Message has not been executed
Self::ensure_l1_message_not_executed(&nonce).map_err(|_| Error::<T>::L1MessageAlreadyExecuted)?;

// Store infornamtion about message being processed
// The next instruction executes the message
// Either successfully or not
L1Messages::<T>::mutate(|nonces| nonces.insert(nonce));

// Execute
let tx_execution_infos = transaction
.execute(
&mut BlockifierStateAdapter::<T>::default(),
&Self::get_block_context(),
&RuntimeExecutionConfigBuilder::new::<T>().build(),
)
.map_err(|e| {
log::error!("Failed to consume l1 message: {}", e);
Error::<T>::TransactionExecutionFailed
})?;
.execute(
&mut BlockifierStateAdapter::<T>::default(),
&Self::get_block_context(),
&RuntimeExecutionConfigBuilder::new::<T>().build(),
)
.map_err(|e| {
log::error!("Failed to consume l1 message: {}", e);
Error::<T>::TransactionExecutionFailed
})?;

let tx_hash = transaction.tx_hash;
Self::emit_and_store_tx_and_fees_events(
tx_hash,
Expand All @@ -789,10 +787,10 @@ pub mod pallet {
Transaction::L1Handler(input_transaction),
tx_execution_infos.revert_error,
);

Ok(())
}

/// DeployTransaction, type of transaction used before Starknet v0.10.1.
/// Before you can calculate the transaction hash, get the deployed contract address.
/// # Arguments
Expand All @@ -808,17 +806,17 @@ pub mod pallet {
pub fn deploy(origin: OriginFor<T>, transaction: DeployTransaction) -> DispatchResult {
// This ensures that the function can only be called via unsigned transaction.
ensure_none(origin)?;

let input_transaction = transaction;
let chain_id = T::ChainId::get();
let transaction = input_transaction.into_executable::<T::SystemHash>(chain_id, false);

// Check if contract is deployed
ensure!(
!ContractClassHashes::<T>::contains_key(transaction.contract_address),
Error::<T>::AccountAlreadyDeployed
);

// Execute
let tx_execution_infos = transaction
.execute(
Expand All @@ -830,19 +828,19 @@ pub mod pallet {
log::error!("failed to deploy transaction: {:?}", e);
Error::<T>::TransactionExecutionFailed
})?;

let tx_hash = transaction.tx_hash;
Self::emit_and_store_tx_and_fees_events(
tx_hash,
&tx_execution_infos.execute_call_info,
&tx_execution_infos.fee_transfer_call_info,
);
Self::store_transaction(tx_hash, Transaction::Deploy(input_transaction), tx_execution_infos.revert_error);

Ok(())
}
}

#[pallet::inherent]
impl<T: Config> ProvideInherent for Pallet<T> {
type Call = Call<T>;
Expand Down
30 changes: 17 additions & 13 deletions crates/pallets/starknet/src/transaction_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,23 @@ impl<T: Config> Pallet<T> {

match transaction {
UserOrL1HandlerTransaction::User(transaction) => {
let validation_result =
match transaction {
// There is no way to validate it before the account is actuallly deployed
UserTransaction::DeployAccount(_) => Ok(None),
UserTransaction::Deploy(_) => Ok(None), //TODO : Verify this (an account can do a DeployTransaction without being declared first?)
UserTransaction::Declare(tx, contract_class) => tx
.try_into_executable::<T::SystemHash>(chain_id, contract_class.clone(), false)
.map_err(|_| InvalidTransaction::BadProof)?
.validate_tx(&mut state, &block_context, &mut execution_resources, &mut initial_gas, false),
UserTransaction::Invoke(tx) => tx
.into_executable::<T::SystemHash>(chain_id, false)
.validate_tx(&mut state, &block_context, &mut execution_resources, &mut initial_gas, false),
};
let validation_result = match transaction {
// There is no way to validate it before the account is actuallly deployed
UserTransaction::DeployAccount(_) => Ok(None),
UserTransaction::Deploy(_) => Ok(None), /* TODO : Verify this (an account can do a
* DeployTransaction without being declared first?) */
UserTransaction::Declare(tx, contract_class) => tx
.try_into_executable::<T::SystemHash>(chain_id, contract_class.clone(), false)
.map_err(|_| InvalidTransaction::BadProof)?
.validate_tx(&mut state, &block_context, &mut execution_resources, &mut initial_gas, false),
UserTransaction::Invoke(tx) => tx.into_executable::<T::SystemHash>(chain_id, false).validate_tx(
&mut state,
&block_context,
&mut execution_resources,
&mut initial_gas,
false,
),
};

if let Err(TransactionExecutionError::ValidateTransactionError(
EntryPointExecutionError::PreExecutionError(PreExecutionError::UninitializedStorageAddress(
Expand Down
15 changes: 8 additions & 7 deletions crates/primitives/transactions/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use starknet_api::transaction::{Fee, TransactionVersion};

use super::compute_hash::ComputeTransactionHash;
use super::{
DeclareTransaction, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, DeployAccountTransaction, DeployTransaction,
HandleL1MessageTransaction, InvokeTransaction, InvokeTransactionV0, InvokeTransactionV1,
DeclareTransaction, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, DeployAccountTransaction,
DeployTransaction, HandleL1MessageTransaction, InvokeTransaction, InvokeTransactionV0, InvokeTransactionV1,
};

impl DeclareTransactionV0 {
Expand Down Expand Up @@ -218,11 +218,12 @@ impl DeployTransaction {
offset_version: bool,
) -> btx::DeployTransaction {
let account_address = self.get_account_address();
let transaction_hash: Felt252Wrapper =
self.compute_hash_given_contract_address::<H>(chain_id.into(), account_address, offset_version, None).into();
let transaction_hash: Felt252Wrapper = self
.compute_hash_given_contract_address::<H>(chain_id.into(), account_address, offset_version, None)
.into();
let contract_address: Felt252Wrapper = account_address.into();
//let transaction_hash = self.compute_hash::<H>(chain_id, offset_version, None);
// let transaction_hash = self.compute_hash::<H>(chain_id, offset_version, None);

btx::DeployTransaction {
tx: sttx::DeployTransaction {
version: sttx::TransactionVersion(StarkFelt::from(1u128)),
Expand All @@ -234,7 +235,7 @@ impl DeployTransaction {
contract_address: contract_address.into(),
}
}

pub fn from_starknet(inner: starknet_api::transaction::DeployTransaction) -> Self {
Self {
class_hash: inner.class_hash.into(),
Expand Down
3 changes: 2 additions & 1 deletion crates/primitives/transactions/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use blockifier::transaction::objects::{
use blockifier::transaction::transaction_types::TransactionType;
use blockifier::transaction::transaction_utils::{update_remaining_gas, verify_no_calls_to_other_contracts};
use blockifier::transaction::transactions::{
DeclareTransaction, DeployTransaction, DeployAccountTransaction, Executable, InvokeTransaction, L1HandlerTransaction,
DeclareTransaction, DeployAccountTransaction, DeployTransaction, Executable, InvokeTransaction,
L1HandlerTransaction,
};
use mp_fee::{calculate_tx_fee, charge_fee, compute_transaction_resources};
use mp_felt::Felt252Wrapper;
Expand Down

0 comments on commit 8960a6e

Please sign in to comment.